Skip to content

feat(agent-invocations): Gate child reports and send results first - #3042

Closed
sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/child-report-gate
Closed

sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/child-report-gate

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Every child Run's final response went to its parent as a result, and that result woke the parent. In prod, a parent ran about 47 Turns, and only 4 of them came from a Slack message. Most of the rest were PR Watch events on its child Threads: each bot comment or CI run woke the parent, so the parent kept steering children that should run on their own.

Prior art: Claude Code does not send a child's final response to the parent. A child reports through a tool (SubagentHandback, or message_coordinator/no_reply_needed for project threads). If the child ends silent, Claude Code re-asks a fixed number of times, then gives the parent a "no report was delivered" note. Codex queues child results in the parent's mailbox, and the parent is not woken by default.

Change:

  • A child's final response is not sent to the parent. Only messageAgent to parent reaches it, or the Run ends with noReply (optionally with a note) or reportBlocked. One exception: after a turn-limit stop, the final response is sent as a report. TERMINOLOGY.md defines final response, parent task, own work, and report.
  • sendReportToParent is the one place that sends a report. messageAgent and both turn-limit paths call it. It saves the report in the Agent invocation's report_log (migration 0095_agent_invocation_report_log), keyed by tool call id: a retry of one call sends once, and the same text sent twice is two reports.
  • Reply gate: AgentRun.replyGate is generic, and the child-agent wiring supplies it. When the Run ended with a final response, without messageAgent to parent, noReply, or reportBlocked after the latest task, it gets one reminder per task (replyReminderTaskId in Turn state) and continues. Logged as agent.turn.reply_gate.{remind,reported,missing}.
  • Send first, no delivery state. finishAgentInvocation is the one finish path. When the parent is owed a result, it appends it to the parent's inbox first, with the fixed message id agent-invocation:<id>:result, then saves the terminal status. A crash between the two leaves the Agent invocation open, so worker recovery finishes it again from the saved Turn and report_log, and the inbox drops the second copy.
  • Who is owed a result: a parent task always (a person's stop of the child still reports stopped). Own work only when it failed or is blocked. Nothing when the parent stops the child, or when a running Run read the task (steered). A result whose child was stopped before the parent read it starts no work.
  • Parent task reports are folded into one <agent-result>, so the parent wakes once per task. Own work reports arrive as <agent-message>s. Own work that newer work ends fails and names its saved input label.
  • Removed: the heartbeat resend of pending results, and every read of parent_mailbox_status. Readers use the invocation status, isParentTask (parentToolCallId is set), and the child Conversation's stoppedAt.

Rollout:

  • Rollback shim: only the finish path and the tree stop still write parent_mailbox_status: appended when a result was sent, steered when nothing was owed. main accepts both and never sends either again. A later cleanup PR stops this write and drops the column.
  • Leftover rows: migration 0095 moves replaced and terminal pending rows to steered. A later invocation already sent a replaced row's result. A pending row is one whose send failed or crashed on main; sending it now would wake the parent with an old result, so it is settled, not sent.
  • Rollback to main: rows this runtime finished read as sent or settled, so nothing is sent twice. Rows still open finish under main as before.

Supersedes #3055.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 9, 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 Nov 10, 2026 4:38am UTC

Request Review

@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.

@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.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

17 screenshot changes — 17 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Page · Desktop
Automation Page · Desktop
Changed
Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Show 11 more changed screenshots
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Event Log Virtual · Desktop
Conversation Event Log Virtual · Desktop
Changed
Conversation Fork Dialog · Desktop
Conversation Fork Dialog · Desktop
Changed
Conversation Fork Dialog · Mobile
Conversation Fork Dialog · Mobile
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Conversation Share Details · Desktop
Conversation Share Details · Desktop
Changed
Conversation Stop Active · Mobile
Conversation Stop Active · Mobile
Changed
Conversations Sections Collapsed · Desktop
Conversations Sections Collapsed · Desktop
Changed
Memories · Mobile
Memories · Mobile
Changed
Push Notifications Tip · Desktop
Push Notifications Tip · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@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.

@dcramer dcramer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

whats the source of the large volume of code in this diff? i expected it'd be a little more compact.

@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.

dcramer added a commit that referenced this pull request Nov 10, 2026
#3042 adds a **Final response** entry to `TERMINOLOGY.md`. This PR swaps
the other names for that idea ("final text", "final answer", "final
reply", "final assistant text") to "final response". It covers runtime
comments, the `dispatch.delivery` prompt lines, the root
failure-reporting rule, skills, docs, eval criteria, and test error
messages. Only wording changes. Behavior stays the same.

Left as they are:
- Lines that #3042 rewrites: `system-prompt-rules.ts` child rules
(62-67, 208) and `agent/types.ts:282`. Changing them here would cause
merge conflicts.
- Identifiers such as `deliversFinalText`, test data strings ("Final
answer: 42."), `CHANGELOG.md`, and Pi protocol text in
`pi-agent-integration` references.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A6844406fb7378eb1ae46b6bb243e702d -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A6844406fb7378eb1ae46b6bb243e702d)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A6844406fb7378eb1ae46b6bb243e702d/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
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.

Stale Bugbot comment from a previous run.

@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.

…ry state

A parent task sends its result to the parent's inbox before its terminal
status is saved. The inbox drops a second copy by message id, so recovery
can finish a crashed invocation again from its saved Turn and report log.
Own work sends a result only when it fails or is blocked.

Child reports go through messageAgent and a report log. A reply gate
reminds a child Run once per task when it ends without a report.

The old parent_mailbox_status column is written for rollback only.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the feat/child-report-gate branch from 67980c1 to 1a765d4 Compare November 10, 2026 04:37
@sentry-junior sentry-junior Bot changed the title feat(agent-invocations): Gate child Run reports on a tool call feat(agent-invocations): Gate child reports and send results first Nov 10, 2026
-- a later agent invocation already sent the result of a `replaced` row, and a
-- `pending` row is one whose send failed or crashed. Its result is not sent
-- again: that send would wake the parent with an old result.
UPDATE "junior_agent_invocations" SET "parent_mailbox_status" = 'steered'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we even need to track this status?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not for this runtime. On 1a765d46e, nothing reads parent_mailbox_status. It is written only to keep a rollback to main safe: main's heartbeat sends again every result still marked pending, and it treats appended/steered as done. This UPDATE settles the rows that main left, so a rollback does not send them again. The finish path writes appended/steered for the same reason. When we can no longer roll back to main, the cleanup PR can stop these writes and drop the column.

Work on this PR is paused for the redesign, so I'm not changing it now.

@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 2 potential issues.

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 1a765d4. Configure here.

? undefined
: readBlockedReport(turn.piMessages.slice(turn.turnStartMessageIndex));
return await completeAgentInvocation({
...completeOptions,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Heartbeat drop skips subagent ended

Medium Severity

When a child Run exhausts retries, endAgentInvocationsOfStoppedWork now sends the owed result and finishes the Turn, but it never calls recordSubagentEnded. The old heartbeat sweep that wrote subagent_ended was removed, so the parent dashboard can keep pairing subagent_started with no end after a lost worker.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1a765d4. Configure here.

// cannot tell this Turn from earlier history of a named child.
const blocked =
turn.turnStartMessageIndex === undefined
? undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Heartbeat omits own-work reports

Medium Severity

Heartbeat recovery passes sendResult into endAgentInvocationsOfStoppedWork but not enqueueMessage. Own work delivers reports only through sendReportToParent's enqueue path, including a turn-limit final response, so a lost-worker give-up can save those reports in report_log and never send them to the parent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1a765d4. Configure here.

@sentry-junior

sentry-junior Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the child-agent redesign; series starts with #3059. Evals and recovery tests will be carried into later PRs.

sentry-junior Bot added a commit that referenced this pull request Nov 16, 2026
Reviewers asked whether a stored field was needed in #2306,
#2824, #2828, #2850,
#2951, #3042, #3181, and
#3383. No check can tell which state the owner can give,
so this is a rule.
sentry-junior Bot added a commit that referenced this pull request Nov 16, 2026
Review flagged a stored field that the provider or existing rows could
give in #2306, #2824, #2828,
#2850, #2951, #3042,
#3181, and #3383.

The rule goes in the interface-design Lifecycle state section, next to
the rule that owns copies, instead of AGENTS.md. It names the cases that
need a stored value: an earlier-time snapshot, missing read authority,
and a measured read cost. Those cases match the durable payloads in
serverless-background-work.md and the stored handles in
context-bound-systems.md.

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

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 1a765d46 Deployed Nov 10, 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.

2 participants