Skip to content

fix(subagents): deliver finished results instead of refusing on store path or operator authority - #200760

Merged
obviyus merged 4 commits into
mainfrom
fix/subagent-delivery-root
Nov 18, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/subagent-delivery-root

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Finished subagent results were dropped by identity checks that run after the work is done:

  • Store-path veto. Each result recorded the requester's session store path at spawn. If the path resolved differently later (for example after a config reload republished the resolver), the result was suspended as "store replaced" and never delivered. Delivery never used that path: it finds the requester by agent and session key.
  • Operator-authority refusals. A settle turn refused to run when a child's retained operator custody was missing or revoked. The parent then saw "authority is no longer active" and the result was lost.

Previous fixes exempted one case at a time.

Fix

Delete both refusal classes. A finished result is delivered to the requester chat by (requesterAgentId, requesterSessionKey).

  • Removed the store-path comparison as a delivery veto: settle-wake isStoreCurrent / retireReplacedStore, the store branch in isSubagentCompletionDeliveryAllowed, suspendReplacedStoreNotifications and its store-owner registration, the post-announce store block, and the storeReplaced plumbing through the completion mutation kernel and receipt admission.
  • Removed requiredCompletionEntries and the authority throws. fix: preserve subagent results under each requester turn #200873 already splits settle batches by retained operator turn; within a batch, runWithSubagentCompletionBatchAuthority now runs under retained custody only when every member has the same live source and permission ceiling, and otherwise at the System write-only baseline, which settle turns already use after every Gateway restart. It never borrows a sibling's permissions.
  • Kept: explicit stop/cancel, requester deletion, cancellation-notice callers, and the temporary access-policy outage retry.

User impact

Subagent results no longer disappear after config edits or Gateway restarts. A continuation turn that lost its original operator custody runs at the baseline permission instead of being dropped; this already happens after every restart.

Accepted tradeoffs (maintainer decision)

  • Revoked requester. If the operator who spawned a child loses access before the child finishes, the result still wakes the requester session, at the System write-only baseline. It is no longer dropped. Gateway admission still checks the requester session.
  • Different physical store, same session key. If session.store is changed to a different database that has its own session with the same key, a pending result from the old store is delivered to that session. This reverses the automatic suspension from fix: keep child notifications out of replaced session stores #152828. Delivery has no stored identity that separates a moved store from an unrelated one; adding one is a schema change and is out of scope here.

Evidence

  • Regression in subagent-registry.requester-delivery.test.ts, red on the merge base (zero settle turns) and green with the fix: a finished child with a mismatched recorded requesterStorePath and a live requester is delivered through the real in-process dispatcher.
  • subagent-control.publication.test.ts now asserts that a revoked owner's result is delivered at the baseline.
  • Affected registry, announce, completion, sweep-settle and restart-custody suites pass after rebasing on fix: preserve subagent results under each requester turn #200873 (189 tests across 8 files).
  • test/gateway-subagent-completion-restart.e2e.test.ts (real Gateway restart): 8 of 9 cases pass. announcing-crash fails identically on the merge base when run alone; fix: preserve subagent results under each requester turn #200873 documents the same pre-existing failure.
  • Full build and packed install smoke pass.
  • Production: 46 lines added, 271 removed; tests: net -439 lines.

Known follow-ups, not changed here: a deleted requester can leave an owed wake retrying (pre-existing); ensureSubagentControllerOwnsRun still compares the recorded store path for kill/steer control.

@clawsweeper

clawsweeper Bot commented Nov 17, 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 gateway Gateway runtime agents Agent runtime and tooling size: XL labels Nov 17, 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR removes store-path delivery vetoes and makes missing, revoked, or mixed completion custody fall back to System authority.

Example: A finished child targets agent:main:main after its requester moves from sessions.json to moved-sessions.json.

  • Before: The recorded store mismatch suspends delivery.
  • After: The result can reach the requester in its current store.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The direction is useful, but authority isolation and consumer repairs remain, and shipped-flow proof is absent; persisted columns and serialization remain unchanged.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Completed delegated work remains saved but never reaches the requester after store changes or completion-custody loss.
Reason: Reliable result delivery has clear user value, and the maintainer-authored PR explicitly approves the changed delivery policy.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this maintainer-directed repair addresses result loss, but its baseline fallback preserves ambient authority and its cutover leaves broken consumers.

