Repository navigation
Give each Codex sub-agent follow-up its own timeline row - #5211
Merged
Merged
Conversation
iipanda
marked this pull request as ready for review
October 8, 2026 13:39
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
force-pushed
the
fix/timeline-duplicate-delegations
branch
from
October 8, 2026 19:36
cdedb24 to
dd8c0d3
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.
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 (
onExecBeginintool-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.timeline-pagination.ts. The oversized tree is fully built before pagination serializes it, so that change didn't address the crash.How you verified
delegation-item-projectiontest: 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 onmainand passes with the projection change alone./root/counterrows 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