fix(codex): parse the new rollout schema (item_completed) from Codex ≥ ~0.149 - #170
Open
DaeYounLee wants to merge 1 commit into
Open
fix(codex): parse the new rollout schema (item_completed) from Codex ≥ ~0.149#170DaeYounLee wants to merge 1 commit into
DaeYounLee wants to merge 1 commit into
Conversation
…≥ ~0.149 Recent Codex CLI versions replaced the user_message / agent_message / function_call vocabulary with item_completed wrappers, leaving sessions with empty chat, no tool timeline, no turn count and a status stuck on Waiting. Handle the new item types — UserMessage/AgentMessage for chat, CommandExecution (with real durations) and Extension for the tool timeline, FileChange for file accesses, which the old schema never carried at all — and adjust generating-state transitions via task_started/turn_aborted. Old-schema parsing is untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Recent Codex CLI versions (observed on v0.149) changed the rollout session format. Sessions recorded by these versions show up in abtop with:
initial_promptnever populated, so the session summary stays—Root cause
The codex collector matches the old event vocabulary (
event_msg→user_message/agent_message/task_complete,response_item→function_call). New rollouts no longer emit any of those — everything arrives asevent_msgwithpayload.type == "item_completed", wrapping a typeditem:{"type":"event_msg","payload":{"type":"item_completed","item":{ "type":"AgentMessage","content":[{"type":"Text","text":"…"}],"phase":"final_answer"}, "started_at_ms":1787291153283,"completed_at_ms":1787291154027}} {"type":"event_msg","payload":{"type":"item_completed","item":{ "type":"CommandExecution","command":["/bin/zsh","-lc","sed -n '1,240p' README.md"], "parsed_cmd":[{"type":"read","cmd":"sed -n '1,240p' README.md","path":"/work/README.md"}], "started_at_ms":1787291167583,"completed_at_ms":1787291168442}} {"type":"event_msg","payload":{"type":"item_completed","item":{ "type":"FileChange","changes":{"/work/report.md":{"type":"add"}}}}}(Synthetic samples; field shapes match real rollouts. Note the inconsistent casing —
"Text"on AgentMessage content vs"text"on UserMessage.)Changes
One new arm in the
event_msgmatch plus ahandle_item_completed()helper:UserMessageinitial_prompt, marks model generatingAgentMessageCommandExecutionparsed_cmd[0].type(read/write/…), real duration fromstarted_at_ms/completed_at_ms; file accesses fromparsed_cmd[].pathFileChangeadd→ Write, else Edit) plus anedittool-call entryExtensionkind(e.g.web.search) with itsqueryTwo small state fixes for the new schema:
task_startednow marks the model as generating (there is nouser_messageevent anymore to do it), andturn_abortedclears it.Side effect worth calling out: codex sessions gain
file_accesses— the old schema never carried file information, soAgentSession.file_accesseswas always empty for codex.FileChangeandparsed_cmdnow populate it, capped atMAX_FILE_ACCESSESlike the claude collector.Existing text hygiene is reused: chat goes through
clean_chat_text, tool args throughsanitize_tool_arg,MAX_CHAT_MESSAGESstill applies.Relation to #160 / #161
Complementary, not overlapping: #161 targets the previous generation (Codex 0.144.x —
custom_tool_callinresponse_item, intermediateagent_messageevents), while this PR targets theitem_completedvocabulary that replaced it. One coordination note: 0.149 rollouts still writecustom_tool_callalongsideitem_completed.CommandExecutionfor the same call — this PR reads only the latter, so nothing double-counts today, but if both PRs land it would be worth deduplicating bycall_idin a follow-up.Backward compatibility
The old-schema arms are untouched and the two vocabularies never coexist in one file, so rollouts from older Codex versions parse exactly as before. All existing tests pass unchanged.
Testing
CommandExecutiontool call with real duration + file access fromparsed_cmd,FileChange→ Write/Edit accessescargo test— 204 passed, 0 failed;cargo clippy --all-targets -- -D warningsclean