Skip to content

fix(update): size the disk preflight with the same calculation activation enforces - #183177

Merged
steipete merged 2 commits into
mainfrom
upd/upd-l1902
Oct 25, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/upd-l1902

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #183091. Thanks @etzelm for the detailed phase timings, sizing analysis, and recovery evidence.
Related: #183133.

What Problem This Solves

An update can pass its initial disk check, spend minutes validating, and then refuse activation because the database backup requires substantially more space than the disposable candidate copy.

User Impact

Git and package updates now refuse before staging when measured space cannot satisfy the activation database backup or a separate source volume's rollback requirement. The message reports exact required and free bytes and lists the database families largest first. Unknown measurements remain best effort.

This runs in the installed updater; installing a newer candidate cannot replace an older updater's initial check. It does not reserve space against later builds, retained runtimes, newly discovered plugin/external state, or concurrent disk use, so activation keeps its complete admission check.

Why This Change Was Made

The initial check inherited the intentionally smaller S + L + 64 MiB candidate-copy budget. Activation still enforces 2S + 3L + 64 MiB for backup/rollback/scratch. Both phases now call the same backup-space owner, including aggregation of separate source volumes (S + L + 64 MiB per volume). Git checks .artifacts; package routes check their package manager's durable backup destination, including native project placement.

The candidate allocator retains its smaller budget and temporary-directory selection. The larger backup allowance is unchanged: #182632 reuses digests within an observation, but does not eliminate snapshot, rollback-copy, or acquisition/publication files. Optional prior captures also do not replace the current automatic rollback contract. Recovery policy stays intact, with no schema or dependency changes and no new configuration or CLI options.

Evidence

Current head: 50de0118bb2e29c6fd548feba62ddc2c129afc51.

The implementation, live proof, consumer runs, and initial gates below were checked at a561c03037c5d9cdafde1827c6c360eefd4f29e4. To resolve a real PR conflict, this head integrates main c800ae545e06dedfd4f65f1eac69a4a6a4d6809a, preserves #183075's resource-test cleanup, and reapplies only the new regression. Production changes remain byte-for-byte identical. Fresh integrated-head proof: the full resource suite 25/25 passed, including the capacity regression in 125 ms; infra-test tsgo passed; and a fresh isolated Codex review of the nine-file diff found no actionable P0–P2 defects. Resource wall time was 453.13 s, including 183.624 s shared compiled-worker preparation.

OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/infra/update-candidate-rehearsal.resources.test.ts --maxWorkers=1

The integrated lint wrapper stalled while preparing the newly pinned Bun fork, before linting. After stopping only this lane's wrapper and settling its preparation lock, direct native type-aware oxlint was verified with a temporary deliberate no-map-spread violation (exit 1, oxc(no-map-spread) at line 707), then passed on the restored real file (exit 0). The canary was restored byte-for-byte and is absent from the commit; no rule or suppression changed.

node_modules/.bin/oxlint --type-aware --tsconfig test/tsconfig/tsconfig.core.test.infra.json --threads=1 --report-unused-disable-directives-severity error src/infra/update-candidate-rehearsal.resources.test.ts

Node 26.12.1, with isolated HOME and OPENCLAW_STATE_DIR under the worktree's .artifacts/ directory before every product/test invocation.

The baseline snapshot implementation returned exit 0 with 100 MiB free although activation needed about 120 MiB; the regression failed with expected 0 to be 1. The fixed regression refuses at 100 MiB, admits at 140 MiB, preserves unknown-space best effort, leaves the source bytes unchanged, and allocates no backup directory. The existing candidate-copy test still succeeds within its smaller 100 MiB budget.

Focused proof: resource suite 27/27 passed, Git entry-point suite 5/5 passed, and npm/package entry-point regression passed. The new capacity regression takes 77 ms and the package regression 585 ms. A test-authoring repair replaced recursive multi-MiB Buffer assertions with exact Buffer.equals: capacity-test time fell 36.961 s → 0.077 s. The first package attempt was stopped after its equivalent recursive comparison grew to about 6 GiB RSS; the repaired test passed without adding retries or longer timeouts, skipping cases, or weakening assertions. Final Git file: 100.55 s wall, about 3.5 s tests; resource focused replay: 93.98 s wall, 77 ms test; package file: 18.69 s wall, 585 ms test. Most wall time is shared transform/compiled-worker preparation. CI timings are pending.

export HOME="$PWD/.artifacts/upd-l1902/home"
export OPENCLAW_STATE_DIR="$PWD/.artifacts/upd-l1902/state"
mkdir -p "$HOME" "$OPENCLAW_STATE_DIR"
OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/infra/update-candidate-rehearsal.resources.test.ts src/cli/update-cli/update-command-git-snapshot.test.ts src/cli/update-cli/update-command-package-space.test.ts --maxWorkers=1
# After fixing the Buffer assertion cost, reuse the unchanged sibling proof:
OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/infra/update-candidate-rehearsal.resources.test.ts src/cli/update-cli/update-command-package-space.test.ts --maxWorkers=1 -t 'preflights activation backup separately|refuses a package update before staging'
OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/cli/update-cli/update-command-git-snapshot.test.ts --maxWorkers=1

Live local production Git-updater entry-point proof used real Git commands and real filesystem free-space readings, with a sparse SQLite-family fixture to cross the capacity threshold without filling the host disk. Candidate requirement 1,738,414,757,888 bytes fit; activation required 4,345,936,231,424 bytes, against 3,476,654,669,824 bytes available at its backup destination. snapshot-space-preflight refused in 9 ms, with zero validation and mutation hooks, unchanged fixture HEAD and file length, and the dominating database path in the diagnostic. The fixture was removed afterward. This proves pre-staging refusal, rather than a full successful upgrade.

node --import ./scripts/tsx.mjs .artifacts/upd-l1902/live-space.ts
# status=error; reason=snapshot-capacity-insufficient; validations=0; mutations=0

The 30 additional consumer files ran with their original argument order: 319 passed, 31 PostgreSQL cases skipped by existing no-connection guards, 11 original-capture cases refused the host's group-writable volume ancestor. All 11 failures reproduce with untouched base production at 3940719bedc79e132a03e1805dcebc24173bad93; the committed capacity regression also fails there with the expected 0 versus 1 admission result. The same 11 capture cases plus the fixed regression then all pass (12/12) with a task-owned private temp directory under macOS's per-user temp root. No permission guard or volume permissions were changed. Private replay: 238.09 s wall (53% transform, 42% tests), including 104.31 s shared compiled-worker preparation; the private directory was removed after settlement.

Existing slow integration proof on the implementation head: the 13 update-command-database-rollback.test.ts scenarios total 429.068 s of test time (package case 64.090 s); update-database-restore.test.ts totals 183.719 s (largest case 17.136 s). These unchanged fixtures repeatedly launch Doctor/service/inspection processes and verify real custody and restoration across each failure scenario. Reducing that fixture/process cost is a separate test-owner refactor; no timeouts, retries, or assertions were relaxed.

Additional consumer command
OPENCLAW_VITEST_RUNTIME=node OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1 node scripts/run-vitest.mjs \
  src/infra/update-database-backup.test.ts \
  src/infra/update-candidate-state.cleanup.test.ts \
  src/infra/update-candidate-state.budget.test.ts \
  src/infra/update-candidate-snapshot-watchdog.test.ts \
  src/infra/update-candidate-snapshot.plugin-inspection.test.ts \
  src/infra/update-database-restore.test.ts \
  src/infra/update-run-ledger.compaction.test.ts \
  src/infra/backup-database-resources.test.ts \
  src/infra/database-engine/doctor-migration.postgres.test.ts \
  src/infra/database-engine/agent-port.postgres.test.ts \
  src/infra/database-engine/update-preflight.conformance.test.ts \
  src/cli/update-cli/update-command-initial-admission.test.ts \
  src/cli/update-cli/update-command-metadata-diagnostics.test.ts \
  src/cli/update-cli/update-command-target.n1-prefix.test.ts \
  src/commands/doctor-session-transcript-labels.reuse.test.ts \
  src/cli/update-cli/update-command-target-settlement.test.ts \
  src/cli/update-cli/update-command-wrapper-retirement.test.ts \
  src/cli/update-cli/update-command-source.test.ts \
  src/cli/update-cli/update-execution.runtime.process.test.ts \
  src/cli/update-cli/update-command-admission.test.ts \
  src/cli/update-cli/update-command-freebsd-pkg.test.ts \
  src/cli/update-cli/update-command-git-dry-run.test.ts \
  src/cli/update-cli/update-command-schema-cleanup.test.ts \
  src/cli/update-cli/update-command-package.test.ts \
  src/cli/update-cli/update-command-execution-validation.test.ts \
  src/cli/update-cli/update-command-database-rollback.test.ts \
  src/cli/update-cli/update-command-database-retention.test.ts \
  src/cli/update-cli/update-command-git-timeout.test.ts \
  src/cli/update-cli/update-command-execution.test.ts \
  src/commands/doctor-maintenance.database-writes.test.ts \
  --maxWorkers=1

