Skip to content

fix: recover agent databases after orphan session window repair - #167366

Merged
steipete merged 9 commits into
mainfrom
fix/sqlite-integrity-latch-recovery
Oct 9, 2026
Merged

steipete merged 9 commits into
mainfrom
fix/sqlite-integrity-latch-recovery

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #167287

What Problem This Solves

Fixes: fresh agent work can retain a cached integrity refusal after database repair, and an orphan session window can prevent Doctor from reaching its repair during a release upgrade.

User Impact

Operators can stop the Gateway, run openclaw doctor --fix, and restart. Doctor preserves the original database before removing windows whose session node is missing. Fresh admission rechecks a latched integrity failure so repaired state can become usable again. Only if Doctor still cannot repair the offline database does the guidance advise preserving the database/WAL and restoring a verified backup.

Doctor retains exclusive maintenance ownership. The orphan-producing operation and repeated-failure notifications remain outside this recovery fix; the linked issue stays open.

Why This Change Was Made

The recorded maintainer design puts backed-up orphan cleanup in Doctor. When the pre-migration integrity gate finds damage, Doctor first invokes that narrow repair, then retries the unchanged complete migration backup. Existing-schema maintenance ownership preserves shared schema 19 until the rollback group is captured. Other FK violations remain refused, including another broken FK on the orphan or its children. Original violations are classified before deletion; complete integrity and current maintenance authority are checked before commit.

Main 15305ccd53dedd1663a89f92a402480d7b71bbf8 was merged without rebasing, including #167476 (fs-safe 0.25.0) and #167482 (state-derived volume Doctor budget). Main's read-only write guard remains before latched revalidation; healthy admission does not run the recovery scan. Worker/process verification, WAL-aware preservation, rollback, cascades and FTS cleanup retain their existing owners. No new schema/FK, config option, public protocol or runtime compatibility reader.

Coordinator dispositions: the +260 production LOC exception is accepted, as is the in-place Doctor proof limitation: Doctor correctly refuses while a running Gateway owns the database; same-PID recovery after external repair plus offline Doctor repair with backup and post-restart success is the accepted proof. Peter separately approved the narrowly bounded metadata snapshot exception.

Exact delta against merged main: production +335/−75 = +260, tests/support +385/−42 = +343, docs +30/−0, tooling +2/−0. Growth provides backed-up orphan repair, pre-migration ordering, unrelated-damage refusal, and latch recovery; no unrelated deletion or code compression funds it. The two tooling lines qualify this Doctor helper's FK PRAGMAs under the existing maintenance rule; ordinary row operations still use Kysely.

Evidence

Final pushed head: 7ca3721b3d9cdcbd45254876a00f8810d7e5d931, tree 80af0addcb5c99d99580ca6e0f462b0907c51b2d. Full merged-source autoreview and the final tooling-only autoreview are both scoped-clean through P2; deslop completed. Runtime proof is pinned to its parent 6fccdf3bd84ea8f03ba3406237e79c50374944d4, tree aac6098fca19f3be05f9835ca37b3efd758aac85: the only subsequent diff is the two-line guard qualification. All production, tests, docs, package inputs and dependencies are identical.

Local six-file proof passed 64 tests, 758.18 seconds including cold preparation. Core types passed in 19.441 seconds, covering test graphs in 210.648 seconds, targeted lint in 51.987 seconds, and format/diff checks passed. Final tooling guard, lint and format passed locally and the architecture guard passed in exact-head CI.

node scripts/run-vitest.mjs \
  src/commands/doctor-migration-backup.test.ts \
  src/commands/doctor-rehearsal-capture.test.ts \
  src/commands/doctor-rehearsal-databases.test.ts \
  src/flows/doctor-health.update-schema.test.ts \
  src/infra/state-migrations.media-persistence.historical.test.ts \
  src/state/openclaw-agent-db.integrity-recovery.test.ts --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --changed-paths-json "$(cat /tmp/orphanland-approved-native/required-proof/module-files.json)"

The fresh production-only negative control kept final tests and reverted only production to merged main 15305ccd53dedd1663a89f92a402480d7b71bbf8: 3 intended failures / 1 pass / 11 skipped, 146.36 seconds Vitest / 486.305 seconds total. Orphan upgrade fails at the original migration backup gate; unrelated-FK refusal remains intact. Production and test hashes were verified after restoration.

