GeezerVison is showing github.com — fix(command-code): pair tool results and synthesize missing-result errors by Wibias · Pull Request #1411 · lidge-jun/opencodex
Conversation
Wibias
commented
Aug 10, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Command Code (
/alpha/generate) rejects any assistant tool call that has no matching tool result on the continuation, surfacing as a generic 502 (Tool result is missing for tool call <id>). The adapter now keeps that pairing invariant before sending: every declared call is closed by a result, and orphan results degrade to text carriers.
- Tool results that match a declared assistant call keep the native
tool-result wire shape (unchanged); unpaired calls get an explicit error-text result so the upstream never fails the whole turn.
- The upstream missing-tool-result error is now classified distinctly (
errorType: upstream_error, code: missing_tool_result) so the dashboard/logs distinguish provider-side tool-result validation from generic stream failures.
Validation
bun test tests/command-code-provider.test.ts — pass (26 tests, incl. new pairing, orphan-carrier, and classification coverage)
bun run typecheck — pass
bun run privacy:scan — pass
- Pre-open gate (
pre-open-gate.mjs) — ready; bug + security lenses and required probes verified
- Full
bun run test — not fully green on this machine; failures reproduced identically on the base tip (2036ed734) in unrelated subsystems (catalog writer, codex-auth WHAM, restore/journal) and are pre-existing Windows/Bun environment issues, not caused by this change
Review notes
Fixes #1383
Summary by CodeRabbit
- Bug Fixes
- Improved handling of assistant tool calls and their results during command processing.
- Converts unmatched tool results into readable user content.
- Reports unresolved tool calls with explicit error results instead of leaving requests incomplete.
- Preserves images included in tool results.
- Provides clearer error details when upstream responses omit required tool results.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…rors
The /alpha/generate wire requires every assistant tool-call to be closed
by a matching tool-result. Codex history can leave a call unpaired
(interrupted turns, compaction, multi-step rounds), and the upstream
rejects that with 'Tool result is missing for tool call <id>', surfacing
as a generic 502 (#1383).
- Track declared assistant tool-call ids and pair tool results to them.
- Close every declared call that never received a result with an explicit
error-text tool-result before the next non-tool message.
- Degrade orphan tool results (no declared call) to a user text carrier
instead of a 400-prone standalone tool message.
- Classify the upstream missing-tool-result error distinctly
(errorType upstream_error, code missing_tool_result).
|
✅ Deterministic PR hygiene checks passed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Aug 10, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8d6568a8-fd09-498e-8c0b-857d028ee6ab
📥 Commits
Reviewing files that changed from the base of the PR and between aca2752 and fc1c729.
📒 Files selected for processing (2)
src/adapters/command-code.ts
tests/command-code-provider.test.ts
📝 Walkthrough
Walkthrough
wireMessages now preserves assistant tool-call/result pairing, synthesizes results for unresolved calls, converts orphan results to user text, buffers images, and classifies upstream missing-tool-result stream errors with dedicated metadata.
Changes
Command Code tool-result handling
| Layer / File(s) |
Summary |
Tool-call and result wiring src/adapters/command-code.ts, tests/command-code-provider.test.ts |
The adapter pairs results by call ID, buffers tool-result images, converts orphan results to user text, and synthesizes error results before later messages or completion. Tests cover these cases and preserve contiguous tool results. |
Missing-tool-result stream classification src/adapters/command-code.ts, tests/command-code-provider.test.ts |
The adapter recognizes spaced and underscored missing-tool-result errors and emits errorType: "upstream_error" with code: "missing_tool_result". Other errors retain the generic 502 response shape. Tests verify the terminal done event. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Sequence Diagram(s)
sequenceDiagram
participant Client
participant CommandCodeAdapter
participant wireMessages
participant CommandCodeProvider
Client->>CommandCodeAdapter: submit conversation
CommandCodeAdapter->>wireMessages: serialize tool calls and results
wireMessages-->>CommandCodeAdapter: paired or synthesized tool results
CommandCodeAdapter->>CommandCodeProvider: send continuation
CommandCodeProvider-->>CommandCodeAdapter: stream response or missing-tool-result error
CommandCodeAdapter-->>Client: response or classified stream error
Loading
Possibly related PRs
- lidge-jun/opencodex#1066: Modifies the same Command Code adapter and tests for related tool-call/result pairing and stream error handling.
Suggested reviewers: ingwannu, lidge-jun
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title clearly identifies the primary change: pairing tool results and synthesizing errors for missing results. |
| Linked Issues check |
✅ Passed |
The changes address issue #1383 by pairing tool results, synthesizing missing-result errors, preserving images, and classifying upstream validation failures. |
| Out of Scope Changes check |
✅ Passed |
All changes support issue #1383, including image buffering needed to preserve tool-result adjacency and targeted regression tests. |
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
- Create stacked PR
- Commit on current branch
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
ocx-120-provider-compatibility-command-code-returns-502
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adapters/command-code.ts`:
- Around line 99-112: Update the image-carrier handling in
src/adapters/command-code.ts around lines 99-112 to buffer user image carriers
while pendingCalls is non-empty, flushing them only after every
assistant-declared call has a native or synthesized tool result so tool results
remain contiguous. Add the two-call image-first scenario in
tests/command-code-provider.test.ts around lines 165-183 and assert both
tool-result messages precede the user image carrier.
In `@tests/command-code-provider.test.ts`:
- Around line 360-372: Extend the missing-tool-result coverage in the test using
createCommandCodeAdapter and isMissingToolResultError by adding an upstream
error message containing “tool_result is missing” instead of the spaced variant.
Assert that parsing produces the same errorType “upstream_error” and code
“missing_tool_result” while preserving the existing response behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8e72932b-8a05-4368-980c-e969d2ff3856
📥 Commits
Reviewing files that changed from the base of the PR and between 4f32280 and aca2752.
📒 Files selected for processing (2)
src/adapters/command-code.ts
tests/command-code-provider.test.ts
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
CodeRabbit flagged that a paired tool result carrying an image emitted its
user image carrier immediately, breaking the adjacency of remaining pending
tool results on the /alpha/generate wire (assistant -> tool(call_1) -> user
image -> tool(call_2)).
Buffer image carriers while any declared call is still pending and flush
them only after every call has its native or synthesized result. Also add
the underscored tool_result is missing classification test.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 15, 2026
agentHits
pushed a commit
to agentHits/opencodex
that referenced
this pull request
Sep 17, 2026
…patibility-command-code-returns-502
fix(command-code): pair tool results and synthesize missing-result errors
Reviewers
lidge-jun
Awaiting requested review from lidge-jun
lidge-jun is a code owner
Ingwannu
Awaiting requested review from Ingwannu
Ingwannu is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
bug
Something isn't working
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|