Repository navigation
fix(codex): keep code-tool calls in session transcripts - #361
Conversation
Newer Codex CLIs call MCP tools from inside their exec code tool. The session file then records the call only as an event_msg item_completed event with an McpToolCall item, which the session parser skipped. When the session transcript was longer than the stream one, skill-up used it and tool_called missed calls that did run. Parse McpToolCall items into a tool call and tool result. A failed MCP call now keeps its error message as the tool result content on both the stream and the session path. Closes alibaba#359
…ipts Adding MCP calls made the session transcript longer, so it could now win over a stream transcript that held command_execution calls the session parser still dropped. Parse CommandExecution items as well, joining the session argv into the shell string the stream reports. Codex also writes a CommandExecution item for a direct exec_command function call, under the same ID and after the function_call line, so skip items whose call is already recorded.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1debbd5fb6
ℹ️ 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".
A direct exec_command call is recorded twice in the session file: as a function_call and as a CommandExecution item under the same ID. Instead of dropping the item, give the recorded call the item's name and arguments (command_execution with a command string), so a winning session transcript matches what the stream reports. The result still comes from function_call_output. A command that fails before its process starts has no exit code. Treat a failed status as an error on both the stream and the session path.
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Newer Codex CLIs run MCP tools and shell commands from inside their
execcode tool. In the session file, such a call appears only as anevent_msgitem_completedevent, with anMcpToolCallorCommandExecutionitem. The session parser skipped these events. When the session transcript was longer than the stream transcript, skill-up used it, sotool_calledfailed on runs where the tool did run.This PR teaches the session parser both item types, in the form the stream transcript uses. It also keeps the error message of a failed MCP call as the tool result content, and reports a command that failed before it started as an error, on both the stream and the session path.
Related issues
Closes #359
Changes
internal/agent/codex.go:item_completedevent into a tool call and a tool result when the item is anMcpToolCall(namedmcp__<server>__<tool>, as on the stream path) or aCommandExecution(namedcommand_execution, with the argv joined into the shell string the stream reports). It skips other item types.CommandExecutionitem for a directexec_commandfunction call, with the same ID, after thefunction_callline. The parser records such a call once: the call takes the item's name and arguments (command_executionwith acommandstring, as on the stream path), and the result keeps thefunction_call_outputcontent. If the item reports failure, the result is an error, whichever of the two lines comes first.result: nulland anerror.message. The tool result content is now that message instead of an empty string, on the stream path (mcp_tool_call) and the session path.failedstatus now makes its result an error, on both paths.internal/agent/codex_test.go: tests built from hand-written event lines in the shape Codex CLI 0.166 writes:McpToolCallitem and aCommandExecutionitem, next tocustom_tool_calllines and anAgentMessageitem that stay ignored;McpToolCallitem and a failedCommandExecutionitem;exec_commandcall and its matchingCommandExecutionitem, which must appear once, in the stream's form, with thefunction_call_outputcontent;mcp_tool_callthat failed with an error message;Runwhere the session transcript is longer than the stream one and wins. The test checks the session-only call IDs, so it fails if the stream transcript is used or if the session one drops the command. This is the bug(codex): tool_called misses MCP calls Codex makes from its code tool #359 case.CHANGELOG.md: one line under Unreleased, Fixed.Test plan
make testpassesmake verify: fmt and vet pass. Lint reports 4 staticcheck SA5011 findings ininternal/agent/custom_test.go, a file this PR does not touch; on my machine cleanmainreports the same 4.golangci-lint run ./...outside the Makefile cache and the pre-commit incremental lint report 0 issues.Runtest fail without the parser change and pass with it. The direct-call and failed-command tests fail on the earlier commits of this branch and pass on the head.environment.type: none,bypass_sandbox: "true", existing login) went from 50% (tool_calledfalse) to PASS 100%. On that run's files the session transcript has 12 messages and the stream 6; both now carry the same two calls (command_execution,mcp__shop__get_order).Notes for reviewers
function_calland as anMcpToolCallitem. Every directexec_commandcall (347 of them) also has aCommandExecutionitem with the same ID, always after thefunction_call; the merge above records such a call once and keeps its output. I had no session files from older CLIs such as the default pin 0.80.0. There, the parser behaves as before unless such items appear.exec_commandwith the raw arguments string there.custom_tool_callandcustom_tool_call_output(the code tool itself) are still skipped. Theiroutputis an array in 0.166 and does not decode into the current payload struct. The calls the code ran are what judges need, and those now come from the items.