Skip to content

fix(subagents): show child delivery notices as child results, not failed replies - #204089

Merged
obviyus merged 6 commits into
mainfrom
fix/child-delivery-notice-ux
Nov 23, 2026
Merged

obviyus merged 6 commits into
mainfrom
fix/child-delivery-notice-ux

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a child (subagent) result could not be handed to its parent turn, recordRequiredCompletionNotice wrote the notice as customType run-failed-before-reply. The Control UI renders that type as a failed reply: a red "Couldn't finish this reply" badge with "Report a bug". This happened even when no reply was running and the child ended days earlier.

Seen in production. Child deliveries suspended by the old store-path veto (removed in #200760) stayed suspended. They expired after the 7-day retention, and the expiry sweep put red failed-reply badges under unrelated later turns. One notice was for a child that had been killed on purpose and had no captured result. The badge showed a raw session key, a run id, the word killed, and the text "…then retry or resend your request", but there was no request to retry.

#200760 fixed the root cause of the suspension. This PR fixes how the remaining failure, expiry and idle-expiry notices are shown.

Solution

All changes are in the notice owner, recordRequiredCompletionNotice, and its copy:

  • Killed or cancelled child with no captured result → no notice. The function filters each batch member: endedReason === "subagent-killed", not a steer restart, and no captured result text. Live siblings in the same batch still get their notice. A killed child that holds a captured result still shows it. There are no per-caller checks.
  • Child-delivery notices use customType: "subagent-completion", the child-result row kind the function already writes for kind === "result". No UI reader treats this type as a run error, so the red badge and "Report a bug" go away. No new customType. Old stored rows render as before.
  • Model context: unchanged. The design planned excludeFromContext: true for all notices. That rested on packages/agent-core/.../session.ts excluding every run-failed-before-reply row. That is one reader only. The SQLite model-context projection and cli-runner/session-history.ts read only excludeFromContext. So an unconsumed failure notice did reach the parent model, as docs/tools/subagents/announce.md documents ("available to the requester model if it never consumed the original result"). The existing conditional stays as it was: the notice enters model context only while a batch member's result is unconsumed (local review finding, round 3).
  • Copy: " finished on UTC, but its result couldn't be added to this conversation automatically. Details are below." The heading makes no "saved result is below" claim, because a private completionTarget=parent handoff or an uncaptured child has only identity and status. Each child section starts with its session key and run id, then the label and status. The heading label is bounded to 200 characters, so a long label cannot push the ids out of the 512-character header or the 32,000-character limit (local review findings, rounds 1-3).
  • Yielded requester (a requester that ended its turn waiting on the child): stays a run error, because no reply was made. Its copy (child_completion_delivery_failed) now reads "This reply was waiting for a child agent whose result couldn't be added to this conversation automatically. Check the child session for its outcome." It no longer says "retry or resend your request".

Accepted edge cases (no code for them):

  • A yielded batch now writes a run-error row and a separate child row.
  • A retry across the upgrade can duplicate one legacy row, because dedupe is scoped per customType.

Impact

  • Child-delivery failure, expiry and idle-expiry notices show as neutral rows, not as failed replies.
  • An intentional kill writes no notice.
  • No schema, stored-row, protocol or dependency change.

Evidence

  • New unit test subagent-registry.store-replaced.test.ts › "records a child-result notice for live children and none for a killed child":
    • Base f595f0237a35: red. It writes the incident row, run-failed-before-reply, "…retry or resend your request", Child agent:main:subagent:killed … killed.
    • Head: green.
  • Updated the existing tests that pinned run-failed-before-reply for child-delivery notices. The gateway and e2e assertions that check for no failed reply stay as they are.
  • ocx test on touched tests and every test that imports a changed source or test-support file (29 files). oxfmt and oxlint pass. pnpm check:changed passes except the dead export scan, which flags scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs. That file is not in this diff.
  • Not ours:
    • subagent-registry-worker.test.ts › "releases serialized payloads…" (GC retention) fails on base f595f0237a35 too.
    • subagent-registry-lifecycle.test.ts failed on different tests in two loaded runs. It passed alone on head and on base.
  • Real-product E2E: isolated scratch Gateway from source, real agent turns on Claude through the Control UI. The agent spawned two children; state was edited so one child was killed with no result and both deliveries were suspended for more than 7 days. Then the real sweeper ran discardExpiredSubagentDelivery.
    • Before (base): both children show the red "Couldn't finish this reply" + "Report a bug", the killed one included.
    • After (head): the ok child shows a neutral System row with its result and no badge. The killed child writes no row.

obviyus and others added 2 commits November 23, 2026 19:17
- Write child delivery failure/expiry notices as subagent-completion, excluded from model context
- Skip the notice for killed children with no captured result, per batch member
- Replace 'retry or resend your request' child-delivery copy

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR renders child-delivery failures as neutral child-result rows and suppresses notices for intentionally killed children without captured output.

Example: A completion batch contains the child labeled Release notes and an intentionally killed child with no output.

  • Before: The conversation receives a failed-reply notice containing both children.
  • After: A neutral child-result row shows Release notes and omits the killed child.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has clear value and green checks, but contains a concrete recovery-copy defect and lacks after-fix product proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Old child-delivery outcomes appear beneath later turns as failed replies, including intentionally killed children with nothing to show.
Reason: The maintainer-authored direction addresses an observed misleading error presentation using an existing transcript row type.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR addresses a concrete, still-present mismatch between child-delivery outcomes and failed-reply presentation.

Priority: P2
Reviewed head: 739812470d63514e49c55a5ded2b34b6c464004f

Before merge

  • Avoid promising saved answers when no answer is displayed (P2) - A failed child can have no captured text, and private requester handoffs deliberately set captured to an empty string at lines 49–51. Those supported inputs produce only identity/status text, yet the new heading promises that their saved results are below. The changed child_completion_delivery_failed copy also unconditionally claims that the saved result is shown. Qualify both messages so they describe any available output without promising an answer that is missing or intentionally private, and retain useful recovery guidance for the no-output case.

Findings

  • [P2] Avoid promising saved answers when no answer is displayed — src/agents/subagents/completion/subagent-completion-notice-text.ts:29-30

Tests

  • Missing end-to-end proof: Provide redacted after-fix Control UI screenshots or a recording showing a neutral saved-result notice and suppression of an empty killed-child notice, including a live sibling.
Agent review details

How this fits together

The subagent completion owner receives terminal delivery outcomes and captured child results, then appends visible notices to the requester transcript for Control UI rendering.

flowchart TD
  A[Terminal child outcomes] --> B[Completion notice owner]
  B --> C[Filter empty intentional stops]
  C --> D[Format public saved results]
  D --> E[Requester transcript]
  E --> F[Control UI child result row]
Loading

Technical review

Best possible solution:

Keep the existing notice owner and neutral row type, while making recovery copy truthful when saved output is absent or private.

Do we have a high-confidence way to reproduce the issue?

Current-main source selects the failed-reply custom type for these notices, and the supplied production screenshots show the resulting badge; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Changing presentation at the existing notice producer is the smallest complete approach, and the per-member filter preserves live siblings without adding another delivery owner.

Full review comments:

  • [P2] Avoid promising saved answers when no answer is displayed — src/agents/subagents/completion/subagent-completion-notice-text.ts:29-30
    A failed child can have no captured text, and private requester handoffs deliberately set captured to an empty string at lines 49–51. Those supported inputs produce only identity/status text, yet the new heading promises that their saved results are below. The changed child_completion_delivery_failed copy also unconditionally claims that the saved result is shown. Qualify both messages so they describe any available output without promising an answer that is missing or intentionally private, and retain useful recovery guidance for the no-output case.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 59ae4e0f760f.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/subagents/completion/subagent-completion-captured-notice.test.ts src/agents/subagents/registry/subagent-registry.store-replaced.test.ts
  • pnpm test src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts
  • pnpm check:changed --base f595f02
  • git diff --check

What I checked:

PR surface

Source +10, Tests +50. Total +60 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 29 19 +10
Tests 5 59 9 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 88 28 +60

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Misleading historical child-delivery notices create limited user confusion without establishing a broken current reply or urgent delivery regression.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Misleading historical child-delivery notices create limited user confusion without establishing a broken current reply or urgent delivery regression.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 23, 2026, 9:16 AM ET / 14:16 UTC.

@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

After (head 7422135, same real-sweeper journey as the before screenshots in the PR body): the ok child's expiry notice is a neutral System row with no red badge and no Report a bug. The killed child (no captured result) writes no row; only one notice exists in the conversation.

After: ok child expiry notice renders as neutral child result row

After: killed child has no notice; only the ok child row appears

@obviyus
obviyus merged commit d66eeff into main Nov 23, 2026
195 of 198 checks passed
@obviyus
obviyus deleted the fix/child-delivery-notice-ux branch November 23, 2026 15:18
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as d66eeff. Bug: child delivery failure/expiry notices were written as run-failed-before-reply, so the Control UI showed a red "Couldn't finish this reply" + Report a bug, also for children killed on purpose. Fix: the notice owner writes the existing subagent-completion row kind, skips killed children with nothing captured, and drops the "retry or resend your request" copy. Model-context behavior is unchanged. Proof: new unit test red on base, green on head. Real-sweeper Control UI before/after above. CI green, local review clean. The ui-e2e header-geometry failure passed on one rerun; it imports no changed file.

tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…203176)

