Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Jan 17, 2026

Summary

  • drop orphaned tool-call/tool-result pairs before provider transforms
  • wire the self-healing pass into the model message pipeline
  • add unit coverage for the orphaned tool cleanup

Rationale

  • providers (e.g., OpenAI Responses) reject tool calls without matching outputs; interrupted or corrupted histories can leave orphans that brick retries
  • request-time pruning unblocks sends without mutating persisted history

Why ignoreIncompleteToolCalls is insufficient

  • ignoreIncompleteToolCalls only removes explicitly incomplete tool-call parts (e.g., input-available during streaming) during conversion
  • the failures here come from completed tool-call parts whose matching tool-result messages are missing after crashes/truncation
  • the SDK does not validate cross-message pairing, so the orphan survives conversion and only fails at provider validation time

Regression Risk

  • Low: only removes unmatched tool-call/tool-result parts; valid pairs (including tool results embedded in assistant messages) are preserved
  • Worst case, we hide a missing result, but that request would be invalid anyway for strict providers

Testing

  • bun test src/browser/utils/messages/modelMessageTransform.test.ts
  • make typecheck
  • make static-check (fails locally: zizmor 403 from GitHub advisories)

Generated with mux • Model: openai:gpt-5.2-codex • Thinking: xhigh • Cost: $6.19

@github-actions github-actions bot added the enhancement New feature or functionality label Jan 17, 2026
Copy link

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

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: 95e69119fb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammar-agent ammar-agent force-pushed the response-handling-ptbm branch from 95e6911 to 5b2b6cc Compare January 17, 2026 21:53
@ammar-agent
Copy link
Collaborator Author

@codex review

Updated to treat tool results embedded in assistant messages as valid pairings and to drop orphan tool results in assistant content. Added coverage for both cases.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammario ammario merged commit 5376583 into main Jan 17, 2026
21 checks passed
@ammario ammario deleted the response-handling-ptbm branch January 17, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants