Skip to content

fix: complete reasoning passback + fix stripGarbledToolXML discarding…#1

Open
pragan333 wants to merge 1 commit into
mainfrom
fix/openai-sse-and-bugfixes
Open

fix: complete reasoning passback + fix stripGarbledToolXML discarding…#1
pragan333 wants to merge 1 commit into
mainfrom
fix/openai-sse-and-bugfixes

Conversation

@pragan333

Copy link
Copy Markdown
Owner

… valid content

  • Copy resp.Thinking to assistant message in agent loop so reasoning_content is actually passed back to thinking models (Kimi, DeepSeek) on multi-turn
  • Fix stripGarbledToolXML returning empty string when valid content remains after stripping XML artifacts

… valid content

- Copy resp.Thinking to assistant message in agent loop so reasoning_content
  is actually passed back to thinking models (Kimi, DeepSeek) on multi-turn
- Fix stripGarbledToolXML returning empty string when valid content remains
  after stripping XML artifacts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two bugs in the agent loop:

  1. Reasoning passback fix (loop.go): The assistant message built during the tool-call loop was missing resp.Thinking, so thinking models (Kimi, DeepSeek) never received their reasoning_content echoed back in subsequent loop turns — breaking multi-turn coherence for those models.
  2. stripGarbledToolXML fix (sanitize.go): The function previously discarded all content (return "") even when valid non-XML text remained after stripping garbled XML artifacts. The fix returns the stripped-clean remaining text instead, along with a more descriptive warning log message.

Changes:

  • Propagate resp.Thinking into the assistant message during the tool-call loop to enable reasoning_content passback for thinking models on multi-turn conversations
  • Fix stripGarbledToolXML to return remaining content instead of an empty string when valid text survives the XML stripping

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/agent/loop.go Adds Thinking: resp.Thinking to the assistant message struct in the tool-call loop, enabling reasoning content passback
internal/agent/sanitize.go Fixes stripGarbledToolXML to return remaining non-XML content rather than silently discarding it; updates the log message to reflect the new behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 109 to +114
if cleaned != "" && hasIndicator {
slog.Warn("stripped garbled tool call response",
slog.Warn("stripped garbled tool call XML, preserving remaining content",
"original_len", len(content),
"remaining_len", len(cleaned),
)
return ""
return cleaned

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

The new behavior of stripGarbledToolXML — returning cleaned when valid content remains after removing XML artifacts — is not covered by any tests. The internal/agent package has test files for other modules (input_guard_test.go, loop_history_test.go, toolloop_test.go), but sanitize.go has no dedicated test file at all.

This is a behavior-changing fix (previously returned "", now returns the remaining text), and it would benefit from test cases covering at minimum:

  1. A response that contains only garbled XML → should return ""
  2. A response with garbled XML plus real text → should return the real text
  3. A response with no garbled XML → should be returned unchanged

Copilot uses AI. Check for mistakes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ccf40188b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/agent/loop.go
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.

3 participants