Skip to content

Run child agents as ordinary Conversations #3060

Open

Description

@sentry-junior

Intent

A child agent (Thread or Task) and an Automation run are ordinary Conversations. They use the same worker, inbox, Turn lifecycle and agent loop as a root. Only these things can differ by Conversation kind:

  • the system prompt
  • the enabled tools
  • the actor (a Task runs as the system actor)
  • where a reply goes
  • whether a Turn must explicitly reply

All other behavior is the same for every kind.

Why

  • Children have their own worker, their own steering drain, their own finish paths and per-invocation delivery state (parent_mailbox_status, outbox repairs, subagent_* markers). Each copy drifted from the root path, and each fix added a status or a repair job.
  • feat(agent-invocations): Gate child reports and send results first #3042 tried to add a reply gate on top of this. Four review rounds found new edge cases each time: lost reports, a stop that dropped results, stale rows sent again. The cause was the architecture, not the gate. feat(agent-invocations): Gate child reports and send results first #3042 is closed.
  • Every child Run's final response goes to the parent, also for Watch work such as PR bot comments or CI events. The parent wakes up for each event and steers work that the child should own.
  • Automation runs have their own answer tool (finishAutomationRun) and reminder. Its three results are the same choices as reply, noReply and reportBlocked.

Target design

One switch. turnBehavior({ kind, personInput }) in conversations/kind-behavior.ts returns a plain object for the behavior that differs. No other code branches on kind, a parent, parentToolCallId, declaresResult or Source. An architecture check enforces this, with a baseline of the legacy branches that goes to zero.

Kinds: root, thread, task, and automation for scheduled and event Automation runs. Plugin dispatches stay root.

Delivery and the reply gate:

  • A Turn that a person opened (Source slack or web) always delivers its final response where that person is. It has no gate. This includes people who reply in an Automation run's Slack thread.
  • Root Turns are never gated.
  • Every other Turn on a non-root kind must end with one of the same three answer tools. These Turns come from parent input, Watch, timers and the Automation dispatch. The Turn gets 1 re-ask.
    • reply: kind decides where it goes. For thread and task it goes to the parent. For automation it goes to the run's Destination, then to the run's Slack thread after the first post.
    • noReply: stay quiet.
    • reportBlocked: for thread and task it goes to the parent. For automation it blocks the Automation with the reason.
    • If the answer is still missing: a Thread or Automation run stays quiet and records telemetry. A Task's parent is told that no reply was sent.
  • A final response on a non-root kind stays in its own Conversation.
  • messageAgent stays for messages between agents. It is not the reply path.
  • An Automation run ends when its Turn ends, like any Conversation. There is no separate end-run tool. If one is needed later, it stops the Conversation.

Parent controls: spawn, message and stop are plain writes.

  • Spawn creates the Conversation and its binding, then adds the task to its inbox.
  • Message adds one inbox message.
  • Stop sets stopped_at on the subtree. The child's worker checks it at each step boundary and ends its own Turn.
  • A worker never changes another worker's state. Supersede runs only in the owning worker.

No delivery state. A reply is a message in another Conversation's inbox, like a Slack message to a root. Inbox message ids remove duplicates. Status comes from the child's Turn lifecycle. The Agent invocation table and parent_mailbox_status are removed after in-flight work drains.

Failures use the root paths: failed Turns, lost workers and retry exhaustion. A Task's parent gets the failure. Other kinds store it and report it through telemetry.

Plan

Each step is a separate PR. Each PR can be deployed and rolled back safely.

  1. Per-kind table, with no behavior change. Prompt mode, tools, agent tools, delivery and the Automation gate read turnBehavior. Also add the architecture check and its baseline. (ref(conversations): Route per-kind behavior through turnBehavior #3059, merged)
  2. Kind automation.
  3. Shared answer tools for Automation runs. Add reply. Automation runs use reply, noReply and reportBlocked, and every non-person Turn on automation is gated. remindMissingAutomationResult becomes remindMissingAnswer. Delete finishAutomationRun and the automationRun flag. Old root rows of runs in progress at deploy keep their outcome mapping until they finish.
  4. Children reply with reply. It works without an open invocation row. Gate child Turns. The worker checks stopped_at at each step boundary. Carry over the child-agent evals from feat(agent-invocations): Gate child reports and send results first #3042.
  5. Children with no open invocation run on the shared Conversation worker (conversation-turn). Carry over and rewrite the recovery tests from feat(agent-invocations): Gate child reports and send results first #3042.
  6. Behind a flag: spawn and messageAgent stop writing invocation rows and markers. Turn on failure notices for children.
  7. Remove the legacy child worker, steering drain and repair jobs. Then drop the Agent invocation table and parent_mailbox_status. Move the dispatch worker onto conversation-turn after this step, as a separate change.

Known costs

  • A Watch Turn on a non-root kind that ends with plain text pays 1 re-ask.
  • There is no automatic "done" signal. waiting_on reads the child's activity status.
  • A wrong noReply hides findings.
  • The stop check adds one SQL read per model step.

Related

via @dcramer.

--

View Session [Sentry]

Activity

  1. sentry-junior commented on Nov 12, 2026

    @sentry-junior
    ContributorAuthor

    Open bugs on the legacy Agent invocation path, for steps 6–7. They come from the review of #2627. #2640 fixed them, but it is closed because it conflicts with the use of beforeWorkStops in createEndStoppedChildWork (#3206).

    • Stop paths that skip the hook. Only clearExpiredConversationLease calls beforeWorkStops. When work stops, recordConversationRetry (an error escapes the last try) and recordAttemptFailure (dead-lettering) drop the mailbox, but they do not end the child's open Agent invocations. So an appended follow-up stays pending, its id is still in inboundMessageIds so it cannot be appended again, and the parent never gets a result.
    • Failed before the stop commits. The hook writes Postgres before writeConversation, and it holds the 10s mutation lock without extending it. If the lock runs out or the heartbeat dies before the write, the work can start again with its invocations already failed.

    I read this from main at 6c1cbde, and I did not run a test there. When step 7 removes the legacy worker, both bugs go away. Until then, the test in #2640 (agent-invocation-worker-crash.test.ts: "tells the parent about dropped work when a child worker fails past its last retry") reproduces the first one.

  2. 17 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions