Skip to content

fix(update): successful updates leave full database copies in the npm global root - #160348

Merged
steipete merged 7 commits into
mainfrom
fix/update-retire-verified-database-snapshots
Sep 28, 2026
Merged

steipete merged 7 commits into
mainfrom
fix/update-retire-verified-database-snapshots

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: every successful package update leaves a full copy of every SQLite database in the npm global root (<global node_modules>/.openclaw.package-backup-<pid>-<ts>.databases), and nothing ever removes it. This came from #158163 (d780fdc), which deliberately retained pre-migration snapshots after success "until the operator removes them". In practice nobody finds them, and disk grows by the full state size on every update.

Release gate context: 2026.9.7 Full Release Validation (release-checks 36381536769) failed update-first-hop-compat-2026.9.2..9.5 with "update left transaction residue … .openclaw.package-backup-*.databases" after the candidate-driven hop. The snapshot code is an ancestor of the release/2026.9.7 cut.

Retention change approved by Peter (maintainer): retire the snapshot sibling after verified-success activation, and keep it on rollback, unverified, or failed outcomes.

User Impact

  • New updates remove their pre-migration database snapshots once activation is verified, together with the old package backup they belong to. Rollback (including a successful restore), failed or unverified completion, and refused restoration keep them. A cleanup failure produces the existing recoverable-maintenance warning, with the retained path.
  • Snapshots already piled up by earlier updates are NOT deleted automatically. No durable receipt proves their ownership and successful outcome. Instead, Doctor now reports them (core/doctor/update-snapshots, warning only, never removed even with --fix) with their count, total size, and exact per-directory removal commands, plus a reminder to confirm no update or recovery needs them. Updater-driven Doctor passes skip this check, so an in-flight update's own snapshot is not reported.

Why This Change Was Made

Automatic database restoration is only eligible before the candidate Gateway is admitted. After verified activation the old package backup is already retired, so the snapshots no longer serve automatic recovery. They now share that backup's lifetime in retireVerifiedPackageSwap, on both the activation and non-activation paths. Cleanup uses the original databaseBackupRoot, not activation's rewritten backup path, and goes through the same authority- and identity-checked discardPackageUpdateBackup helper. The Doctor discovery is a bounded, read-only scan of the npm global root: one directory level, capped entries, depth, and a 200 ms budget, with no symlink following. The structured Doctor contribution runner now forwards ctx.env, so the update-phase marker check sees the real environment. Docs for update recovery and Doctor checks are updated.

Evidence

  • Regressions in package-update-swap.test.ts and package-update-activation-lifetime.test.ts (ordinary and journaled success remove the sibling; rollback and unverified completion retain it) fail on the original code. New src/flows/doctor-update-snapshots.test.ts covers discovery, sizes, commands, no-finding, and update-pass skip. Removing the registration makes it fail.
  • Testbox (tbx_01m3kjnp1b8xdt9ckdwary2247, tbx_01m3kn3k8x1gycsaybdar7erhb): 164 focused update tests passed (6 platform skips). pnpm test src/infra/package-update-swap.test.ts --maxWorkers=1 7.4 s; package-update-activation-lifetime.test.ts 31.7 s (existing process-death suite; the added case is 0.37 s); the Doctor test runs in ~80 ms of test time. pnpm tsgo:core, core test type shards, oxfmt, and scoped oxlint passed.
  • Independent Codex autoreview is clean through P2 for both commits' scope. The one accepted P2 (ctx.env forwarding) is fixed.
  • Exact-lane proof (update-first-hop-compat-2026.9.2..9.6 against merged main) follows after landing.

Capture the database snapshot leak after ordinary and journaled verified activation, while preserving snapshots for rollback, refusal, and unverified completion. Cover maintenance advisories and leave older snapshots untouched.

Both success regressions fail on the original production code. This is regression coverage only; the candidate implementation still needs a safe post-settlement cleanup boundary before landing.
Report older npm-global pre-migration snapshots with bounded size inspection and quoted manual removal commands. Keep discovery warning-only and defer updater-driven Doctor passes using existing markers. Preserve the flow environment in structured checks.
@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 cli CLI command changes commands Command implementations size: M labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. 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 28, 2026, 7:53 AM ET / 11:53 UTC (Revision 5).

ClawSweeper review

What this changes

The branch retires pre-migration SQLite snapshots after verified npm package activation and adds warning-only Doctor discovery and recovery guidance for retained copies.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: current main still retains database snapshots after successful updates. The latest head addresses the earlier Doctor discovery finding, leaving a distinct, coherent fix under review.

Priority: P2
Reviewed head: 4b8a454cb29ada2c55345271d561d45680ce62fe

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused lifecycle and Doctor coverage support the patch; the shipped-updater behavior still needs its required proof cell.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The Repository State identifies a member-authored PR, so the external-contributor proof gate does not apply. Focused Testbox tests exercise transaction and Doctor owners, but the repository-required published-driver × candidate update result is not recorded; no stored-data format changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The Repository State identifies a member-authored PR, so the external-contributor proof gate does not apply. Focused Testbox tests exercise transaction and Doctor owners, but the repository-required published-driver × candidate update result is not recorded; no stored-data format changes.
Evidence reviewed 8 items Current main retains snapshots: The activation path returns after retiring the package backup, before any database-snapshot cleanup. The central change is therefore absent from fetched main.
Verified retirement boundary: The proposed retirement path sends the original snapshot sibling through the existing authority- and identity-checked filesystem remover; transaction completion excludes rollback outcomes.
Rollback retention: Completion requires a verified outcome and passes no snapshot path to retirement after rollback.
Findings None None.
Security None None.

