Skip to content

[ENG-20103] fix(sessions): agent forgets a sub-agent's result after the completion run answers through the message tool - #225

Merged
orswn merged 2 commits into
boonfrom
okka/completion-run-leaf-reset
Sep 16, 2026
Merged

orswn merged 2 commits into
boonfrom
okka/completion-run-leaf-reset

Conversation

@orswn

@orswn orswn commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-20103 (https://linear.app/getboon/issue/ENG-20103)

What Problem This Solves

Fixes an issue where a user who delegates work to a sub-agent in Boon Web chat would, on the next prompt, be told the sub-agent "is still running" or "never sent a completion signal" even though the agent had already posted the result to the thread.

The trigger is a sub-agent completion run that answers through the message tool. Right after that run ends, the session transcript receives a leaf control row whose target is the sessions_yield marker written before the run. Every later prompt is then compiled from that stale branch, so the completion prompt, the model's answer and the delivery mirror are invisible to the model. Observed on v2026.6.11-boon.40 in a paid Boon Web environment: four completion runs out of four that used the message tool were side-branched; the two that ended with sessions_yield were kept.

Why This Change Was Made

SessionManager.mergePromptReleasedSessionEntries persists a leaf control that always points at the merging manager's own in-memory leaf. When the lane that merges a delivery mirror is behind a peer run that already appended a whole turn to the same file, that row moves the file's active branch back to the stale leaf and hides the peer run's turn.

The merge now tracks whether any merged transcript row, or opaque link, has a parent this manager has never seen. Such a row proves the manager's leaf is no longer the file's active leaf, so the navigation write is skipped and the file keeps its natural leaf. Healthy merges are unchanged: a mirror whose parent is the lane's own assistant row still gets the restoring control, so delivery mirrors stay out of the prompt as before. Global metadata rows (custom, label, session_info) are excluded from the check because they resolve outside the active branch.

Non-goals: no repair of transcripts already carrying a stale leaf row; the fix stops new ones. The stale-lane full-rewrite path (getPersistedFileEntries) is not changed; no rewrite appears in the incident transcript.

User Impact

After a sub-agent reports back in Boon Web, the agent remembers that exchange on later turns. No change for ordinary turns, for completion runs that end with sessions_yield, or for how delivery mirrors are kept out of the model context.

Evidence

Unit test keeps a peer run's turn active when merging a later delivery mirror in session-manager.test.ts reproduces the production row shape (yield marker, peer user and assistant rows appended by another run, then the peer's delivery mirror merged with persistLeaf: true).

Without the fix:

AssertionError: expected [ { type: 'leaf', …(6) } ] to deeply equal []
+ { "appendMode": "side", "appendParentId": "peer-mirror", "targetId": "<yield marker>", "type": "leaf" }

With the fix:

suite result
src/agents/sessions/session-manager.test.ts 48 passed
src/agents/embedded-agent-runner/run/attempt.session-lock.test.ts 108 passed
transcript.test.ts, transcript-tree.test.ts, session-file-repair.test.ts, session-transcript-runtime.test.ts, replay-history.test.ts 119 passed
pnpm tsgo, oxlint and format:check on touched files, pnpm check:test-types clean

Before / After

Before (v2026.6.11-boon.40, paid Boon Web, two sub-agents; the first one reported at 5:42 PM):

Before, v2026.6.11-boon.40: the first sub-agent reported "Done" at 5:42 PM; at 5:51 PM the agent says it is still waiting on that sub-agent

After (this branch, fresh thread, same prompt shape):

After, this branch: the sub-agent result is posted at 8:45 PM; at 8:48 PM the agent quotes the exact result and time

Live check on this branch with a local paid gateway and anychat-boon-web v0.0.43-alpha, fresh thread, same prompt shape as the incident (spawn with sessions_spawn, yield, sub-agent sleeps 30 s, completion run answers through the message tool):

  • Transcript after the completion run: the mid-run leaf row targets the run's own assistant row (mirror hidden, as designed). No end-of-run leaf row targets the pre-run yield marker.
  • The next prompt ("Did the sleep test sub-agent finish? What exactly did it report, and when?") compiled 10 messages including the completion prompt and the result, and the agent answered with the exact reported text and time.
  • On v2026.6.11-boon.40 the same shape produced the stale row two seconds after each message-tool completion run and the next prompt's compiled context did not contain the completion rows.

