Skip to content

the cagent-output fence may not always be at the start of the response#38

Merged
derekmisler merged 1 commit intodocker:mainfrom
derekmisler:better-extraction-of-cagent-output-when-an-agent-t
Feb 13, 2026
Merged

the cagent-output fence may not always be at the start of the response#38
derekmisler merged 1 commit intodocker:mainfrom
derekmisler:better-extraction-of-cagent-output-when-an-agent-t

Conversation

@derekmisler
Copy link
Contributor

@derekmisler derekmisler commented Feb 10, 2026

Summary

Fixes a bug in the cagent-output extraction logic where code fences that don't start at the beginning of a line were not being properly detected. This occurs when AI agents emit conversational text before the code fence, causing the extraction to fail and potentially leak agent thoughts into the final output.

Changes

Modified

  • .github/workflows/pr-describe.yml: Updated JavaScript extraction logic to use regex matching instead of relying on line-based parsing for cagent-output blocks
  • action.yml: Modified AWK script to remove line-start anchoring (^) from the cagent-output pattern matching, allowing detection of code fences that appear mid-line
  • tests/test-output-extraction.sh: Added comprehensive test case (1b) to verify extraction works when code fence is preceded by agent thoughts on the same line

Technical Details

The core issue was that the extraction logic used ^```cagent-output pattern matching, which only worked when the code fence started at the beginning of a line. However, AI agents sometimes emit conversational text like "I'll analyze the PR..." immediately before the code fence without a newline, causing the pattern to fail.

Key changes:

  • GitHub Workflow: Added regex-based extraction (raw.match(/```cagent-output\n([\s\S]*?)```/)) as a fallback to handle cases where the composite action's cleaning doesn't catch everything
  • Composite Action: Updated AWK script to use /```cagent-output/ instead of /^```cagent-output$/ and implemented proper state-based capturing that works regardless of line position
  • Test Suite: Added test case that simulates real-world scenario where agent emits "I'll analyze the PR by reading..." before the code fence, ensuring the fix prevents agent thoughts from leaking into the final output

Testing

  • Added test case 1b that verifies extraction works with mid-line code fences
  • Test includes validation that agent thoughts are properly excluded from clean output
  • Maintains backward compatibility with existing line-start code fences
  • Both AWK-based (composite action) and JavaScript-based (workflow) extraction methods updated

Breaking Changes

None - this is a backward-compatible bug fix that improves robustness.

Related Issues

None explicitly referenced - this addresses a reliability issue discovered during PR description generation workflows.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added explaining the fix
  • Comprehensive test coverage added
  • No new warnings introduced
  • Tests pass locally
  • Security implications considered (prevents information leakage)

@derekmisler derekmisler self-assigned this Feb 10, 2026
@derekmisler
Copy link
Contributor Author

/describe

@docker-agent
Copy link

docker-agent bot commented Feb 10, 2026

✅ PR description has been generated and updated!

@derekmisler derekmisler marked this pull request as ready for review February 10, 2026 16:34
@derekmisler derekmisler requested a review from a team as a code owner February 10, 2026 16:34
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Found 2 issues in the changed code that should be addressed:

  1. JavaScript regex inconsistency - The regex in pr-describe.yml doesn't handle mid-line code fences like the AWK script does
  2. Missing error handling - File read operation lacks try-catch wrapper

Both issues are in .github/workflows/pr-describe.yml and relate to the fallback extraction logic.

@derekmisler derekmisler force-pushed the better-extraction-of-cagent-output-when-an-agent-t branch from 5215bf1 to fbc8ae5 Compare February 11, 2026 14:47
@derekmisler
Copy link
Contributor Author

/review

Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Found 2 potential issues with the regex pattern in the JavaScript extraction code. The AWK script changes look solid.

Issues Found

  • Medium severity: Regex requires newline before closing fence
  • Low severity: Regex captures unwanted content when no newline after opening fence

Both issues could cause extraction failures in edge cases.

@derekmisler derekmisler force-pushed the better-extraction-of-cagent-output-when-an-agent-t branch from fbc8ae5 to 066e3a5 Compare February 11, 2026 15:00
@derekmisler derekmisler force-pushed the better-extraction-of-cagent-output-when-an-agent-t branch from 066e3a5 to 8746079 Compare February 13, 2026 14:34
@derekmisler derekmisler merged commit c75fae9 into docker:main Feb 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants