Skip to content

fix(doctor): updates fail on a full disk because Doctor copies a stopped database just to read it - #196346

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-inspect-drained-db-in-place
Nov 10, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-inspect-drained-db-in-place

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Related: #174599, #188025, #194325

What Problem This Solves

Fixes: an update fails on a nearly full disk, leaving the Gateway stopped, when Doctor copies a stopped agent database just to read it during activation.

User Impact

User impact: updates on hosts with large agent databases no longer need free space equal to the largest database for Doctor's read-only session inspection. On the affected Gateway that copy needed 21 GiB with 16 GiB free, so session-entry-state refused and the update stopped. No configuration or migration is needed.

Why This Change Was Made

Update activation runs Doctor inside the updater's migration capture. Captured inspections read each agent database through a private whole-file byte copy (#174599) so that nothing is written beside the source: no locks, WAL, index or sidecars, and the idle WAL header the updater verifies stays intact. During activation, though, the Gateway is stopped and Doctor holds schema-maintenance custody. When the family is also drained (no journal, empty WAL), the copy protects nothing. The source has no frames to interpret and no other owner can open it. On the affected Gateway the agent database Doctor inspected had a 0-byte WAL.

The artifact-preserving reader (openSqliteReadOnlyDatabase) now opens a drained, custodied source in place through an immutable read-only URI. That is the same open #194325 uses for the updater's generation reads. It adds nothing beside the source, and at close it rejects the read if the inode, size or mtime changed or the family stopped being drained. The captured session-entry-state scan uses that owner when the source qualifies. Undrained families, uncustodied readers and every non-captured path keep the private copy unchanged.

Update behavior: the change runs in the candidate's Doctor and keys only on custody and on-disk drained state, so updates driven by already-published updaters benefit as soon as the candidate includes it. The installed updater's preflight is unchanged. A separate change will make that budget accurate.

Evidence

  • Real full-disk reproduction. A 192 MiB APFS volume held the test state and private-snapshot root (OPENCLAW_UPDATE_IN_PROGRESS=1, TMPDIR on the volume, as shipped updaters set). It contained a 31 MiB drained agent database with 18 MiB free, and the captured session-entry-state scan ran under maintenance custody.
    • Base: Failing check session-entry-state (step-refused): SQLite read-only worker failed while creating its private snapshot, the exact production error.
    • This change: the scan succeeds and finds the legacy entry, the capture receipt reports the database unchanged, source bytes are identical, and free space is unchanged at 18 MiB.
  • New src/commands/doctor-session-entry-state.capture.test.ts:
    • A drained captured database is inspected without requesting a private copy. This case fails on main (one copy) and passes here.
    • An in-place read whose source changes mid-scan is refused. With the close-time check disabled the test fails.
    • The existing private-snapshot reader-close test now uses an undrained WAL family, so the copy path stays covered.
      The capture tests moved out of doctor-session-entry-state.test.ts into this sibling file, with shared fixtures in a .test-support.ts file, to keep that file under its line cap. No coverage was dropped.
  • The 63 test files touching artifact-preserving reads, captured Doctor scans and update capture pass (635 tests; 65 are platform or Postgres skips). node scripts/check-changed.mjs passes typecheck, lint, format and the ratchets. Its dead-export scan fails only on files this PR does not touch (src/daemon/launchd.ts, src/plugins/provider-runtime.ts), a failure already on main.
  • Not run: the published-driver × candidate Docker cell. CI selects it only for main-tier and manual or release runs, not ordinary PRs, and the local host lacked disk space for its images.

…ped database just to read it

During update activation Doctor holds schema-maintenance custody and the Gateway
is stopped, yet its captured inspections still read every agent database
through a private whole-file copy. On a host with a 21 GiB agent database that
copy did not fit, session-entry-state refused, and the update left the Gateway
stopped.

When Doctor has custody and the family is drained (no journal, empty WAL),
the artifact-preserving reader now opens the source in place through an
immutable read-only URI, adding no lock, WAL or index beside it, and rejects
the read if the source changed. Undrained or uncustodied reads keep the
private copy. Captured inspection tests move to a sibling file to keep the
session-entry test under its line cap.
@clawsweeper

clawsweeper Bot commented Nov 10, 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 commands Command implementations size: M labels Nov 10, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Doctor reads drained SQLite databases in place under maintenance custody instead of making a full-size inspection copy.

Example: The reported APFS reproduction has a 31 MiB drained agent database and 18 MiB free.

  • Before: The captured session inspection fails while creating its private snapshot.
  • After: The reported scan succeeds with unchanged source bytes, an unchanged capture receipt, and 18 MiB still free.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful patch with meaningful real-SQLite regressions and a detailed capacity reproduction, but incomplete shipped-update validation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update can stop the Gateway and fail because a read-only Doctor inspection needs another database-sized allocation.
Reason: The maintainer-authored direction addresses a concrete availability failure without adding configuration, a schema, or another state owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses an evidenced update failure still present on main, and inspection found no concrete introduced defect.

Priority: P1
Reviewed head: f9d7903275e992e536ca7d5c6d160c0cb4aa0cd7

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a v2026.11.2-to-candidate update exercising the captured inspection with settings and session data preserved.
Agent review details

How this fits together

Update activation invokes Doctor under migration capture and maintenance custody; the session scanner reads agent SQLite rows and returns repair candidates while preserving the captured source.

flowchart TD
  A[Update activation] --> B[Captured Doctor scan]
  B --> C[Artifact-preserving reader]
  C --> D[Custodied and drained source]
  C --> E[Private snapshot fallback]
  D --> F[Immutable read and close-time validation]
  E --> G[Session inspection results]
  F --> G
Loading

Technical review

Best possible solution:

Keep copy avoidance in the existing artifact-preserving reader, with maintenance custody, drained-family eligibility, source validation, and the existing snapshot fallback.

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

Current-main source requires a whole-file snapshot in the reported captured scan, matching the supplied full-disk reproduction; no target code was executed during this review.

Is this the best way to solve the issue?

The focused change removes unnecessary copying through existing ownership and immutable-open contracts while retaining private recovery for undrained or uncustodied sources.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Captured session inspection changes intended behavior with a stated reason (8f62210: Captured scans used private images to preserve source artifacts and update attribution.)
  • Artifact-preserving native reader keeps the original intent (3be8851: Read-only Doctor must not migrate, checkpoint, or modify existing database families; immutable reads preserve that invariant for drained sources under custody.)
  • Awaited snapshot fallback keeps the original intent (7ce05f4: Large private-image preparation must remain cancellable and retain owned cleanup; families still requiring copies keep that path.)
  • Private reader closure keeps the original intent (c9e7493: Disposable inspection readers must close before snapshot removal; the moved regression retains this check with an undrained WAL family.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3be8851 adds src/infra/sqlite-snapshot-source.ts:49 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3be885108e5e; files: src/infra/sqlite-snapshot-source.ts)
  • Jason (Json): Raw commit 942a27d adds src/infra/sqlite-snapshot-source.ts:213 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 942a27def95d; files: src/infra/sqlite-snapshot-source.ts)

PR surface

Source +54, Tests +138. Total +192 across 5 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 2 57 3 +54
Tests 3 257 119 +138
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 314 122 +192

Preflight source

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

Review metrics

Metric Value Why it matters
Production versus test growth Production +54 net lines; tests and support +138 net lines Production growth implements eligibility and validation in the existing owner; test growth adds two distinct regressions and preserves the moved cleanup regression.

Labels

Label changes:

  • add P1: The reported capacity failure aborts update activation and leaves the Gateway stopped on installations with large agent databases.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The reported capacity failure aborts update activation and leaves the Gateway stopped on installations with large agent databases.
  • 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.

Rank-up moves

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

  • Record the latest-stable upgrade through the shipped updater with settings and session data retained.

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 November 9, 2026, 7:44 PM ET / November 10, 2026, 00:44 UTC.