Fresh AWS module coverage accounts for all 78 explicit files: 955 tests passed / 14 skipped / 7 inherited failures, 74 passing files / 1 skipped / 3 failed. The first invocation completed 41 files; two explicit supplements ran the 37 previously unexecuted files (28 then 9), without rerunning completed tests. Command times: 215.869 + 745.547 + 105.331 seconds. Core types passed in 16.825 seconds and the covering test graphs in 134.655 seconds on the same lease. The seven failures are the separately reproduced hydration/conversation/sharing cases below; this module run is not claimed all-green.

Exact-head CI completed: 84 success, 23 skipped, 5 failed test jobs plus the aggregate gate. CI used merge 104a8336533bf89f38a9cb7e319b559e274d74f1 of this head into newer main 0ffd46b94dd3cd168ca9cda60d4c095dd4bfa275. All ten failed assertions reproduce without this PR:

  • Hydration stream (one assertion) and conversation list (one): fixed history-lane spies no longer match cold-read routing. Main 15305… reproduces them; quarantine/refusal behavior remains covered.
  • Session sharing (five): raw foreign fixture writes lose canonical-key admission. Main 15305… reproduces all five. Combined conversation/sharing replay: 6 failures / 15 passes, 256.019 seconds; hydration replay: 1 failure / 6 passes, 76.775 seconds.
  • Pending-input custody (three): the unchanged two files pass 70/70 on 15305… (118.889 seconds), then reproduce the exact three CI failures on CI's main parent 0ffd46… (3 failures / 67 passes, 95.842 seconds). Main's fix(storage): preserve committed facts when publication fails #167570 changed post-commit publication to preserve committed results while these assertions still expect throws. Relevant test and owner blobs match CI's merge; these failures are inherited from that newer main, not from the earlier branch base.

The two previously documented failures were also rechecked on merged main 15305…: the catalog import-cycle guard fails in 107.351 seconds; the unchanged auth product test times out at 180 seconds (1 failure / 1 pass; 479.88 seconds Vitest, 2,054.712 seconds including cold build). Newer CI main fixes the import cycle; the final architecture job passes. The final CI run does not repeat that auth failure. No test timeout, assertion or baseline was changed to obtain green.

The earlier real-Gateway recovery proof remains scoped to d4ace35335a7bb0f80b9a92004be2dae8551e480: fresh Testbox tbx_01m4en070169jybpp22drdastp (run), isolated state/ephemeral port and a synthetic local OpenAI-compatible provider. A persisted cron job failed on the orphan before provider I/O. Doctor refused concurrent maintenance. External synthetic repair let the next job succeed with the same Gateway PID 19272. After stopping the Gateway and reseeding, actual Doctor removed one orphan, preserved original history in its backup and the valid control row, and the next job succeeded after restart (PID 21117). Flow: 313.923 seconds. The fresh upgrade proof below covers the subsequent migration-ordering change; the earlier run is not presented as exact-head live proof.

ClawSweeper's review of 7ca3721… reports no actionable code findings and confirms the migration-ordering fix. Its remaining “Add data-model compatibility proof” request is addressed below; its prior blocked verdict predates this evidence update. No merge performed.

Data-model compatibility

Data-model compatibility: PASS under approved metadata exception. Approval: comment 6073779390.

Fresh AWS lease cbx_937345b59de7 (crimson-crayfish-9fc5, c7a.8xlarge, eu-west-1; Node 24.19.0 / pnpm 12.5.1), no hydration, GITHUB_ACTIONS=false. Frozen candidate is 6fccdf3… with fs-safe 0.25.0; candidate tarball SHA-256 6854774aa6158a03e3386a03baabfd8838cf06df5d176ea71841f84ca4cd2b9b. Baseline is latest published stable [email protected], registry-integrity verified, build bcfc88812a35243893585dbeca87ca41b48272ca. Both version strings say 2026.9.9, so installed file hashes/build identity establish which package ran.

