Skip to content

fix(codex): project session McpToolCall into tool_called - #363

Open
Oscar-Williams wants to merge 1 commit into
alibaba:mainfrom
Oscar-Williams:fix/codex-custom-tool-call
Open

Oscar-Williams wants to merge 1 commit into
alibaba:mainfrom
Oscar-Williams:fix/codex-custom-tool-call

Conversation

@Oscar-Williams

Copy link
Copy Markdown

Summary

Codex session JSONL records MCP tool use as event_msg with type: item_completed and a nested TurnItem whose type is McpToolCall (PascalCase, per openai/codex). Session parsing previously only handled agent_message / token_count, so those tools never appeared in tool_called.

This change expands the nested item on the session payload and projects McpToolCall through the existing codexMCPToolName helper as mcp__<server>__<tool>, including the tool result and status: failed mapped to error.

Related issues

Closes #359

Changes

  • Expand session event_msg item_completed nested TurnItem for McpToolCall / mcpToolCall / mcp_tool_call
  • Project those calls as mcp__<server>__<tool> with arguments and result status
  • Cover success and status: failed session shapes in TestParseCodexSessionFile*

Test plan

  • Extended TestParseCodexSessionFile with issue bug(codex): tool_called misses MCP calls Codex makes from its code tool #359 session shapes (custom_tool_call name=exec + item_completed / McpToolCall); asserts mcp__shop__get_order, Arguments, and that exec is not projected as a tool call
  • Added TestParseCodexSessionFile_McpToolCallFailedStatus for status: failed
  • Red/green/mutation on those tests
  • go test ./internal/agent/
  • make test (includes go test -race ./...)
  • go vet ./... and revive pass; make verify / golangci-lint still fail on clean main with the same examples export data mismatch (reproduced at 99894b3)

Session JSONL records MCP tools as event_msg item_completed with a nested
TurnItem type McpToolCall (PascalCase). Expand that item and map it through
codexMCPToolName so tool_called sees mcp__<server>__<tool>. Leave
custom_tool_call names like exec alone.

Closes alibaba#359
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:51:11.233428Z 18bc362 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 18bc36246c

ℹ️ 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/codex.go
Comment on lines +1335 to +1336
return []transcript.Message{
*call,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reconcile completed MCP items with existing call records

For direct MCP invocations, Codex records both a response_item/function_call and an event_msg/item_completed/McpToolCall with the same call ID, as reproduced with codex-cli 0.163.0. parseCodexSessionResponseItem already emits the former, so unconditionally emitting another call here makes one invocation appear twice in Transcript.ToolCalls(). This inflated session transcript can also replace the correctly counted stdout transcript in buildSessionResult, exposing duplicated tool usage to script and agent judges. Reconcile the records by call ID while retaining the normalized MCP name and arguments.

Useful? React with 👍 / 👎.

Comment thread internal/agent/codex.go
ToolResult: &transcript.ToolResultInfo{
CallID: item.ID,
Status: codexMCPToolResultStatus(item.Status),
Content: codexMCPToolResultContent(item.Result),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve failure diagnostics from the MCP error field

When an MCP invocation fails at the RPC or transport level, Codex writes status: "failed" and error: {"message": ...} with no result, as reproduced with codex-cli 0.163.0. The new codexSessionTurnItem ignores error, so serializing only item.Result produces an empty ToolResult.Content and discards the failure diagnostic from this normalized result. Consumers inspecting the failed tool result therefore cannot determine its cause. Decode and forward the error when the result is absent; the added failed-status test only covers a non-null result.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

bug(codex): tool_called misses MCP calls Codex makes from its code tool

2 participants