Not verified: a same-build A/B without the fix (the control is the boon.40 incident transcript), and repair of transcripts already damaged.

…ry mirror

A sub-agent completion run that answers through the message tool ends
with a leaf control that points at the merging manager's own leaf. When
that manager is behind a peer run on the same transcript, the row moves
the active branch back to the pre-run yield marker and every later
prompt loses the completion exchange; the agent then tells the user the
sub-agent is still running.

Skip the navigation write when a merged transcript row or opaque link
has a parent this manager never saw. Such a row proves the manager's
leaf is stale, so the file keeps its natural leaf. Merges whose rows
descend from the lane's own leaf still write the restoring control, so
delivery mirrors stay out of the prompt as before.

ENG-20103
@orswn
orswn requested a review from a team September 16, 2026 14:04
@claude

claude Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@orswn

orswn commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

/cr

@claude

claude Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

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

cubic analysis

All reported issues were addressed across 2 files

Linked issue analysis

Linked issue: ENG-20103: Boon Agent: agent forgets a sub-agent's completed result on the next turn after answering through the message tool

Status Acceptance criteria Notes
✅ After a message-tool sub-agent completion, the next compiled context contains the completion prompt and agent reply. The PR reports a live verification where the next prompt compiled the completion prompt and result; the regression test also verifies the peer turn remains in rebuilt context.
✅ Asking what the sub-agent reported returns the reported result rather than saying it is still running. The PR reports a live follow-up prompt receiving the exact reported text and time.
✅ Delivery mirror rows written after a visible reply remain out of model context. The change preserves the restoring leaf for healthy merges and the regression setup models a delivery mirror whose visible peer reply remains active while the mirror is not made part of the context.
⚠️ Ordinary turns and completion runs ending with sessions_yield behave as before. The PR explicitly states these paths are unchanged and reports broad related test suites passing, but the provided diff does not add focused coverage for both ordinary turns and sessions_yield completion runs.
✅ A regression test reproduces the lost-context transcript shape and fails on the current fork. A targeted test constructs the yield marker, peer completion turn, and delivery mirror, and the PR provides the pre-fix assertion failure and passing result after the fix.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

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

Review — APPROVE (augusteo / Samwise sweep)

ENG-20103 — fix(sessions): sub-agent result forgotten after completion run answers through the message tool

Correctness ✅

  • The drift detection is ordered correctly: isKnownMergeParentId(sourceEntry.parentId) is evaluated against the entry's original parent before the entry is reparented to sideBranchParentId and inserted into byId, so a mirror whose parent is a peer-run row flags drift exactly as intended, while batch-internal chains (later rows parented to earlier rows in the same merge) resolve as known because earlier entries land in byId as the loop proceeds.
  • Global metadata (custom, label, session_info) is correctly excluded from the drift check — those resolve outside the active branch, matching the PR description.
  • The guard at the persist gate skips only the leaf navigation write; the in-memory merge, opaqueParentsById bookkeeping, and promptReleasedSideBranchParentId advancement all still run, so subsequent merges chain correctly off the merged rows.
  • Extending sawUnknownMergeParent to the unresolved-leaf-control path (!leafState) is the right conservative call — if a merged navigation control can't be resolved, writing our own restoring control on top would be guessing.
  • Healthy-merge behavior preserved: a mirror parented to the lane's own assistant row still satisfies isKnownMergeParentId, so the restoring leaf write and the existing "side delivery stays out of the prompt" behavior (covered by the pre-existing test just above) are unchanged.

Tests ✅

  • The new test reproduces the exact production scenario end-to-end: yield marker → peer run appends a full turn → mirror merged with persistLeaf: true → asserts no leaf row is written, the reopened session's leaf is not the stale yield marker, the peer turn is visible in buildSessionContext(), and the follow-up user turn descends from peer-mirror. Strong coverage.

Security ✅

  • No user-input handling, no new persistence surface beyond skipping a write. Nothing to flag.

Notes (non-blocking)

  • Most CI check-runs were still queued at review time (the completed ones are green) — worth confirming the suite goes green before merge.
  • Acknowledged non-goal: transcripts already carrying a stale leaf row aren't repaired by this; stops new ones only. Fine as scoped.

Clean, minimal, well-reasoned fix. Approving on 6224b909.