The older captures lacked compiled Doctor artifact bytes and original Linux file-stat witnesses needed by the exact validator; this authorized rerun recreated only the native seeded-orphan proof. Initial native run completed Doctor repair, migration, strict backups and SDK readback. The first metadata comparison then exposed a validator representation mismatch: the canonical reader strips part of packageBuild, while the writer stores the complete object. The corrected external validator compares the complete raw stored index with the complete canonical rebuild in the writer's JSON representation before comparing reader projections. Full packageBuild is also compared with frozen package JSON; no field is dropped or allowance expanded.

Final validator run PASS, 12.722 seconds, against both after-Doctor and after-read captures. The validator lives outside the repository, so there is no in-repository validator to commit. It names each allowed table/field explicitly and checks:

  • config_health_entries: only last_known_good_json and updated_at_ms; the fingerprint matches actual config bytes/stat identity and monotonic observation time. Security/identity fields remain exact.
  • config_machine_state: only the config.lastTouchedAt and plugins.installedIndex rows' value_json/updated_at_ms. All other rows/columns remain exact. The rebuilt bundled index matches all 66 manifest hashes, 63 package JSON hashes and 15 Doctor artifact hashes; user install records, policy and disabled status are preserved.
  • Config: only meta.migrations.webhookListeners (exact empty Telegram/Feishu/Teams/Nextcloud receipt) and wizard.lastRunAt (monotonic). Every other config value remains exact.

All 70 other preexisting protected tables remain byte/count-identical, including every session, transcript, stored plugin setting and quarantine row. Upgraded SDK readback loads six sessions and all 24 message appends, reads all four plugin settings, and still enforces the original quarantine. All 74 post-migration protected tables and full config remain exact after readback. Each agent's new empty session_reactions table is checked against main's canonical DDL. Shared migration 19→20 retires four empty tables; update receipts record the refused published-driver attempt. The complete database inventory is therefore not claimed unchanged.

Stored data Before orphan Seeded After Doctor
Session nodes 6 6 6
Session windows 6 7 6
Transcript events, including headers 30 30 30
Stored plugin settings 4 4 4
Quarantine decisions 1 1 1
Shared-state schema 19 19 20

Exactly one repair backup preserves the orphan and all 30 original protected agent tables; SHA-256 62021c4565f031dc7e1c1d0848652dbdf9dbd5a0775dd7382c272bc6aa0b18d0. Three healthy migration backups share one rollback group and retain original schemas 24/24/19 and all original protected rows. All four original backup file hashes remain exact after validation. The final evidence bundle was downloaded and hash-verified: 5f7ce1cd50cb6021991cbea44f0c52bbc738e8ec77e94473c01de77629046895.

Commands used (proof helpers are external, synthetic and bound to the frozen head/tree):

node scripts/crabbox-wrapper.mjs run --provider aws --id cbx_937345b59de7 \
  --fresh-pr openclaw/openclaw#167366 --no-hydrate --keep --keep-on-failure \
  --timing-json --script /private/tmp/oc-r6-orphanland/approved-native-bootstrap.sh
# Within the isolated proof environment:
openclaw update --tag "file:$CANDIDATE" --yes --no-restart --json
npm install --global --prefix "$PROOF/npm-prefix" "file:$CANDIDATE"
openclaw doctor --fix --non-interactive
# Read-only validation against captured state on the same frozen lease:
node scripts/crabbox-wrapper.mjs run --provider aws --id cbx_937345b59de7 \
  --no-sync --no-hydrate --keep --keep-on-failure --timing-json \
  --script /private/tmp/oc-r6-orphanland/approved-validator-v2-run.sh

The original published updater still refuses the seeded damaged input at candidate-state-snapshot, before candidate activation; its release package and 72 protected tables are preserved. The candidate cannot patch that already-installed driver. The explicit package-manager install then exercises the candidate's actual Doctor repair. This limitation remains visible despite the compatibility PASS.

The already-passing stock base,sqlite-volume scenarios are retained as historical evidence at 8ed2da3cd990237b23c7feae9350892144fcc0f0, lease cbx_d1452a89845a; they were not rerun or relabeled as current-head evidence. Stock run: base 1,512 seconds, volume 2,335 seconds. The large fixture preserves 4,800 sessions, 23,890 transcript events, 2,200 cron jobs and 512 plugin settings; a real Gateway reads eight conversations across two agents. Idempotent Doctor takes 473 seconds under main's state-derived 717-second budget, and final restart succeeds.