Priority: P1
Reviewed head: 1b4f93e9acd4b412fed78e5fa2f8af8c6fd9c8b5

Before merge

  • Enter an explicit System scope for ordinary fallback delivery (P1) - For a revoked or mixed result batch evaluated inside an existing Gateway request scope, this run() preserves that scope's client. The changed automation-custody fixture already supplies an unrelated ambient operator, but mocks delivery before real admission. Actual Gateway dispatch reads scope.client.internal.operatorRunAuthority and its authenticated profile, and ignores the explicit System actor while a scoped client exists. The continuation can therefore borrow that operator's identity or still fail on an inherited revoked authority instead of using the promised baseline. Apply the same correction to the single-entry and exception fallbacks, preserving the independently admitted cancellation-only path.
  • Remove the retired notification benchmark consumer (P2) - This unchanged script still destructures suspendReplacedStoreNotifications from the module whose export this PR deletes. Because tsconfig.scripts.json includes scripts/**/*, that leaves a missing-property type error; running --operation notification-retirement would also call undefined. Remove the obsolete benchmark mode and its associated setup alongside the deleted production path.
  • Update the revoked-registration consumer test (P2) - The revoked case still requires runWithCompletionAuthority to throw after cleanup. The new implementation has no custody at that point and returns the callback value, so this existing assertion necessarily fails. Adapt this consumer to the approved fallback contract while retaining its rejected-execution and replaced-Gateway protections.
  • Resolve security concern: Ambient operator identity survives fallback - This affects admission authority rather than display provenance: Gateway dispatch gives the scoped operator precedence over the requested System actor.

Findings

  • [P1] Enter an explicit System scope for ordinary fallback delivery — src/agents/subagents/registry/subagent-registry-memory.ts:399-400
  • [P2] Remove the retired notification benchmark consumer — scripts/perf/subagent-sweep-measure.ts:119-120
  • [P2] Update the revoked-registration consumer test — src/agents/subagents/registry/subagent-control.publication.test.ts:192-194
  • [medium] Ambient operator identity survives fallback — src/agents/subagents/registry/subagent-registry-memory.ts:400

Tests

  • Missing end-to-end proof: Provide redacted Gateway output showing requester delivery after a store change and mixed or revoked custody, including the actual fallback execution principal; redact IPs, keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The subagent registry retains completed child results and completion custody; settlement batches submit those results through Gateway admission into the requester conversation.

flowchart LR
  A[Child completion] --> B[Subagent registry]
  C[Retained operator custody] --> B
  B --> D[Requester settlement]
  D --> E[Gateway admission]
  E --> F[Requester conversation]
Loading

Technical review

Best possible solution:

Keep logical-chat delivery in the existing completion owner, explicitly enter write-only System authority on ordinary fallback, and update the obsolete consumers.

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

Current-main source shows both refusal paths, and the author reports red/green regressions; this review did not execute target code.

Is this the best way to solve the issue?

Removing the delivery vetoes is a focused use of existing owners, but calling an unscoped callback does not establish the promised baseline authority.

Full review comments:

  • [P1] Enter an explicit System scope for ordinary fallback delivery — src/agents/subagents/registry/subagent-registry-memory.ts:399-400
    For a revoked or mixed result batch evaluated inside an existing Gateway request scope, this run() preserves that scope's client. The changed automation-custody fixture already supplies an unrelated ambient operator, but mocks delivery before real admission. Actual Gateway dispatch reads scope.client.internal.operatorRunAuthority and its authenticated profile, and ignores the explicit System actor while a scoped client exists. The continuation can therefore borrow that operator's identity or still fail on an inherited revoked authority instead of using the promised baseline. Apply the same correction to the single-entry and exception fallbacks, preserving the independently admitted cancellation-only path.
    Confidence: 0.96
  • [P2] Remove the retired notification benchmark consumer — scripts/perf/subagent-sweep-measure.ts:119-120
    This unchanged script still destructures suspendReplacedStoreNotifications from the module whose export this PR deletes. Because tsconfig.scripts.json includes scripts/**/*, that leaves a missing-property type error; running --operation notification-retirement would also call undefined. Remove the obsolete benchmark mode and its associated setup alongside the deleted production path.
    Confidence: 1
  • [P2] Update the revoked-registration consumer test — src/agents/subagents/registry/subagent-control.publication.test.ts:192-194
    The revoked case still requires runWithCompletionAuthority to throw after cleanup. The new implementation has no custody at that point and returns the callback value, so this existing assertion necessarily fails. Adapt this consumer to the approved fallback contract while retaining its rejected-execution and replaced-Gateway protections.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Store-path delivery vetoes changes intended behavior with a stated reason (6abc70a: Prevent delayed child notifications from contaminating a different physical session store after configuration reload.)
  • Retained completion custody and mixed-source refusals changes intended behavior with a stated reason (e2e5b0b: Let results survive source-turn completion while preserving original permission ceilings and refusing stale or incompatible sources.)
  • Requester claim reconciliation changes intended behavior with a stated reason (ac7fd54: Preserve accepted watched follow-up obligations after requester retirement using retained custody and ordinary settlement.)
  • Permanent delivery-failure recording keeps the original intent (fa40e29: Report required completions that permanently cannot reach their requester; the PR removes the store-specific failure cause while retaining other failure reporting.)