@orswn
orswn merged commit b980148 into boon Sep 16, 2026
145 of 147 checks passed
@orswn
orswn deleted the okka/completion-run-leaf-reset branch September 16, 2026 15:05

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

Review: ENG-20103 — completion-run leaf reset (#225)

Verdict: Approve. Covers head 6224b909 specifically (cubic's pass reviewed 0a214cf2; the delta since is +13 lines of extra test assertions only).

What I verified in code (not just the diff)

  1. The merge-batch shape the fix relies on is the designed one. classifyPromptReleasedSessionLines (attempt.session-lock.ts) only accepts transcript-only assistant rows (delivery-mirror / gateway-injected) as mergeable message lines when not validating owned writes; a peer run's regular user/assistant rows are intentionally not mergeable through this path. So "the mirror is the only row this manager merges, with a parent it has never seen" is the real production shape, and the test models it faithfully.
  2. The guard can only suppress a navigation write, never corrupt data. Merged entries are pushed/indexed regardless; only the restoring leaf control is skipped. A missed detection degrades to the old behavior, not a new failure mode.
  3. Healthy merges stay pinned. The existing applies merged leaf controls across separate callbacks / side-delivery tests assert the restoring control is still written when the mirror's parent is the lane's own reply, and the mirror stays out of context. 96/96 session-manager tests pass locally (see below).
  4. Skipping the leaf write cannot leak the mirror into model context. The natural leaf becomes the mirror row (it has no appendMode:"side" — confirmed the writer at transcript-append.ts:698 only marks side when the file is already in side mode), but the prompt path drops transcript-only assistant rows via normalizeAssistantReplayContent (attempt.ts:4780) keyed on the openclaw/delivery-mirror marker, independent of branch position.
  5. Intra-batch chains don't false-positive: byId is updated as the loop progresses, so a batch containing its own ancestors resolves. Global metadata rows (custom/label/session_info) are correctly excluded — they resolve outside the active branch. The new sawUnknownMergeParent = true on unresolvable peer leaf controls is consistent: an unresolvable navigation target means the peer navigated somewhere this manager can't see.
  6. RED-GREEN verified locally: the new test fails against base session-manager.ts with exactly the PR's reported assertion (a leaf row targeting the yield marker is written), and passes with the fix.

Local verification

  • session-manager.test.ts (+ matched sibling): 96 passed
  • attempt.session-lock.test.ts, transcript.test.ts, transcript-tree.test.ts, session-file-repair.test.ts, session-transcript-runtime.test.ts, replay-history.test.ts (+ matched siblings): 399 passed / 8 files
  • Reviewed at 6224b909; worktree install pnpm install --frozen-lockfile, vitest run on the touched suites.
  • CI status is not independently verifiable from this token (check-runs 403) — taking the reported green as stated. Review posts as augusteo.

One open question (non-blocking)

The expectedPublishedEntries path sets allowAnyMessage: true (attempt.session-lock.ts:790), so same-process owned writes can merge regular peer rows. If a peer completion run shares the gateway process and its turn rows + mirror ever arrive in one validated batch, every parent resolves intra-batch and the restoring leaf would still be written targeting the stale leaf. Was that path ruled out for the Boon Web topology (e.g. the peer turn always arrives via requiresReload/full reload instead)? If reachable, it may be worth a follow-up — not a blocker for this fix, which addresses the observed incident shape.

Nits (non-blocking)

  • None. The stated non-goals (no repair of already-damaged transcripts, stale-lane full-rewrite path unchanged) are accurately scoped.

orswn added a commit that referenced this pull request Sep 17, 2026
Routine release chore for the next train. Root package.json to
2026.6.11-boon.44, plugin package.json files synced via
scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files
regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a
CHANGELOG.md section for boon.44.

Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately
published plugin source changed since boon.43 (#227 moves
diagnostics-otel into the gateway bundle), so a gateway roll delivers
the whole release.
orswn added a commit that referenced this pull request Sep 17, 2026
…226)

Routine release chore for the next train. Root package.json to
2026.6.11-boon.44, plugin package.json files synced via
scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files
regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a
CHANGELOG.md section for boon.44.

Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately
published plugin source changed since boon.43 (#227 moves
diagnostics-otel into the gateway bundle), so a gateway roll delivers
the whole release.
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.

3 participants