Skip to content

fix: let updates proceed while a busy agent database keeps writing - #201327

Merged
RomneyDa merged 1 commit into
mainfrom
codex/issue-200791
Nov 18, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
codex/issue-200791

Conversation

@steipete

@steipete steipete commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Related: #200791

What Problem This Solves

Updating while the Gateway is busy writing to a large agent database could be refused before anything changed: "SQLite source did not stabilize (reason=wal-copy-unstable, attempts=10)". Retrying a few minutes later, after the agent turn finished, was the only way through.

User Impact

Update admission and other read-only database inspections no longer give up on a large WAL database that an active writer keeps checkpointing. They take one consistent SQLite read snapshot instead. Idle, crashed, and index-less databases keep the existing byte-for-byte private copy, so nothing changes for them.

Why This Change Was Made

Artifact-preserving inspection copies the database bytes and compares them until they hold still. Appends to the WAL are already tolerated, but a checkpoint during the main-file copy (or the WAL restart after it) invalidates the attempt. With a multi-GB agent database, one copy takes longer than the writer's checkpoint interval, so all ten attempts lose and backoff cannot help.

When every attempt lost to committed writes (wal-copy-unstable, main-changed-during-copy, wal-changed-during-copy) on a complete WAL family (main file, WAL, and index present, no rollback journal), the copy owner now takes one read transaction through the existing online-backup path. Only a live connection can keep checkpointing, so its WAL index is current: the read cannot recover the index or change the 96-byte commit header that update captures compare, only reader slots after it (the same contract #175774 accepted for verified live owners). Source identity is pinned across the backup. Rollback-journal families still refuse, because a native reader would block their writer.

Accepted edge case: if the writer closes in the instant between the last failed copy and the native open, the read-only open sees a closed family. This is visible as a normal refusal or a later capture warning, not data loss.

Rejected alternatives: longer retry backoff (each attempt outlasts the checkpoint interval, so waiting between attempts does not create a quiet window); requiring a recorded owner (agent databases have no owner record, only the shared state database does).

Production LOC: +44/-4 in src/infra/sqlite-readonly-location.ts. Tests +43/-4, docs +12/-2.

Evidence

  • Regression test takes one read transaction when a live WAL writer outlasts every raw copy fails on base with the exact reported error and passes with the fix. keeps a WAL family without its index byte-neutral when every raw copy changes passes on both and pins that the source is unchanged and no -shm is created.
  • Local probe on a 600 MB WAL database with a checkpointing writer: raw copy failed 10/10 (wal-copy-unstable, 24 s); online backup succeeded in 3.4 s. With checkpoints disabled the raw copy succeeds, which confirms checkpoints, not appends, are the cause.
  • sqlite-readonly-location*, openclaw-database-preflight, and update-command-admit suites pass (215 tests). pnpm tsgo:core is clean. Autoreview (P2) is scoped-clean.
  • Live update on Crabbox AWS Linux with a running Gateway, a 1.8 GB agent database, and an external writer committing to it throughout:
    • Base, main 7eb33ccb25f, update 2026.11.30 → 2026.11.31: the update was refused at candidate admission with SQLite source did not stabilize (reason=wal-copy-unstable, attempts=10) (exit 1).
    • With this fix, update 2026.11.30 → fix build: candidate admission passed and the update completed (updated to 2026.11.32, exit 0). I confirmed the installed dist contains the change.

Artifact-preserving SQLite inspection copies the database bytes and
compares them until they hold still. A live writer that checkpoints during
every copy (a busy Gateway agent turn on a large agent database) exhausts
all ten attempts, so update admission refused with "SQLite source did not
stabilize (reason=wal-copy-unstable, attempts=10)".

When every attempt loses to committed writes on a complete WAL family
(main, WAL and index present, no rollback journal), take one SQLite read
transaction through the existing online-backup owner instead. Only a live
connection can keep checkpointing, so its WAL index is current: the read
cannot recover it or change the 96-byte commit header that update captures
compare, only reader slots after it. Idle, crashed and index-less families
never churn and keep the byte-neutral copy; rollback-journal families keep
refusing because a native reader would block their writer.

Refs #200791
@clawsweeper

clawsweeper Bot commented Nov 18, 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: S labels Nov 18, 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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR falls back to SQLite online backup when repeated checkpoint activity prevents a consistent private file copy.

Example: Update admission inspects a 2 GB WAL database while an agent keeps checkpointing it.

  • Before: All ten copy attempts can fail with wal-copy-unstable, refusing the update.
  • After: A complete WAL family can use one consistent online backup after copy retries are exhausted.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-consistent, but required product-path proof remains insufficient and hosted product checks were skipped.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An update can be refused while a healthy agent database keeps checkpointing, forcing the user to retry after activity settles.
Reason: The maintainer-authored direction repairs an established update failure using an existing owner; the broader linked heartbeat problem remains correctly referenced as related work.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a source-confirmed update failure through the existing snapshot owner, with no definite introduced defect found.

Priority: P2
Reviewed head: f91caeb2a2a6308b7d867932a83b4f9cb54bf0db

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Show a latest-stable-to-candidate update through the shipped updater while an independently checkpointing agent database exhausts raw copies, with admission succeeding and existing settings and data preserved.
Agent review details

How this fits together

Update admission and database inspection send source database paths to an isolated snapshot worker, which returns a consistent private database image for validation.

flowchart TD
  A[Update admission or inspection] --> B[Isolated snapshot worker]
  B --> C[Artifact preserving copy]
  C --> D[Consistent private image]
  C --> E[Checkpoint retries exhausted]
  E --> F[Complete WAL family check]
  F --> G[Existing online backup owner]
  G --> D
Loading

Technical review

Best possible solution:

Let the existing snapshot owner capture a consistent busy-WAL image while retaining source identity checks and private recovery for incomplete or rollback-journal families.

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

The current-main regression and copy/WAL verification code establish checkpoint-driven exhaustion; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

The smallest complete repair belongs in the existing copy owner and reuses its online-backup implementation; the patch does that without adding a competing manager or configuration option.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Artifact-preserving asynchronous acquisition changes intended behavior with a stated reason (9a01463: Shared coherent copy drivers preserve recovery artifacts and physical identity while supporting independent recovery images.)
  • Live-owner versus private-copy selection changes intended behavior with a stated reason (fix(sqlite): snapshot live databases through the online-backup owner #175774: Verified live owners permit native read transactions; other sources retain private copying to preserve coordination artifacts.)
  • Inspection byte-copy transfer policy keeps the original intent (8051834: Avoid source-inode cloning and copy-offload stalls during live inspection.)
  • Snapshot exhaustion diagnostics keeps the original intent (751d5f8: Retain the final consistency reason and attempt count without claiming the diagnostic change repairs acquisition.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 751d5f8 adds src/infra/sqlite-readonly-location.ts:622 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 751d5f8b6634; files: src/infra/sqlite-readonly-location.ts)
  • Vincent Koc: Raw commit ec7f8e9 adds src/infra/sqlite-readonly-location.ts:331 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ec7f8e9dd1c3; files: src/infra/sqlite-readonly-location.ts)
  • Dallin Romney: Raw commit 8051834 adds src/infra/sqlite-readonly-location.ts:659 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8051834a3ded; files: src/infra/sqlite-readonly-location.ts)
  • Jason (Json): Raw commit 9a01463 adds src/infra/sqlite-readonly-location.ts:591 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9a0146355c02; files: src/infra/sqlite-readonly-location.ts)

