Repository navigation
fix(codex): read the response of a model request in a live session (0.4.1) - #336
Merged
Merged
Conversation
Codex writes the token_usage_record line of a request after the PostModelRequest hook has returned, so plugin 0.4.0 found no response in a live session and added 0.5 s to every model request (#335). - Take the response items written since the previous token_usage_record of the turn when the closing line is not in the file yet. - Match a closed request by response_id, else by turn and token counts. - Wait (up to 0.25 s) only when the file has nothing of the request yet. - Do not read the file for compaction requests. - Docs: response.tool_calls[].id is the model's call id; it equals tool_use_id for a direct function call, not for the commands an exec call runs. - Version 0.4.1. Fixes #335 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Fixes #335.
Problem
Codex writes the
token_usage_recordline of a request after thePostModelRequesthook has returned. Plugin 0.4.0 looked for that line, so in a live session it found no response, sent the row as 0.3.0 did, and added 0.5 s to every model request.Change
transcript.py: when the closing line is not in the file, the response is the output items written since the previoustoken_usage_recordof the turn (or the start of the turn). A file that has the closing line is matched on it, byresponse_idwhen both sides have one, else by turn and token counts.kindcontainscompaction) are not looked up: their summary is not a response item. Found in the live compaction run, where each one cost the full wait.docs/cim.md,CLAUDE.md):response.tool_calls[].idis the model's call id. It equalstool_use_idfor a function called directly (spawn_agent,wait_agent) and not for shell commands, where the model callsexecand each command has an id of its own. Also:PostModelRequestand the tool hooks of the same response run in no fixed order.Tests
Unit tests: 122 pass (12 need the SDK; run with it too). New: the file cut where a live hook sees it,
response_idmatching, no wait when the items are there, compaction.Live, Codex CLI 0.172.0 (
codex exec), plugin from this branch, local Timeplus Enterprise 3.5.1-rc.1 with app 0.13.0. For every model request, what was stored was compared with the response read from the finished rollout file byresponse_id.exec, failing command,apply_patch, effort high, long answerAGENTGUARD_LLM_CONTENT=falseAGENTGUARD_LLM_CONTENT_CHARS=20AGENTGUARD_INGEST_API=rest(port 8000)resume)interruptrow sentllm_responseCIM rows carry the response on both exports; the Agent Monitor shows the LLM calls of a running Codex turn.Not tested
PermissionRequest:codex execcannot ask for permission, so the hook did not fire.codex execwas run).🤖 Generated with Claude Code