Skip to content

fix(update): preserve failure history during database rollback - #160614

Merged
steipete merged 5 commits into
mainfrom
codex/preserve-update-history
Sep 29, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/preserve-update-history

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes lost update history when a failed update restores its database snapshot: rollback could erase failure details, revive deleted runs, and discard runs created since capture.

User Impact

Database rollback preserves current update history while restoring captured application state. Original recovery snapshots remain unchanged. This requires the repaired updater to drive the update; already-running older drivers retain their existing recovery limits.

Unsupported history schemas, changed application data, or lost ownership still refuse restoration before displacement. Current data and recovery snapshots remain available; the updater does not force a lossy rollback.

Why This Change Was Made

The existing restore owner prepares a private copy of the shared snapshot and overlays complete current history rows, including rowids and opaque fields. Existing database exclusions remain held through preparation and publication. Inspection uses the retained updater runtime after package replacement. Completed work and settled refusals clean the private copy; a move or uncertain child settlement retains recovery material.

Integration with current main preserves its generation-mismatch diagnostic inside that cleanup structure. No new manager, ledger, schema, dependency, or configuration option is introduced by this change.

Related: #144005, #145169, #158491. Continues the recovery work contributed by @fuller-stack-dev.

Evidence

Current candidate f4e8100d137217e0e1d88d50ef260b1279ca74b5 integrates pinned main 4d4d99d6250ff63e9de09da840ad9e65836d201c.

  • All 24 tests passed: 12 restore-owner cases and 12 CLI database-rollback scenarios, including package/Git recovery, migration intervals, intervening writes, and serving/unsettled-candidate refusal. Combined wall time was 486.70 s; per-file Vitest durations were 195.15 s and 280.04 s. One assertion extends the existing foreign-write case to require the changed database in the refusal diagnostic; omitting the diagnostic produced the intended failure in 61.10 s, without adding another case or fixture.
  • The complete changed-file check plan passed in 1171.59 s, including production types, all 27 test type graphs, formatting, lint, storage/schema/import guards, and unused-export checks. Whitespace checks passed.
  • Fresh independent review of the complete candidate finished through P2 with no actionable findings.

The test command was node scripts/run-vitest.mjs src/infra/update-database-restore.test.ts src/cli/update-cli/update-command-database-rollback.test.ts --maxWorkers=1. Existing native SQLite, filesystem, ownership, and subprocess coverage accounts for the runtime; the added assertion reuses an existing scenario.

Historical installed proof, not execution of the current candidate: Crabbox run qualified source head 50d83060e95e4df8032d408086cfa6804505bba2. Maintainers independently inspected the completed native payload and retained results despite the canceled public Actions run. The source-built package was SHA-256 77d8c541faad314c8e208a1fdabfb878e0b1a002480360079491f18265bc9015 (113,893,441 bytes). Build/packaging took 538.50 s and the installed scenario 471.30 s.

That installed updater preserved all three nonexecuting history rows and all 18 fields, opaque JSON, additions/deletions, and rowid 9007199254740993 while restoring application databases after an injected Doctor failure. The active run finished rolled-back; original snapshots, backup/session records, restored package identity, and the previous Gateway's serving build and health were verified. A refusing candidate worker confirmed use of the retained updater runtime. Those restore/inspection implementations are unchanged except for main's preserved refusal diagnostic; the new source integration tests above are separate evidence.

Installed Linux CLI, SQLite, package recovery, and Gateway processes were real. Service-manager responses, candidate metadata, and admitted Doctor writes/failure were synthetic. This is not proof of the integrated candidate's installed package, native systemd/macOS/Windows, model inference, general NOCOW behavior, or post-serving rollback. The canonical build's report-only size warning and post-run tooling warnings were retained and reconciled; no budget or bypass was changed.

The older 50d CI run remains recorded as 117 successful, 45 canceled, 20 skipped, and two failed jobs (an unrelated UI request-timing assertion and its aggregate). The canonical UI correction is included from #160366. That old CI result and its admin attribution are not current-candidate CI proof; this integration push receives fresh CI, Security Review, and ordinary native merge admission.