Testing

Proof path: in-process harness.

Security

Needs attention: The fallback does not isolate the execution principal from ambient operator context.

Evidence

Security concerns:

  • [medium] Ambient operator identity survives fallback — src/agents/subagents/registry/subagent-registry-memory.ts:400
    This affects admission authority rather than display provenance: Gateway dispatch gives the scoped operator precedence over the requested System actor.
    Confidence: 0.96

What I checked:

PR surface

Source -231, Tests -411, Docs +10. Total -632 across 24 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 11 59 290 -231
Tests 10 440 851 -411
Docs 3 36 26 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 535 1167 -632

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 P1: Finished delegated work can fail to return to its requester, breaking an active agent workflow.
  • add merge-risk: 🚨 security-boundary: The new fallback can select an ambient operator as the execution principal instead of the promised System principal.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: Finished delegated work can fail to return to its requester, breaking an active agent workflow.
  • merge-risk: 🚨 security-boundary: The new fallback can select an ambient operator as the execution principal instead of the promised System principal.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • 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 17, 2026, 2:32 PM ET / 19:32 UTC.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 18, 2026
… path or operator authority

Finished child results route to the requester by agent and session key. The recorded store path no longer vetoes delivery, and missing, revoked or mixed operator custody falls back to the System write-only baseline instead of dropping the result.
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 540cdffdb6b80f3617c112897a458aaf770bca3e
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/subagents/registry/subagent-completion-batch-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override

Landing head 540cdff outside the landpr merge helper, by maintainer decision.

Local ClawSweeper review: one finding, accepted. The review flags that a revoked operator's pending result starts a requester turn at the System write-only baseline instead of being refused. That is the intended behavior of this PR, recorded under "Accepted tradeoffs" in the description: a finished result is delivered, never dropped, and settle turns already run at that baseline after every Gateway restart. The merge helper requires a zero-finding review and has no path for an accepted finding, so this merge bypasses it.

Red required check not caused by this PR: checks-node-changed-compact-large-25 (and openclaw/ci-gate, which reports it).

  • Failing tests: subagent-spawn.production-boundary.test.ts > delegates participant custody (visible=true, queued=false, independent=false|true), expected { type: 'human', id: 'alice' } to match object { type: 'agent', id: 'main' }.
  • The same two cases fail with the same assertion on current main (ff216927e473) without this PR. This PR does not touch spawn participant ownership.
  • It failed identically on the original run and on one --failed rerun.

Every other failure seen on earlier heads was caused by this PR and is fixed on this head.

@obviyus
obviyus merged commit 714129c into main Nov 18, 2026
186 of 192 checks passed
@obviyus
obviyus deleted the fix/subagent-delivery-root branch November 18, 2026 05:04
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 714129c.

  • Bug: finished subagent results were dropped after the work was done, by a store-path comparison and by operator-authority refusals. Users saw "execution authority is no longer active" after config edits and restarts, and the result was lost.
  • Fix: both refusal classes are deleted. A result is delivered to the requester by agent and session key. A batch keeps retained operator custody when it is live and shared; otherwise it runs at the System write-only baseline. Stop, requester deletion and the access-policy outage retry are unchanged.
  • Proof: the store-path regression is red on the merge base and green with the fix; the affected registry, announce, completion, sweep-settle and restart-custody suites pass; full build and packed install smoke pass. Production code: 46 lines added, 271 removed.
  • Override: one accepted review finding and one red check that also fails on main, recorded in the override comment above.