How this fits together

The package updater captures database snapshots before migrations, swaps the installed package, and settles the result after Gateway activation or rollback. Standalone Doctor reports leftover snapshots to operators without removing them.

flowchart LR
A[Installed updater] --> B[Package swap and snapshots]
B --> C{Verified outcome?}
C -->|Successful activation| D[Retire obsolete copies]
C -->|Rollback or uncertain| E[Keep recovery copies]
E --> F[Standalone Doctor warning]
Loading

Before merge

  • Resolve merge risk (P1) - No published-driver × candidate update result is recorded for this head, so the shipped-updater handoff has not yet demonstrated verified-success cleanup while preserving failed or unverified recovery copies.
  • Complete next step (P2) - Record the repository-required published-driver × candidate update result for verified snapshot cleanup before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +169, Tests +264, Docs +20. Total +453 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 6 191 22 +169
Tests 3 294 30 +264
Docs 3 25 5 +20
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 510 57 +453

Review metrics

Metric Value Why it matters
Production and test growth production +169 net lines, tests +264 net lines The new Doctor scan accounts for substantial production growth and has registered-flow and lifecycle regression coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-update-snapshots.ts, migration/backfill/repair: src/flows/doctor-health-contribution.ts, migration/backfill/repair: src/flows/doctor-health-contributions-initial.ts, unknown-data-model-change: src/commands/doctor-update-snapshots.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove the shipped-updater handoff (recommended)
    Record a published-driver × candidate update result for verified cleanup before merging, alongside the focused retention cases already reported.

Technical review

Best possible solution:

Keep snapshot retirement inside verified transaction completion, preserve uncertain recovery material, and use standalone Doctor to guide inspection of older copies.

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

Yes, from source: current main returns from the activation retirement path without deleting the snapshot sibling. I did not execute an update in this read-only review.

Is this the best way to solve the issue?

Yes, the retained package transaction is the owner of snapshot lifetime, and warning-only Doctor discovery avoids deleting older copies whose outcomes cannot be established.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The Repository State identifies a member-authored PR, so the external-contributor proof gate does not apply. Focused Testbox tests exercise transaction and Doctor owners, but the repository-required published-driver × candidate update result is not recorded; no stored-data format changes.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Successful updates can accumulate full database copies, but the reported failure does not stop the update workflow.
  • merge-risk: 🚨 compatibility: Verified success changes the prior retention behavior; the PR records maintainer acceptance, while shipped-updater compatibility proof remains outstanding.
  • merge-risk: 🚨 session-state: The change deletes pre-migration database copies after verified activation, making the verified-outcome boundary consequential for recovery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The Repository State identifies a member-authored PR, so the external-contributor proof gate does not apply. Focused Testbox tests exercise transaction and Doctor owners, but the repository-required published-driver × candidate update result is not recorded; no stored-data format changes.

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)
  • Vincent Koc: 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 update result showing verified-success snapshot cleanup.

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 (4 earlier review cycles)
  • reviewed 2026-09-28T09:44:12.066Z sha 5e197d5 :: blocked before merge. :: [P2] Report incomplete scans even when no snapshot was found
  • reviewed 2026-09-28T10:29:34.598Z sha 611e091 :: blocked before merge. :: [P2] Report incomplete scans even when no snapshot was found
  • reviewed 2026-09-28T10:57:27.544Z sha e91719d :: blocked before merge. :: [P2] Include cleanup-failure snapshot names in Doctor discovery
  • reviewed 2026-09-28T11:29:52.832Z sha b0ea337 :: blocked before merge. :: [P2] Include cleanup-failure snapshot names in Doctor discovery

@steipete

Copy link
Copy Markdown
Contributor Author

CI note: the only failure on 5e197d5 was src/cli/daemon-cli.update-run.test.ts > refreshes the foreground report after published driver terminal settlement: the spawned published-driver child was killed by the test's own 15 s spawn timeout (null/SIGTERM, empty stderr) while sibling cases in the same file passed in ~170 ms. That path (finishUpdateRun) is untouched here; it is a cold-start timing flake under shard load. Re-running the failed job once; flake follow-up tracked separately.

@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 Sep 28, 2026
@steipete steipete self-assigned this Sep 28, 2026
@steipete
steipete merged commit 8b3f9bd into main Sep 28, 2026
235 checks passed
@steipete
steipete deleted the fix/update-retire-verified-database-snapshots branch September 28, 2026 12:41
@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 29, 2026
… global root (openclaw#160348)

* test(update): cover database snapshot retirement

Capture the database snapshot leak after ordinary and journaled verified activation, while preserving snapshots for rollback, refusal, and unverified completion. Cover maintenance advisories and leave older snapshots untouched.

Both success regressions fail on the original production code. This is regression coverage only; the candidate implementation still needs a safe post-settlement cleanup boundary before landing.

* fix(update): retire database snapshots after verified activation

* fix(doctor): report retained update database snapshots

Report older npm-global pre-migration snapshots with bounded size inspection and quoted manual removal commands. Keep discovery warning-only and defer updater-driven Doctor passes using existing markers. Preserve the flow environment in structured checks.

* test(doctor): avoid unbound snapshot repair assertion

* fix(doctor): warn when snapshot discovery is incomplete

* fix(doctor): report snapshots retired after failed cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes 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. P2 Normal backlog priority with limited blast radius. 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