## Problem

A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back.

Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class.

## Change

Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once.

- **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake.
- **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished.
- **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded.
- **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended.
- **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure.
- **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority.
- **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried.
- **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once.
- `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate.
- Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`.

Product decisions, under the rules "no stranded user" and "no false done":
- A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings.
- A followup caller gets one reply, after all results are in. The session itself is still woken for each result.

## Evidence

**Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it.
- Base `eb7ca3d33375`: both cases red (`expected [] to have a length of 1`: no wake).
- Head: both cases green.

**Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once).

**Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child).

**Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields.

| | alpha ended | first parent wake | beta yielded | beta ended | second parent wake |
|---|---|---|---|---|---|
| base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none |
| head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) |

The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change.

**Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `eb7ca3d33375` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions).

**Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base.

## Size

Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code.

## Accepted edge cases

- If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today.
- A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion.

## Merge danger

- **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran.
- **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 09d956b)

Release adaptation: Kept stable QA Gateway fixture lifecycle; filtered intentionally silent partial-result wakes.

Companion audit: #203222 selected. #204249, #204069, #204048, #203892, #202513, #198960 not applicable (refactors/test cleanup); #204260, #204178, #204098, #204089, #203839, #203271 missing in lane and not prerequisites.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…led replies (openclaw#204089)