Carry complete current update_runs rows into the private database restore source
under the existing exclusion, leaving original snapshots unchanged. Keep the
inspection worker on the retained updater runtime after package replacement.

Related: #144005, #145169, #158491
Co-authored-by: Jason (Json) <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 28, 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 size: M labels Sep 28, 2026
@steipete steipete self-assigned this Sep 28, 2026
@steipete
steipete marked this pull request as ready for review September 28, 2026 18:10
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 1:35 AM ET / 05:35 UTC (Revision 8).

ClawSweeper review

What this changes

The branch prepares a private SQLite restore copy that carries forward current update history, adds rollback and retained-runtime coverage, and documents the recovery behavior.

Merge readiness

⛔ Blocked before merge - 4 items remain

Current main still restores the captured shared database without preserving update records written afterward. This PR addresses that loss, but its changed rollback contract needs explicit acceptance and existing-state upgrade proof.

Priority: P1
Reviewed head: f4e8100d137217e0e1d88d50ef260b1279ca74b5
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair is focused and its historical runtime account is detailed, while upgrade compatibility and rollback-contract acceptance remain open.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The ordinary contributor proof gate does not apply to this maintainer PR. Its body reports an installed Linux rollback at the earlier source head and current-head focused tests; equivalent restore-preparation source was verified, while the linked canceled run exposes no inspectable native artifact here. Existing-state upgrade compatibility remains unproven for the integrated candidate.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate does not apply to this maintainer PR. Its body reports an installed Linux rollback at the earlier source head and current-head focused tests; equivalent restore-preparation source was verified, while the linked canceled run exposes no inspectable native artifact here. Existing-state upgrade compatibility remains unproven for the integrated candidate.
Evidence reviewed 9 items Current-main behavior: Current main publishes each captured database directly; it does not carry later update-history rows into the restored shared database.
Introduced restore behavior: The PR prepares a private shared-database copy under the existing exclusion before displacement and uses it as the publication source.
History preservation and refusal: The inspection child verifies both history-table contracts, copies complete rows and rowids into the private image, and refuses an unsupported layout before publication.
Findings None None.
Security None None.

How this fits together

The updater captures application databases before migration and restores them if activation fails. The restore path decides whether recovery is safe, then replaces database files and records the outcome in update history.

flowchart LR
  A[Failed update] --> B[Captured databases]
  A --> C[Current update history]
  B --> D[Restore preparation]
  C --> D
  D --> E{Safe to restore?}
  E -->|Yes| F[Restored application data and history]
  E -->|No| G[Retained data and recovery guidance]
Loading

Decision needed

Question Recommendation
Should an unsupported update-history layout refuse automatic database rollback, leaving recovery to the operator, for updates driven by the repaired updater? Accept guarded refusal: Record acceptance of fail-safe refusal and its recovery guidance after the supported existing-state upgrade path is qualified.

Why: That choice changes the documented rollback and persistence contract; source correctness alone cannot accept its operator impact.

Before merge

  • Resolve merge risk (P1) - A current or captured history table that fails the new contract check now refuses rollback before displacement. This protects data but can leave a failed installation awaiting operator recovery; the changed rollback contract needs recorded maintainer acceptance.
  • Resolve merge risk (P1) - The integrated head has focused tests, and an earlier revision has reported installed proof, but the PR does not establish a published-driver × current-candidate existing-state upgrade cell for this persistence behavior.
  • Complete next step (P2) - Record owner acceptance of the rollback refusal contract and qualify a published-driver × current-candidate existing-state upgrade before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +214, Tests +201, Docs +3. Total +418 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 288 74 +214
Tests 3 217 16 +201
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 508 90 +418

Review metrics

Metric Value Why it matters
Implementation and test growth production +214 net lines; tests and test support +201 net lines The production growth implements private restore preparation and retained worker routing; the PR explains that scope and exercises the restore owner.
Stored representation 1 existing ledger table copied; 0 schema migrations Rollback persistence changes even though the table shape does not.

