Skip to content

fix(delegation): deliver every subagent answer to its parent exactly once - #1015

Merged
astyfx merged 21 commits into
mainfrom
fix/subagent-results-and-attribution
Nov 19, 2026
Merged

astyfx merged 21 commits into
mainfrom
fix/subagent-results-and-attribution

Conversation

@astyfx

@astyfx astyfx commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

A parent turn receives its subagents answers under a character budget. When the budget was exceeded, later answers lost their body and were then treated as already delivered, so the parent never saw them (synthesis #4; it happened in the conversation that produced this work).

  • Every finished answer reaches the parent in full exactly once. Delivery is decided by identity (child run and the turn that produced the answer), recorded in its own table when the provider runtime hands the turn to the provider; run_receipts is untouched and a database written by this change still opens in 0.35.2.
  • An answer that does not fit is carried whole to a later turn, oldest first, with a note and a reference for what is still owed; subagent text is framed as untrusted data.
  • Owed answers are selected from the database (40 per turn), so nothing is starved with many children.
  • A refused turn records nothing; a failed record write prefers a rare duplicate over a loss.
  • Upgrade: answers finished before the parent task\x27s most recent turn are classified as delivered once, so history does not replay. Answers that 0.35.x already dropped stay lost.

Note: last fix round not re-verified

The independent reviewer found a new edge path in each of five rounds (refused turns, restart during admission, repeated compaction, failed record writes, notice-only reviews). All reported paths are fixed with regression tests, and the report has a state-transition table naming the test for every state change, but the last round has not been re-verified by the reviewer. Opened for review at the owner's request.

Review and verification

Written and reviewed by different providers: each branch was implemented by one model, reviewed independently by a model of the other provider, and fixed until the reviewer's blocking findings were resolved. Lead checks on the rebased head: bun run typecheck, bun run lint, bun run check:i18n, bun run check:doc-paths, bun run check:max-lines-ratchet, bun run build:pages, git diff --check, and every changed unit test file run one per process: all exit 0. New regression tests fail on the previous code and pass now. Not verified: the installed Electron app, live providers, real macOS sleep, real GitHub calls.

Part of the design-review follow-up (synthesis priorities 1–14).

🤖 Generated with Claude Code

@upwind-code-us

upwind-code-us Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Upwind Code Scan

Upwind code scan | ✅ Passed

✅ No new findings in this PR vs main

Scan New in this PR Fixed Status
IaC 0 0 ✅ Passed

View full scan details in Upwind Console →

Scan history (2 commits)
Commit Scanned at IaC
b86fef9 2026-11-19 07:53 UTC 0 / 0
d40d7df (latest) 2026-11-19 11:37 UTC 0 / 0

Last updated: d40d7df · 2026-11-19 11:37 UTC

@astyfx
astyfx marked this pull request as ready for review November 19, 2026 11:02
@astyfx
astyfx requested a review from a team as a code owner November 19, 2026 11:02
@astyfx
astyfx requested review from JongSikLim and heath-s and removed request for a team November 19, 2026 11:02

@heath-s heath-s left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved

astyfx and others added 21 commits November 19, 2026 20:22
The result receipt now records the child turn that produced its answer,
and the summary carries that turn and the receipt time. A follow-up or a
stop moves the step's target and update time, not the answer, so the
parent can tell an answer it already has from a new one and its read
reference points at the finished turn rather than a running follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delivery state was a list of delivered keys searched in the resident
message window, so after an upgrade or a restart of a long task every
past answer looked new and replayed at 8,000 characters per turn. An
answer is now new when it was recorded after the previous parent turn
began, or when that turn deferred it; only the newest assistant message
is read, and history saved before this change behaves as on main.

An answer that does not fit the shared budget whole is deferred instead
of cut to a fragment, and new answers take the budget oldest first. A
held review says so only while its answer is new, a subagent's reason
is folded to one line, and the block says subagent text is data.

The pending assistant row no longer takes its turn id at creation; the
first provider event binds it as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reading the answer of a specific child turn paged back through the
whole task when that turn left no message, decoding every page, and a
single unreadable older row failed the read. It now stops at the turn's
own rows or anything older and falls back to the turn receipt when an
older page cannot be read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…edger

A parent turn decided which subagent answers were new from its previous
turn's start time and a deferral list on the newest assistant message. An
answer recorded between the read and that start time, or deferred by a turn
followed by a message without the list, was never carried.

Each answer is now a result receipt of its child run. A committed parent
turn adds a `delivery` receipt naming itself for each answer it carried;
any answer without one is owed, oldest first, under the same budget.
Answers recorded before this version are settled once on first sight
against the parent's most recent turn. `ChatMessage.deferredResultKeys`
is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ries

In latest-reply mode an attachment holds the child's newest reply, yet every
waiting answer of that child was recorded as delivered. Only the answer that
is the child's latest reply, while no turn of it runs, is settled by the
attachment now; its older answers are carried under Subagent results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…provider

Delivery was recorded before the provider start: a turn refused afterwards
(a control change, a cancelled queue slot, a policy refusal) lost its answers,
and the renderer swallowed a failed write. The turn request now names the
answers it carries (subagentAnswers), and the provider runtime tells the host
once it hands the turn to Claude or Codex; only then is delivery written. A
failed write is logged and leaves the answers owed, so they can come twice but
are never lost. A request the transport had to cut claims none.

Delivery records move beside the run ledger (delegated-answer-store), which
selects the owed page in SQLite: no answer waits behind the newest 50
children and nothing already delivered is read. The upgrade cut runs once per
parent and only for answers older than this version's first start. Result
receipts keep the shape 0.35.2 parses (the child turn is read from the
receipt key), so a database this version used still opens in 0.35.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… cut

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts the prompt

The host recorded a turn's subagent answers before runProviderTurnImpl's
own refusals (no workspace folder, a tool-less turn the provider cannot
run) and before the adapter reached its provider, so a refused turn
settled answers the model never saw. Adapters now call onPromptAccepted
where they commit retrieved-context dedup: Claude's input queue took the
prompt, Codex acknowledged turn/start, an ACP prompt returned. A native
slash command or a context without the Subagent results part gets no hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… it unseen

The receipts settled an attached child's newest answer as carried by the
attachment, but the attachment is read separately: a failed read leaves
it empty, findings selection or transport compaction cuts it, and the
answer was still recorded as delivered. Every owed answer now travels in
Subagent results; an attachment only decides whether a composer review is
shared or held. The conversation-flow doc names the acceptance hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compaction cut every retrieved-context part to 12 KB (4 KB when
aggressive). Subagent results past that lost their middle rows, the
answers at the end still went out, but the request no longer matched
and dropped its delivery refs, so the same answers came back on every
oversized turn. The part is now never cut, only dropped (after other
low-priority parts), and its refs go with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cut compares each answer's own record time with the upgrade moment,
written once per database before this version can write a receipt, so a
legacy parent whose turns carry no start time still keeps every answer
finished after the upgrade, including ones its first read sees beside
older ones. Reopening the database never moves that moment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ratchet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er attaches it

A review the user started from the composer was settled by a one-line
notice that carried no text, so the parent never received it through
Subagent results. The review is addressed to the user: it now stays owed,
is only counted while unattached, and is carried whole (and settled) in the
turn the user attaches it to. Owed reviews sort after other answers so
unattached ones never fill the read page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it at 2,000 characters

An answer longer than the per-result cap was cut and still recorded as
delivered. Answers now go whole or wait for a later turn with a reference;
the oldest carried answer goes even when it alone exceeds the turn's
budget. The only hard size is the receipt bound applied when an answer is
stored: such an answer goes as its stored head with a too-large reference
to stave_get_task, and that reference is its delivery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…estart run records them

A host turn that waited in admission and ran again after a restart was
saved without its subagent answer refs, so the provider accepted the answers
but no delivery was recorded and the next turn sent them again. Admission
now saves the refs with the queued start, and the recovered run records
exactly those once its provider accepts the prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… failing

A delivery write that kept failing left the answers owed, so every turn
sent the same answers again without bound. The host now counts failed
writes per answer: after three in a row it stops carrying that answer in
both the host's and the renderer's turn read, and the task gets one
notification naming only the answers. A single failure still resends, as
a rare duplicate is preferred over a lost answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unattached one stays owed

These composer tests still expected the removed held notice and the latest
reply special case, and fed no owed answers, so they failed since the
answer ledger replaced receipt results. They now read owed answers like the
real turn start does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@astyfx
astyfx force-pushed the fix/subagent-results-and-attribution branch from b86fef9 to d40d7df Compare November 19, 2026 11:36
@astyfx
astyfx merged commit e16db2c into main Nov 19, 2026
14 checks passed
@astyfx
astyfx deleted the fix/subagent-results-and-attribution branch November 19, 2026 11:50
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.

2 participants