Skip to content

fix: pause interrupted shell turns when their result is unknown - #205859

Merged
vincentkoc merged 3 commits into
mainfrom
fix/restart-uncertain-shell-receipt
Nov 26, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
fix/restart-uncertain-shell-receipt

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

A Gateway restart can interrupt a shell command after it creates a reminder but before the chat saves the result. In a reproduced case the agent repeated the command, created a second reminder and told the user the work was complete. The same confirmation was possible when the command had never reached the scheduler.

User Impact

When a managed chat has an interrupted shell command with no verified terminal result, the Gateway tells the user that the effect is unknown and pauses that turn. A separate queued message can still receive a reply. A saved terminal result lets ordinary restart recovery continue. A command that cannot record its session ownership is refused before dispatch.

Why This Change Was Made

The native shell records a private invocation identity before local execution, remote dispatch or a deferred approval. The session store checks the writer, run and lifecycle revision before admitting the command. An accepted tool result, a terminal poll of the same process, or a recorded terminal decision from its deferred approval can settle it. Gateway and node approvals record a definite denial or an observed exit before attempting follow-up delivery. An approval still waiting, a lost node response and uncertain process cleanup leave the receipt outstanding.

Restart reconciles accepted observations in the session store. If an original call is still pending, it saves the uncertainty notice, uses the admitted input’s verified return route and acknowledges the exact restart marker. The receipt contains no command text. The change uses the existing session row and transcript indexes.

Evidence

  • In the negative control, the recovery model gave two success replies and increased the job count from one to two. The original report and control are documented on the issue.
  • In the packaged Gateway test, the shell was interrupted before it started the scheduler CLI and after that CLI committed its job but before the shell replied. In both direct shell and Code Mode, each run produced two uncertainty notices, zero model dispatches for the ambiguous turns, one CLI start and one distinct job. Each answered a fresh queued message and resumed the control turn with a saved shell result. AWS proof
  • A real background process and two terminal polls verified that the second observation can settle the command when the first is never saved. The 65th outstanding command and a stale writer were refused before creating their test files. The host records at most 64 outstanding calls. It checks the bounded actor identity window or makes one indexed lookup per candidate without loading transcript bodies. Signal, memory-limit, cancellation and timeout results remain uncertain even if accompanied by a numeric exit code. Admission checks
  • The original-channel fixture exercises the exact account, thread and reply anchor, plus a replaced restart marker and transcript-only recovery. The channel adapter in this fixture is synthetic. The existing queued-input, lifecycle-writer and nested-result files also passed. Their run also exposed a setup failure in the new shell test. The final candidate runs that test in the broker-backed lane and passed. Sibling checks
  • Gateway and node approval tests exercised known denial, ordinary exit and a lost response. The gateway also recorded the exit before a failing follow-up. The session-store test kept one approval pending while accepting 65 other completions, including exit code 3. A duplicate denial wrote one observation, and a late callback could not settle a replacement session writer’s call. A lost node response remained outstanding. Across the two host suites and two Gateway suites, 95 tests passed. AWS approval and session-store checks
  • The packaged candidate exercised both shell crash windows through direct exec and Code Mode. Each mode recorded two uncertainty notices, zero recovery model dispatches, one CLI start and one saved job. The independent queued message got a reply and the terminal-result control resumed. AWS packaged Gateway replay
  • The published v2026.11.10 Gateway created a session, set its label and thinking preference, wrote a transcript message and stopped during an ordinary provider call. Its persisted restart marker had no shell-receipt field. The candidate reused the same database, returned the same session ID, label, preference and original message ID, role and content, resumed that ordinary turn once and emitted zero uncertainty notices. AWS upgrade
  • All nine restart acceptance cases passed on CI’s pinned Bun revision. SIGTERM during an active shell produced one uncertainty notice, one original user entry, one shell callback and zero model requests to resume that turn. A separate queued message in the same session produced one provider request and the expected reply. The SIGKILL, operator authority, dashboard, suspend/reopen and blocked-store cases also passed. Restart acceptance suite
  • The session-store repair has the same tree as the tested AWS checkout, 112970b976eb7479479a8125a0272e2bc3803666. Scoped lint reported zero errors and warnings. Gateway test types passed. The identity ratchet decreased from 6,205 comparisons in 1,557 files to 6,200 in 1,556. The before-exit and post-exit assertions both passed. Commit review reported no actionable P0/P1 findings. Exact tree, authenticated upgrade and focused checks
  • The final foreground regression uses the normal exec tool and a supervisor that returns exit code 0 or 3 while descendant cleanup remains unconfirmed. On the previous head both results incorrectly acquired a terminal receipt. The repaired tool keeps the observed exit code and cleanup warning in both cases and issues zero terminal receipts. Foreground, terminal poll and deferred Gateway approvals now consult the same process-owner cleanup flags. Before · After
  • On the final signed tree, 135 tests passed across the seven foreground, cleanup, gateway/node approval, session-store and Gateway prestart files. The failed marker-write test now exercises the storage writer used in production. Sharing the two shell-session fixtures brought the test-line ratchet from +434 to +400 with zero allocation credit, including when applied to the exact CI merge that failed. Core, agent, Gateway and Gateway-method test types passed, and scoped lint reported zero errors or warnings. Targeted commit review found no actionable P0/P1 issue. AWS production-owner and CI parity checks

