Skip to content

fix(codex): isolate subagent app-server events#1520

Open
AaronZ345 wants to merge 1 commit into
chenhg5:mainfrom
AaronZ345:agent/codex-filter-subagent-events
Open

fix(codex): isolate subagent app-server events#1520
AaronZ345 wants to merge 1 commit into
chenhg5:mainfrom
AaronZ345:agent/codex-filter-subagent-events

Conversation

@AaronZ345

Copy link
Copy Markdown
Contributor

Summary

  • ignore Codex app-server lifecycle notifications that belong to subagent threads instead of the active cc-connect thread
  • scope item, completion, and token-usage notifications to the active parent turn
  • preserve compatibility with older app-server notifications that omit thread or turn IDs
  • add regression coverage proving child turns cannot overwrite or complete the parent turn

Root cause

Codex app-server multiplexes parent and subagent events over the same connection. Its v2 protocol includes threadId on turn/started, turn/completed, and thread/status/changed, plus both threadId and turnId on item and token-usage notifications.

cc-connect parsed those fields but did not validate them. When a subagent started, its turn/started notification replaced the parent's currentTurn and cleared pending parent messages. When that child thread became idle or completed, cc-connect called completeTurn() and emitted an empty EventResult. 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 ultra run, 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 logging unsolicited 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=1
  • go test -race ./agent/codex -run 'TestAppServerSession_(IgnoresSubagentLifecycleNotifications|IgnoresSubagentTokenUsageNotifications)' -count=1
  • go test -tags no_web ./cmd/cc-connect ./agent/codex -count=1
  • go vet ./agent/codex
  • git diff --check

@AaronZ345 AaronZ345 requested a review from chenhg5 as a code owner July 10, 2026 04:48
@AaronZ345 AaronZ345 force-pushed the agent/codex-filter-subagent-events branch 2 times, most recently from 90eec94 to c4b5592 Compare July 14, 2026 03:03
@AaronZ345

Copy link
Copy Markdown
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!

@AaronZ345 AaronZ345 force-pushed the agent/codex-filter-subagent-events branch from c4b5592 to 347cbab Compare July 14, 2026 14:38
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.

1 participant