The private-temp replay used this exact test selection (also used for the base replay):

private_tmp="$(mktemp -d "$(getconf DARWIN_USER_TEMP_DIR)openclaw-update-space-XXXXXX")"
TMPDIR="$private_tmp" OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/infra/update-database-backup.test.ts src/infra/update-candidate-rehearsal.resources.test.ts --maxWorkers=1 -t 'seals\ equivalent\ original\ bytes\ under\ isolated\ and\ maintenance\-owned\ capture|keeps\ maintenance\ capture\ isolated\ for\ large\ sources|keeps\ maintenance\ capture\ isolated\ for\ live\-reads\-admitted\ sources|validates\ link\ changes\ during\ original\ file\ capture|validates\ unlink\ changes\ after\ original\ file\ capture|validates\ content\ changes\ during\ original\ file\ capture|validates\ content\ changes\ after\ original\ file\ capture|refuses\ to\ seal\ an\ original\ capture\ when\ an\ absent\ database\ retains\ \-wal\ data|refuses\ to\ seal\ an\ original\ capture\ when\ an\ absent\ database\ retains\ \-journal\ data|seals\ the\ chosen\ manual\ image\ without\ discarding\ later\ live\ writes|seals\ a\ verified\ manual\ image\ with\ its\ unavailable\-generation\ warnings|preflights activation backup separately'
# The task-owned private directory was removed after the runner settled.

Core, infra-test, and CLI-update-test tsgo; touched production/test type-aware oxlint; oxfmt; docs MDX; max-lines ratchet; and git diff --check pass. Madge reports 0 cycles. Full check:changed SQLite inventory is skipped under the local gate budget; PR CI supplies broad proof. No remote lease was used. An isolated Codex review, supplied with the unchanged activation destination owners, found no actionable P0–P2 defects.

Whole-change LOC against the base: production +136/-59, tests +105/-5, docs +2/-2. The backup/rollback admission implementation moved to one shared owner; candidate allocation policy and activation's safety allowance remain intact.

@clawsweeper

clawsweeper Bot commented Oct 25, 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 size: M labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR checks activation backup and rollback capacity before staging Git and package updates.

Example: Two 8 MiB database families, 140 MiB available for candidate copies, and 100 MiB at the backup destination.

  • Before: Preflight admits staging although activation requires 120 MiB.
  • After: Preflight refuses before staging and reports the backup-space shortfall.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused production repair with partial runtime evidence, an introduced portable-test defect, and outstanding update-contract validation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update can spend substantial time validating before discovering a backup-space shortage that was measurable before staging.
Reason: The maintainer-authored direction restores early capacity admission without changing recovery policy, adding options, or inflating disposable candidate requirements; later disk consumption remains an explicitly accepted limitation.

Regression provenance

Regression provenance — verified: source commit 712db88927aa by Jason (Json); canonical PR #173284 (blame-to-merge-commit).

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: this PR addresses a current updater sizing defect with a shared calculation, but introduces an order-dependent regression assertion.

Priority: P2
Reviewed head: a561c03037c5d9cdafde1827c6c360eefd4f29e4

Before merge

  • Compare directory entries without depending on enumeration order (P2) - The new backupShortfall case creates both openclaw.json and agents, but fs.readdir does not guarantee their order. A filesystem returning ['openclaw.json', 'agents'] fails this assertion even when preflight correctly refuses and preserves state. The author discussion on fix(update): refuse Git updates early when database backup space is insufficient #183133 records this same failure and its sorting repair. Sort the returned entries or compare unordered membership.
  • Complete next step - Resolve GitHub's reported merge conflict for this PR and validate the affected result.

Findings

  • [P2] Compare directory entries without depending on enumeration order — src/cli/update-cli/update-command-git-snapshot.test.ts:180-182

Tests

  • Missing end-to-end proof: Supply redacted shipped-CLI refusal and sufficient-space evidence, including fresh-profile behavior and an upgrade from the latest stable release preserving settings and database content.