Across the PR, production source changed by +991/−117 lines and tests by +430/−29. The production additions give the session writer one bounded way to connect dispatch, accepted results and restart reporting across direct, nested, background and deferred execution.

The same WebChat conversation is shown immediately before and after the fixture Gateway restarted. The temporary fixture path is redacted.

WebChat shows the synthetic scheduler command running

WebChat reports that the shell effect is unknown and that the turn was paused without retry

Related to issue 187354, reported by @fonchaves. Their scheduler catalog fix and the typed restart fix landed separately. The reported ARM container OOM and SQLite lease contention remain unverified.

Record native shell dispatch before work can start. On restart, continue after a saved terminal result, or report uncertainty without asking the model to repeat or confirm an unknown effect.

Refs #187354
@vincentkoc vincentkoc self-assigned this Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Nov 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 26, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 26, 2026 08:36
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR records shell dispatch receipts and pauses interrupted turns whose terminal results were not durably saved.

Example: A reminder command creates one job, then the Gateway restarts before saving its result.

  • Before: Recovery can repeat the command, create a second job, and claim success.
  • After: Recovery posts an uncertainty notice without dispatching the interrupted turn to the model; a separate queued message can still run.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused recovery repair is supported by production-entry-point evidence and resolves prior findings; the partial linked-issue scope caps the overall tier at C.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): Inspected WebChat before/after images show the uncertainty pause; self-contained maintainer results cover packaged direct-exec and Code Mode crash windows, queued-message delivery, saved-result continuation, and the stable-release upgrade. Linked AWS pages were inaccessible here, which does not invalidate the supplied evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: After a restart, the assistant can repeat a shell action whose effect already committed and falsely confirm completion.
Reason: The maintainer-authored direction addresses demonstrated duplicate effects; Related wording correctly leaves the broader report's unverified OOM and contention symptoms open.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a demonstrated recovery defect that remains on main; the prior findings are resolved and no new actionable defect was found.

Reviewed head: e0de568a8c11e308d24d641719d0adbf41a5c173

Before merge

None.

Findings

None.

Agent review details

How this fits together

Managed embedded turns dispatch shell commands through the exec owners, persist accepted observations through the session writer, and let Gateway restart recovery choose between ordinary continuation and an uncertainty notice.

flowchart TD
  A[Managed chat turn] --> B[Session writer admits shell receipt]
  B --> C[Gateway or node execution]
  C --> D[Accepted terminal observation]
  D --> E[Session receipt reconciliation]
  E --> F[Gateway restart recovery]
  F --> G[Continue verified turn]
  F --> H[Pause uncertain turn]
Loading

Technical review

Best possible solution:

Keep shell admission, accepted-result reconciliation, and restart settlement under the existing session writer while preserving independent queued-input admission.

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

The linked maintainer reproduction records duplicate scheduling after restart, and current main still sends ambiguous shell work through ordinary model recovery; this read-only review ran no target code.

Is this the best way to solve the issue?

