Skip to content

fix(agents): sub-agent turns can ship narration as the final reply before work finishes - #301

Merged
convyusboy merged 2 commits into
boonfrom
worktree-polished-mixing-popcorn
Oct 21, 2026
Merged

convyusboy merged 2 commits into
boonfrom
worktree-polished-mixing-popcorn

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: https://linear.app/getboon/issue/ENG-21585

What Problem This Solves

Fixes an issue where a turn that delegates work to a sub-agent (e.g. OCR/doc-conversion fan-out) could reply to the user with a mid-turn status line instead of the real answer, while the sub-agent's actual result was still in flight. This surfaced on the doc-conversion eval scenario (run 39192943221): the agent dispatched two OCR sub-agents (notes_keynotes, title_block), then ended its turn with "Reading title block and notes tiles." instead of calling sessions_yield — and that narration was delivered as the final reply.

Why This Change Was Made

sessions_spawn is documented as fire-and-forget: it returns {status: "accepted"} immediately and the child runs out-of-band. The contract for "my answer depends on this child" is that the model calls sessions_yield to pause the turn, but nothing in the runtime enforced that — a model that forgot to yield had its narration promoted straight to the final answer.

This adds a runtime backstop: resolveImplicitYieldContinuationInstruction (run/incomplete-turn.ts) detects a turn about to finalize with visible narration, a sub-agent accepted this turn that is still live (checked via the subagent registry, scoped to just this turn's spawns so an unrelated already-settled descendant never triggers it), and no explicit yield — and forces one bounded continuation instructing the model to call sessions_yield for real. It reuses the existing settled-tool-continuation pattern (same shape as resolveSettledToolContinuationInstruction) rather than synthesizing fake tool-call evidence, so the forced yield is a genuine tool call that plugin after_tool_call hooks and the eval harness's own yield detection see identically to an explicit one. Capped at one continuation attempt, same as the sibling patterns in this file.

Not harness-restricted (unlike the settled-tool continuation): sessions_spawn/sessions_yield are ordinary catalog tools any harness can call, and the race this guards against is a model-behavior gap, not a harness-specific one.

User Impact

A turn that spawns a sub-agent and forgets to yield now gets resumed to actually wait for and deliver the sub-agent's real result, instead of shipping a stub status line as the answer.

Evidence

  • 8 new unit tests covering every branch of resolveImplicitYieldContinuationInstruction (src/agents/embedded-agent-runner/run/incomplete-turn.test.ts), TDD'd red → green.
  • 2 new integration tests through the real runEmbeddedAgent loop (src/agents/embedded-agent-runner/run.incomplete-turn.test.ts): one reproducing the doc-conversion shape (narration over a live spawn → forced yield continuation), one confirming an explicit sessions_yield is left alone.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.incomplete-turn.test.ts src/agents/embedded-agent-runner/run/incomplete-turn.test.ts — 132/132 passing.
  • pnpm tsgo (core) — clean.

Follow-up (not in this PR)

The scenario's own header comment ("HOURLY smoke set... pages the on-call responders") and the ticket's "hourly P0" framing are stale: both the hourly and the 6/12h scheduled cadences for agent-regression.yml were cut on 2026-10-14 (now weekly-full + manual dispatch only). Flagging on the Linear ticket separately; not touched here to keep this PR scoped to the runtime fix.

🤖 Generated with Claude Code


Summary by cubic

Fixes a race where a turn that spawns a sub-agent (for example, OCR/doc-conversion fan-out) and forgets to call sessions_yield shipped its mid-turn narration as the final answer while the sub-agent's real result was still in flight. The runtime now forces one bounded sessions_yield continuation whenever a turn finalizes with visible narration and a sub-agent spawned this turn is still live, so the sub-agent's actual result is delivered instead of the status line. Closes ENG-21585.

  • The forced continuation only fires when sessions_yield is in the turn's visible tool set, so the model has a way to comply.
  • The check is scoped to this turn's own spawns via the subagent registry; a missing registry row means the child already finished, so unrelated settled descendants never trigger it.
  • The continuation lands as a real sessions_yield tool call, so plugin after_tool_call hooks and eval harness yield detection see it identically to an explicit call.
  • 13 unit and 3 integration tests cover every branch, including confirming an explicit sessions_yield is left untouched.

Written for commit e26342d. Summary will update on new commits.

View guided diff Turn on auto-fix

@convyusboy
convyusboy requested a review from a team October 21, 2026 06:12

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 4 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/agents/embedded-agent-runner/run.ts Resolved
Comment thread src/agents/embedded-agent-runner/run.ts Resolved

@boon-hermes-bot boon-hermes-bot 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.

LGTM! Approved. Detailed review:

Evidence Map

  • Surface: src/agents/embedded-agent-runner/run.ts, incomplete-turn.ts, unit & integration tests.
  • Entry point: runEmbeddedAgentInternal loop prior to finalize.
  • Owner boundary: Embedded agent runner incomplete-turn safety.
  • Callers & Callees: Calls resolveImplicitYieldContinuationInstruction, checking hasLivePendingAcceptedSessionSpawn against the subagent registry.
  • Sibling surfaces: Perfectly aligns with the existing resolveSettledToolContinuationInstruction pattern.
  • Tests: 13 unit tests + 3 integration tests covering positive, completed-child, explicit-yield, and edge cases. Verified all 138 tests pass locally.

Clean implementation and all cubic review comments have been properly addressed.

convyusboy and others added 2 commits October 21, 2026 19:44
…b-agent spawn (ENG-21585)

A turn that spawns a sub-agent (sessions_spawn is fire-and-forget) and
then ends with plain narration instead of calling sessions_yield
shipped that narration as the final reply while the sub-agent's real
result was still in flight. doc-conversion hit this: the agent
dispatched OCR sub-agents, wrote "Reading title block and notes
tiles.", and that status line was delivered as the answer instead of
the transcribed content.

Add resolveImplicitYieldContinuationInstruction (incomplete-turn.ts):
when an attempt is about to finalize with visible narration, a live
sub-agent accepted this turn, and no explicit yield, force one bounded
continuation instructing the model to call sessions_yield for real.
This reuses the existing settled-tool-continuation pattern and
produces a genuine tool call (not synthesized metadata), so plugin
hooks and the eval harness's own yield detection see it the same way
an explicit yield would.

hasLivePendingAcceptedSessionSpawn (run.ts) scopes the check to this
turn's own accepted spawns via the subagent registry, so an unrelated
already-settled descendant never forces a continuation.

Tests: 8 new unit tests covering every branch of the resolver, plus 2
new integration tests through the real runEmbeddedAgent loop (TDD'd
red/green). 132/132 passing in the touched files; pnpm tsgo clean.

Linear: ENG-21585

Co-Authored-By: Claude Opus 5 <[email protected]>
- Fix a real CI type error: test file imported a nonexistent
  AssistantMessage export from runtime/index.js; use
  EmbeddedRunAttemptResult["currentAttemptAssistant"] instead, matching
  this file's established pattern.
- Gate the forced continuation on sessions_yield actually being in the
  turn's visible tool set (attempt.visibleToolNames) — some tool
  profiles expose sessions_spawn without sessions_yield, and forcing
  an unfollowable instruction wastes the one-shot retry.
- Correct the registry-miss semantics: a missing row means the run
  already ended and was cleaned up (registerSubagentRun always runs
  before sessions_spawn returns "accepted", so there's no register-vs-read
  race to defend against), not that registration is still landing.
  Flip the check accordingly and add integration coverage for both the
  live-and-pending and gone-and-done cases.
- Fix a broken compile-time type assertion in the test file (the old
  ternary silently widened to `never` on a mismatch instead of erroring);
  use an AssertTrue<T extends true> constraint instead.
- Add missing unit coverage for the lastToolError, clientToolCalls,
  didSendDeterministicApprovalPrompt, and committed-media-delivery
  suppression guards.
- Drop Linear ticket references from code comments and a test title
  per repo convention; trim comments to the shape this file's siblings
  use.

All touched-file tests green (13 unit + 125 integration), pnpm tsgo
and pnpm check:test-types both clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
@convyusboy
convyusboy force-pushed the worktree-polished-mixing-popcorn branch from 554e22d to e26342d Compare October 21, 2026 12:46
@convyusboy
convyusboy merged commit 3342432 into boon Oct 21, 2026
143 of 145 checks passed
@convyusboy
convyusboy deleted the worktree-polished-mixing-popcorn branch October 21, 2026 13:58
convyusboy added a commit that referenced this pull request Oct 26, 2026
* chore(release): bump version 2026.6.35-boon.1 -> 2026.6.35-boon.2

Cuts the fork release covering the 9 PRs merged to boon since v2026.6.35-boon.1:
#298 (ENG-21265) stuck-generation cut-off retry + sub-agent spawn backstop,
#299 workspaceDir threading through outbound channel media adapters,
#304 (ENG-19208) real inbound media path in the system prompt,
#301 (ENG-21585) forced sessions_yield on narrated sub-agent turns,
#305 message-tool source reply observed outside message_tool_only,
#306 (ENG-19103) reasoning-stream callbacks honor message_tool_only,
#303 sub-agent/completion-turn usage attribution,
#302 clears 7 high-severity pnpm-audit-prod advisories,
#300 (ENG-21588) boon-estimation trajectory label detail.

Bump root package.json/npm-shrinkwrap.json, all bundled plugin manifests, and
the version + openclaw peer floor in every extension npm-shrinkwrap.json. Add
the 2026.6.35-boon.2 CHANGELOG.md section. No additional dependency or source
changes beyond what already shipped in #299 and #302.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* docs(changelog): fold PR #309's advisory fixes into the 2026.6.35-boon.2 entry

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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