RomneyDa added a commit that referenced this pull request Nov 18, 2026
… path or operator authority (#200760)

Backport-of: #200760
Source-commit: 714129c

Adapt completion delivery to the release branch without removing control-scope store checks. Retain private-result/reset incarnation fences, current requester and run identity, cancellation, consumed receipts, and live authority checks. Missing/revoked/mixed completion custody uses the explicit System write-only baseline, never ambient or sibling authority. Temporary access-policy outages remain retryable.

Validation: six baseline regression failures reproduced by the isolated worker; parent targeted completion suites and core types, typed lint, formatting and diff checks. Full exact-candidate qualification remains required. Package/tag/npm publication held.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
… path or operator authority (openclaw#200760)

## Problem

Finished subagent results were dropped by identity checks that run after the work is done:

- **Store-path veto.** Each result recorded the requester's session store path at spawn. If the path resolved differently later (for example after a config reload republished the resolver), the result was suspended as "store replaced" and never delivered. Delivery never used that path: it finds the requester by agent and session key.
- **Operator-authority refusals.** A settle turn refused to run when a child's retained operator custody was missing or revoked. The parent then saw "authority is no longer active" and the result was lost.

Previous fixes exempted one case at a time.

## Fix

Delete both refusal classes. A finished result is delivered to the requester chat by `(requesterAgentId, requesterSessionKey)`.

- Removed the store-path comparison as a delivery veto: settle-wake `isStoreCurrent` / `retireReplacedStore`, the store branch in `isSubagentCompletionDeliveryAllowed`, `suspendReplacedStoreNotifications` and its store-owner registration, the post-announce store block, and the `storeReplaced` plumbing through the completion mutation kernel and receipt admission.
- Removed `requiredCompletionEntries` and the authority throws. openclaw#200873 already splits settle batches by retained operator turn; within a batch, `runWithSubagentCompletionBatchAuthority` now runs under retained custody only when every member has the same live source and permission ceiling, and otherwise at the System write-only baseline, which settle turns already use after every Gateway restart. It never borrows a sibling's permissions.
- Kept: explicit stop/cancel, requester deletion, cancellation-notice callers, and the temporary access-policy outage retry.

## User impact

Subagent results no longer disappear after config edits or Gateway restarts. A continuation turn that lost its original operator custody runs at the baseline permission instead of being dropped; this already happens after every restart.

## Accepted tradeoffs (maintainer decision)

- **Revoked requester.** If the operator who spawned a child loses access before the child finishes, the result still wakes the requester session, at the System write-only baseline. It is no longer dropped. Gateway admission still checks the requester session.
- **Different physical store, same session key.** If `session.store` is changed to a different database that has its own session with the same key, a pending result from the old store is delivered to that session. This reverses the automatic suspension from openclaw#152828. Delivery has no stored identity that separates a moved store from an unrelated one; adding one is a schema change and is out of scope here.

## Evidence

- Regression in `subagent-registry.requester-delivery.test.ts`, red on the merge base (zero settle turns) and green with the fix: a finished child with a mismatched recorded `requesterStorePath` and a live requester is delivered through the real in-process dispatcher.
- `subagent-control.publication.test.ts` now asserts that a revoked owner's result is delivered at the baseline.
- Affected registry, announce, completion, sweep-settle and restart-custody suites pass after rebasing on openclaw#200873 (189 tests across 8 files).
- `test/gateway-subagent-completion-restart.e2e.test.ts` (real Gateway restart): 8 of 9 cases pass. `announcing-crash` fails identically on the merge base when run alone; openclaw#200873 documents the same pre-existing failure.
- Full build and packed install smoke pass.
- Production: 46 lines added, 271 removed; tests: net -439 lines.

Known follow-ups, not changed here: a deleted requester can leave an owed wake retrying (pre-existing); `ensureSubagentControllerOwnsRun` still compares the recorded store path for kill/steer control.
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
* fix: keep subagent results owed under their requester authority

* test: keep restored notices pending until requester admission

* fix: retry unavailable settle wakes only before execution

* refactor: keep retained completion admission in the registry owner

(cherry picked from commit f444d3b)

Release adaptation: port only requester-turn batch selection and safe uncommitted retry, the prerequisite consumed by #200760. Retain baseline absent restart-interrupted sweep and its unrelated recovery tests; do not resurrect that separate behavior.
Follow-up: #200760 selected next replaces strict batch admission with System-baseline delivery. Bounded companion audit requested; no later #200873 mentions through pinned main besides #200760.
Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit 21b77b640fa48258014c1513f907e3aec0c81557)
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
… path or operator authority (#200760)

Finished subagent results were dropped by identity checks that run after the work is done:

- **Store-path veto.** Each result recorded the requester's session store path at spawn. If the path resolved differently later (for example after a config reload republished the resolver), the result was suspended as "store replaced" and never delivered. Delivery never used that path: it finds the requester by agent and session key.
- **Operator-authority refusals.** A settle turn refused to run when a child's retained operator custody was missing or revoked. The parent then saw "authority is no longer active" and the result was lost.

Previous fixes exempted one case at a time.

Delete both refusal classes. A finished result is delivered to the requester chat by `(requesterAgentId, requesterSessionKey)`.

- Removed the store-path comparison as a delivery veto: settle-wake `isStoreCurrent` / `retireReplacedStore`, the store branch in `isSubagentCompletionDeliveryAllowed`, `suspendReplacedStoreNotifications` and its store-owner registration, the post-announce store block, and the `storeReplaced` plumbing through the completion mutation kernel and receipt admission.
- Removed `requiredCompletionEntries` and the authority throws. #200873 already splits settle batches by retained operator turn; within a batch, `runWithSubagentCompletionBatchAuthority` now runs under retained custody only when every member has the same live source and permission ceiling, and otherwise at the System write-only baseline, which settle turns already use after every Gateway restart. It never borrows a sibling's permissions.
- Kept: explicit stop/cancel, requester deletion, cancellation-notice callers, and the temporary access-policy outage retry.

Subagent results no longer disappear after config edits or Gateway restarts. A continuation turn that lost its original operator custody runs at the baseline permission instead of being dropped; this already happens after every restart.

- **Revoked requester.** If the operator who spawned a child loses access before the child finishes, the result still wakes the requester session, at the System write-only baseline. It is no longer dropped. Gateway admission still checks the requester session.
- **Different physical store, same session key.** If `session.store` is changed to a different database that has its own session with the same key, a pending result from the old store is delivered to that session. This reverses the automatic suspension from #152828. Delivery has no stored identity that separates a moved store from an unrelated one; adding one is a schema change and is out of scope here.

- Regression in `subagent-registry.requester-delivery.test.ts`, red on the merge base (zero settle turns) and green with the fix: a finished child with a mismatched recorded `requesterStorePath` and a live requester is delivered through the real in-process dispatcher.
- `subagent-control.publication.test.ts` now asserts that a revoked owner's result is delivered at the baseline.
- Affected registry, announce, completion, sweep-settle and restart-custody suites pass after rebasing on #200873 (189 tests across 8 files).
- `test/gateway-subagent-completion-restart.e2e.test.ts` (real Gateway restart): 8 of 9 cases pass. `announcing-crash` fails identically on the merge base when run alone; #200873 documents the same pre-existing failure.
- Full build and packed install smoke pass.
- Production: 46 lines added, 271 removed; tests: net -439 lines.

Known follow-ups, not changed here: a deleted requester can leave an owed wake retrying (pre-existing); `ensureSubagentControllerOwnsRun` still compares the recorded store path for kill/steer control.

(cherry picked from commit 714129c)

Release adaptation: retain baseline deleted session identity allowlist and omit incoming unrelated restored-running-child test since baseline has no restart-interrupted sweep owner. Requester batch dependency #200873 selected immediately before.
Follow-up: no later #200760 mention through pinned main; store kill/steer authority checks remain intentionally unchanged.
Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit d361b6ff3c0a18a6a3f4431c67ddf2f0129c352b)
obviyus added a commit that referenced this pull request Nov 23, 2026
…led replies (#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 #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:** "<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 `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]>
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 docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. scripts Repository scripts security-sensitive-changed size: XL 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