Repository navigation
fix(gateway): settle refused restart completions once with one notice - #204609
Conversation
A restart completion whose requester's access has ended (grant or access record gone, profile deleted, or admission policy refusal) is now settled once instead of being refused at every restart. The run record keeps the result with its delivery marked discarded. The requesting chat gets one fixed notice per recovery pass; results older than 7 days settle without a notice and are counted in one log line. Any other failure stays pending and retries at the next restart. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…r latest time - Settle only refusals caused by an ended grant or access record, or a deleted profile. Refusals without a cause keep retrying: some compare state the new process rebuilds. - The 7-day cutoff uses the latest recorded time on the row (capture, end, delivery attempt); creation time only when nothing later exists. - The notice row keeps only a digest of the settled run IDs as its dedupe key. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…mission mock Co-authored-by: obviyus <[email protected]>
|
Codex review: blocked before merge. What this changesThis PR settles permanently refused restart completions and records one chat notice for recent results. Example: Two child results captured yesterday belong to one chat whose saved access grant was revoked.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this maintainer-authored PR addresses a current restart-recovery defect; the refusal notice needs actionable recovery guidance. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway startup restores pending subagent completion obligations, re-admits their saved requesters, and either resumes delivery or records a terminal refusal. flowchart TD
A[Gateway startup] --> B[Pending child results]
B --> C[Requester admission]
C --> D[Resume authorized delivery]
C --> E[Classify refusal]
E --> F[Keep other failures pending]
E --> G[Append recent result notice]
G --> H[Persist discarded delivery]
Technical reviewBest possible solution: Keep settlement in the existing custody owner, preserve admission and result payloads, and give affected users a clear way to inspect saved work or request it again. Do we have a high-confidence way to reproduce the issue? Current-main source retains refused pending deliveries, and the PR reports matching base-red regression tests; no target code was executed during this read-only review. Is this the best way to solve the issue? The narrow error classification and existing transcript and registry owners provide a focused solution without weakening admission or introducing parallel storage. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d7616118b058. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +154, Tests +330, Docs +11. Total +495 across 5 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 24, 2026, 6:51 AM ET / 11:51 UTC. |
|
Maintainer override: the only red job is not caused by this PR.
|
|
Landed as b3dfd35. A restart-recovery refusal caused by an ended grant or access record, or a deleted profile, now settles the owed subagent result once. The run record keeps the result, and the requesting chat gets one notice (none for results older than 7 days). Every other failure keeps retrying. Proof: red on merge base a3443e9 (refused child re-admitted at every restart), green on the head; real-admission revoked-device test; local review clean. |
|
Process note: this merge used an override for |
…#204609) ## Problem When the Gateway restarts, restart recovery tries to deliver finished subagent results that are still owed to their requesting chat. It re-admits the saved requester first. When that admission is refused because the requester's access has ended, `session-restart-resume-custody.ts` only logged a warning. The result was never settled, so it was retried and refused again at every restart. The user saw nothing, not even that a result was lost. On one production deployment this showed as 88 refusal lines over 6 restart bursts, for 38 child results in 20 chats. 36 of those rows are in `subagent_runs`, created 10-29 to 11-23, and most are weeks old. The same rows were refused at every restart. The refusal itself is correct and does not change: one-time admission says replayed work checks its requester again when it starts. ## Fix `session-restart-resume-custody.ts` settles a definitely refused completion once: - **Closed refusal list.** Only an explicit ended-access marker settles: a `GatewayOperatorRecoveryAuthorizationError` whose cause is `GatewayOperatorAccessDeniedError` with `grant-revoked` or `access-record-inactive` (the saved plugin grant or access record ended or was replaced), or `UserProfileNotFoundError` (the saved profile is gone). Everything else stays pending and retries at the next restart, as before. That includes refusals without a cause (listed below), thrown policy errors (`policy-check-failed`), an unavailable access owner, timeouts and database errors. - **Settle.** The run record keeps the completion and its delivery payload. Delivery becomes `discarded` with `lastError` naming the reason, `suppressCompletionDelivery` retires the obligation and the pending requester wake is cleared, so the row leaves the restart pending set. Nothing is deleted. - **Notice.** The original requesting chat, and only that chat (the session ID of the chat whose pending results recovery holds), gets one `openclaw.system-note`: "A background task's result couldn't be delivered because the access it ran under has ended." It names no requester, grant or result. Several results settled in the same chat in one pass produce one notice. The notice is written before the rows settle, so a failed notice leaves them pending. A repeated notice for the same results is not written twice. The row's `details` hold only `source` and a SHA-256 digest of the settled run IDs (the dedupe key), so no run, child or requester ID enters the chat row. - **7-day cutoff.** A result whose latest recorded time is more than 7 days before the settle settles without a chat notice. Each recovery pass logs one count-only line for them. The latest recorded time is the maximum of `completion.capturedAt`, `completion.fallbackCapturedAt`, `execution.endedAt` (stored rows keep it under `parentCompletion.execution.endedAt`), `delivery.payload.endedAt`, `delivery.createdAt`, `delivery.enqueuedAt`, `delivery.lastAttemptAt` and `delivery.suspendedAt`. The row's `createdAt` is used only when none of these exist. This errs toward notifying. `requesterSettleWake.nextAttemptAt` is a future schedule and is not used. Docs: `docs/gateway/restart-recovery.md` describes the settle, the notice and the cutoff. ## Expected effect on first deploy (production counts as of 2026-11-24, by the latest recorded time per row) - 7 days or newer: 9 rows in 6 chats, so 6 chats get one notice each. - Older than 7 days: 27 rows in 15 chats settle silently, with one summary log line per recovery pass. One chat is in both groups. - 2 of the 38 refused ids are not in `subagent_runs` and are unaffected. - After that, those rows are no longer retried at restart. Related: #204551 (weeks-old pending child results are the same "results without a settled owner" class). ## No-cause refusal sites (classified; none settle) Every `GatewayOperatorRecoveryAuthorizationError` thrown without a cause, at head: - `src/gateway/operator-admission.ts:264`: OpenClaw ID disabled in config (policy). - `src/gateway/operator-admission.ts:271`: tunnel principal not found while OpenClaw ID is not enabled (config state). - `src/gateway/operator-admission.ts:274`: tunnel principal no longer current (membership). - `src/gateway/operator-admission.ts:291` (`refuse()`): profile id changed, shared session generation mismatch, auth method disabled, password fallback generation changed, device token or key not current. Mixed. The shared generation is compared against state the new process rebuilds, so it cannot be certified as a policy-only decision. - `src/gateway/operator-admission.ts:310`: channel identity missing or not current (identity). - `src/gateway/operator-admission.ts:422`: live ingress binding aborted or profile changed (live sources only). - `src/gateway/operator-admission.ts:439`, `:474`, `:479`: person-principal auth error, role excludes the agent, no scopes left (policy). - `src/gateway/operator-run-recovery.ts:91`: role no longer grants the start (policy). - `src/gateway/remote-ingress-principal-recovery.ts:88`, `:114`: ingress grant missing, ingress identity or scope changed. Because `:291` mixes policy with rebuilt process state, no-cause refusals are excluded rather than marked; they keep today's retry. Every refusal seen in production carries `grant-revoked` (88 log lines) or `access-record-inactive` (3 log lines), so this exclusion does not change the expected counts. A revoked device keeps being refused at every restart (test below), as before this change. ## Which change made weeks-old rows eligible (investigation only) Neither candidate changes eligibility. #203839 (92e92d7) changes how a recovered cohort owns its queued settle input. #203901 (e58ca10) changes only yielded children that wait for a message. The pending-child filter in `recoverRequesterCompletionCustody` is identical at 648619c and e2973f9. So these rows were already eligible before the deploy. The refusal path is #202513 (3ad2cce). For a role-enforced person, the legacy session-principal wake used to take its scopes from the current role. It now uses the recorded session source as the authority, and that source's saved plugin grant is checked. Not bisected end to end. These old results should be settled, not delivered: their requester's access has ended, and one-time admission re-checks replayed work at start. ## Evidence - `src/gateway/session-restart-resume-custody.refusal.test.ts` uses real custody, the real SQLite registry and real chat transcripts, and replaces only requester admission to choose the exact refusal: - refused children settle once across two restarts, one notice in the requesting chat, none in another chat (`grant-revoked` and `access-record-inactive`); - a result older than 7 days settles with no notice and with the summary line; a fresh one notifies; - an old row (created and ended 30 days ago) whose result was captured yesterday notifies; - a refusal without an ended-access cause, a thrown policy error, an unavailable owner and a database error each stay pending across two restarts, with no notice; - the notice row contains no run ID or child session key; - when the notice cannot be written, the refused child stays pending, the failure stays inside that chat's recovery (recovered siblings keep custody; local review finding), and the next restart settles it with one notice. - On merge base a3443e9 the settle cases fail (`expected 2 to be 1`: the refused child is re-admitted at the second restart; `expected 'pending' to be 'discarded'`). The recent-capture case fails the same way (`expected 'pending' to be 'discarded'`); base 4 failed, 4 passed. On the head, 9/9 pass; with `session-restart-resume-custody.test.ts`, 26/26. - `session-restart-resume-custody.test.ts`, new case: a requester whose paired device token was revoked after the spawn is still refused by the real admission at both restarts, and its result stays pending. - `test/gateway-restart-resume.e2e.test.ts` on the head: 5/6 pass. The remaining case, `restart markers survive graceful shutdown (blocked store: false)`, also fails on main. It is a shutdown-ordering assertion (`[close-backfill-proof]` after the clean-close receipt), and in the earlier main run an `Unexpected end of JSON input` from the mock provider harness. No completion refusal is logged in either run. Filed as #204596. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit b3dfd35) Co-authored-by: RomneyDa <[email protected]>
…openclaw#204609) ## Problem When the Gateway restarts, restart recovery tries to deliver finished subagent results that are still owed to their requesting chat. It re-admits the saved requester first. When that admission is refused because the requester's access has ended, `session-restart-resume-custody.ts` only logged a warning. The result was never settled, so it was retried and refused again at every restart. The user saw nothing, not even that a result was lost. On one production deployment this showed as 88 refusal lines over 6 restart bursts, for 38 child results in 20 chats. 36 of those rows are in `subagent_runs`, created 10-29 to 11-23, and most are weeks old. The same rows were refused at every restart. The refusal itself is correct and does not change: one-time admission says replayed work checks its requester again when it starts. ## Fix `session-restart-resume-custody.ts` settles a definitely refused completion once: - **Closed refusal list.** Only an explicit ended-access marker settles: a `GatewayOperatorRecoveryAuthorizationError` whose cause is `GatewayOperatorAccessDeniedError` with `grant-revoked` or `access-record-inactive` (the saved plugin grant or access record ended or was replaced), or `UserProfileNotFoundError` (the saved profile is gone). Everything else stays pending and retries at the next restart, as before. That includes refusals without a cause (listed below), thrown policy errors (`policy-check-failed`), an unavailable access owner, timeouts and database errors. - **Settle.** The run record keeps the completion and its delivery payload. Delivery becomes `discarded` with `lastError` naming the reason, `suppressCompletionDelivery` retires the obligation and the pending requester wake is cleared, so the row leaves the restart pending set. Nothing is deleted. - **Notice.** The original requesting chat, and only that chat (the session ID of the chat whose pending results recovery holds), gets one `openclaw.system-note`: "A background task's result couldn't be delivered because the access it ran under has ended." It names no requester, grant or result. Several results settled in the same chat in one pass produce one notice. The notice is written before the rows settle, so a failed notice leaves them pending. A repeated notice for the same results is not written twice. The row's `details` hold only `source` and a SHA-256 digest of the settled run IDs (the dedupe key), so no run, child or requester ID enters the chat row. - **7-day cutoff.** A result whose latest recorded time is more than 7 days before the settle settles without a chat notice. Each recovery pass logs one count-only line for them. The latest recorded time is the maximum of `completion.capturedAt`, `completion.fallbackCapturedAt`, `execution.endedAt` (stored rows keep it under `parentCompletion.execution.endedAt`), `delivery.payload.endedAt`, `delivery.createdAt`, `delivery.enqueuedAt`, `delivery.lastAttemptAt` and `delivery.suspendedAt`. The row's `createdAt` is used only when none of these exist. This errs toward notifying. `requesterSettleWake.nextAttemptAt` is a future schedule and is not used. Docs: `docs/gateway/restart-recovery.md` describes the settle, the notice and the cutoff. ## Expected effect on first deploy (production counts as of 2026-11-24, by the latest recorded time per row) - 7 days or newer: 9 rows in 6 chats, so 6 chats get one notice each. - Older than 7 days: 27 rows in 15 chats settle silently, with one summary log line per recovery pass. One chat is in both groups. - 2 of the 38 refused ids are not in `subagent_runs` and are unaffected. - After that, those rows are no longer retried at restart. Related: openclaw#204551 (weeks-old pending child results are the same "results without a settled owner" class). ## No-cause refusal sites (classified; none settle) Every `GatewayOperatorRecoveryAuthorizationError` thrown without a cause, at head: - `src/gateway/operator-admission.ts:264`: OpenClaw ID disabled in config (policy). - `src/gateway/operator-admission.ts:271`: tunnel principal not found while OpenClaw ID is not enabled (config state). - `src/gateway/operator-admission.ts:274`: tunnel principal no longer current (membership). - `src/gateway/operator-admission.ts:291` (`refuse()`): profile id changed, shared session generation mismatch, auth method disabled, password fallback generation changed, device token or key not current. Mixed. The shared generation is compared against state the new process rebuilds, so it cannot be certified as a policy-only decision. - `src/gateway/operator-admission.ts:310`: channel identity missing or not current (identity). - `src/gateway/operator-admission.ts:422`: live ingress binding aborted or profile changed (live sources only). - `src/gateway/operator-admission.ts:439`, `:474`, `:479`: person-principal auth error, role excludes the agent, no scopes left (policy). - `src/gateway/operator-run-recovery.ts:91`: role no longer grants the start (policy). - `src/gateway/remote-ingress-principal-recovery.ts:88`, `:114`: ingress grant missing, ingress identity or scope changed. Because `:291` mixes policy with rebuilt process state, no-cause refusals are excluded rather than marked; they keep today's retry. Every refusal seen in production carries `grant-revoked` (88 log lines) or `access-record-inactive` (3 log lines), so this exclusion does not change the expected counts. A revoked device keeps being refused at every restart (test below), as before this change. ## Which change made weeks-old rows eligible (investigation only) Neither candidate changes eligibility. openclaw#203839 (7b99025) changes how a recovered cohort owns its queued settle input. openclaw#203901 (9e3b3a0) changes only yielded children that wait for a message. The pending-child filter in `recoverRequesterCompletionCustody` is identical at edcaafd and 954c6f8. So these rows were already eligible before the deploy. The refusal path is openclaw#202513 (f1b2b4a). For a role-enforced person, the legacy session-principal wake used to take its scopes from the current role. It now uses the recorded session source as the authority, and that source's saved plugin grant is checked. Not bisected end to end. These old results should be settled, not delivered: their requester's access has ended, and one-time admission re-checks replayed work at start. ## Evidence - `src/gateway/session-restart-resume-custody.refusal.test.ts` uses real custody, the real SQLite registry and real chat transcripts, and replaces only requester admission to choose the exact refusal: - refused children settle once across two restarts, one notice in the requesting chat, none in another chat (`grant-revoked` and `access-record-inactive`); - a result older than 7 days settles with no notice and with the summary line; a fresh one notifies; - an old row (created and ended 30 days ago) whose result was captured yesterday notifies; - a refusal without an ended-access cause, a thrown policy error, an unavailable owner and a database error each stay pending across two restarts, with no notice; - the notice row contains no run ID or child session key; - when the notice cannot be written, the refused child stays pending, the failure stays inside that chat's recovery (recovered siblings keep custody; local review finding), and the next restart settles it with one notice. - On merge base ad80d6c the settle cases fail (`expected 2 to be 1`: the refused child is re-admitted at the second restart; `expected 'pending' to be 'discarded'`). The recent-capture case fails the same way (`expected 'pending' to be 'discarded'`); base 4 failed, 4 passed. On the head, 9/9 pass; with `session-restart-resume-custody.test.ts`, 26/26. - `session-restart-resume-custody.test.ts`, new case: a requester whose paired device token was revoked after the spawn is still refused by the real admission at both restarts, and its result stays pending. - `test/gateway-restart-resume.e2e.test.ts` on the head: 5/6 pass. The remaining case, `restart markers survive graceful shutdown (blocked store: false)`, also fails on main. It is a shutdown-ordering assertion (`[close-backfill-proof]` after the clean-close receipt), and in the earlier main run an `Unexpected end of JSON input` from the mock provider harness. No completion refusal is logged in either run. Filed as openclaw#204596. Co-authored-by: Ayaan Zaidi <[email protected]>
## Problem
Refused operator work had no single owner for what the person sees. Each throw site wrote its own sentence, so the same cause read differently by entry point, scope ids and internal words leaked ("Gateway access stopped [access-cause=grant-revoked]", "Restart recovery could not admit this input"), the D23 channel text was copied twice, and the model only got a "do not retry" hint for method-scope refusals. Other refusals reached the model as raw errors, which it paraphrased or retried.
## Fix
- New owner `src/gateway/operator-refusal.ts`: one cause table (same pattern as `connect-error-details.ts`). Each cause has a required `why` and `nextStep`; the compiler rejects a cause without a next step. Text shape: "I did not <action>. <whose access and why>. <one next step>." Causes: `access-ended`, `sign-in-ended`, `role-denies`, `channel-unverified`, `owner-removed`, `requester-access-ended`, `invitation-ended`, `github-not-linked` (only on the path where linking helps: a profile with no linked account and no write access).
- `OperatorRefusalError(cause, { action })` replaces `GatewayOperatorRecoveryAuthorizationError` and its free-text messages. Admission (`operator-admission.ts`) and the recovery helpers pick a cause; R5 ("Gateway access is not active for this requester") is now `role-denies`; R3/R13 (`access-cause=grant-revoked`) are now `access-ended` with the cause chain kept.
- Refusal sites moved onto the table: R9 / requester write (`role-denies`), R8/D23 channel identity (`channel-unverified`, was duplicated), GitHub link (`github-not-linked`), ownerAllowFrom removal (`owner-removed`), restart completion notice (`requester-access-ended`).
- Delivery: chat already shows `OperatorRefusalError.message` (`agent-runner-error-handler.ts`). The tool adapter now returns the same sentence plus "Do not retry." for any refusal (and for method-scope refusals, through the same table). `sessions.github.*` errors keep the typed failure for in-process tool callers (`errorShapeFromError`), so R9 reaches the model as a refusal.
- Boundary lint `no-operator-refusal-construction` (shrink-only, ceiling 9): `new OperatorRefusalError` or a subclass outside the owner fails unless the file is listed. No wording lint.
R3 retry loop: already settled by #204609 (definite refusals settle once); unchanged here except the class name and the notice text.
Not in this PR (remaining refusal texts, follow-up): `operator-role-policy.ts` request-time agent refusal, channel run authorization notice in `agent-runner-error-handler.ts`, `github-publication-failure.ts` workflow permission, `session-access-authority.ts` / tool-policy refusals, connect-time `access-cause` texts (connect owner).
Production `src`: net positive (recorded): the cause table is the new owner; 9 free-text refusal producers and one duplicate moved onto it.
## User impact
Example (revoked member's queued message): "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." The model gets the same sentence plus "Do not retry."
## Evidence
- `src/gateway/operator-refusal.test.ts`: one case per cause through the real tool adapter (sentence + "Do not retry."), plus the in-process Gateway method path. Red on base (no owner).
- Updated contract tests: restart completion notice, tool-bridge member refusal, GitHub inspection, recovery.
- E2E (isolated Gateway, real model) on `2926527b454e`: R/Q/S pass; #205337 (comment)
- Known gap: a queued `/followup` refusal shows the existing pending-input status in chat, not the cause sentence (needs a queue-lifecycle notice or a pending-input field; follow-up).
Co-authored-by: Ayaan Zaidi <[email protected]>
…law#205337) ## Problem Refused operator work had no single owner for what the person sees. Each throw site wrote its own sentence, so the same cause read differently by entry point, scope ids and internal words leaked ("Gateway access stopped [access-cause=grant-revoked]", "Restart recovery could not admit this input"), the D23 channel text was copied twice, and the model only got a "do not retry" hint for method-scope refusals. Other refusals reached the model as raw errors, which it paraphrased or retried. ## Fix - New owner `src/gateway/operator-refusal.ts`: one cause table (same pattern as `connect-error-details.ts`). Each cause has a required `why` and `nextStep`; the compiler rejects a cause without a next step. Text shape: "I did not <action>. <whose access and why>. <one next step>." Causes: `access-ended`, `sign-in-ended`, `role-denies`, `channel-unverified`, `owner-removed`, `requester-access-ended`, `invitation-ended`, `github-not-linked` (only on the path where linking helps: a profile with no linked account and no write access). - `OperatorRefusalError(cause, { action })` replaces `GatewayOperatorRecoveryAuthorizationError` and its free-text messages. Admission (`operator-admission.ts`) and the recovery helpers pick a cause; R5 ("Gateway access is not active for this requester") is now `role-denies`; R3/R13 (`access-cause=grant-revoked`) are now `access-ended` with the cause chain kept. - Refusal sites moved onto the table: R9 / requester write (`role-denies`), R8/D23 channel identity (`channel-unverified`, was duplicated), GitHub link (`github-not-linked`), ownerAllowFrom removal (`owner-removed`), restart completion notice (`requester-access-ended`). - Delivery: chat already shows `OperatorRefusalError.message` (`agent-runner-error-handler.ts`). The tool adapter now returns the same sentence plus "Do not retry." for any refusal (and for method-scope refusals, through the same table). `sessions.github.*` errors keep the typed failure for in-process tool callers (`errorShapeFromError`), so R9 reaches the model as a refusal. - Boundary lint `no-operator-refusal-construction` (shrink-only, ceiling 9): `new OperatorRefusalError` or a subclass outside the owner fails unless the file is listed. No wording lint. R3 retry loop: already settled by openclaw#204609 (definite refusals settle once); unchanged here except the class name and the notice text. Not in this PR (remaining refusal texts, follow-up): `operator-role-policy.ts` request-time agent refusal, channel run authorization notice in `agent-runner-error-handler.ts`, `github-publication-failure.ts` workflow permission, `session-access-authority.ts` / tool-policy refusals, connect-time `access-cause` texts (connect owner). Production `src`: net positive (recorded): the cause table is the new owner; 9 free-text refusal producers and one duplicate moved onto it. ## User impact Example (revoked member's queued message): "I did not run your queued request. Your role on this Gateway does not allow it. Ask a Gateway admin to do it, or to add the permission to your role." The model gets the same sentence plus "Do not retry." ## Evidence - `src/gateway/operator-refusal.test.ts`: one case per cause through the real tool adapter (sentence + "Do not retry."), plus the in-process Gateway method path. Red on base (no owner). - Updated contract tests: restart completion notice, tool-bridge member refusal, GitHub inspection, recovery. - E2E (isolated Gateway, real model) on `2926527b454e`: R/Q/S pass; openclaw#205337 (comment) - Known gap: a queued `/followup` refusal shows the existing pending-input status in chat, not the cause sentence (needs a queue-lifecycle notice or a pending-input field; follow-up). Co-authored-by: Ayaan Zaidi <[email protected]>
…elded session (#204801) ## Problem `src/gateway/session-yield-sweep.test.ts` > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled `main` (run 45403387860): `expected undefined to be 'failed'` at the final status check. Since #204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (`shouldWake`, `session-yield-sweep.ts:45`). When the exec completion's wake settles as `cancelled`, `settleOwedExecWake` withholds the owed row asynchronously: `readPendingOwed` and then `withhold` on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before `withhold` committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset. ## Solution Test-only change. After the wake settles, the test waits until `shouldWake` (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session. #204609 and #204621 do not touch this path. #204609 changes only `session-restart-resume-custody.ts`, which only the restart path imports. #204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked. ## Impact No change to production code or user behavior. ## Evidence - Before: intermittent red on scheduled `main` with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, `checks-node-compact-large-14`, after #205835), `expected undefined to be 'failed'` in the exec-completion case. The race mechanism (`settleOwedExecWake` withholds the owed row after the wake settles) is unchanged on current `main`. - Negative control (deterministic): with a 500 ms delay inserted before that `withhold` (local throwaway change), current `main` fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3. - Without the delay, interleaved runs of `session-yield-sweep.test.ts` with this change applied to current `main`: 20/20 green (main alone was also 20/20 locally; the natural race is rare). ## Merge danger Two-way door: test-only, a revert fully undoes it. Blast radius: one test file. Co-authored-by: Ayaan Zaidi <[email protected]>
…ction Release adaptation: Bind the stable harness policy before tool preparation; preserve scoped configs and workspace floors. Leave mixed artifact, SQL, startup and model-lease restructuring out. Companion audit: Release-only SHA is outside pinned main. Keep the matching #203901 host binding only; #204023 is CI/macOS and #204609 is separate restart settlement. The captured reader and artifact retry already exist. (cherry picked from commit a38363b) Co-authored-by: RomneyDa <[email protected]>
…elded session (openclaw#204801) ## Problem `src/gateway/session-yield-sweep.test.ts` > "settles only an unreachable parked lifecycle (exec-completion)" fails intermittently on scheduled `main` (run 45403387860): `expected undefined to be 'failed'` at the final status check. Since openclaw#204265, the yield sweep keeps a yielded session waiting while it has a stored owed exec result (`shouldWake`, `session-yield-sweep.ts:45`). When the exec completion's wake settles as `cancelled`, `settleOwedExecWake` withholds the owed row asynchronously: `readPendingOwed` and then `withhold` on the database worker. The test resolved the wake and advanced the fake clock straight away. When the sweep tick ran before `withhold` committed, the sweep still saw the pending row and correctly left the session waiting, so the status stayed unset. ## Solution Test-only change. After the wake settles, the test waits until `shouldWake` (the stored-row check the sweep itself uses) reports no owed result, then advances the clock. Product behavior is unchanged: the next sweep tick settles the session. openclaw#204609 and openclaw#204621 do not touch this path. openclaw#204609 changes only `session-restart-resume-custody.ts`, which only the restart path imports. openclaw#204621 changes reply-operation backend readiness, which none of these modules use; the test's wake is mocked. ## Impact No change to production code or user behavior. ## Evidence - Before: intermittent red on scheduled `main` with the assertion above: run 45403387860, and again in run 45849028735 (2026-11-26, `checks-node-compact-large-14`, after openclaw#205835), `expected undefined to be 'failed'` in the exec-completion case. The race mechanism (`settleOwedExecWake` withholds the owed row after the wake settles) is unchanged on current `main`. - Negative control (deterministic): with a 500 ms delay inserted before that `withhold` (local throwaway change), current `main` fails the exec-completion case 3/3 with the same assertion; with this change it passes 3/3. - Without the delay, interleaved runs of `session-yield-sweep.test.ts` with this change applied to current `main`: 20/20 green (main alone was also 20/20 locally; the natural race is rare). ## Merge danger Two-way door: test-only, a revert fully undoes it. Blast radius: one test file. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
When the Gateway restarts, restart recovery tries to deliver finished subagent results that are still owed to their requesting chat. It re-admits the saved requester first. When that admission is refused because the requester's access has ended,
session-restart-resume-custody.tsonly logged a warning. The result was never settled, so it was retried and refused again at every restart. The user saw nothing, not even that a result was lost.On one production deployment this showed as 88 refusal lines over 6 restart bursts, for 38 child results in 20 chats. 36 of those rows are in
subagent_runs, created 10-29 to 11-23, and most are weeks old. The same rows were refused at every restart.The refusal itself is correct and does not change: one-time admission says replayed work checks its requester again when it starts.
Fix
session-restart-resume-custody.tssettles a definitely refused completion once:GatewayOperatorRecoveryAuthorizationErrorwhose cause isGatewayOperatorAccessDeniedErrorwithgrant-revokedoraccess-record-inactive(the saved plugin grant or access record ended or was replaced), orUserProfileNotFoundError(the saved profile is gone). Everything else stays pending and retries at the next restart, as before. That includes refusals without a cause (listed below), thrown policy errors (policy-check-failed), an unavailable access owner, timeouts and database errors.discardedwithlastErrornaming the reason,suppressCompletionDeliveryretires the obligation and the pending requester wake is cleared, so the row leaves the restart pending set. Nothing is deleted.openclaw.system-note: "A background task's result couldn't be delivered because the access it ran under has ended." It names no requester, grant or result. Several results settled in the same chat in one pass produce one notice. The notice is written before the rows settle, so a failed notice leaves them pending. A repeated notice for the same results is not written twice. The row'sdetailshold onlysourceand a SHA-256 digest of the settled run IDs (the dedupe key), so no run, child or requester ID enters the chat row.completion.capturedAt,completion.fallbackCapturedAt,execution.endedAt(stored rows keep it underparentCompletion.execution.endedAt),delivery.payload.endedAt,delivery.createdAt,delivery.enqueuedAt,delivery.lastAttemptAtanddelivery.suspendedAt. The row'screatedAtis used only when none of these exist. This errs toward notifying.requesterSettleWake.nextAttemptAtis a future schedule and is not used.Docs:
docs/gateway/restart-recovery.mddescribes the settle, the notice and the cutoff.Expected effect on first deploy (production counts as of 2026-11-24, by the latest recorded time per row)
subagent_runsand are unaffected.Related: #204551 (weeks-old pending child results are the same "results without a settled owner" class).
No-cause refusal sites (classified; none settle)
Every
GatewayOperatorRecoveryAuthorizationErrorthrown without a cause, at head:src/gateway/operator-admission.ts:264: OpenClaw ID disabled in config (policy).src/gateway/operator-admission.ts:271: tunnel principal not found while OpenClaw ID is not enabled (config state).src/gateway/operator-admission.ts:274: tunnel principal no longer current (membership).src/gateway/operator-admission.ts:291(refuse()): profile id changed, shared session generation mismatch, auth method disabled, password fallback generation changed, device token or key not current. Mixed. The shared generation is compared against state the new process rebuilds, so it cannot be certified as a policy-only decision.src/gateway/operator-admission.ts:310: channel identity missing or not current (identity).src/gateway/operator-admission.ts:422: live ingress binding aborted or profile changed (live sources only).src/gateway/operator-admission.ts:439,:474,:479: person-principal auth error, role excludes the agent, no scopes left (policy).src/gateway/operator-run-recovery.ts:91: role no longer grants the start (policy).src/gateway/remote-ingress-principal-recovery.ts:88,:114: ingress grant missing, ingress identity or scope changed.Because
:291mixes policy with rebuilt process state, no-cause refusals are excluded rather than marked; they keep today's retry. Every refusal seen in production carriesgrant-revoked(88 log lines) oraccess-record-inactive(3 log lines), so this exclusion does not change the expected counts. A revoked device keeps being refused at every restart (test below), as before this change.Which change made weeks-old rows eligible (investigation only)
Neither candidate changes eligibility. #203839 (92e92d7) changes how a recovered cohort owns its queued settle input. #203901 (e58ca10) changes only yielded children that wait for a message. The pending-child filter in
recoverRequesterCompletionCustodyis identical at 648619c and e2973f9. So these rows were already eligible before the deploy.The refusal path is #202513 (3ad2cce). For a role-enforced person, the legacy session-principal wake used to take its scopes from the current role. It now uses the recorded session source as the authority, and that source's saved plugin grant is checked. Not bisected end to end.
These old results should be settled, not delivered: their requester's access has ended, and one-time admission re-checks replayed work at start.
Evidence
src/gateway/session-restart-resume-custody.refusal.test.tsuses real custody, the real SQLite registry and real chat transcripts, and replaces only requester admission to choose the exact refusal:grant-revokedandaccess-record-inactive);expected 2 to be 1: the refused child is re-admitted at the second restart;expected 'pending' to be 'discarded'). The recent-capture case fails the same way (expected 'pending' to be 'discarded'); base 4 failed, 4 passed. On the head, 9/9 pass; withsession-restart-resume-custody.test.ts, 26/26.session-restart-resume-custody.test.ts, new case: a requester whose paired device token was revoked after the spawn is still refused by the real admission at both restarts, and its result stays pending.test/gateway-restart-resume.e2e.test.tson the head: 5/6 pass. The remaining case,restart markers survive graceful shutdown (blocked store: false), also fails on main. It is a shutdown-ordering assertion ([close-backfill-proof]after the clean-close receipt), and in the earlier main run anUnexpected end of JSON inputfrom the mock provider harness. No completion refusal is logged in either run. Filed as test: gateway-restart-resume e2e graceful-shutdown case fails with 'Unexpected end of JSON input' in the mock provider #204596.