Repository navigation
fix: preserve requester permissions when interrupted work resumes - #200394
Conversation
Carry the original bounded requester source through restart recovery and retain service installation facts for received connection work. Co-authored-by: vincentkoc <[email protected]>
Keep the existing checkpoint programs and assertions while avoiding required-result mode, which correctly refuses an explicit unfinished yield. Co-authored-by: vincentkoc <[email protected]>
Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: ae7b4a92-2ec6-4092-8b76-1f63dfd010ef
|
🦞👀 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. |
|
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Integrate main for the observed merge-context failures, retain all eight authority regressions in the existing restart admission suite, and require that fixture consumer in affected-owner planning. This removes the extra hosted job without raising the budget. Co-authored-by: vincentkoc <[email protected]>
Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: 8ac7f510-c978-4fdc-b8a3-66ff171f5424
Co-authored-by: vincentkoc <[email protected]>
Exercise distinct signed-in requester profiles instead of loopback owner credentials, and change only the captured profile after shutdown. Keep the healthy sibling and visible refusal assertions unchanged. Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
|
Merged via squash.
|
… crashes (#200533) ## Problem An accepted (acknowledged) queued chat message could disappear without a trace: - It could be cancelled with no stored reason. History showed nothing, and retrying the same message ID could return a cached success although the message never ran. - A Gateway crash (SIGKILL) lost it. Recovery depended on a graceful-shutdown marker, so a crash before the acknowledgment, or between claiming the message and the turn taking it over, left neither a queued row nor a running turn. On restart nothing answered and nothing explained why. This changes #185730's accepted SIGKILL loss for acknowledged queued input. ## Fix **Recorded end causes** - Store a closed `end_cause` (`user-stop`, `delete`, `reset`, `revoked`, `restart-unrecoverable`, `overflow`, `policy-refused`, `failed`) through the existing pending-input owner. One settlement owner classifies causes (an explicit Stop, delete, reset or revocation wins over a temporary outage), releases consumed custody and records terminal endings. - Temporary authority or dispatch outages: before the input is accepted (no acknowledgment sent; the caller gets the error), the row ends `failed`, as main cancels it today. After acceptance, the row stays queued and the failed attempt gives up its live ownership, so the existing owner (follow-up drain, mailbox, or startup replay) runs it once. - Read durable cancellation before cached success/abort responses; a queued retry reports in flight. - Chat shows one translated sentence per cause (for example "The Gateway restarted before this message ran. Send it again."). A message the user stopped shows no notice, as before (#186073). - Channel redelivery under a fresh run ID still reclaims an attempt that ended `failed`, `restart-unrecoverable`, or with no recorded cause (#193602). Explicit caller retries may reopen a cancelled row unless a final completion receipt exists or the user stopped it. One function (`isRetryableSessionPendingInputEndCause`) defines retryable endings for redelivery and Doctor repair; when Doctor merges two copies of one input, a deliberate ending in either copy wins. **Crash recovery** - Store the already captured, authenticated sender source on the pending row (`origin_source_json`). Startup replays queued, unconsumed rows in FIFO order after running-root resume admission and revalidates current authority when work starts. A missing source ends as `restart-unrecoverable`. The column is cleared when custody ends. It is not the retired, untrusted `recovery_intent_json` envelope; historical v24 interruption is unchanged. - The transaction that appends the user message and consumes the pending row also writes the turn's existing lifecycle start fields, so restart recovery always finds the input as either a queued row or a running turn. No new table, scheduler or reconstruction machinery. - If replay defers because authority or dispatch is temporarily unavailable, the session keeps its older rows ahead of new input: the shared admission point (`waitForAgentInputAdmission`) runs that session's deferred replay once before admitting fresh input, and refuses fresh input with the same retryable error while it still defers. Other sessions are unaffected. No timer or retry loop. - Legacy `queuedInputSources` move from shutdown markers to their pending rows through the startup/Doctor rewrite owner. #200394's `resumeAfterRestart.operatorSource` (the interrupted root requester) is kept; a crash writes no marker, so source-less root recovery keeps the existing session-principal policy. ## Agent schema 43 (one bump) The agent database schema advances from 42 to 43 on SQLite and PostgreSQL through the existing versioned migration owners. It adds nullable `end_cause` and `origin_source_json` to `session_pending_inputs` and, in the same transaction, sets `end_cause = 'user-stop'` for older cancelled rows whose message carries `__openclaw.pendingInputCancelledByUser: true` or `display: false` (message bytes unchanged; dismissed rows stay hidden). Runtime readers use only `end_cause`. Every pre-43 historical schema, including the schema-14 preflight, is derived without the two columns; PostgreSQL v42 predecessor DDL is unchanged. Older builds refuse schema 43; rollback needs the pre-upgrade backup and the matching binary. No schema-version bypass. Pre-migration backup: `session_pending_inputs` is the agent schema's only `AUTOINCREMENT` table, and the scoped migration snapshot does not cover `AUTOINCREMENT` tables (shared `sqlite_sequence`), so Doctor takes its existing full-database backup for 42 → 43 wherever that table exists. Upgrades from stable 2026.11.4 already take a full backup (schema 30 has no scoped entry). For stores already on 42 this is a one-time copy about the size of the agent database (3.0 GB on one measured long-lived store). The migration inserts no rows, and no backup code changes. ## User impact - A queued message survives a crash: it is answered once, or ends with a visible reason. Same-ID retries never start a second answer. - Cancelled messages explain why, in plain words, instead of looking successful. - During a startup access outage, new messages in an affected session get a "try again" error until its older messages have run; nothing runs out of order. Accepted edges: - Explicit `sessions.delete` removes input rows and message bodies; the delete confirmation is the visible result. - Stop on 2026.11.4 and earlier wrote no marker; such rows stay generically cancelled and reclaimable by a same-content channel redelivery, as on main. - An accepted input whose path has no in-process retrier (direct agent execution after acknowledgment) and that hits a temporary outage stays visibly queued until the next Gateway start replays it. - The upgrade from 42 to 43 takes a full-database backup where `session_pending_inputs` exists (see Agent schema 43). - No exactly-once guarantee for external tool effects or provider billing. ## Evidence - Head `ed2c3b46d558`, rebased on current main: format, lint and line caps pass; `pnpm tsgo:core`, all `pnpm tsgo:core:test` configurations and the script typecheck pass; all baseline ratchets and the import-cycle guard pass. Regression tests (each red on an earlier head) cover deferred replay ordering, the shared-store graceful-restart agent, pre-acceptance outages, an accepted follow-up that waits out an outage and then runs exactly once, a same-key attempt with a different run ID (refused), startup replay racing the follow-up drain (one run), a user Stop during an outage, and the original abort signal on cleanup. An internal stop is not recorded as `user-stop`; only a user-initiated Stop is. Only the recorder that confirmed a relinquish may re-attach its queued row; a fresh send, a redelivery or a row whose settlement failed cannot (the revoked-parent-after-stop test stays refused). Startup replay re-attaches only its exact durable row by input ID after a deferred outage. - Schema: reopening a main v42 PostgreSQL store failed before the migration (`PostgreSQL schema drift detected against generated DDL`) and now migrates to 43; 10 real PostgreSQL tests pass. The v14-to-v15 migration test failed with `column definitions differ for session_pending_inputs` before the historical-schema fix and passes now. Each review fix carries a regression test that failed before it. - Crash proof on head `ed2c3b46d558`: isolated source Gateway, Node inspector, real model, external SIGKILL at the exact breakpoint; `plugins.allow=["openai"]`, `plugins.slots.memory="none"`, `cron.enabled=false`. Baseline is main at `6747b1ec5ae3`. | Fault | Main answers / queued model calls | This PR answers / queued model calls | Stored outcome | | --- | --- | --- | --- | | Message row written, before acknowledgment | 0 / 0 | 1 / 1 | Answered; no pending row; session done | | Message claimed, before the turn took it over | 0 / 0 | 1 / 0 (one running-turn recovery call) | Answered; the message was already in the transcript and the row gone at the pause; session done | Each produced exactly one answer and no extra model calls after a same-ID retry. Earlier runs on pre-43 head `975900737b4f` covered a crash just after takeover (one answer, no duplicate) and mid-turn (one answer). - Upgrade from 2026.11.4 (schema 27), clean shutdown and SIGKILL: both reach schema 43 with both columns; a message still queued after the SIGKILL ends `cancelled / restart-unrecoverable`, shown in history and on same-ID retry, with zero model calls. Both this branch and pinned main fail their first start after that SIGKILL with a secrets/SQLite disk-I/O error and succeed on the second start; filed separately as #200617. Doctor's Control UI build during that upgrade is #200618. - Chat notice before/after screenshots are in the PR comments. No full release declaration proof or real PostgreSQL conformance suite is claimed beyond the tests above. Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#200394) * fix: preserve requester permissions when interrupted work resumes Carry the original bounded requester source through restart recovery and retain service installation facts for received connection work. Co-authored-by: vincentkoc <[email protected]> * test(qa): select intentional suspension for restart checkpoints Keep the existing checkpoint programs and assertions while avoiding required-result mode, which correctly refuses an explicit unfinished yield. Co-authored-by: vincentkoc <[email protected]> * fix: preserve requester permissions when interrupted work resumes Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: ae7b4a92-2ec6-4092-8b76-1f63dfd010ef * Publish openclaw/gentle-lobster-4 Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: 8ac7f510-c978-4fdc-b8a3-66ff171f5424 * fix: align restart refusal proof with requester authority Co-authored-by: vincentkoc <[email protected]> * test: revoke the captured restart requester in process proof Exercise distinct signed-in requester profiles instead of loopback owner credentials, and change only the captured profile after shutdown. Keep the healthy sibling and visible refusal assertions unchanged. Co-authored-by: vincentkoc <[email protected]> * test: keep restart admission imports type-only Co-authored-by: vincentkoc <[email protected]> --------- Co-authored-by: vincentkoc <[email protected]>
… crashes (openclaw#200533) ## Problem An accepted (acknowledged) queued chat message could disappear without a trace: - It could be cancelled with no stored reason. History showed nothing, and retrying the same message ID could return a cached success although the message never ran. - A Gateway crash (SIGKILL) lost it. Recovery depended on a graceful-shutdown marker, so a crash before the acknowledgment, or between claiming the message and the turn taking it over, left neither a queued row nor a running turn. On restart nothing answered and nothing explained why. This changes openclaw#185730's accepted SIGKILL loss for acknowledged queued input. ## Fix **Recorded end causes** - Store a closed `end_cause` (`user-stop`, `delete`, `reset`, `revoked`, `restart-unrecoverable`, `overflow`, `policy-refused`, `failed`) through the existing pending-input owner. One settlement owner classifies causes (an explicit Stop, delete, reset or revocation wins over a temporary outage), releases consumed custody and records terminal endings. - Temporary authority or dispatch outages: before the input is accepted (no acknowledgment sent; the caller gets the error), the row ends `failed`, as main cancels it today. After acceptance, the row stays queued and the failed attempt gives up its live ownership, so the existing owner (follow-up drain, mailbox, or startup replay) runs it once. - Read durable cancellation before cached success/abort responses; a queued retry reports in flight. - Chat shows one translated sentence per cause (for example "The Gateway restarted before this message ran. Send it again."). A message the user stopped shows no notice, as before (openclaw#186073). - Channel redelivery under a fresh run ID still reclaims an attempt that ended `failed`, `restart-unrecoverable`, or with no recorded cause (openclaw#193602). Explicit caller retries may reopen a cancelled row unless a final completion receipt exists or the user stopped it. One function (`isRetryableSessionPendingInputEndCause`) defines retryable endings for redelivery and Doctor repair; when Doctor merges two copies of one input, a deliberate ending in either copy wins. **Crash recovery** - Store the already captured, authenticated sender source on the pending row (`origin_source_json`). Startup replays queued, unconsumed rows in FIFO order after running-root resume admission and revalidates current authority when work starts. A missing source ends as `restart-unrecoverable`. The column is cleared when custody ends. It is not the retired, untrusted `recovery_intent_json` envelope; historical v24 interruption is unchanged. - The transaction that appends the user message and consumes the pending row also writes the turn's existing lifecycle start fields, so restart recovery always finds the input as either a queued row or a running turn. No new table, scheduler or reconstruction machinery. - If replay defers because authority or dispatch is temporarily unavailable, the session keeps its older rows ahead of new input: the shared admission point (`waitForAgentInputAdmission`) runs that session's deferred replay once before admitting fresh input, and refuses fresh input with the same retryable error while it still defers. Other sessions are unaffected. No timer or retry loop. - Legacy `queuedInputSources` move from shutdown markers to their pending rows through the startup/Doctor rewrite owner. openclaw#200394's `resumeAfterRestart.operatorSource` (the interrupted root requester) is kept; a crash writes no marker, so source-less root recovery keeps the existing session-principal policy. ## Agent schema 43 (one bump) The agent database schema advances from 42 to 43 on SQLite and PostgreSQL through the existing versioned migration owners. It adds nullable `end_cause` and `origin_source_json` to `session_pending_inputs` and, in the same transaction, sets `end_cause = 'user-stop'` for older cancelled rows whose message carries `__openclaw.pendingInputCancelledByUser: true` or `display: false` (message bytes unchanged; dismissed rows stay hidden). Runtime readers use only `end_cause`. Every pre-43 historical schema, including the schema-14 preflight, is derived without the two columns; PostgreSQL v42 predecessor DDL is unchanged. Older builds refuse schema 43; rollback needs the pre-upgrade backup and the matching binary. No schema-version bypass. Pre-migration backup: `session_pending_inputs` is the agent schema's only `AUTOINCREMENT` table, and the scoped migration snapshot does not cover `AUTOINCREMENT` tables (shared `sqlite_sequence`), so Doctor takes its existing full-database backup for 42 → 43 wherever that table exists. Upgrades from stable 2026.11.4 already take a full backup (schema 30 has no scoped entry). For stores already on 42 this is a one-time copy about the size of the agent database (3.0 GB on one measured long-lived store). The migration inserts no rows, and no backup code changes. ## User impact - A queued message survives a crash: it is answered once, or ends with a visible reason. Same-ID retries never start a second answer. - Cancelled messages explain why, in plain words, instead of looking successful. - During a startup access outage, new messages in an affected session get a "try again" error until its older messages have run; nothing runs out of order. Accepted edges: - Explicit `sessions.delete` removes input rows and message bodies; the delete confirmation is the visible result. - Stop on 2026.11.4 and earlier wrote no marker; such rows stay generically cancelled and reclaimable by a same-content channel redelivery, as on main. - An accepted input whose path has no in-process retrier (direct agent execution after acknowledgment) and that hits a temporary outage stays visibly queued until the next Gateway start replays it. - The upgrade from 42 to 43 takes a full-database backup where `session_pending_inputs` exists (see Agent schema 43). - No exactly-once guarantee for external tool effects or provider billing. ## Evidence - Head `ed2c3b46d558`, rebased on current main: format, lint and line caps pass; `pnpm tsgo:core`, all `pnpm tsgo:core:test` configurations and the script typecheck pass; all baseline ratchets and the import-cycle guard pass. Regression tests (each red on an earlier head) cover deferred replay ordering, the shared-store graceful-restart agent, pre-acceptance outages, an accepted follow-up that waits out an outage and then runs exactly once, a same-key attempt with a different run ID (refused), startup replay racing the follow-up drain (one run), a user Stop during an outage, and the original abort signal on cleanup. An internal stop is not recorded as `user-stop`; only a user-initiated Stop is. Only the recorder that confirmed a relinquish may re-attach its queued row; a fresh send, a redelivery or a row whose settlement failed cannot (the revoked-parent-after-stop test stays refused). Startup replay re-attaches only its exact durable row by input ID after a deferred outage. - Schema: reopening a main v42 PostgreSQL store failed before the migration (`PostgreSQL schema drift detected against generated DDL`) and now migrates to 43; 10 real PostgreSQL tests pass. The v14-to-v15 migration test failed with `column definitions differ for session_pending_inputs` before the historical-schema fix and passes now. Each review fix carries a regression test that failed before it. - Crash proof on head `ed2c3b46d558`: isolated source Gateway, Node inspector, real model, external SIGKILL at the exact breakpoint; `plugins.allow=["openai"]`, `plugins.slots.memory="none"`, `cron.enabled=false`. Baseline is main at `c303d979c41b`. | Fault | Main answers / queued model calls | This PR answers / queued model calls | Stored outcome | | --- | --- | --- | --- | | Message row written, before acknowledgment | 0 / 0 | 1 / 1 | Answered; no pending row; session done | | Message claimed, before the turn took it over | 0 / 0 | 1 / 0 (one running-turn recovery call) | Answered; the message was already in the transcript and the row gone at the pause; session done | Each produced exactly one answer and no extra model calls after a same-ID retry. Earlier runs on pre-43 head `975900737b4f` covered a crash just after takeover (one answer, no duplicate) and mid-turn (one answer). - Upgrade from 2026.11.4 (schema 27), clean shutdown and SIGKILL: both reach schema 43 with both columns; a message still queued after the SIGKILL ends `cancelled / restart-unrecoverable`, shown in history and on same-ID retry, with zero model calls. Both this branch and pinned main fail their first start after that SIGKILL with a secrets/SQLite disk-I/O error and succeed on the second start; filed separately as openclaw#200617. Doctor's Control UI build during that upgrade is openclaw#200618. - Chat notice before/after screenshots are in the PR comments. No full release declaration proof or real PostgreSQL conformance suite is claimed beyond the tests above. Co-authored-by: Ayaan Zaidi <[email protected]>
…00394) * fix: preserve requester permissions when interrupted work resumes Carry the original bounded requester source through restart recovery and retain service installation facts for received connection work. Co-authored-by: vincentkoc <[email protected]> * test(qa): select intentional suspension for restart checkpoints Keep the existing checkpoint programs and assertions while avoiding required-result mode, which correctly refuses an explicit unfinished yield. Co-authored-by: vincentkoc <[email protected]> * fix: preserve requester permissions when interrupted work resumes Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: ae7b4a92-2ec6-4092-8b76-1f63dfd010ef * Publish openclaw/gentle-lobster-4 Worked on by: - @vincentkoc Co-authored-by: vincentkoc <[email protected]> OpenClaw-Publication: 8ac7f510-c978-4fdc-b8a3-66ff171f5424 * fix: align restart refusal proof with requester authority Co-authored-by: vincentkoc <[email protected]> * test: revoke the captured restart requester in process proof Exercise distinct signed-in requester profiles instead of loopback owner credentials, and change only the captured profile after shutdown. Keep the healthy sibling and visible refusal assertions unchanged. Co-authored-by: vincentkoc <[email protected]> * test: keep restart admission imports type-only Co-authored-by: vincentkoc <[email protected]> --------- Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit d80fbe7) Backport review: Preserve accepted operator identity across restart recovery and fail closed for a missing known source; do not widen the session owner authority. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit b5a4aaedd058d8914bd2512c09362f1de0e9dfa0)
Related: #182042, #182043 (distinct completion-recovery paths; this change repairs interrupted root turns).
What Problem This Solves
After a Gateway restart, interrupted work in a shared session can resume without the person who authorized it, or as the session's owner instead. Follow-up tools then reject the task or see the wrong person's permissions.
User Impact
Interrupted turns can resume as their original requester, within that requester's original limits and current access. Revoked or unavailable sources still fail closed. Existing markers without an original source retain their previous recovery policy; already-yielded roots with only child work alive are not covered by this change. No configuration or migration is required.
Why This Change Was Made
Reuse the existing shutdown marker and recovery owner to preserve the interrupted turn's bounded authentication source, apply its scope ceiling before session admission, and resume the accepted access grant rather than requesting another one. Do not select a later participant or substitute the session owner.
Also retain service-installation facts through the existing connection-work owner. Losing those host facts in socket callbacks caused the initial trusted-proxy connection to conflict with an already-retained database worker. This restores the same host policy without capturing requester/startup authority or weakening the worker guard. No GitHub credential or permission checks change.
Evidence
049f7fffc862659317db98a35862ac4e62a26053, the documented QA runtime build passed. All seven tests selected from the failed CI run passed locally: five real Gateway restart process tests and two Workshop tests. All 11 admission controls passed. The owningtsconfig.test.root.other.jsontypecheck, core lint for both touched tests, format and diff checks passed. Two all-type imports were corrected to top-levelimport typedeclarations.2ee2d08dff5863a45c57c706ad257447773c499b, P0–P2: complete, scoped-clean, no actionable findings. Earlier complete runtime/main-integration reviews remain applicable to the unchanged runtime.Credit: @vincentkoc for reporting the incident and directing the investigation and fix.
Work sessions
Linked for team reference; these sessions aren’t public.
Worked on by