Repository navigation
fix(agents): bind native replies and usage to the requested turn - #570
Merged
Merged
Conversation
Claude Code and Codex run turns of their own (wakeups, finished tasks, CLI-queued work). Their replies, usage and callbacks were read into whichever prompt was being answered. - claude: every prompt is sent under a command uuid; only the turn started under it answers the prompt. A turn of the CLI's own is dropped from the answer, its usage still charged to the session; a prompt merged into one fails as contended. - codex: a turn is the one turn/start answers with. Notifications before that answer wait for it; other turns' items, completions and usage never reach the turn, and a turn's tokens are its own requests' rather than the thread's rise. - codex: ended turns are remembered, so late output is dropped and late totals settle on the meter without reopening the turn or rewinding the count. - codex: approvals and questions reach hooks only for the turn under way or the goal being read; others, and idle threads, get an RPC error. A goal's thread stays its session's for usage after the goal returns.
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 6, 2026
…urn-binding # Conflicts: # docs/reference/agents.md # src/hmz/coganchor/agents/codex.py
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 6, 2026
…urn-binding # Conflicts: # src/hmz/coganchor/agents/codex.py # tests/integration/test_agents_codex.py
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.
Claude Code and Codex run turns of their own (wakeups, finished tasks, CLI-queued work). On main those turns' replies, usage and callbacks were read into whichever prompt was being answered. Ported from the internal fork (63952525, bf74ff8c, d7349846, 0402ccd7, ad06f99c), as behaviour rather than diff, and without the fork's new
unpromptedwatcher event.Claude Code
task_notification, a uuid hmz never gave) is left out of the answer and the events. Its usage, live and at itsresult, still goes to the session meter and budget.contended, so it is retried.Codex
turn/startanswers with. Notifications that arrive before that answer wait for it. Other turns' items, completions and usage never reach the turn reader.tokensandspentcover only its own requests, not the thread's rise across the turn.agent.askonly for the turn under way or the goal being pursued. Others, and callbacks for idle threads, get an RPC error. Callbacks held while a turn is still starting are refused if the turn is abandoned.Docs:
docs/reference/agents.md(Sessions and turns,contended).Tests
tests/integration/test_agents_reply_binding.py: 7 of its 9 tests fail on main and all pass here. The other 2 guard that the CLI's own usage still counts against the budget.turnIdon callbacks. The Codex integration fakes answerturn/startwith a turn id, as real Codex does.uv run --all-extras pytestpasses.pre-commit run --all-filesis clean.