Agent review details

How this fits together

The updater measures known SQLite families before staging, checks candidate and durable-backup destinations, and returns admission diagnostics; activation independently rechecks its complete inventory.

flowchart TD
  A[Git or package update] --> B[Measure known database families]
  B --> C[Candidate copy capacity]
  B --> D[Shared backup and rollback capacity]
  C --> E[Admit or refuse staging]
  D --> E
  E --> F[Validation]
  F --> G[Activation capacity recheck]
Loading

Technical review

Best possible solution:

Keep the shared backup-space owner and distinct candidate budget, with an order-independent Git regression assertion.

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

Current-main source establishes admission between the candidate and activation thresholds, and the linked report records a matching late failure; no target code was executed during this review.

Is this the best way to solve the issue?

The production change is focused: it reuses measured inventory, shares activation's existing policy, checks actual destination volumes, and preserves unknown-capacity best effort and final activation checks.

Full review comments:

  • [P2] Compare directory entries without depending on enumeration order — src/cli/update-cli/update-command-git-snapshot.test.ts:180-182
    The new backupShortfall case creates both openclaw.json and agents, but fs.readdir does not guarantee their order. A filesystem returning ['openclaw.json', 'agents'] fails this assertion even when preflight correctly refuses and preserves state. The author discussion on fix(update): refuse Git updates early when database backup space is insufficient #183133 records this same failure and its sorting repair. Sort the returned entries or compare unordered membership.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 7cf2696 adds src/infra/update-candidate-snapshot.ts:100 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7cf2696575cb; files: src/infra/update-candidate-snapshot.ts)
  • Jason (Json): Raw commit 712db88 adds src/infra/update-candidate-snapshot.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 712db88927aa; files: src/infra/update-candidate-snapshot.ts)

PR surface

Source +77, Tests +100, Docs 0. Total +177 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 136 59 +77
Tests 3 105 5 +100
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 243 66 +177

Labels

Label changes:

  • add P2: The change prevents avoidable late update failures and extended operator-managed downtime; the reported incident recovered through rollback.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The change prevents avoidable late update failures and extended operator-managed downtime; the reported incident recovered through rollback.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Add shipped-CLI and latest-stable upgrade evidence for the changed admission path.

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.

Reviewed October 24, 2026, 11:12 PM ET / October 25, 2026, 03:12 UTC.

@steipete
steipete marked this pull request as ready for review October 25, 2026 03:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T03:24:47.220214Z 50de011 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50de0118bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let warnings: string[] = [];
if (params.backupDirectory) {
try {
const backup = await checkUpdateDatabaseBackupSpace(params.backupDirectory, size);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate canonical database paths for backup admission

When a configured agentDir or OPENCLAW_AGENT_DIR is a symlink alias of the default agent directory, collectStateDatabasePaths() retains both locators and size counts the same database twice. Activation instead resolves those locators with fs.realpath() and deduplicates them in canonicalDatabaseInventory(). Passing the candidate-copy measurement into this new hard gate therefore rejects updates that activation can accommodate: a single 16 MiB family discovered through two aliases requires 112 MiB for the candidate and 144 MiB for the actual backup, but this check demands 176 MiB and refuses with 160 MiB free. Measure a canonical, deduplicated inventory for backup admission while preserving the candidate allocator's separate accounting. This also preserves the repository's best-effort update contract rather than introducing a refusal without a real capacity shortfall.

AGENTS.md reference: AGENTS.md:L78-L78

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 8738c09 into main Oct 25, 2026
204 of 206 checks passed
@steipete
steipete deleted the upd/upd-l1902 branch October 25, 2026 03:50
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…tion enforces (openclaw#183177)

The update disk preflight budgeted S + L + 64 MiB while activation required 2S + 3L + 64 MiB (S = all SQLite bytes, L = largest family), so an update could pass preflight, validate for 15 minutes with the Gateway stopped, then fail in activation for disk space. Git and package updates now share one budget owner (update-database-backup-space.ts), so the preflight refuses up front, before validation or downtime, with the required and free bytes and the largest database families. The activation reserve is unchanged. Fixes openclaw#183091. Thanks @etzelm.
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Update disk preflight passes with a 9.3 GiB estimate, then activation needs 22.7 GiB and fails after 15 minutes of validation

1 participant