Skip to content

fix: tell the user when a finished subagent's report can't start in their chat - #207194

Merged
obviyus merged 2 commits into
mainfrom
core/failed-announce-visible
Nov 28, 2026
Merged

obviyus merged 2 commits into
mainfrom
core/failed-announce-visible

Conversation

@obviyus

@obviyus obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

When a subagent finishes, OpenClaw runs a turn in the parent chat to report the result. If that turn fails before it starts (for example, the chat's access program is not available for the model), the user in the channel sees nothing. The completion ends undelivered with only a log warning.

User Impact

When a channel-delivered subagent report turn (settle or announce) fails before it starts, the user now gets one failure notice in that channel: "OpenClaw couldn't finish this request…". This is the notice requester turns already get when model-runtime admission refuses them (#171021), which keeps working for every delivered turn. A direct-message completion that owes the user a reply instead receives the child's result as plain text. Unchanged: ordinary chat turns keep their own failure surfaces for other errors; a turn that started and then failed gets no notice and no resend, because its reply may already have reached the user; private and internal runs, cancelled runs and revoked sources stay silent.

Why This Change Was Made

The command runner (run-embedded-attempt.ts) owns the channel-visible failure notice for a turn that never started. #171021 qualified it only for a typed initial admission refusal (a wrapper class plus a first-candidate check), so it could prove the turn had committed no work. The runner already tracks that fact per run: executionStarted is set by the runtime's lifecycle start, and the runner already reports providerStarted: false on its lifecycle error when it is false. The qualifier is now !executionStarted plus either a subagent completion turn (any pre-start failure, on any fallback candidate) or a runtime admission refusal (any delivered turn, as before). A live model switch still retries. The PreparedModelRuntimeInitialRunAdmissionError wrapper and the candidate counter existed only for the old qualifier, so they are removed.

Direct-message completions run with deliver: false, so no command notice reaches them. For those, the rethrown error carries providerStarted: false, and resolveFailedAnnounceResponse takes its existing text fallback on that fact. It now reads a structural incomplete_result code instead of matching a message regex. The cases do not overlap: with deliver: true the command returns a failed result, so the announce error path is not reached.

Not changed, on purpose:

  • No transcript-only notice (recordGatewaySessionRunFailure or chat inject): those never reach channel users.
  • No resend on "any failure without send evidence". Message-tool send evidence exists only on successful results, so that rule would duplicate replies the model already sent by tool.

Known gaps, named but not coded:

  • Gateway shutdown aborts every run with one shared reason object, so the mark is skipped when the run's abort signal has fired.
  • The notice copy is generic. Billing and rate-limit specific copy (resolveAgentRunFailureNotice) does not apply to this path, as before.
  • The WebSocket callGateway path loses the error cause, so there an incomplete model response no longer triggers text. Completions dispatch in-process.
  • A custom CLI backend that sends through loopback message delivery without streaming tool starts could still get a duplicate. Bundled backends stream tool starts.

Evidence

  • Real access gate, in-process (throwaway test, not committed): the catalog advertised one access program and the session requested another. The agent dispatch (deliver: false) rejected with GatewayClientRequestError → cause FailoverError(OPENAI_ACCESS_PROGRAM_UNAVAILABLE, providerStarted: false), with 0 provider requests.
  • agent-command.admission-failure.test.ts: on a completion turn, an ordinary error, a missing runtime owner and a refusal after a live model switch each deliver one channel notice; a runtime refusal of an ordinary chat turn still does. Private, internal, cancelled, revoked-source, started-execution runs and an ordinary chat error deliver nothing. Owner mark: set before start, absent after start. The existing sent and failed delivery receipts still pass.
  • subagent-announce-obligation.test.ts: a pre-start failure and an incomplete model response choose the text fallback. A turn that started and then failed does not.
  • Red on the merge base 7e7e84039907 for the owner mark and the obligation cases (run for the previous head of this branch).
  • Proof tier: vitest-source. I did not run a live channel end to end.

… it starts

- The command owner already reports providerStarted: false on its lifecycle error when
  execution never started; the rethrown error now carries the same fact, except for a
  shared shutdown abort reason.
- resolveFailedAnnounceResponse takes the existing text fallback on that fact or on a
  structural incomplete_result code; the message regex is gone.
- A turn that started and then failed still gets no resend, since its reply may already
  have been sent by tool.
…before it starts

- The command failure reply (#171021) now qualifies on the run-scoped executionStarted fact.
  A subagent completion turn (settle or announce) that fails before it starts, on any
  fallback candidate, gets one channel notice; a runtime admission refusal still gets it on
  any delivered turn. A live model switch still retries; other chat errors are unchanged.
- PreparedModelRuntimeInitialRunAdmissionError and the candidate counter existed only for
  the old qualifier; they and the orchestrator wrapper are removed.
- deliver: false direct-message completions keep the text fallback from the previous commit.
@clawsweeper

clawsweeper Bot commented Nov 28, 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR sends a channel failure notice or direct-message child result when a subagent reporting turn fails before execution starts.

Example: A finished child's reporting turn for Discord channel 123 fails before execution because the selected access program is unavailable.

  • Before: The channel receives no immediate outcome.
  • After: The channel receives one existing OpenClaw failure notice while the run remains failed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified blocking defect, but required proof of the changed user-visible delivery behavior is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A finished subagent's reporting turn can fail before execution and leave the channel user without an immediate outcome.
Reason: The maintainer-authored direction addresses silent feedback failure through existing delivery surfaces while preserving silence for cancelled, internal and already-started runs.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a current gap in completion feedback, has maintainer-approved direction through its authorship, and introduces no definite code defect found in this review.

Reviewed head: 7ec8889d61b2ac100f72a18ef5eff11d108114dc

Before merge

None.

Findings

None.

Agent review details

How this fits together

Subagent completion delivery starts a requester turn through Gateway dispatch; the command runner records execution and delivery outcomes, while the announce owner decides whether to send the child's result directly.

flowchart TD
  A[Finished subagent] --> B[Completion delivery owner]
  B --> C[Gateway requester turn]
  C --> D[Command execution owner]
  D --> E[Normal channel finalization]
  D --> F[Error with execution fact]
  F --> B
  B --> G[Direct message text fallback]
Loading

Technical review

Best possible solution:

Use the existing command finalizer for pre-start channel notices and the existing announce decision owner for direct-message fallback, preserving history settlement and transport receipts.

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

Current-main source shows an ordinary pre-start completion error bypassing the narrowly typed notice path; the author also reports a real access-gate rejection, but this read-only review ran no target code.

Is this the best way to solve the issue?

The change uses the existing execution fact, delivery finalizer and fallback policy owner, removing the obsolete wrapper without adding a competing delivery path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Initial-admission wrapper and first-candidate restriction changes intended behavior with a stated reason (612bb71: Prove that execution had committed no work before synthesizing a failure notice and handing delivery to ordinary finalization.)
  • Announce failure classification changes intended behavior with a stated reason (ae6f813: The split preserved the existing incomplete-response text fallback; local searches across earlier paths encountered unavailable old objects, leaving its original introduction unknown.)
  • Central completion decision ownership keeps the original intent (811f999: Keep completion policy in one owner while transport adapters execute decisions and lifecycle owners persist outcomes.)
  • Requester-history settlement changes intended behavior with a stated reason (cded11f: Retain a child's end state as model-visible history when its requester turn cannot consume it, without delivery retry ladders or visible history dumps.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +17, Tests +109, Docs +7. Total +133 across 12 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 62 45 +17
Tests 5 169 60 +109
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 238 105 +133

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 rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 27, 2026, 10:53 PM ET / November 28, 2026, 03:53 UTC.

@obviyus
obviyus merged commit 17e2ec9 into main Nov 28, 2026
145 checks passed
@obviyus
obviyus deleted the core/failed-announce-visible branch November 28, 2026 04:27
@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 17e2ec9.

  • Bug: when a parent's subagent report turn failed before it started (for example, an access program the model's account doesn't offer), the child's result was lost and the user saw nothing.
  • Fix: the command runner treats "the turn never started" as one fact per run. Delivered channel turns get the existing failure notice; direct-message completions get the child's result as text. Turns that already started are not resent.
  • Proof: QA Lab end to end with a real Gateway and qa-channel. On main the direct chat showed only "Worker started."; on this head the child's result appeared once, and the parent made 0 provider requests. Unit and integration tests fail on main and pass here; CI green; local review clean.

ArcueidMP added a commit to ArcueidMP/openclaw that referenced this pull request Nov 28, 2026
Main stopped wrapping initial runtime admission refusals in run-orchestrator
(openclaw#207194). Keep releasing the recovery probe when the first runtime
acquisition is refused by admission, and rethrow the refusal unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…heir chat (openclaw#207194)

## What Problem This Solves

When a subagent finishes, OpenClaw runs a turn in the parent chat to report the result. If that turn fails before it starts (for example, the chat's access program is not available for the model), the user in the channel sees nothing. The completion ends undelivered with only a log warning.

## User Impact

When a channel-delivered subagent report turn (settle or announce) fails before it starts, the user now gets one failure notice in that channel: "OpenClaw couldn't finish this request…". This is the notice requester turns already get when model-runtime admission refuses them (openclaw#171021), which keeps working for every delivered turn. A direct-message completion that owes the user a reply instead receives the child's result as plain text. Unchanged: ordinary chat turns keep their own failure surfaces for other errors; a turn that started and then failed gets no notice and no resend, because its reply may already have reached the user; private and internal runs, cancelled runs and revoked sources stay silent.

## Why This Change Was Made

The command runner (`run-embedded-attempt.ts`) owns the channel-visible failure notice for a turn that never started. openclaw#171021 qualified it only for a typed initial admission refusal (a wrapper class plus a first-candidate check), so it could prove the turn had committed no work. The runner already tracks that fact per run: `executionStarted` is set by the runtime's lifecycle `start`, and the runner already reports `providerStarted: false` on its lifecycle error when it is false. The qualifier is now `!executionStarted` plus either a subagent completion turn (any pre-start failure, on any fallback candidate) or a runtime admission refusal (any delivered turn, as before). A live model switch still retries. The `PreparedModelRuntimeInitialRunAdmissionError` wrapper and the candidate counter existed only for the old qualifier, so they are removed.

Direct-message completions run with `deliver: false`, so no command notice reaches them. For those, the rethrown error carries `providerStarted: false`, and `resolveFailedAnnounceResponse` takes its existing text fallback on that fact. It now reads a structural `incomplete_result` code instead of matching a message regex. The cases do not overlap: with `deliver: true` the command returns a failed result, so the announce error path is not reached.

Not changed, on purpose:

- No transcript-only notice (`recordGatewaySessionRunFailure` or chat inject): those never reach channel users.
- No resend on "any failure without send evidence". Message-tool send evidence exists only on successful results, so that rule would duplicate replies the model already sent by tool.

Known gaps, named but not coded:

- Gateway shutdown aborts every run with one shared reason object, so the mark is skipped when the run's abort signal has fired.
- The notice copy is generic. Billing and rate-limit specific copy (`resolveAgentRunFailureNotice`) does not apply to this path, as before.
- The WebSocket `callGateway` path loses the error cause, so there an incomplete model response no longer triggers text. Completions dispatch in-process.
- A custom CLI backend that sends through loopback message delivery without streaming tool starts could still get a duplicate. Bundled backends stream tool starts.

## Evidence

- End to end, real Gateway and qa-channel (QA Lab, mock provider; the failure happens before any provider call). A parent in a direct chat spawns a subagent. The parent is then switched to a provider whose API key is a missing secret, so its report turn fails before dispatch with `SecretSurfaceUnavailableError`.
  - Merge base `8bc436bfb55f`: the completion turn fails and "Subagent completion direct announce failed" is logged. The chat shows only the parent's "Worker started."; the child's result never arrives.
  - This branch at `7ec8889d61`: the chat shows "Worker started." and then the child's result text exactly once, through one direct-fallback receipt. The parent made 0 provider requests after the switch.
  - The scenario is not committed here; it can follow as a regression scenario.
- In-process run against the real access gate (throwaway test): the `agent` dispatch rejected with `GatewayClientRequestError` → cause `FailoverError(OPENAI_ACCESS_PROGRAM_UNAVAILABLE, providerStarted: false)`, with 0 provider requests.
- `agent-command.admission-failure.test.ts`: on a completion turn, an ordinary error, a missing runtime owner and a refusal after a live model switch each deliver one channel notice; a runtime refusal of an ordinary chat turn still does. Private, internal, cancelled, revoked-source, started-execution runs and an ordinary chat error deliver nothing. Owner mark: set before start, absent after start. The existing sent and failed delivery receipts still pass.
- `subagent-announce-obligation.test.ts`: a pre-start failure and an incomplete model response choose the text fallback. A turn that started and then failed does not.
- The new tests fail on the merge base and pass here; every silent case passes on both.
- Not run end to end: the group-chat notice path (covered by the command tests above).

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Preserve the existing requester restart reason in announce classification so unconsumed completed results remain pending for startup custody. Existing consumption receipts prevent replay; permanent refusals, explicit cancellation, and ambiguous sends retain their policies.

(cherry picked from commit b8b06c4)

Follow-ups: fca5133 fix: preserve child completion inputs across Gateway restarts (#208367) [not selected for this narrow backport]; b7967b2 fix: deliver a saved child answer after a Gateway crash (#207706) [not selected for this narrow backport]; 17e2ec9 fix: tell the user when a finished subagent's report can't start in their chat (#207194) [not selected for this narrow backport]; 811f999 refactor(subagents): centralize completion delivery decisions (#206383) [not selected for this narrow backport]; 50a6774 fix: retain channel requester when child completion resumes parent [separately ordered lane row]; d2699a8 chore: carry and enforce participant limits on admitted runs (#204847) [not selected for this narrow backport]; 57dd84b fix(agents): settle every undelivered child completion into history; drop delivery dispositions (#204260) [separately ordered lane row]; cded11f fix(agents): deliver a child's end state as parent history, not a turn obligation (#204178) [not selected for this narrow backport]; 92e92d7 fix: preserve restarted child results and gateway test ownership (#203839) [not selected for this narrow backport]; 09d956b fix(subagents): wake a yielded requester for each ready child result (#203176) [not selected for this narrow backport]; 9f35510 fix: retain child results behind live requester turns (#203198) [separately ordered lane row]; c23cd7f fix: preserve private child results during restart (#203156) [separately ordered lane row]

Release adaptation: Keep stable requester fixture setup and insert the two consumed/unconsumed restart cases without moving its existing lost-yield test.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…heir chat (#207194)

(cherry picked from commit 17e2ec9)

Release adaptation: Reuse stable command finalization for delivered completion turns that never start, preserve legacy ordinary-chat refusal conditions and do not reinterpret aggregate settlement failures.

Companion audit: Do not import the divergent fallback error-type and deleted announcement-obligation owner; no direct later reference follow-up identified.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…heir chat (#207194)

When a subagent finishes, OpenClaw runs a turn in the parent chat to report the result. If that turn fails before it starts (for example, the chat's access program is not available for the model), the user in the channel sees nothing. The completion ends undelivered with only a log warning.

When a channel-delivered subagent report turn (settle or announce) fails before it starts, the user now gets one failure notice in that channel: "OpenClaw couldn't finish this request…". This is the notice requester turns already get when model-runtime admission refuses them (#171021), which keeps working for every delivered turn. A direct-message completion that owes the user a reply instead receives the child's result as plain text. Unchanged: ordinary chat turns keep their own failure surfaces for other errors; a turn that started and then failed gets no notice and no resend, because its reply may already have reached the user; private and internal runs, cancelled runs and revoked sources stay silent.

The command runner (`run-embedded-attempt.ts`) owns the channel-visible failure notice for a turn that never started. #171021 qualified it only for a typed initial admission refusal (a wrapper class plus a first-candidate check), so it could prove the turn had committed no work. The runner already tracks that fact per run: `executionStarted` is set by the runtime's lifecycle `start`, and the runner already reports `providerStarted: false` on its lifecycle error when it is false. The qualifier is now `!executionStarted` plus either a subagent completion turn (any pre-start failure, on any fallback candidate) or a runtime admission refusal (any delivered turn, as before). A live model switch still retries. The `PreparedModelRuntimeInitialRunAdmissionError` wrapper and the candidate counter existed only for the old qualifier, so they are removed.

Direct-message completions run with `deliver: false`, so no command notice reaches them. For those, the rethrown error carries `providerStarted: false`, and `resolveFailedAnnounceResponse` takes its existing text fallback on that fact. It now reads a structural `incomplete_result` code instead of matching a message regex. The cases do not overlap: with `deliver: true` the command returns a failed result, so the announce error path is not reached.

Not changed, on purpose:

- No transcript-only notice (`recordGatewaySessionRunFailure` or chat inject): those never reach channel users.
- No resend on "any failure without send evidence". Message-tool send evidence exists only on successful results, so that rule would duplicate replies the model already sent by tool.

Known gaps, named but not coded:

- Gateway shutdown aborts every run with one shared reason object, so the mark is skipped when the run's abort signal has fired.
- The notice copy is generic. Billing and rate-limit specific copy (`resolveAgentRunFailureNotice`) does not apply to this path, as before.
- The WebSocket `callGateway` path loses the error cause, so there an incomplete model response no longer triggers text. Completions dispatch in-process.
- A custom CLI backend that sends through loopback message delivery without streaming tool starts could still get a duplicate. Bundled backends stream tool starts.

- End to end, real Gateway and qa-channel (QA Lab, mock provider; the failure happens before any provider call). A parent in a direct chat spawns a subagent. The parent is then switched to a provider whose API key is a missing secret, so its report turn fails before dispatch with `SecretSurfaceUnavailableError`.
  - Merge base `7e7e84039907`: the completion turn fails and "Subagent completion direct announce failed" is logged. The chat shows only the parent's "Worker started."; the child's result never arrives.
  - This branch at `7ec8889d61`: the chat shows "Worker started." and then the child's result text exactly once, through one direct-fallback receipt. The parent made 0 provider requests after the switch.
  - The scenario is not committed here; it can follow as a regression scenario.
- In-process run against the real access gate (throwaway test): the `agent` dispatch rejected with `GatewayClientRequestError` → cause `FailoverError(OPENAI_ACCESS_PROGRAM_UNAVAILABLE, providerStarted: false)`, with 0 provider requests.
- `agent-command.admission-failure.test.ts`: on a completion turn, an ordinary error, a missing runtime owner and a refusal after a live model switch each deliver one channel notice; a runtime refusal of an ordinary chat turn still does. Private, internal, cancelled, revoked-source, started-execution runs and an ordinary chat error deliver nothing. Owner mark: set before start, absent after start. The existing sent and failed delivery receipts still pass.
- `subagent-announce-obligation.test.ts`: a pre-start failure and an incomplete model response choose the text fallback. A turn that started and then failed does not.
- The new tests fail on the merge base and pass here; every silent case passes on both.
- Not run end to end: the group-chat notice path (covered by the command tests above).

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

Release adaptation: Keep the release direct-delivery owner; use pre-start receipts at its guarded text-fallback boundary, and move the regression to the real release delivery fixture without importing the main-only completion owner rewrite.

Co-authored-by: RomneyDa <[email protected]>
obviyus added a commit that referenced this pull request Nov 30, 2026
…208772)

## Approved scope

Maintainer decision (@obviyus, 2026-11-30 08:29 IST, "yes"), quoted verbatim:

> the child's result stays HIDDEN exactly as #204178 has it, PLUS ONE separate short displayed line at the same owner, emitted only for the give-up case where no parent turn consumed the hidden row: 'Child <label> finished, but its result couldn't reach this chat: <reason>. Send a message to continue.' No result dump; nothing else in #204178 changes.

## What Problem This Solves

A child's completion that no parent turn consumes settles at once as a hidden, model-visible status entry in the parent's history (#204178). The parent model reads that entry on its next turn and decides what to tell the person.

When no parent turn is running, nothing else wakes the parent, so the person never learns that the child finished. One example is a parent whose completion turn was refused before it started by its access-program check.

- Production, one Gateway, 14.7 h: 85 of 91 refused completions settled this way within 2 s.
- 14 parent sessions never ran again, and their people saw nothing.

Reproduced on `main` with a real Gateway (local fake provider, the real OpenAI route through a managed proxy):
- A parent bound to a managed worktree spawns a child. The child finishes, and the parent's completion turn is refused before start.
- The parent chat shows nothing after the parent's own tool turn. The hidden entry holds the child's result.
- 3/3 runs.

## Solution

This adds one notice on top of #204178 and changes nothing else in it.

`appendChildStatusToRequester` is the single owner that every undelivered child completion passes through: the requester-settle batch, the announce give-up, media-queue recovery and the legacy suspended-row sweep.

1. It writes the hidden status entry exactly as before. The result stays hidden.
2. Then, only if no turn is running on the parent's own session, it writes ONE separate displayed line:

   > Child "<label>" finished, but its result couldn't reach this chat: <reason>. Send a message to continue.

**How "no parent turn consumed the hidden row" is decided at the owner:**
- The owner runs only on give-up. Children whose input a parent turn already consumed, and delivered children, never reach it.
- At the moment of give-up, `isSessionRunActive(<parent session id>)` is checked.
  - **Running:** that turn reads the entry on its next model call, so no line is written.
  - **Not running:** nothing will read the entry until the person sends a message, so the line is written.
- The check uses the physical session id, so another agent's session that shares a raw key such as `global` does not hide the line.

**What the line is:**
- It is `display: true, excludeFromContext: true`. The model context is unchanged, and the line carries no result.
- It is deduped by the same status id.
- No retry, timer or new state is added.
- `formatAnnounceDeliveryError` no longer repeats the delivery error as a `direct-primary:` phase, so the reason in the line reads once.

## User Impact

- **Idle Control UI and task parents:** when a child's result cannot reach the parent, the chat shows one short line with the reason. Sending a message lets the parent read the result.
- **Running parents, delivered completions and channel parents:** unchanged. The #207194 channel notice stays as it is, and the line is a history row that is not sent to the channel.
- **Accepted edge:** while the cause persists, the person's next message can be refused too. An access-program refusal is fixed separately.
- **Accepted edge, not coded:** a give-up that lands after a running parent turn's last model call gets no line, and the next turn reads the entry. This is rare: a completion for a running parent normally joins that turn.

## Evidence

- `subagent-child-status-history.test.ts`:
  - **Red on the merge base, green here:**
    - an idle parent gets exactly one line after a settle-path give-up, and after an announce-path give-up, with the label and the reason;
    - **no displayed row contains the child's result**, and the result is still in the hidden entry;
    - another agent's running session with the same raw key does not hide the line.
  - **Green on both:**
    - a running parent gets no line; making the check key-scoped or removing it turns this or the shared-key case red;
    - a delivered completion writes neither row;
    - the existing entry, budget, compaction and mid-turn tests pass, which shows the line stays out of the model context.
- **Real Gateway, F3** (a refused completion into an idle managed-worktree parent): merge base 3/3 with no line; this branch 3/3 with the line shown and the result kept only in the hidden entry. Before/after screenshots are below.
- **Tests that import the changed modules, and the delivery and settlement suites:** 26 files green. One case, `subagent-completion-replay.test.ts` "does not replay an announcement settled in requester history", failed once inside the 25-file batch under host load, with a residual root at teardown (28.6 s instead of about 4 s). It passes alone on this branch and on the merge base.

## The system-cancelled completions on one production Gateway (deploy window, exact scorecard rows)

None would get the line; all end delivered:
- **6 pause wakes** (`requester-settle … :pause`): yield acknowledgements, not child results. Paused children never reach the give-up owner, and the results arrived later through normal completions.
- **3 expired announces** (`announce:v1`, one parent): all three expired while the parent's own run was auto-compacting (17:56:29 start, 17:57:43 "succeeded; retrying prompt"; the third during the retried prompt). That run was active, so no line; its retried model call read the hidden entries written at +0 s.

Co-authored-by: Ayaan Zaidi <[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 docs Improvements or additions to documentation impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant