Skip to content

fix: keep child notifications out of replaced session stores - #152828

Merged
steipete merged 8 commits into
mainfrom
upd/heartbeat-wake-lifecycle
Sep 19, 2026
Merged

steipete merged 8 commits into
mainfrom
upd/heartbeat-wake-lifecycle

Conversation

@steipete

@steipete steipete commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #152288

What Problem This Solves

Fixes delayed child notifications creating and contaminating a parent conversation in a different physical session store after session.store is reloaded.

User Impact

Queued notifications stay with their original store. Replaced-store work ends with a recorded store-replaced non-outcome; stale automatic child-result delivery is suspended while results and completed tasks remain available for explicit recovery. Same-store replacement and in-process restart retain queued handoff.

Historical records with unknown provenance stay unbound: watches require fresh registration and suspended child delivery requires explicit recovery. Selecting the old store again does not resurrect retired notifications. This is the accepted conservative behavior of the approved nullable-provenance design, rather than guessing ownership from the current configuration.

Why This Change Was Made

Gateway shutdown stops the heartbeat runner (src/gateway/server-close.ts:510), but src/infra/session-event-wake.ts intentionally retains work for replacement. The retained work and child-registry projection lacked physical-store identity. A new runner could therefore combine new configuration with an old notice and child result.

The notification lifecycle captures ownership and retires mismatched work at accepted-store publication. Watcher cursors retain their original binding. The registry scopes child context and completion batches to the physical parent and uses its existing completion owner to suspend stale automatic delivery without changing task outcomes or delivered receipts.

The approved same-version schema change is exactly three bare nullable TEXT columns: session_watch_cursors.watcher_store_path, subagent_runs.requester_store_path, and subagent_runs.controller_store_path. Canonical declarations and idempotent first-write ensures preserve old-reader compatibility. No new table, schema-version bump, option, environment setting, or dependency is introduced. The v13 migration now projects NULL for registered additive columns absent from released tables and preserves values already present; missing required columns still fail.

Production: +650/-121, net +529. This CI repair adds 10 net production lines beyond the previous head. The growth from the originally accepted +392 covers reproduced notification/settlement review findings and the released-schema migration repair, within existing owners.

Owner Added/deleted Net
Notification lifecycle and accepted store selection +202/-4 +198
Watcher provenance +91/-27 +64
Child ownership, completion, and schema migration +357/-90 +267

Tests/support: +1342/-149 (net +1193). Docs: +21. The unchanged connected-wave selector now lives in the existing registry-query module to satisfy the line cap; fixture setup and one unchanged result test moved into existing support/sibling files. No new module or ratchet baseline change.

The broader registry refactor remains excluded and preserved on upd/heartbeat-wake-lifecycle-full at e0dfe3e8d93e35261e288cc7246dd1365ab3cbc9, with no PR. The issue follow-up note records that separation.

