Skip to content

orchestrator: report a spawned child's turn to its parent session - #1825

Merged
nikhilunni merged 3 commits into
mainfrom
feat/child-session-reports-to-parent
Nov 19, 2026
Merged

nikhilunni merged 3 commits into
mainfrom
feat/child-session-reports-to-parent

Conversation

@nikhilunni

Copy link
Copy Markdown
Contributor

Problem

A session spawns child sessions with spawn_session. The parent learns that a child finished only when it polls wait_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 subsession task with a parent task and a spawning session) ends a run (run_completed or run_interrupted), the consumer sends the spawning session this prompt:

    Child session "<canonical task name>" (<child session id>) finished a turn (<completed | failed | interrupted>).
    
    <last assistant message of that run, first 4000 characters, with a note when cut>
    
    Use read_session for its full output.
    
  • Idempotent. The prompt id is child_report:<child session id>:<run id>. The coordinator accepts a repeated prompt id as a no-op (session_outbox is keyed on prompt_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 ran terminate_session), when the session is not a spawned child, or when the parent session has ended (the coordinator refuses the prompt with FailedPrecondition/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_session description 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.
  • Full bun test (orchestrator): 2460 pass, 219 skip (live Postgres), 0 fail. CI's orchestrator lane runs bun test, so it runs the new file.

🤖 Generated with Claude Code

nikhilunni and others added 3 commits November 19, 2026 11:59
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>
@nikhilunni
nikhilunni merged commit fb39353 into main Nov 19, 2026
26 checks passed
@nikhilunni
nikhilunni deleted the feat/child-session-reports-to-parent branch November 19, 2026 20:18
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