umask 022
GITHUB_ACTIONS=false \
OPENCLAW_CURRENT_PACKAGE_TGZ=/tmp/orphanland-ordering-proof/stock-logs/openclaw-package/openclaw-current.tgz \
OPENCLAW_DOCKER_ALL_BUILD=0 \
OPENCLAW_DOCKER_ALL_LOG_DIR=/tmp/orphanland-ordering-proof/stock-rerun-logs \
[email protected] \
OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=base,sqlite-volume \
OPENCLAW_UPGRADE_SURVIVOR_LIVE_MODELS= \
OPENCLAW_UPGRADE_SURVIVOR_LIVE_OPENAI=0 \
OPENCLAW_UPGRADE_SURVIVOR_DOCKER_RUN_TIMEOUT=2500s \
pnpm test:docker:published-upgrade-survivor

The AWS lease is released, confirmed by crabbox list --provider aws; no owned lease remains active. Completed review and baseline worktrees were removed. No operator Gateway, state or ports were touched. The PR remains open and ready for review, with the inherited CI failures documented; it has not been merged.

Landing evidence for 67c17df5a7b85ec42df9454fc3918b76e2d45a42

This is the coordinator-approved head after clean main merges, including the pending-input and quarantine-hydration test fixes. The coordinator reports core types and all seven changed test files passing on this merged tree. The scoped runtime and compatibility evidence above remains historical evidence for the unchanged recovery implementation.

Current-head CI run 37893488384, attempt 1 completed with 86 successful jobs, 23 skipped jobs, one inherited test-job failure and its downstream aggregate gate failure; no jobs were cancelled. The sole failing case is src/gateway/conversation-list.test.ts → worker conversation reads > refuses a replaced source while conversation-rows is pending: Error: Conversation read was not dispatched (PR job 113699823793).

The same case and error independently fail in scheduled main run 37889372602, job 113686779732, on 53868c16088fd9cc86e84340178d8291c7a6f133. The test, promise gate and relevant conversation-read source blobs match that baseline, the PR's tested merge 4a6cb3b5a60c326e2db3631da6988a42903823e7, and main e6ca676b02b6cd6e9a56f588ba5c0e784a6d27d1. The fixture watches historyLane.pool.run, while cold reads route through targetDiscoveryLane; no damaged database or latched integrity refusal exists in this fixture. These causal routing owners are untouched by this PR. This is independent baseline execution plus current-source revalidation, not a newly executed current-main test.

Landing uses the native inherited-failure exception and retains the failed CI result. The independently enforced security and review gates still apply. Related: #167287 stays open; orphan production and repeated-failure notifications remain outside this recovery fix.

@clawsweeper

clawsweeper Bot commented Oct 8, 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 scripts Repository scripts size: XL labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 17:57
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds backed-up Doctor cleanup of orphan session windows and rechecks cached database integrity failures after repair.

Example: The operator runs Doctor on a database containing orphan-window referencing missing-node.

  • Before: The foreign-key refusal can block the migration backup before repair runs.
  • After: Doctor preserves the original database, removes the orphan window, and retries the complete migration backup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The recovery patch is correct and well-proven, but it addresses only part of the linked recurring-orphan problem.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded real Gateway work recovers after repair, and the published 2026.9.9 installation-to-candidate Doctor run exercises orphan cleanup before migration with protected user rows and backup hashes preserved. The recovery owners remain unchanged through the reviewed head; the older published updater's pre-activation refusal remains explicitly documented.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Scheduled agent work stays blocked after database repair, and an upgrade can stop before Doctor reaches orphan cleanup.
Reason: Reliable recovery is valuable and its Doctor-owned direction is recorded. This PR uses Related appropriately because it does not identify the orphan producer or implement repeated-failure notifications.

Merge readiness

✅ Ready for maintainer review

Keep open: this is useful, maintainer-approved recovery work that current main does not provide. No actionable patch findings remain; the orphan-producing operation remains a separate investigation.

Priority: P1
Reviewed head: 67c17df5a7b85ec42df9454fc3918b76e2d45a42

Before merge

None.

Findings

None.

Agent review details

