Skip to content

fix(session): only end a Codex tool round on items that start a message - #1260

Merged
SaulMoro merged 2 commits into
Tencent:mainfrom
jayhemnani9910:fix/codex-tool-round-flush
Oct 21, 2026
Merged

SaulMoro merged 2 commits into
Tencent:mainfrom
jayhemnani9910:fix/codex-tool-round-flush

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1254, from SaulMoro's review there. The Codex reader holds the images a tool returned until the round's tool results are done, but it ended the round on any response_item that isn't a tool output, including types it ignores like web_search_call. If one of those fell between two outputs of the same round, the next output was appended to the image message (user[tool_result], user[image, tool_result]), the mixed shape #1254 avoids for codebuddy/workbuddy.

The round now ends only on function_call, custom_tool_call, reasoning and non-developer message items. Developer messages are skipped, so they no longer end it either.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes
  • npx vitest run: 11270 passed; the same 5 tests fail on main without this change (cursor-bubble-range, cursor-user-images x2, submodule-checkout x2)
  • New test in session-cmd.test.ts (call c1, call c2, output c1 with an image, then a web_search_call or a developer message, then output c2); both cases fail on main and pass here

teamai session migrate 019e0000-1111-7222-8333-666666666667 -s codex -t claude-code --cwd /work/app --json, with HOME in a scratch dir and the CLI built from each commit. The rollout has calls c1 (view_image) and c2 (shell), c1's output with a 1x1 PNG, then a web_search_call or a developer message, then c2's output and a final assistant message. Message shapes in the written Claude Code session:

web_search_call between the outputs
main     user[text] assistant[tool_use,tool_use] user[tool_result] user[image,tool_result] assistant[text]
f51ebc3  user[text] assistant[tool_use,tool_use] user[tool_result,tool_result] user[image] assistant[text]
df1e5d6  same as f51ebc3

developer message between the outputs
main     user[text] assistant[tool_use,tool_use] user[tool_result] user[image,tool_result] assistant[text]
f51ebc3  same as main
df1e5d6  user[text] assistant[tool_use,tool_use] user[tool_result,tool_result] user[image] assistant[text]

Fidelity is 91.4% in all six runs (shell and view_image have no Claude Code tool).

Related Issues

#1254

Notes for Reviewers

Codex isn't known to write a rollout in this order, so this only closes the gap.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification record — src/session-flow/adapters/codex.ts:533 changes runtime behavior, but the PR description records only type checking, lint, and unit tests. The first ## Code Review Rules item requires an end-to-end / real-CLI verification record. After npm run build, run one representative real-CLI scenario and document the result; no full provider × agent matrix is required.

No other confident findings in the specified diff. I did not run, build, or install anything.

@SaulMoro
SaulMoro self-requested a review October 21, 2026 10:50

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at f51ebc32 (merged with origin/main 2aa8a8ad).

Findings

  • [P1 blocking] Missing real-CLI verification record. src/session-flow/adapters/codex.ts:533 changes runtime behavior, and the first ## Code Review Rules item requires an end-to-end / real-CLI verification record in the PR description beyond unit tests and type checks. Please add a real-CLI session migrate record to the PR description.
  • [P3 nit] message with role === 'developer' still triggers flushToolImages(). At src/session-flow/adapters/codex.ts:534, flushToolImages() runs when ptype === 'message', before if (role === 'developer') continue; at line 538. If Codex emits a developer response_item between two tool outputs of the same round, the first output's images will still be flushed before the second output arrives. Checking (ptype === 'message' && payload.role !== 'developer') (or flushing inside each handled branch) avoids that.

Local verification (macOS)

  • Merges cleanly with origin/main (2aa8a8ad), npx tsc --noEmit is clean, and session-cmd.test.ts + claude-tool-result-images.test.ts pass.
  • Built the CLI (npm run build) and ran teamai session migrate 019e0000-1111-7222-8333-666666666667 -s codex -t claude-code --cwd /work/app --json on a rollout containing c1 (image output), an ignored web_search_call, and c2 (text output). The migrated Claude Code transcript wrote 4 messages in the expected order: [["user",["text"]],["assistant",["tool_use","tool_use"]],["user",["tool_result","tool_result"]],["user",["image"]]].

They are skipped, like web_search_call, so they no longer flush the
round's images before its last tool output.
@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

Both done in df1e5d6. The description now has a real teamai session migrate run (codex to claude-code) on main, the previous head and this one. A developer message between two outputs of a round no longer flushes the images; the test runs with both a web_search_call and a developer message in that spot.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification record — still unresolved. src/session-flow/adapters/codex.ts:533 changes runtime behavior, but the PR description lists only type checking, lint, and unit tests. The first ## Code Review Rules item requires a real-CLI verification record after npm run build. Document one representative scenario and its result; no full provider × agent matrix is required.

No other confident findings in the specified diff. I did not run, build, or install anything.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

This re-reviews df1e5d6 against the Request changes of f51ebc3. Both findings are resolved.

The description has a real teamai session migrate 019e0000-1111-7222-8333-666666666667 -s codex -t claude-code --cwd /work/app --json record. We ran that command on this head. Exit 0. The written session is user[text] assistant[tool_use,tool_use] user[tool_result,tool_result] user[image]. Both tool results stay in one user message, and the image follows them. Fidelity on this transcript is 90.0%. The CI comment that still calls the record missing was fetched before this description edit.

A developer message no longer flushes the round. src/session-flow/adapters/codex.ts:534 excludes role === 'developer' from startsMessage.

#1263 also edits src/session-flow/adapters/codex.ts, only findCodexCli. This PR owns buildMessages.

@SaulMoro
SaulMoro merged commit 603a7de into Tencent:main Oct 21, 2026
17 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.

3 participants