Evidence

  • Original real-Gateway different-store reproduction failed; same-store control passed. Supported CLI replay on the previous head 3510e55ee38 observed 25 seconds, zero provider requests, no replacement parent/child, and skipped / store-replaced. Same-store in-process restart retained PID/session identity and delivered the queued primary heartbeat. The CI repair preserves that notification behavior; owned Gateways were stopped and their ports verified closed.
  • Original exact-head CI exposed 50 failing cases across 12 files. All 12 full failing files plus three owner siblings now pass: 475 passed, one existing skipped, 375.96s. After the test-only extractions, the complete affected files passed again: 288 passed, one existing skipped, 76.88s. No retries, widened timeouts, weakened delivery assertions, or CI reruns.
  • Released-state migration proof covers runtime and Doctor opening historical wide rows with both absent and present provenance, preserving exact stored rows. Full released binding, update-admission, plugin-deferral, audit-reader, preflight, and Matrix Doctor files pass. Existing older-reader open/read, NULL, lazy-first-write, and transaction rollback proofs also pass.
  • Source/export collision, session-accessor boundary, schema-baseline verification, suppression ratchet, assertion safety, config docs, plugin inventory, line-cap checks, and canonical Kysely generation verification pass. Baseline/inventory artifacts remain unchanged. The duplicated test-only literal registry/column-order inventories were replaced by canonical SQLite shape, actual drop/ensure/open, exact persisted-row, uniqueness, and independent STRICT-datatype assertions.
  • Full pnpm check:changed passed, including production/test types, all dead-export scans, core lint and zero runtime import cycles. Fresh complete-candidate API P1 autoreview was scoped-clean (two passes, zero findings); the reviewed bytes are committed as 14a75661ff37c1629ac6ade4f1311241a4a08adb. That push encountered an overlapping docs addition on current main; the rebased head is a7e7728dd4daee18c210771cd1f318311948480a. Range-diff confirms unchanged production/test patches and both docs paragraphs retained. On the rebased head, all 476 tests across 16 files passed (one existing skip; 480.21s), and fresh committed-branch API P1 review is scoped-clean with zero findings in both passes. The full changed-file gate passed again on this head, including core/test types, lint, storage guards, and zero runtime import cycles. Exact-head CI run 35447237184 completed successfully on attempt 1. The REST-backed watcher observed completion and REST verified the exact SHA. The current openclaw/ci-gate, security-sensitive review, and dependency-review statuses are all success. The latest security-review execution also passed; earlier review-check failures occurred before CI completion and are historical. No CI reruns. ClawSweeper’s exact-head review reports no concrete contributor-facing code blocker; its accepted compatibility-risk note is answered in the review response.
Classification of the failed CI jobs on 3510e55
Failing job(s) Cause and repair
check-source-contracts Physical-path resolver collided with the existing logical Gateway resolver. Renamed the physical owner and all callers to resolvePhysicalSessionStorePath; collision guard passes.
checks-fast-baseline-ratchets Requester-settle module grew past 700 counted lines. Moved its unchanged pure wave selector to the existing query owner; all line caps pass without baseline changes.
compact-small-9, compact-large-6/7/11/15/18, changed-extensions-bundle-22 v13 rebuild selected new columns from old tables lacking them. The migration now projects unknown additive facts as NULL, preserves present facts, and keeps required-column errors. Full affected suites pass.
compact-large-7 (additional) Test duplicated the complete additive-column registry as a literal inventory. Replaced that mirror with uniqueness/STRICT-datatype checks while retaining actual canonical-column, drop/ensure/read, and maintenance validation.
compact-large-6 (additional), compact-small-11 Direct SQLite fixtures omitted requester/controller provenance. Seeded the real fixture store at the producer; unchanged catch-up and real parent-turn assertions pass.
compact-large-12 Attempt fixture changed physical stores between captures while its child record used another store. One isolated test-owned store now binds record, config, and session target; unchanged prompt/context assertions pass.
compact-large-4 Strict call-shape expectation omitted the new physical scope argument. It now expects explicit NULL for unknown scope; delivery/idempotency assertions remain intact.
Aggregate CI gate and three review executions Downstream of incomplete/failed CI; logs state that CI completion reevaluates security review. No bypass. ClawSweeper's separate resolver-collision finding is fixed; its legacy-behavior decision and compatibility proof requests are addressed above.

Landing review dispositions

The latest ClawSweeper review (September 19, 2026, 14:31 UTC, exact head a7e7728dd4daee18c210771cd1f318311948480a) contains no remaining actionable correctness finding and no separate Rank-up moves. Its remaining compatibility-risk item is dispositioned as retain the accepted recovery policy: historical watches with unknown provenance require fresh registration, suspended child delivery requires explicit recovery, and selecting a former store does not re-arm retired delivery. The existing maintainer response and compatibility evidence above cover this accepted tradeoff and the three approved nullable ownership columns. No semantic change or review rerun is needed.

@clawsweeper

clawsweeper Bot commented Sep 19, 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.

@steipete
steipete marked this pull request as ready for review September 19, 2026 11:35
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 19, 2026
@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 19, 2026, 11:35 AM ET / 15:35 UTC (Revision 5).

ClawSweeper review

What this changes

Binds queued notifications and child-result context to their original session database, preserves same-store handoff, and adds compatible storage provenance and migration coverage.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/state/openclaw-state-schema.sql. Prefer a design that avoids changing persisted SQLite tables. Migration or upgrade compatibility proof is recorded, but maintainers should still confirm that the schema change is necessary.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, review-ready fix. Current main still lacks the repair; the earlier resolver finding is resolved, and the maintainer has accepted the documented recovery policy. No remaining actionable blocker was identified.

Priority: P2
Reviewed head: a7e7728dd4daee18c210771cd1f318311948480a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound repair with real Gateway evidence, focused lifecycle and migration coverage, and resolved prior feedback.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded supported-CLI Gateway proof shows replaced-store work produces no provider request or replacement conversation, while same-store restart delivers the retained heartbeat; current source and production-path coverage support those outcomes and the added retirement guards.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded supported-CLI Gateway proof shows replaced-store work produces no provider request or replacement conversation, while same-store restart delivers the retained heartbeat; current source and production-path coverage support those outcomes and the added retirement guards.
Evidence reviewed 10 items Repair remains necessary: The inspected main revision still has only logical agent/session ownership in this module, without the PR’s physical-store resolver or retirement checks.
Latest-release check: The v2026.9.5 ownership implementation tracks agent identity, not physical session-store provenance. Its source was retrieved through REST after the local release-blob read failed.
Queue retirement and handoff: Accepted-store publication retires mismatched pending work, aborts active work, records store-replaced, and prevents retired wakes from retrying. Same-store lifecycle coverage preserves queued payloads and their delivery context.
Findings None None.
Security None None.

How this fits together

Child activity produces notifications and completion results that can wake a parent conversation. The Gateway’s notification and subagent owners now compare captured database ownership with the accepted session-store configuration before allowing that work onward.

flowchart TD
  A[Child activity and results] --> B[Capture original session store]
  B --> C[Queued notices and completion records]
  D[Accepted Gateway configuration] --> E{Original store still selected?}
  C --> E
  E -->|Yes| F[Parent wake and result context]
  E -->|No| G[Record retirement and retain recoverable results]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +526, Tests +1193, Docs +21, Generated +3. Total +1743 across 53 files.

View PR surface stats
Area Files Added Removed Net
Source 28 647 121 +526
Tests 21 1342 149 +1193
Docs 3 21 0 +21
Config 0 0 0 0
Generated 1 3 0 +3
Other 0 0 0 0
Total 53 2013 270 +1743

Review metrics

Metric Value Why it matters
Persisted ownership 3 nullable TEXT columns; no schema-version bump The accepted compatibility contract keeps historical ownership unknown and requires explicit recovery instead of assigning old records to the current store.
Production versus regression coverage Production net +529; tests/support net +1193 The body explains production growth within existing lifecycle owners and the released-schema migration repair.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-schema.sql. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #152288
Summary: This PR is the explicit implementation candidate for the reported cross-store notification defect; the linked issue remains open pending landing.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Retain the accepted store-isolation and explicit-recovery policy while preserving completed results, delivered receipts, and same-store handoff.

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

Yes: the reported child follow-up, session.store reload, and delayed-wake sequence matches the inspected main implementation and supplied real-Gateway evidence; this review did not execute it.

Is this the best way to solve the issue?

Yes: extending existing notification, completion, and storage owners repairs the physical-store boundary without discarding valid same-store handoff or introducing a competing delivery mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The demonstrated context-isolation defect requires changing physical session stores while child notifications remain pending.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded supported-CLI Gateway proof shows replaced-store work produces no provider request or replacement conversation, while same-store restart delivers the retained heartbeat; current source and production-path coverage support those outcomes and the added retirement guards.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded supported-CLI Gateway proof shows replaced-store work produces no provider request or replacement conversation, while same-store restart delivers the retained heartbeat; current source and production-path coverage support those outcomes and the added retirement guards.

Evidence