How this fits together

Each agent stores session identities and transcript windows in SQLite. Database admission checks that state before agent work runs, while Doctor owns offline repair and migration.

flowchart TD
  A[Agent session database] --> B[Database admission]
  B --> C{Integrity refusal cached?}
  C -->|Yes| D[Native integrity verifier]
  D --> B
  C -->|Healthy| E[Agent work proceeds]
  A --> F[Offline Doctor maintenance]
  F --> G[Preserve original backup]
  G --> H[Remove orphan windows and retry migration backup]
Loading

Technical review

Best possible solution:

Keep recovery in the existing Doctor and admission owners, while the linked issue separately identifies and repairs the orphan-producing writer.

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

Yes for the recovery defects: seeded missing-node windows exercise the real integrity refusal, and recorded Gateway and production-only negative controls demonstrate blocked admission and migration backup. The operation creating real-world orphans remains unknown.

Is this the best way to solve the issue?

Yes for recovery: the patch reuses Doctor's backup, maintenance, transaction, and verification owners without adding a runtime data-deletion path. It deliberately leaves the producing defect to the linked investigation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned repair implementation: The repair preserves a WAL-aware original image, classifies all original foreign-key violations before deletion, removes only windows missing their node, checks full integrity, and revalidates maintenance authority immediately before commit. (src/infra/state-migrations.session-window-repair.ts:29, 67c17df5a7b8)
  • Earlier ordering finding resolved: The migration-backup owner now invokes narrow orphan repair after a terminal integrity failure and retries its existing complete backup operation. (src/commands/doctor-migration-backup.ts:63, 67c17df5a7b8)
  • Accepted recovery boundary: fix: recover agent databases after orphan session window repair #167366 (comment) accepts backed-up Doctor deletion of unreachable windows while retaining the separate investigation at Orphan session_windows rows repeatedly fail foreign_key_check, blocking all cron jobs and heartbeats #167287. Dependent history is removed from the live database but remains recoverable in the original backup.
  • Real Gateway recovery: The inspected PR body records an isolated real Gateway cron failure before provider I/O, refusal of concurrent Doctor maintenance, successful recovery after external repair with Gateway PID 19272 unchanged, and offline Doctor repair followed by successful work after restart. This evidence is explicitly scoped to d4ace35, not presented as an exact-head run. (d4ace35335a7)
  • Published-release compatibility proof: The full inspected body, captured with SHA-256 df650497c81c415e85a12f62d6c8d6d85cb0b623cd85b7d569c64240606c0d1e, reports actual Doctor execution after installing the frozen candidate over [email protected]. Session windows changed 7→6 while six session nodes, 30 transcript events, four plugin settings, and one quarantine decision were preserved. The validator checked protected rows and original backup hashes under the narrow metadata exception approved at fix: recover agent databases after orphan session window repair #167366 (comment). (6fccdf3bd84e)
  • Proof scope and updater limitation: The published updater refuses the seeded damaged input at candidate-state-snapshot before candidate activation and preserves the installed package and protected tables. Explicit package-manager installation then exercises candidate Doctor recovery; this proves recovery and data compatibility, not automatic recovery by the already-installed updater. Later source comparison found the recovery owners unchanged; Doctor's surrounding exit/custody changes came from merged main. (src/flows/doctor-health.ts:58, 67c17df5a7b8)

Likely related people:

  • Peter Steinberger: Raw commit 8a754c5 adds src/state/openclaw-agent-db-terminal.ts:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8a754c57f597; files: src/state/openclaw-agent-db-terminal.ts)
  • Vincent Koc: Raw commit 1592d42 adds src/infra/sqlite-integrity.ts:65 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1592d422ee41; files: src/infra/sqlite-integrity.ts)

PR surface

Source +260, Tests +343, Docs +30, Other +2. Total +635 across 22 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 12 335 75 +260
Tests 8 385 42 +343
Docs 1 30 0 +30
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 22 752 117 +635

Review metrics

Metric Value Why it matters
Production versus test growth production +335/−75; tests/support +385/−42 The production growth supports preserving repair backups, migration ordering, unrelated-damage refusal, and recovery from cached failures.

Root-cause cluster