Merge-risk options

Maintainer options:

  1. Qualify the supported upgrade (recommended)
    Exercise a published updater against copied existing state and this candidate, then record acceptance of the history-layout refusal and its recovery path.
  2. Retain more legacy recovery
    If the supported upgrade cell exposes an established layout that must roll back automatically, add a narrowly verified preservation path before merging.

Technical review

Best possible solution:

Preserve the canonical update ledger alongside restored application data, keep unsupported layouts fail-safe with clear recovery guidance, and qualify the supported upgrade path against copied existing state.

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

Yes, from source: write or remove update-history rows after capture, then restore the captured shared database on current main. Its publication loop replaces those later rows; no current-main execution was performed in this read-only review.

Is this the best way to solve the issue?

Yes, provisionally. Preparing a private restore image within the existing exclusion preserves history without altering original snapshots; the intentional mismatch refusal and supported upgrade path still need acceptance and proof.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ec101d561e2c.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Failed updates can erase recovery history, an urgent update workflow defect.
  • merge-risk: 🚨 compatibility: A history-schema mismatch now refuses rollback, and the existing-state upgrade path has not been qualified for this head.
  • merge-risk: 🚨 availability: A refused rollback after failed activation can leave the Gateway stopped until operator recovery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor proof gate does not apply to this maintainer PR. Its body reports an installed Linux rollback at the earlier source head and current-head focused tests; equivalent restore-preparation source was verified, while the linked canceled run exposes no inspectable native artifact here. Existing-state upgrade compatibility remains unproven for the integrated candidate.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a published-driver × candidate rollback result using copied existing state.
  • Obtain explicit acceptance of the history-schema refusal and operator recovery behavior.

Rating scale

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

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

Workflow

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

History

Review history (7 earlier review cycles)
  • reviewed 2026-09-28T18:19:09.855Z sha f1cdefa :: blocked before merge. :: [P2] Clean staged copies after pre-publication refusal
  • reviewed 2026-09-28T18:51:22.593Z sha fd58c8c :: blocked before merge. :: [P2] Clean scratch after a failed first publication with no displacement
  • reviewed 2026-09-28T19:03:08.792Z sha 0c634a0 :: blocked before merge. :: [P2] Clean the prepared copy when the first move is refused
  • reviewed 2026-09-28T19:30:41.654Z sha 50d8306 :: blocked before merge. :: none
  • reviewed 2026-09-28T19:45:30.479Z sha 50d8306 :: blocked before merge. :: none
  • reviewed 2026-09-28T22:59:13.419Z sha 50d8306 :: blocked before merge. :: none
  • reviewed 2026-09-29T05:23:35.949Z sha f4e8100 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 28, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 28, 2026
Integrate pinned main 4d4d99d with the
history-preserving restore owner. Keep prepared-copy cleanup and retain main's
generation-mismatch diagnostic. Extend the existing foreign-write case to
assert that the refusal identifies the changed database.

The diagnostic omission fails its targeted negative control. All 24 restore
and CLI database-rollback cases pass on the integrated tree. Independent P2
review reports no actionable findings. Earlier installed proof remains bound
to 50d8306; it is not execution of this integrated candidate.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 29, 2026
@steipete
steipete merged commit 7a17d8c into main Sep 29, 2026
245 checks passed
@steipete
steipete deleted the codex/preserve-update-history branch September 29, 2026 05:43
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…law#160614)

* fix(update): preserve failure history during database rollback

Carry complete current update_runs rows into the private database restore source
under the existing exclusion, leaving original snapshots unchanged. Keep the
inspection worker on the retained updater runtime after package replacement.

Related: openclaw#144005, openclaw#145169, openclaw#158491
Co-authored-by: Jason (Json) <[email protected]>

* fix(update): clean settled restore preparation failures

* test(update): route restore preparation through host SQLite

* fix(update): clean restore copies after refused first move

---------

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

Labels

cli CLI command changes docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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