## Problem

When a child (subagent) result could not be handed to its parent turn, `recordRequiredCompletionNotice` wrote the notice as customType `run-failed-before-reply`. The Control UI renders that type as a failed reply: a red "Couldn't finish this reply" badge with "Report a bug". This happened even when no reply was running and the child ended days earlier.

Seen in production. Child deliveries suspended by the old store-path veto (removed in openclaw#200760) stayed suspended. They expired after the 7-day retention, and the expiry sweep put red failed-reply badges under unrelated later turns. One notice was for a child that had been **killed** on purpose and had no captured result. The badge showed a raw session key, a run id, the word `killed`, and the text "…then retry or resend your request", but there was no request to retry.

openclaw#200760 fixed the root cause of the suspension. This PR fixes how the remaining failure, expiry and idle-expiry notices are shown.

## Solution

All changes are in the notice owner, `recordRequiredCompletionNotice`, and its copy:

- **Killed or cancelled child with no captured result → no notice.** The function filters each batch member: `endedReason === "subagent-killed"`, not a steer restart, and no captured result text. Live siblings in the same batch still get their notice. A killed child that holds a captured result still shows it. There are no per-caller checks.
- **Child-delivery notices use `customType: "subagent-completion"`**, the child-result row kind the function already writes for `kind === "result"`. No UI reader treats this type as a run error, so the red badge and "Report a bug" go away. No new customType. Old stored rows render as before.
- **Model context: unchanged.** The design planned `excludeFromContext: true` for all notices. That rested on `packages/agent-core/.../session.ts` excluding every `run-failed-before-reply` row. That is one reader only. The SQLite model-context projection and `cli-runner/session-history.ts` read only `excludeFromContext`. So an unconsumed failure notice did reach the parent model, as `docs/tools/subagents/announce.md` documents ("available to the requester model if it never consumed the original result"). The existing conditional stays as it was: the notice enters model context only while a batch member's result is unconsumed (local review finding, round 3).
- **Copy:** "<child label> finished on <date> UTC, but its result couldn't be added to this conversation automatically. Details are below." The heading makes no "saved result is below" claim, because a private `completionTarget=parent` handoff or an uncaptured child has only identity and status. Each child section starts with its session key and run id, then the label and status. The heading label is bounded to 200 characters, so a long label cannot push the ids out of the 512-character header or the 32,000-character limit (local review findings, rounds 1-3).
- **Yielded requester** (a requester that ended its turn waiting on the child): stays a run error, because no reply was made. Its copy (`child_completion_delivery_failed`) now reads "This reply was waiting for a child agent whose result couldn't be added to this conversation automatically. Check the child session for its outcome." It no longer says "retry or resend your request".

Accepted edge cases (no code for them):

- A yielded batch now writes a run-error row and a separate child row.
- A retry across the upgrade can duplicate one legacy row, because dedupe is scoped per customType.

## Impact

- Child-delivery failure, expiry and idle-expiry notices show as neutral rows, not as failed replies.
- An intentional kill writes no notice.
- No schema, stored-row, protocol or dependency change.

## Evidence

- New unit test `subagent-registry.store-replaced.test.ts` › "records a child-result notice for live children and none for a killed child":
  - Base `3baee0bb1290`: **red**. It writes the incident row, `run-failed-before-reply`, "…retry or resend your request", `Child agent:main:subagent:killed … killed`.
  - Head: green.
- Updated the existing tests that pinned `run-failed-before-reply` for child-delivery notices. The gateway and e2e assertions that check for *no* failed reply stay as they are.
- `ocx test` on touched tests and every test that imports a changed source or test-support file (29 files). oxfmt and oxlint pass. `pnpm check:changed` passes except the dead export scan, which flags `scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`. That file is not in this diff.
- Not ours:
  - `subagent-registry-worker.test.ts` › "releases serialized payloads…" (GC retention) fails on base `3baee0bb1290` too.
  - `subagent-registry-lifecycle.test.ts` failed on different tests in two loaded runs. It passed alone on head and on base.
- Real-product E2E: isolated scratch Gateway from source, real agent turns on Claude through the Control UI. The agent spawned two children; state was edited so one child was killed with no result and both deliveries were suspended for more than 7 days. Then the real sweeper ran `discardExpiredSubagentDelivery`.
  - Before (base): both children show the red "Couldn't finish this reply" + "Report a bug", the killed one included.
  - After (head): the ok child shows a neutral System row with its result and no badge. The killed child writes no row.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…led replies (#204089)

When a child (subagent) result could not be handed to its parent turn, `recordRequiredCompletionNotice` wrote the notice as customType `run-failed-before-reply`. The Control UI renders that type as a failed reply: a red "Couldn't finish this reply" badge with "Report a bug". This happened even when no reply was running and the child ended days earlier.

Seen in production. Child deliveries suspended by the old store-path veto (removed in #200760) stayed suspended. They expired after the 7-day retention, and the expiry sweep put red failed-reply badges under unrelated later turns. One notice was for a child that had been **killed** on purpose and had no captured result. The badge showed a raw session key, a run id, the word `killed`, and the text "…then retry or resend your request", but there was no request to retry.

All changes are in the notice owner, `recordRequiredCompletionNotice`, and its copy:

- **Killed or cancelled child with no captured result → no notice.** The function filters each batch member: `endedReason === "subagent-killed"`, not a steer restart, and no captured result text. Live siblings in the same batch still get their notice. A killed child that holds a captured result still shows it. There are no per-caller checks.
- **Child-delivery notices use `customType: "subagent-completion"`**, the child-result row kind the function already writes for `kind === "result"`. No UI reader treats this type as a run error, so the red badge and "Report a bug" go away. No new customType. Old stored rows render as before.
- **Model context: unchanged.** The design planned `excludeFromContext: true` for all notices. That rested on `packages/agent-core/.../session.ts` excluding every `run-failed-before-reply` row. That is one reader only. The SQLite model-context projection and `cli-runner/session-history.ts` read only `excludeFromContext`. So an unconsumed failure notice did reach the parent model, as `docs/tools/subagents/announce.md` documents ("available to the requester model if it never consumed the original result"). The existing conditional stays as it was: the notice enters model context only while a batch member's result is unconsumed (local review finding, round 3).
- **Copy:** "<child label> finished on <date> UTC, but its result couldn't be added to this conversation automatically. Details are below." The heading makes no "saved result is below" claim, because a private `completionTarget=parent` handoff or an uncaptured child has only identity and status. Each child section starts with its session key and run id, then the label and status. The heading label is bounded to 200 characters, so a long label cannot push the ids out of the 512-character header or the 32,000-character limit (local review findings, rounds 1-3).
- **Yielded requester** (a requester that ended its turn waiting on the child): stays a run error, because no reply was made. Its copy (`child_completion_delivery_failed`) now reads "This reply was waiting for a child agent whose result couldn't be added to this conversation automatically. Check the child session for its outcome." It no longer says "retry or resend your request".

Accepted edge cases (no code for them):

- A yielded batch now writes a run-error row and a separate child row.
- A retry across the upgrade can duplicate one legacy row, because dedupe is scoped per customType.

- Child-delivery failure, expiry and idle-expiry notices show as neutral rows, not as failed replies.
- An intentional kill writes no notice.
- No schema, stored-row, protocol or dependency change.

- New unit test `subagent-registry.store-replaced.test.ts` › "records a child-result notice for live children and none for a killed child":
  - Base `f595f0237a35`: **red**. It writes the incident row, `run-failed-before-reply`, "…retry or resend your request", `Child agent:main:subagent:killed … killed`.
  - Head: green.
- Updated the existing tests that pinned `run-failed-before-reply` for child-delivery notices. The gateway and e2e assertions that check for *no* failed reply stay as they are.
- `ocx test` on touched tests and every test that imports a changed source or test-support file (29 files). oxfmt and oxlint pass. `pnpm check:changed` passes except the dead export scan, which flags `scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`. That file is not in this diff.
- Not ours:
  - `subagent-registry-worker.test.ts` › "releases serialized payloads…" (GC retention) fails on base `f595f0237a35` too.
  - `subagent-registry-lifecycle.test.ts` failed on different tests in two loaded runs. It passed alone on head and on base.
- Real-product E2E: isolated scratch Gateway from source, real agent turns on Claude through the Control UI. The agent spawned two children; state was edited so one child was killed with no result and both deliveries were suspended for more than 7 days. Then the real sweeper ran `discardExpiredSubagentDelivery`.
  - Before (base): both children show the red "Couldn't finish this reply" + "Report a bug", the killed one included.
  - After (head): the ok child shows a neutral System row with its result and no badge. The killed child writes no row.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit d66eeff)

Release adaptation: port the child notice assertion into the stable split wake fixture without changing cohort tests. #204748 is a focused fixture clock companion; #204178 and #204260 are later history redesigns, and other audit matches address separate features or fixtures.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant