Skip to content

feat(subagents): Send agent invocation results to the parent conversation - #2106

Merged
dcramer merged 4 commits into
mainfrom
feat/agent-invocation-parent-results
Oct 13, 2026
Merged

dcramer merged 4 commits into
mainfrom
feat/agent-invocation-parent-results

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Before this change, spawnAgent started a child agent, but the parent never saw the result. Now a terminal result wakes the parent Conversation. Part of #2105, refs #878.

  • The SQL write that stores the result also marks it pending for the parent.
  • The worker appends the result to the parent mailbox before it acks the child work. The heartbeat repairs results that stay pending. The message id comes from the agent invocation id, so retries do not add a second parent Turn.
  • The result is a core Event (junior/agent_invocation.{completed,blocked,failed}). It uses the same mailbox and Event Turn path as Watches, but without a Watch. The parent replies at its Location.
  • The result Turn runs as the Actor that spawned the child, read from SQL. A delegated credential subject of a system Actor is not passed yet.
  • The child result is information, not instructions. The automated-turn limit does not drop results.
  • spawnAgent and the result Event give the model only the child conversation_id. The parent reads child history with the existing searchConversationEvents tool. The agent invocation id stays internal.
  • Subagents were never enabled in production, so this PR also removes legacy agent invocation state. Status awaiting_resume is now paused, and every terminal agent invocation has a parentMailboxStatus. Migration 0050 converts existing rows.

Child agents can also start child agents, up to limits.maxAgentDepth:

  • The default, 0, keeps today's behavior: only the root starts children. The worker counts a child's parents and hides spawnAgent once the child is deeper than the limit. Child runs read the root Location and visibility.
  • A child Conversation has no Location, so a result for a child cannot run an Event Turn. It starts a new agent invocation on that child instead, keyed by the result's agent invocation id. It uses the child's parent, Actor, and credentials.
  • The parent gets one report per piece of child work. A child agent invocation that finishes while the child still has open work (another open invocation, an open child, or a sent result that no invocation has received) is marked replaced. That open work starts a later invocation, which sends the report.
  • Result Events no longer put the task in verified details, because the input of an invocation that receives a result holds another child's output.

Codex and Claude Code also push child completion into the parent. Junior must start a new parent Turn for it, because the parent Turn may have ended.

listAgents, stopAgent (including stopping a whole tree of children), and auth pauses are separate follow-ups (#881).

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 13, 2026 8:11pm UTC

Request Review

@dcramer
dcramer marked this pull request as ready for review October 13, 2026 17:11
@github-actions github-actions Bot added the risk: high PR risk score: high label Oct 13, 2026
@sentry-junior
sentry-junior Bot force-pushed the feat/agent-invocation-parent-results branch from 6d53513 to 6795623 Compare October 13, 2026 17:27
@sentry-junior sentry-junior Bot changed the title feat(subagents): Deliver child results to the parent conversation feat(subagents): Send agent invocation results to the parent conversation Oct 13, 2026
@sentry-junior
sentry-junior Bot force-pushed the feat/agent-invocation-parent-results branch from 6795623 to aeeba27 Compare October 13, 2026 17:32

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…tion

A terminal agent invocation result now wakes the parent Conversation.
The SQL write that stores the result marks it pending for the parent. The
worker appends it to the parent mailbox as a junior/agent_invocation.* Event
before it acks the child work, and the heartbeat repairs results that stay
pending.

The result Turn runs as the Actor that spawned the child, read from SQL.
The automated-turn limit does not drop results. spawnAgent returns the
child conversation_id, so the parent can read child history with
searchConversationEvents.

Refs #878, #2105

Co-Authored-By: David Cramer <[email protected]>
…AgentDepth

Add limits.maxAgentDepth. The default, 0, keeps today's behavior: only the
root Conversation can start child agents. The invocation worker counts a
child's parents and hides spawnAgent once the child is deeper than the limit.
Child runs now read the root Location and visibility, not the parent's.

A result for a child Conversation cannot run an Event Turn, because a child
has no Location. Instead it starts a new agent invocation on that child,
keyed by the result's agent invocation id. That invocation uses the child's
parent, Actor, and credentials and skips the busy and active-count checks.

The parent gets one report per piece of child work. A child agent invocation
that finishes while the child still has open work (a queued invocation, a
running child, or a result no invocation has received) is marked `replaced`.
The open work starts a later invocation, which sends the report.

Result Events no longer put the task in verified details. For an invocation
that receives a result, the input holds another child's output.

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1487161. Configure here.

…evals

A replaced child result is never sent, so it no longer counts as an
unreceived result. Before, a child whose own child had replaced a result
never reported to its parent when maxAgentDepth was 2 or more.

Simplify the open-work check to two reads, derive the result agent
invocation id from the result alone, and drop the ancestor loop guard.

Add integration evals for a child agent result and a nested child report
through the real app wiring.

Co-Authored-By: David Cramer <[email protected]>
The integration evals recorded these model responses in https://github.com/getsentry/junior/actions/runs/38459361637.
The evals of this commit replay them in strict mode.

Eval-Suite: integration
@sentry-evals

sentry-evals Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Sentry Evals

junior-behavioral

Run Status Passed Failed Errored Cost Tokens Duration
Head Complete 67 6 0 $0.76 0 251.08s

Base commit 0fece98 has no eval run to compare against.

junior-guardian

Run Status Passed Failed Errored Cost Tokens Duration
Head Complete 53 0 5 $0.01 0 1.00s

Base commit 0fece98 has no eval run to compare against.

junior-integration

Run Status Passed Failed Errored Cost Tokens Duration
Head Complete 94 1 0 $0.49 0 161.74s

Base commit 0fece98 has no eval run to compare against.

junior-router

Run Status Passed Failed Errored Cost Tokens Duration
Head Complete 12 0 0 $0.00 0 0.28s

Base commit 0fece98 has no eval run to compare against.

@dcramer
dcramer merged commit 4fa904a into main Oct 13, 2026
57 of 60 checks passed
@dcramer
dcramer deleted the feat/agent-invocation-parent-results branch October 13, 2026 21:21

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 015e61dc Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant