Skip to content

Give each Codex sub-agent follow-up its own timeline row - #5211

Merged
ymichael merged 3 commits into
get-bb:mainfrom
iipanda:fix/timeline-duplicate-delegations
Oct 8, 2026
Merged

ymichael merged 3 commits into
get-bb:mainfrom
iipanda:fix/timeline-duplicate-delegations

Conversation

@iipanda

@iipanda iipanda commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

When the main agent sends a follow-up to a Codex sub-agent that has finished, the Codex translator reopened the sub-agent's original delegation item: the same id, in the turn that first spawned it. The timeline projection only merges a start event into an existing row while that call is still running, so each reopen added another row with the same id (onExecBegin in tool-activity-projection.ts). Children attach to a delegation by call id, so every copy rendered the sub-agent's entire history. When a sub-agent also followed up its own sub-agents, the copies multiplied at every level. That is the exponential growth in #5210 that exhausted the server heap. Even without nesting, threads showed one delegation many times; one local thread rendered a sub-agent 14 times, with 2,609 timeline rows instead of 982.

What changed

  • plugins/provider-codex/src/translator.ts: a follow-up to a finished sub-agent starts a new delegation. Its id is the follow-up interaction's own id, it is placed in the parent turn that sent the follow-up, and it uses the same path as a newly spawned sub-agent. Each round now appears in the turn where it happened and contains only that round's work. Follow-ups queued while the sub-agent is still running stay in the current round. Nested follow-ups attach to the parent's current round.
  • packages/thread-view/src/tool-activity-projection.ts: a start event for a finished delegation reopens its existing row instead of adding a copy. This fixes threads already stored with reused ids: they show one row per sub-agent, holding every round. Commands keep Fix command timeline durations after approval #5108's behaviour, where a reused call id gets its own row.
  • packages/thread-view/src/normalize-event-projection.ts (from the original version of this PR): each delegation keeps one child per message id. This is a backstop against exponential growth if duplicate ids arrive from another source.
  • Dropped from the original version: the incremental byte budget in timeline-pagination.ts. The oversized tree is fully built before pagination serializes it, so that change didn't address the crash.
  • No wire, schema, CLI, or plugin API changes.

How you verified

  • New delegation-item-projection test: a delegation reopened by a follow-up, with a nested sub-agent that is also reopened, renders one row per delegation with all child messages. It runs in two variants, the last round completing or still running. It fails on main and passes with the projection change alone.
  • Codex translator tests: a follow-up from a later parent turn opens a new delegation in that turn, and the sub-agent's next turn links to it. A new nested test checks that a sub-agent's follow-up to its own sub-agent attaches to the parent's current round. Six tests fail on the old translator.
  • Replayed a stored Codex thread's 6,124 events through the projection: the reopened delegations went from 14 and 6 copies to 1 each; timeline rows fell from 2,609 to 982 and JSON from 14.6 MB to 3.9 MB.
  • Ran real Codex end to end in a worktree dev instance: spawning a sub-agent in turn 1 and following it up in turn 3 produced separate /root/counter rows in turns 1 and 3, containing only "ONE" and only "TWO".
  • pnpm exec turbo run test typecheck lint --filter='...[origin/main]': 38 tasks passed.

Fixes #5210

AGENT GENERATED

iipanda and others added 3 commits October 8, 2026 12:33
When the same message id was projected more than once under a delegation,
each copy was attached as a separate child, and every copy expanded its own
descendants again. The rendered tree grew exponentially with nesting depth:
a Codex thread with about 2,300 message contexts expanded to roughly 8.3
million rendered messages and exhausted the server heap when opened.

A delegation's children now keep one entry per message id, holding the
latest state in the position of the first occurrence. Root messages are
untouched, so a later turn that reuses a call id still keeps its own item.

Timeline pagination also measured an update subtree by serializing all of
it before comparing against the byte budget, so an oversized subtree
allocated a huge string first. It now accumulates row sizes and stops as
soon as the budget is exceeded.
Codex reopens a finished sub-agent's delegation item under its original id
when the parent sends it a follow-up. The tool-activity projection only
merged a start into a history row while the call was still running, so each
follow-up added another row with the same id. Children attach to a
delegation by call id, so every copy rendered the whole subtree and nested
follow-ups multiplied it.

A start for a finished delegation now reopens its existing row. Drop the
incremental byte budget from this branch: the oversized tree is already
built before pagination serializes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A follow-up to a finished Codex sub-agent reopened its original delegation
item in the turn that first spawned it. The timeline then had nowhere to show
the round in the parent turn that sent the follow-up, and every round's work
piled into one row.

Start a new delegation for the follow-up, identified by the interaction and
scoped to the parent's current turn, exactly as a newly spawned sub-agent is.
Follow-ups queued while the sub-agent is still open stay in the open round.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the fix/timeline-duplicate-delegations branch from cdedb24 to dd8c0d3 Compare October 8, 2026 19:36
@ymichael ymichael changed the title Keep repeated nested delegation messages from multiplying the timeline Give each Codex sub-agent follow-up its own timeline row Oct 8, 2026
@ymichael
ymichael merged commit 5b75713 into get-bb:main Oct 8, 2026
44 checks passed
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.

Opening a thread with repeated nested delegation messages exhausts the server heap (exponential timeline expansion)

2 participants