@fuller-stack-dev
fuller-stack-dev merged commit b91520c into openclaw:main Nov 10, 2026
145 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/doctor-inspect-drained-db-in-place branch November 10, 2026 19:22
fuller-stack-dev added a commit to fuller-stack-dev/openclaw that referenced this pull request Nov 10, 2026
fuller-stack-dev added a commit that referenced this pull request Nov 10, 2026
…e runs out (#196370)

* fix(doctor): defer update session-entry inspection when snapshot space runs out

During an update, a SqliteSnapshotCapacityError while staging the read-only
session-entry snapshot refused the required session-entry-state step and
stopped activation, even though nothing had been read or changed. Skip that
target with a recoverable deferred warning instead, and let doctor --fix
finish it after the update. Other failures, and runs outside an update,
still refuse.

* test: allocate update session-entry capacity regression lines

* test(doctor): keep update capacity fixtures on the private-snapshot path

A drained, custodied family is now read in place, so the capacity
deferral applies to families that still hold WAL frames.

* test: allocate drained capture test lines from #196346
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…ped database just to read it (openclaw#196346)

During update activation Doctor holds schema-maintenance custody and the Gateway
is stopped, yet its captured inspections still read every agent database
through a private whole-file copy. On a host with a 21 GiB agent database that
copy did not fit, session-entry-state refused, and the update left the Gateway
stopped.

When Doctor has custody and the family is drained (no journal, empty WAL),
the artifact-preserving reader now opens the source in place through an
immutable read-only URI, adding no lock, WAL or index beside it, and rejects
the read if the source changed. Undrained or uncustodied reads keep the
private copy. Captured inspection tests move to a sibling file to keep the
session-entry test under its line cap.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…e runs out (openclaw#196370)

* fix(doctor): defer update session-entry inspection when snapshot space runs out

During an update, a SqliteSnapshotCapacityError while staging the read-only
session-entry snapshot refused the required session-entry-state step and
stopped activation, even though nothing had been read or changed. Skip that
target with a recoverable deferred warning instead, and let doctor --fix
finish it after the update. Other failures, and runs outside an update,
still refuse.

* test: allocate update session-entry capacity regression lines

* test(doctor): keep update capacity fixtures on the private-snapshot path

A drained, custodied family is now read in place, so the capacity
deferral applies to families that still hold WAL frames.

* test: allocate drained capture test lines from openclaw#196346
RomneyDa added a commit that referenced this pull request Nov 12, 2026
…#196346)

Backport the custodied immutable-read repair while preserving the release
branch synchronous inspection and existing snapshot cleanup owners.

(cherry picked from commit b91520c)

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
vincentkoc added a commit that referenced this pull request Nov 12, 2026
Preserve verified main 0c5c475 and all six planner contribution files.

Account separately for the 128 inherited test lines above the ceiling:
#196346 added 138 LF against
10 prior slack. Keep the planner grant at 157 and the shared scalar intact.

The actual staged checker against 0c5c475 passed: 6,635,333 lines,
6,635,333 ceiling, zero slack.
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 16, 2026
…ped database just to read it (openclaw#196346)

Release-specific adaptation for 2026.11.4: Read an exclusively custodied, drained agent DB in place; keep snapshot fallback and release cache/cleanup ownership.

Source commit: b91520c
Source PR: openclaw#196346

CI qualification pending; source-only verification completed.

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
…e runs out (#196370)

* fix(doctor): defer update session-entry inspection when snapshot space runs out

During an update, a SqliteSnapshotCapacityError while staging the read-only
session-entry snapshot refused the required session-entry-state step and
stopped activation, even though nothing had been read or changed. Skip that
target with a recoverable deferred warning instead, and let doctor --fix
finish it after the update. Other failures, and runs outside an update,
still refuse.

* test: allocate update session-entry capacity regression lines

* test(doctor): keep update capacity fixtures on the private-snapshot path

A drained, custodied family is now read in place, so the capacity
deferral applies to families that still hold WAL frames.

* test: allocate drained capture test lines from #196346

(cherry picked from commit ef47e2e)

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

Labels

commands Command implementations P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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