Repository navigation
orchestrator: report a spawned child's turn to its parent session - #1825
Merged
Merged
Conversation
A parent session learns that a spawned child finished only when it polls wait_sessions inside one of its own turns. A coordinator session that ends its turn while its children run does not see their results until something else wakes it. Add the child-report listener consumer. When a session whose task is a spawned subsession ends a run (run_completed or run_interrupted), the consumer sends the spawning session a prompt. The prompt names the child, its session id and the outcome, and carries the last assistant message of that run (first 4000 characters, with a note when cut). - The prompt id is child_report:<child session>:<run id>. The coordinator accepts a repeated prompt id as a no-op, so a redelivered run end sends no second prompt. - While an assistant message waits for its run end, the consumer commits the idx just before that message, so a listener restart replays it. - A cancelled child task, a session that is not a spawned child, and an ended parent (the coordinator refuses the prompt) send nothing. A transient send error retries five times, then the consumer logs and skips. The child is never blocked. The spawn_session description now tells the parent that a child's final message arrives as a new prompt. Review pass: read each touched file; no stale comments or duplicate logic found. The consumer listens to every event kind on purpose: an event it ignored would commit its own idx past a held message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A child states its result at the end of its last message (a hand-back block, a status line), so a report cut to its first 4000 characters lost exactly that part. Keep the last 4000 characters and say so first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A session spawns child sessions with
spawn_session. The parent learns that a child finished only when it pollswait_sessions(120 s maximum) inside one of its own turns. A long-lived coordinator session ends its turn while its children run, so a child's result stays unread until something else wakes the parent.Change
A new listener consumer,
child-report(orchestrator/src/listeners/child-report-consumer.ts), registered with the other production consumers.When a spawned child (a
subsessiontask with a parent task and a spawning session) ends a run (run_completedorrun_interrupted), the consumer sends the spawning session this prompt:Idempotent. The prompt id is
child_report:<child session id>:<run id>. The coordinator accepts a repeated prompt id as a no-op (session_outboxis keyed onprompt_id), and the text is a function of the replayed events, so a redelivered run end sends no second prompt.Restart safe. The consumer keeps the run's last assistant message in memory. While it holds one, it returns the held floor (the idx just before that message) as its cursor commit, the same seam the OTel exporter uses. A listener restart replays the message before the run end. For this reason the consumer listens to every event kind.
No report when the child task is
cancelled(the parent ranterminate_session), when the session is not a spawned child, or when the parent session has ended (the coordinator refuses the prompt withFailedPrecondition/NotFound; the consumer skips without retry). A transient send error retries through the listener's backoff five times, then the consumer logs and skips. The child session is never blocked.The
spawn_sessiondescription tells the parent that a child's final message arrives as a new prompt.The parent session is the child task's
spawning_session_id. A parked parent resumes to take the prompt; a busy parent queues it.Validation
bun run typecheck(orchestrator): pass.bun test src/listeners/__tests__/child-report-consumer.test.ts: 11 pass. The tests cover one prompt per run end with the expected text and prompt id, the held floor, a replay after restart (same prompt id and text), a message from an earlier run, a cancelled child, a non-child session, an ended parent, the transient retry cap, and truncation.bun test(orchestrator): 2460 pass, 219 skip (live Postgres), 0 fail. CI's orchestrator lane runsbun test, so it runs the new file.🤖 Generated with Claude Code