The coherent fix connects pre-dispatch identity to durable terminal observations and recovery through existing owners; a prompt-only repair already failed the recorded control.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Ordinary restart continuation changes intended behavior with a stated reason (9344233: The earlier redesign replaced competing recovery owners with one ordinary resume input and explicitly accepted imperfect external-effect recovery.)
  • Original execution attribution keeps the original intent (d63a7c9: Carry the interrupted backend run identity so recovery can distinguish attributable outcomes from older same-name operations.)
  • Ambiguous node execution outcomes keeps the original intent (b82dd01: Treat lost or uncertain post-dispatch responses as outcome-unknown rather than retry-safe denial.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit d63a7c9 adds src/gateway/session-restart-resume.ts:542 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d63a7c9ba48d; files: src/gateway/session-restart-resume.ts)

PR surface

Source +874, Tests +401, Docs +2, Other -1. Total +1276 across 44 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 34 991 117 +874
Tests 8 430 29 +401
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 2 -1
Total 44 1424 148 +1276

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +991/−117; tests and test routing +430/−29 The growth connects pre-dispatch admission, accepted observations, and restart reporting across direct, nested, background, and deferred execution without introducing another storage owner.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • merge-risk: 🚨 session-state: The patch changes durable shell-call bookkeeping and restart settlement; pausing ambiguous turns and refusing unrecordable dispatch are explicit maintainer-authored tradeoffs.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-26T08:55:05.398Z sha b9174ab :: blocked before merge. :: [P2] [P2] Keep receipt identity checks inside the session-store owner | [P2] [P2] Update restart acceptance tests for the uncertainty pause
  • reviewed 2026-11-26T09:49:15.596Z sha 44b3895 :: needs changes before merge. :: [P2] Retain foreground receipts when descendant cleanup is uncertain