Relationship: partial_overlap
Canonical: #167287
Summary: This PR addresses recovery from the reported orphan state; the linked issue retains producer diagnosis and repeated-failure notification work.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported integrity refusal disables scheduled agent jobs and heartbeats.
  • merge-risk: 🚨 compatibility: Doctor's pre-migration recovery ordering changes; published-release compatibility evidence now covers preservation of existing settings, rows, and rollback backups.
  • merge-risk: 🚨 session-state: The accepted repair removes unreachable windows and their dependent live history while preserving that history in a verified original backup.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-08T22:26:52.220Z sha 1ad047d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T00:10:20.694Z sha 1ad047d :: blocked before merge. :: [P1] Run orphan repair before the fleet migration backup
  • reviewed 2026-10-09T02:14:56.484Z sha 8ed2da3 :: blocked before merge. :: none
  • reviewed 2026-10-09T03:26:16.512Z sha 8ed2da3 :: blocked before merge. :: none
  • reviewed 2026-10-09T04:31:23.389Z sha 6fccdf3 :: blocked before merge. :: none
  • reviewed 2026-10-09T05:31:33.007Z sha 7ca3721 :: blocked before merge. :: none
  • reviewed 2026-10-09T06:05:27.433Z sha 7ca3721 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T06:14:11.618Z sha da16e6c :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 2:41 AM ET / 06:41 UTC (Revision 14).

@openclaw-barnacle openclaw-barnacle Bot closed this Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 8, 2026
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer design acceptance (storage review checkpoint, docs/reference/database-schemas/storage-changes.md): accepted on 2026-10-08.

Accepted scope: Doctor (openclaw doctor --fix) backs up the agent database first, then removes only session_windows rows whose referenced session_nodes row no longer exists. Those rows are unreachable through any session read path. The repair reports counts and leaves the history recoverable from the backup. It adds no runtime compatibility reader and no schema or FK change.

The producer of these orphans is still unidentified. Current main cascades window deletion, and the lifecycle paths exercised on a real Gateway left no orphans. So this PR stays Related: #167287, and the reporter's evidence request on #167287 remains open.

Before landing, this PR will be reduced in size, rebased onto main's new admission write guard by merge, and re-proven.

Keep Doctor's backed-up missing-node window repair and native rechecks only
while integrity failures are latched. Reuse existing snapshot, transaction,
worker, and rollback owners; remove the extra verifier client and generation
clearing machinery. Preserve main's write-admission guard before recovery.

Related: #167287. The orphan-producing operation remains unidentified.
@openclaw-barnacle openclaw-barnacle Bot closed this Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 8, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed scripts Repository scripts size: XL labels Oct 8, 2026
@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 Oct 8, 2026
Tell operators to stop the Gateway before Doctor repair and restart afterward.
Recommend restoring a verified backup only when Doctor still cannot repair the
offline database. Align the orphan-window docs and emitted-error expectations.

Related: #167287.
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper clawsweeper Bot removed the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Oct 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 9, 2026
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 9, 2026
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer approval (snapshot/baseline exception, root AGENTS.md), 2026-10-08: for the 2026.9.9 -> head upgrade-compatibility proof with a seeded orphan, the strict protected-table snapshot oracle may allow only individually source-verified Doctor-owned metadata changes:

  • config_health_entries and config_machine_state (last-touched metadata and the rebuilt bundled-plugin index);
  • Doctor-owned config provenance fields (the canonical empty webhook-migration receipt and wizard provenance).

Every session, transcript, stored plugin setting and quarantine row, and the original repair backup, must remain byte/count-exact. No other differences are allowed.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 9, 2026
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Oct 9, 2026
@steipete
steipete merged commit a5ab772 into main Oct 9, 2026
172 of 175 checks passed
@steipete
steipete deleted the fix/sqlite-integrity-latch-recovery branch October 9, 2026 06:46
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…claw#167366)

* fix: recover agent databases after orphan session window repair

* fix: clarify offline SQLite repair guidance

Tell operators to stop the Gateway before Doctor repair and restart afterward.
Recommend restoring a verified backup only when Doctor still cannot repair the
offline database. Align the orphan-window docs and emitted-error expectations.

Related: openclaw#167287.

* fix(ci): qualify Doctor foreign-key maintenance pragmas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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