What I checked:

  • Repair remains necessary: The inspected main revision still has only logical agent/session ownership in this module, without the PR’s physical-store resolver or retirement checks. (src/infra/system-event-ownership.ts:1, 84768345f596)
  • Latest-release check: The v2026.9.5 ownership implementation tracks agent identity, not physical session-store provenance. Its source was retrieved through REST after the local release-blob read failed. (src/infra/system-event-ownership.ts:1, ec9c1a13db89)
  • Queue retirement and handoff: Accepted-store publication retires mismatched pending work, aborts active work, records store-replaced, and prevents retired wakes from retrying. Same-store lifecycle coverage preserves queued payloads and their delivery context. (src/infra/session-event-wake.ts:169, a7e7728dd4da)
  • Live ownership reaches delivery: Steering rechecks ownership after preparing results and exposes a live submission guard. Requester-settle delivery composes store ownership into its existing execution predicate; direct delivery carries that predicate through retries and the final platform-send callback. (src/agents/agent-steering-queue.ts:243, a7e7728dd4da)
  • Accepted compatibility disposition: The captured maintainer response explicitly retains unknown provenance as unbound, requires fresh watch registration or explicit child-delivery recovery, and rejects automatic rearming when an old store is selected again. The linked issue discussion also records acceptance of nullable provenance and deferral of the broader registry refactor. Public docs: docs/gateway/configuration/hot-reload.md. (docs/gateway/configuration/hot-reload.md:78, a7e7728dd4da)
  • Storage compatibility: Three bare nullable TEXT columns use the existing additive-column contract. The v13 rebuild projects NULL only for missing registered additive columns and preserves existing values. Added coverage checks runtime/Doctor migration, unchanged version markers, older-reader queries, lazy writes, and transaction rollback. (src/state/openclaw-state-db-schema-v13-widerow.ts:115, a7e7728dd4da)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-19T11:43:59.093Z sha 3510e55 :: blocked before merge. :: [P2] Give the physical-store resolver a distinct exported name
  • reviewed 2026-09-19T14:03:56.822Z sha a7e7728 :: blocked before merge. :: none
  • reviewed 2026-09-19T14:24:22.191Z sha a7e7728 :: blocked before merge. :: none
  • reviewed 2026-09-19T14:31:43.126Z sha a7e7728 :: blocked before merge. :: none

@steipete
steipete force-pushed the upd/heartbeat-wake-lifecycle branch from 14a7566 to a7e7728 Compare September 19, 2026 13:56
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed on a7e7728dd4daee18c210771cd1f318311948480a:

  • Renamed the physical-path owner and callers to resolvePhysicalSessionStorePath; the logical Gateway API is unchanged and the export-collision guard passes.
  • Retained the accepted legacy-record behavior: unknown store provenance remains unbound, watches require fresh registration, and suspended child notifications require explicit recovery. We do not infer an old record's store from current configuration or resurrect retired delivery by selecting a former store again.
  • Compatibility proof now includes the released-schema migration failure exposed by CI. The v13 owner projects NULL for missing registered additive columns, preserves existing values, and still rejects missing required columns. Runtime and Doctor paths, released task bindings, update admission, plugin deferral, old audit readers, preflight, and Matrix Doctor all pass. The three approved nullable TEXT columns remain at the same schema version, with older-reader/open/read and transactional rollback proof.

All 12 CI-failing test files plus four owner/sibling files passed on the rebased head: 476 passed, one existing skipped. The earlier extraction verification passed 288 tests with one existing skip. Full changed checks and fresh API P1 review pass. No baseline artifacts, mocks, delivery assertions, retries, or timeouts were weakened; no CI reruns. The PR body contains the per-job classification and owner LOC delta. New-head hosted CI is being watched through completion.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 19, 2026
@steipete
steipete merged commit 6abc70a into main Sep 19, 2026
236 of 238 checks passed
@steipete
steipete deleted the upd/heartbeat-wake-lifecycle branch September 19, 2026 15:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
…w#152828)

Prevent delayed child notifications and child-result context from entering a replacement physical session store after session.store is reloaded. Capture original-store ownership in the existing notification, watcher, registry, and completion owners; retire mismatched queued work with a recorded store-replaced outcome while preserving same-store handoff, completed results, and committed delivery receipts.

Retain the approved legacy recovery policy: unknown historical provenance remains unbound, watches require fresh registration, and suspended child delivery requires explicit recovery. Returning to a former store does not re-arm retired notifications. Three approved nullable ownership columns preserve the same schema version; the v13 migration projects NULL for absent additive columns and preserves present values.

Validation: 476 tests passed with one existing skip, full changed-file checks passed, scoped Codex autoreview was clean, and exact-head CI completed successfully. Existing isolated Gateway proof observed no provider requests or replacement conversation after a store switch and retained delivery on same-store restart.

Fixes openclaw#152288.
obviyus added a commit that referenced this pull request Nov 17, 2026
…es, steer races and expiry (#200649)

## What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current `main`:

- **Access-policy outage:** a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
- **Steer race:** when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
- **Expiry:** a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

## User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

## Why This Change Was Made

Each fix is at the existing owner:

- **Settle wake:** a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
- **Direct delivery:** an accepted, committed steer returns `delivered` before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
- **Seven-day discard:** this path now calls the same failure-notice writer that other permanent failures already use (#198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

## Evidence

- **Regressions** drive the real lifecycle, announce, completion and SQLite owners: `subagent-result-owed.{policy-outage,expiry-discard}.test.ts`, plus the updated `steering $outcome after $change` direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
  - policy outage: recorded `failed` before, owed and then delivered after;
  - steer race: receipt not delivered before, `{delivered: true, path: "steered"}` after;
  - expiry: no notice before, exactly one visible notice after.
- **Existing suites:** announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The `steering $outcome after $change` contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
- **End to end (source tier, `ocx src`):** an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and `subagent_runs` recorded `delivered/delivered`.
- **Not in this PR:** splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (#152828, unchanged).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…es, steer races and expiry (openclaw#200649)

## What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current `main`:

- **Access-policy outage:** a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
- **Steer race:** when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
- **Expiry:** a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

## User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

## Why This Change Was Made

Each fix is at the existing owner:

- **Settle wake:** a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
- **Direct delivery:** an accepted, committed steer returns `delivered` before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
- **Seven-day discard:** this path now calls the same failure-notice writer that other permanent failures already use (openclaw#198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

## Evidence

- **Regressions** drive the real lifecycle, announce, completion and SQLite owners: `subagent-result-owed.{policy-outage,expiry-discard}.test.ts`, plus the updated `steering $outcome after $change` direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
  - policy outage: recorded `failed` before, owed and then delivered after;
  - steer race: receipt not delivered before, `{delivered: true, path: "steered"}` after;
  - expiry: no notice before, exactly one visible notice after.
- **Existing suites:** announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The `steering $outcome after $change` contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
- **End to end (source tier, `ocx src`):** an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and `subagent_runs` recorded `delivered/delivered`.
- **Not in this PR:** splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (openclaw#152828, unchanged).

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 18, 2026
… path or operator authority (#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. #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 #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 #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.
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 added a commit that referenced this pull request Nov 19, 2026
…es, steer races and expiry (#200649)

## What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current `main`:

- **Access-policy outage:** a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
- **Steer race:** when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
- **Expiry:** a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

## User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

## Why This Change Was Made

Each fix is at the existing owner:

- **Settle wake:** a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
- **Direct delivery:** an accepted, committed steer returns `delivered` before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
- **Seven-day discard:** this path now calls the same failure-notice writer that other permanent failures already use (#198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

## Evidence

- **Regressions** drive the real lifecycle, announce, completion and SQLite owners: `subagent-result-owed.{policy-outage,expiry-discard}.test.ts`, plus the updated `steering $outcome after $change` direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
  - policy outage: recorded `failed` before, owed and then delivered after;
  - steer race: receipt not delivered before, `{delivered: true, path: "steered"}` after;
  - expiry: no notice before, exactly one visible notice after.
- **Existing suites:** announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The `steering $outcome after $change` contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
- **End to end (source tier, `ocx src`):** an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and `subagent_runs` recorded `delivered/delivered`.
- **Not in this PR:** splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (#152828, unchanged).

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

Companion audit: #200581 included; existing authority outage classifier and completion failure owner are present.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit eadbf05817ce8aa5dc0c0e8daf8594486dc7e581)
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)
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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

[Bug]: Session-store reload sends queued heartbeat context into another store

1 participant