Reviewed November 26, 2026, 5:06 AM ET / 10:06 UTC (Revision 3).

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Nov 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 26, 2026
@vincentkoc
vincentkoc merged commit 1de306e into main Nov 26, 2026
297 of 300 checks passed
@vincentkoc
vincentkoc deleted the fix/restart-uncertain-shell-receipt branch November 26, 2026 10:52
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Nov 26, 2026
* commit '399057400013dcfa1923db08be96c6bf46cf7079':
  fix: keep known speakers on meeting notes with missing labels (#205923)
  fix(codex): let saved conversations recover after a remote failure (#201621)
  fix: distinguish namesakes in Google Meet transcript exports (#205915)
  refactor: share Discord meeting transcript publication (#205921)
  test: trim workflow and runtime performance coverage (#205782)
  fix(android): settle startup before checking archive refresh (#205891)
  fix: Gateway retains completed reply runtimes after catalog reloads (#195479)
  fix: clear unused-export failures in dependency checks (#205905)
  refactor: share browser routing for meeting captions and cleanup (#205916)
  fix(ui): update Workshop file preview mode (#205872)
  refactor(android): decouple shared JSON values from node handlers (#202840)
  fix(ci): remove bot credit from release notes (#205914)
  fix: pause interrupted shell turns when their result is unknown (#205859)
  fix(ui): skip publication options for removed workspaces (#205909)
  fix: preserve indentation in document previews (#205834)
  improve(ci): avoid full fixture builds for volume checks (#205903)
  refactor(android): derive connection readiness from its owner (#202898)
vincentkoc added a commit that referenced this pull request Nov 26, 2026
…oid-chat-preview-grapheme-boundary

* commit '0bea7ecb3029583dd49d83f760d4f40c9e1f543c': (129 commits)
  fix(android): settle startup before checking archive refresh (#205891)
  fix: Gateway retains completed reply runtimes after catalog reloads (#195479)
  fix: clear unused-export failures in dependency checks (#205905)
  refactor: share browser routing for meeting captions and cleanup (#205916)
  fix(ui): update Workshop file preview mode (#205872)
  refactor(android): decouple shared JSON values from node handlers (#202840)
  fix(ci): remove bot credit from release notes (#205914)
  fix: pause interrupted shell turns when their result is unknown (#205859)
  fix(ui): skip publication options for removed workspaces (#205909)
  fix: preserve indentation in document previews (#205834)
  improve(ci): avoid full fixture builds for volume checks (#205903)
  refactor(android): derive connection readiness from its owner (#202898)
  fix: preserve side chat text when dictating at the limit (#205710)
  improve(telegram): polling workers start faster and use half the memory (#190890)
  fix: keep speaker identities distinct in meeting notes (#205860)
  fix: wait for cancellation before releasing ACP test preparation (#205893)
  fix: bound workers retained after deleting sessions across agents (#197409)
  fix(memory): keep a child's memory audience after its parent resets (#205887)
  refactor(android): give installed skills one data owner (#202892)
  fix(cli): share process failure listeners across invocations (#205732)
  ...
obviyus added a commit that referenced this pull request Nov 26, 2026
…offline (#205977)

## Problem

An update that crosses an agent database schema version keeps the Gateway down while the pre-migration check scans the whole database. Doctor's migration default is QUICK, but QUICK runs a whole-file `PRAGMA quick_check` plus a whole-file `PRAGMA foreign_key_check` before it checks the tables the migration touches. `quick_check` reads every page, and `transcript_events` carries a foreign key, so both scans grow with the whole agent history.

On a production deploy, a 67.4 GiB agent database spent 34 minutes in this check while the Gateway was stopped. An earlier deploy hit the service start timeout during the same check and needed manual recovery. The migration step itself only added a nullable column.

A clean-close proof does not help here: the migration gate never reads it. Pending migrations always run this check ("Pending migrations cannot inherit an earlier runtime verification").

## Solution

The migration policy owner, `resolveSchemaMigrationIntegrityCheck`, already marks agent version steps 38-42 as `schemaOnly`, because those steps only read and write their declared tables. This change applies the same rule to every agent version step.

The `schemaOnly` check now runs `integrity_check('sqlite_schema')`, then a full `integrity_check(T)` and `foreign_key_check(T)` for each table the step declares. It does not scan other pages. Before, it checked only `schema_meta`.

The migration finalizer (`finishAgentSchemaMigration`) used the same scope only for steps 40-42 and otherwise ran an unqualified `foreign_key_check` inside the migration transaction. A schema-only step now checks only its declared, existing tables there too. A captured whole-file QUICK proof from the pre-migration backup still covers a schema-only step, so the check is not repeated.

A QUICK result never publishes a full-verification receipt. So the next Gateway start owes the whole-database check. It runs in the existing deferred background verifier, the same as any restart without a clean-close proof.

Unchanged: state databases, same-version repairs, unscoped migrations and `--full-integrity-check` keep the whole-file checks.

## Impact

- Offline time for an agent schema step no longer grows with unrelated agent history.
- Corruption in the schema catalog or in a table that the step declares still refuses the migration.
- Accepted tradeoff (maintainer decision): a migration restart now verifies only the schema catalog plus the tables the migration declares before the agent database serves. The whole-file check runs afterwards in the existing deferred background verifier, the same as any restart without a clean-close proof. If a table the migration never touched is corrupt, that check quarantines the agent database when it finishes, and the existing corruption handling applies. Until then the agent serves from the database. In exchange, the Doctor migration phase on a 35.5 GB v43 database without a proof went from 365 s to 5.2 s (see Evidence).
- Docs updated: integrity and recovery, updating, and CLI update.

## Evidence

Measured on a 35.5 GB (33.1 GiB) synthetic agent database at schema v43 with no clean-close proof and an empty WAL. Bulk data sits in a table outside the v43 to v45 scope. Same machine (local NVMe), same fixture bytes (APFS clones), `openclaw doctor --fix --non-interactive` from built `dist/`, one run each:

| Phase | Base `315b916f` | This change |
| --- | --- | --- |
| Doctor "database migrations" (pre-migration check plus v43 to v45) | 365 s, of which about 360 s is the whole-file check | 5.2 s |
| Whole Doctor run | 866 s | 445 s |

The remaining head time is Doctor's archive and original-state copies of the 33 GiB file. Limit: this fixture keeps its bulk in a table without a foreign key, so the base number excludes the whole-file foreign-key scans that FK-bearing history (`transcript_events`) adds in production, before and after the migration. The head run predates the finalizer change, which only removes work. After the migration, the agent integrity gate logs `mode=deferred, outcome=pending`: the whole-database check runs in the background at the next start. The base check cost grows with file size and disk speed. In production the same check took 34 minutes for 67.4 GiB. The scoped check depends only on the declared tables.

Tests:
- New corrupt-fixture test in `src/infra/sqlite-integrity.test.ts`, using the real policy for a v43 to v45 agent step. Corruption in a declared table (`session_nodes`) refuses the step. Corruption in an undeclared table (`cache_entries`) passes the step, and the owed FULL check refuses it.
- New `openclaw-agent-pending-inputs-schema.test.ts` case: a v43 store with an orphan row in an undeclared FK table (`board_tabs`) migrates to the current schema. Base refuses at the pre-migration foreign-key check. With only the pre-migration change, it still refuses in the finalizer ("Agent schema migration failed foreign key validation"). Head passes.
- `openclaw-agent-cold-navigation-migration.test.ts` now expects the scoped sequence for a v38 to current step: the catalog, then each declared table's integrity and foreign-key check, with no whole-file pass.
- The state-database Doctor test that refuses an orphan foreign-key row in an untouched table still passes: state databases keep the whole-file check.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan reports `RecordDeferredShellOutcome` in `src/config/sessions/transcript-shell-receipt.ts`, which comes from `main` (#205859); this branch does not touch that file.

Test cost: about +77 net test lines in existing files; the new cases use one small temporary database each.

Not shown end to end: a later Gateway start detecting untouched-table damage. That path is the existing deferred background verification (production logs show `mode=deferred, outcome=pending` after this kind of migration); this change does not modify it.



## CI: release-update-survivor

CI's `docker-seed-e2e` failed because the `release-update-survivor` lane hit its 3300 s budget (killed at 3310 s). It is not a product failure. I ran the same lane locally (Docker, `OPENCLAW_DOCKER_ALL_LANES=release-update-survivor`, CI env, one lane at a time) on this head and on the base:

| Phase | Head `cb1fb104` | Base `315b916f` |
| --- | --- | --- |
| Release fixture (in-lane candidate build) | ≤ 973 s | 812 s |
| Migration-chain vitest | 54 s | not selected |
| Base install + build + pack (downgrade source) | 867 s | not selected |
| healthy | 227 s, pass (update succeeded, serving schema 43) | 191 s, pass |
| crash | 195 s, pass (update failed, rolled back to schema 42 as designed) | 196 s, pass |
| downgrade | 158 s, pass (`mode=enforced`) | not selected |
| Total | 2516 s, pass | 1222 s, pass |

Every product phase passes, and healthy and crash take about the same time as on the base. The extra time on head is lane work that #205857 added for PRs that change `src/state` schema or migration files: the migration-chain vitest, a full install, build and pack of the base, and the downgrade case. The base does not select it. Every passing CI run of this lane today had it unselected. The CI runner took 2.2x as long as the local machine for the same package build. At that rate this lane's 2516 s is an estimated 90 min on CI, well over the 3300 s budget. This is an estimate: CI did not record per-phase times before it killed the lane. The `docker-seed-e2e` override (and the `openclaw/ci-gate` result that follows from it) is authorized on this evidence.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…claw#205859)

* fix(gateway): pause interrupted shell turns without a verified outcome

Record native shell dispatch before work can start. On restart, continue after a saved terminal result, or report uncertainty without asking the model to repeat or confirm an unknown effect.

Refs openclaw#187354

* fix(gateway): settle deferred shell outcomes in the session store

Refs openclaw#187354

* fix(agents): retain shell receipts when process cleanup is uncertain

Refs openclaw#187354
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…offline (openclaw#205977)

## Problem

An update that crosses an agent database schema version keeps the Gateway down while the pre-migration check scans the whole database. Doctor's migration default is QUICK, but QUICK runs a whole-file `PRAGMA quick_check` plus a whole-file `PRAGMA foreign_key_check` before it checks the tables the migration touches. `quick_check` reads every page, and `transcript_events` carries a foreign key, so both scans grow with the whole agent history.

On a production deploy, a 67.4 GiB agent database spent 34 minutes in this check while the Gateway was stopped. An earlier deploy hit the service start timeout during the same check and needed manual recovery. The migration step itself only added a nullable column.

A clean-close proof does not help here: the migration gate never reads it. Pending migrations always run this check ("Pending migrations cannot inherit an earlier runtime verification").

## Solution

The migration policy owner, `resolveSchemaMigrationIntegrityCheck`, already marks agent version steps 38-42 as `schemaOnly`, because those steps only read and write their declared tables. This change applies the same rule to every agent version step.

The `schemaOnly` check now runs `integrity_check('sqlite_schema')`, then a full `integrity_check(T)` and `foreign_key_check(T)` for each table the step declares. It does not scan other pages. Before, it checked only `schema_meta`.

The migration finalizer (`finishAgentSchemaMigration`) used the same scope only for steps 40-42 and otherwise ran an unqualified `foreign_key_check` inside the migration transaction. A schema-only step now checks only its declared, existing tables there too. A captured whole-file QUICK proof from the pre-migration backup still covers a schema-only step, so the check is not repeated.

A QUICK result never publishes a full-verification receipt. So the next Gateway start owes the whole-database check. It runs in the existing deferred background verifier, the same as any restart without a clean-close proof.

Unchanged: state databases, same-version repairs, unscoped migrations and `--full-integrity-check` keep the whole-file checks.

## Impact

- Offline time for an agent schema step no longer grows with unrelated agent history.
- Corruption in the schema catalog or in a table that the step declares still refuses the migration.
- Accepted tradeoff (maintainer decision): a migration restart now verifies only the schema catalog plus the tables the migration declares before the agent database serves. The whole-file check runs afterwards in the existing deferred background verifier, the same as any restart without a clean-close proof. If a table the migration never touched is corrupt, that check quarantines the agent database when it finishes, and the existing corruption handling applies. Until then the agent serves from the database. In exchange, the Doctor migration phase on a 35.5 GB v43 database without a proof went from 365 s to 5.2 s (see Evidence).
- Docs updated: integrity and recovery, updating, and CLI update.

## Evidence

Measured on a 35.5 GB (33.1 GiB) synthetic agent database at schema v43 with no clean-close proof and an empty WAL. Bulk data sits in a table outside the v43 to v45 scope. Same machine (local NVMe), same fixture bytes (APFS clones), `openclaw doctor --fix --non-interactive` from built `dist/`, one run each:

| Phase | Base `6eac76fb` | This change |
| --- | --- | --- |
| Doctor "database migrations" (pre-migration check plus v43 to v45) | 365 s, of which about 360 s is the whole-file check | 5.2 s |
| Whole Doctor run | 866 s | 445 s |

The remaining head time is Doctor's archive and original-state copies of the 33 GiB file. Limit: this fixture keeps its bulk in a table without a foreign key, so the base number excludes the whole-file foreign-key scans that FK-bearing history (`transcript_events`) adds in production, before and after the migration. The head run predates the finalizer change, which only removes work. After the migration, the agent integrity gate logs `mode=deferred, outcome=pending`: the whole-database check runs in the background at the next start. The base check cost grows with file size and disk speed. In production the same check took 34 minutes for 67.4 GiB. The scoped check depends only on the declared tables.

Tests:
- New corrupt-fixture test in `src/infra/sqlite-integrity.test.ts`, using the real policy for a v43 to v45 agent step. Corruption in a declared table (`session_nodes`) refuses the step. Corruption in an undeclared table (`cache_entries`) passes the step, and the owed FULL check refuses it.
- New `openclaw-agent-pending-inputs-schema.test.ts` case: a v43 store with an orphan row in an undeclared FK table (`board_tabs`) migrates to the current schema. Base refuses at the pre-migration foreign-key check. With only the pre-migration change, it still refuses in the finalizer ("Agent schema migration failed foreign key validation"). Head passes.
- `openclaw-agent-cold-navigation-migration.test.ts` now expects the scoped sequence for a v38 to current step: the catalog, then each declared table's integrity and foreign-key check, with no whole-file pass.
- The state-database Doctor test that refuses an orphan foreign-key row in an untouched table still passes: state databases keep the whole-file check.
- `pnpm check:changed`: typecheck, lint, format and guards pass. The dead-export scan reports `RecordDeferredShellOutcome` in `src/config/sessions/transcript-shell-receipt.ts`, which comes from `main` (openclaw#205859); this branch does not touch that file.

Test cost: about +77 net test lines in existing files; the new cases use one small temporary database each.

Not shown end to end: a later Gateway start detecting untouched-table damage. That path is the existing deferred background verification (production logs show `mode=deferred, outcome=pending` after this kind of migration); this change does not modify it.



## CI: release-update-survivor

CI's `docker-seed-e2e` failed because the `release-update-survivor` lane hit its 3300 s budget (killed at 3310 s). It is not a product failure. I ran the same lane locally (Docker, `OPENCLAW_DOCKER_ALL_LANES=release-update-survivor`, CI env, one lane at a time) on this head and on the base:

| Phase | Head `cb1fb104` | Base `6eac76fb` |
| --- | --- | --- |
| Release fixture (in-lane candidate build) | ≤ 973 s | 812 s |
| Migration-chain vitest | 54 s | not selected |
| Base install + build + pack (downgrade source) | 867 s | not selected |
| healthy | 227 s, pass (update succeeded, serving schema 43) | 191 s, pass |
| crash | 195 s, pass (update failed, rolled back to schema 42 as designed) | 196 s, pass |
| downgrade | 158 s, pass (`mode=enforced`) | not selected |
| Total | 2516 s, pass | 1222 s, pass |

Every product phase passes, and healthy and crash take about the same time as on the base. The extra time on head is lane work that openclaw#205857 added for PRs that change `src/state` schema or migration files: the migration-chain vitest, a full install, build and pack of the base, and the downgrade case. The base does not select it. Every passing CI run of this lane today had it unselected. The CI runner took 2.2x as long as the local machine for the same package build. At that rate this lane's 2516 s is an estimated 90 min on CI, well over the 3300 s budget. This is an estimate: CI did not record per-phase times before it killed the lane. The `docker-seed-e2e` override (and the `openclaw/ci-gate` result that follows from it) is authorized on this evidence.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…chiving (#205026)

* fix(sessions): keep inactive chats eligible for cold storage after archiving

* test(sessions): align archive fixtures and identity baseline

* test(sessions): create a private cold backup restore target

(cherry picked from commit 81d69df)

Follow-ups: 7cb8975 fix: keep forked Claude chats separate after a Gateway crash (#208048) [separately ordered lane row]; ece7a74 improve(workboard): apply the Control UI glossary and style to Workboard copy [not selected for this narrow backport]; b616036 refactor(subagents): simplify ACP spawn relay ownership (#207023) [not selected for this narrow backport]; 93ca762 improve: reduce allocations when preparing session rows (#207109) [not selected for this narrow backport]; 9993328 refactor(subagents): simplify kill claim and ownership handling (#207025) [not selected for this narrow backport]; 97815bd refactor(subagents): consolidate registry cleanup and publication guards (#207064) [not selected for this narrow backport]; e94f799 refactor(subagents): centralize requester turn matching (#206584) [not selected for this narrow backport]; ea77ca3 refactor: report update failures from recorded runs (#206700) [not selected for this narrow backport]; 4d7e00b fix: let started participant runs and requests finish after an access change (#206747) [not selected for this narrow backport]; f89ae43 refactor(subagents): use cleanup and terminal owners in sweeps (#206533) [not selected for this narrow backport]; a882e0f fix(agents): preserve task answers when sessions are reused (#126263) [not selected for this narrow backport]; 81fc833 refactor(subagents): own dormant child Stop decisions (#206479) [not selected for this narrow backport]; 91d4912 fix(update): stop using foreign recovery records as admission (#206295) [not selected for this narrow backport]; be3c73e fix(subagents): finish claimed stops after session rotation (#206405) [not selected for this narrow backport]; ed8b883 fix(update): settle after plugins and share one completion summary (#205987) [not selected for this narrow backport]; 1de306e fix: pause interrupted shell turns when their result is unknown (#205859) [separately ordered lane row]; 16a6aa4 fix(memory): keep a child's memory audience after its parent resets (#205887) [not selected for this narrow backport]; 50a7368 feat: let agents snooze a conversation after replying [not selected for this narrow backport]; 40f3903 fix(ci): remove unused role and workflow exports (#205720) [not selected for this narrow backport]; e43debf refactor(state): migrate in place and remove copy-and-swap (#205165) [not selected for this narrow backport]; 8027293 refactor(plugins): plugin tools take the turn's owner bit; delete the requester-owner continuation (OA2 PR 6j) (#205483) [not selected for this narrow backport]; 13e2ec3 feat: let participants publish through the session's shared GitHub account (#204914) [not selected for this narrow backport]; 5434992 fix: use the configured runtime when switching model providers (#203973) [not selected for this narrow backport]; 5271519 fix(feishu): honor the filename override on sent attachments (#205287) [not selected for this narrow backport]; ca087d4 refactor(admission): drop the replay automationAdmin bit and the R7 source re-check (#205268) [not selected for this narrow backport]

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant