fix(codex): isolate subagent app-server events#1520
Open
AaronZ345 wants to merge 1 commit into
Open
Conversation
90eec94 to
c4b5592
Compare
Contributor
Author
|
Hi @chenhg5, I’ve rebased this PR onto the latest main and all five CI checks are green. Could you please take another look and merge it when you have a chance? Thanks! |
c4b5592 to
347cbab
Compare
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.
Summary
Root cause
Codex app-server multiplexes parent and subagent events over the same connection. Its v2 protocol includes
threadIdonturn/started,turn/completed, andthread/status/changed, plus boththreadIdandturnIdon item and token-usage notifications.cc-connect parsed those fields but did not validate them. When a subagent started, its
turn/startednotification replaced the parent'scurrentTurnand cleared pending parent messages. When that child thread became idle or completed, cc-connect calledcompleteTurn()and emitted an emptyEventResult. Repeated child turns therefore produced repeated empty responses, while parent output could be truncated. Child token usage could also overwrite the parent turn's usage snapshot.This change fixes the event-routing boundary rather than suppressing empty messages. Parent-thread follow-up turns, including results delivered back from subagents, continue through the normal unsolicited-event path.
Live evidence
In a GPT-5.6 Sol
ultrarun, the parent turn completed at 12:15:08. Codex then started subagent turns on distinct thread IDs. Child thread idle transitions at 12:15:15 and 12:15:23 aligned exactly with cc-connect loggingunsolicited turn complete response_len=0. The Codex 0.144.1 generated protocol schema confirms these notifications carry the thread and turn identifiers needed for routing.Validation
go test ./agent/codex -count=1go test -race ./agent/codex -run 'TestAppServerSession_(IgnoresSubagentLifecycleNotifications|IgnoresSubagentTokenUsageNotifications)' -count=1go test -tags no_web ./cmd/cc-connect ./agent/codex -count=1go vet ./agent/codexgit diff --check