PR surface

Source +40, Tests +41, Docs +8. Total +89 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 44 4 +40
Tests 1 45 4 +41
Docs 2 10 2 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 99 10 +89

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.

Labels

Label changes:

  • add P2: The change addresses recoverable update admission failures during sustained database writes, without an established outage or data-loss condition.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The change addresses recoverable update admission failures during sustained database writes, without an established outage or data-loss condition.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 18, 2026, 11:16 AM ET / 16:16 UTC.

@steipete
steipete marked this pull request as ready for review November 18, 2026 16:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T16:31:35.264576Z f91caeb 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.

@RomneyDa
RomneyDa merged commit 07baab5 into main Nov 18, 2026
217 of 220 checks passed
@RomneyDa
RomneyDa deleted the codex/issue-200791 branch November 18, 2026 23:34
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Backport #201327 from main 07baab5,
preserving the release's native-CoW and metadata-inspection paths.

Backport the cold-storage notification assertion from #197510
(2c4413a): registration and restored
transcript notifications are distinct committed changes.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
#201327)

Artifact-preserving SQLite inspection copies the database bytes and
compares them until they hold still. A live writer that checkpoints during
every copy (a busy Gateway agent turn on a large agent database) exhausts
all ten attempts, so update admission refused with "SQLite source did not
stabilize (reason=wal-copy-unstable, attempts=10)".

When every attempt loses to committed writes on a complete WAL family
(main, WAL and index present, no rollback journal), take one SQLite read
transaction through the existing online-backup owner instead. Only a live
connection can keep checkpointing, so its WAL index is current: the read
cannot recover it or change the 96-byte commit header that update captures
compare, only reader slots after it. Idle, crashed and index-less families
never churn and keep the byte-neutral copy; rollback-journal families keep
refusing because a native reader would block their writer.

Refs #200791

(cherry picked from commit 07baab5)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
openclaw#201327)

Artifact-preserving SQLite inspection copies the database bytes and
compares them until they hold still. A live writer that checkpoints during
every copy (a busy Gateway agent turn on a large agent database) exhausts
all ten attempts, so update admission refused with "SQLite source did not
stabilize (reason=wal-copy-unstable, attempts=10)".

When every attempt loses to committed writes on a complete WAL family
(main, WAL and index present, no rollback journal), take one SQLite read
transaction through the existing online-backup owner instead. Only a live
connection can keep checkpointing, so its WAL index is current: the read
cannot recover it or change the 96-byte commit header that update captures
compare, only reader slots after it. Idle, crashed and index-less families
never churn and keep the byte-neutral copy; rollback-journal families keep
refusing because a native reader would block their writer.

Refs openclaw#200791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

2 participants