Skip to content

fix(update): Bun-run updates fail with database is locked before replacing the package - #170519

Merged
RomneyDa merged 2 commits into
mainfrom
fix/bun-update-handoff-lock
Oct 13, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/bun-update-handoff-lock

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: openclaw update run under Bun fails before replacing the package with database is locked on managed-update-handoffs.sqlite.

User Impact

Bun-run updates get past executor admission and handoff lease writes instead of failing every time after a 5 s wait. Update behavior is otherwise unchanged. Node updaters were not affected and behave the same.

Why This Change Was Made

The existing-store helper (withExistingSqliteRollbackDatabase) takes its read snapshot with PRAGMA locking_mode = EXCLUSIVE so a foreign WAL store is refused without creating sidecars, then switches back to NORMAL. SQLite applies NORMAL only at the next file access, so ROLLBACK alone kept the snapshot's SHARED lock until the connection closed. Node closes immediately; Bun's close_v2 defers closing while prepared statements remain, so the update executor's own writer could never commit and timed out with SQLITE_BUSY.

After ending the snapshot, the helper now performs one autocommit PRAGMA schema_version read, which makes SQLite drop the retained lock. It runs only after the store was verified to use a rollback journal, so it cannot create WAL sidecars. The same fix stops a retained reader from holding the lock between observations on Node too.

Update behavior: the installed updater runs first, so this takes effect for updates run by an updater that ships this change. No schema, durability, retention, or lease/authority semantics change.

Evidence

  • Root cause reproduced from source under stock Bun 1.4.2 (macOS): the real withUpdateCommandExecutor admission failed after 4.9 s at step=commit with database is locked; the same driver passes under Node (83 ms) and, with the fix, under Bun (56 ms). Isolated A/B: the existing-store write path failed twice under Bun on main and passes with the fix.
  • Real openclaw update in Docker (Linux, packed build of this branch → version-bumped target, isolated state, --no-restart):
    • Node: completes (exit 0).
    • Bun 1.4.2: no longer hits the lock; it passes admission, staging, candidate doctor, lint, and config validation. It then stops at a separate, pre-existing Bun failure (below).
  • New tests:
    • src/infra/sqlite-existing-database.test.ts (Node): a retained reader releases its snapshot lock while its connection stays open. Fails on main with database is locked, passes here. pnpm test <file> --maxWorkers=1: 2.2 s wall, ~10 ms test.
    • src/infra/sqlite-existing-database.bun.test.ts: runs the existing-store writes and the real update executor admission under Bun. Fails on main with database is locked, passes here (~1.1 s). Wired into the existing checks-fast-bun-launcher task; changes to src/infra/sqlite-existing-database.* now select it.
  • Sibling suites pass: handoff database (24), executor retained/admission, package activation, pending recovery, repair activation, activation bounds, CI scope and workflow planning (605).
  • pnpm tsgo:core, tsgo:scripts, tsgo:core:test, tsgo:test:root, oxlint and oxfmt pass. Autoreview: clean.
Separate pre-existing Bun failure (not fixed here)

With the lock fixed, a Bun-run update fails at candidate-plugins (plugins list --json) with Runtime config source changed during asynchronous preparation. Cause: in Bun 1.4.2, creating the first worker_threads Worker with env: SHARE_ENV replaces the process.env object, and the old object is detached (writes no longer reach the new one). captureRuntimeConfigAsyncReader correctly notices that identity change. Node keeps process.env stable. That fix belongs to the worker/runtime-env owner and is left for its own change.

@clawsweeper

clawsweeper Bot commented Oct 13, 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 scripts Repository scripts size: S labels Oct 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR releases completed SQLite snapshot locks so Bun update admission and later writer commits can proceed.

Example: Run openclaw update under Bun 1.4.2 with an existing managed-update-handoffs.sqlite database.

  • Before: Executor admission fails with database is locked before replacing the package.
  • After: The reported Docker run passes admission and candidate validation before encountering a separately disclosed Bun environment failure.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair appears correct and has native regression coverage; directly inspectable shipped-entry-point evidence remains limited.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor-proof gate; the body reports Docker openclaw update passing the repaired Bun admission path, but supplies no runtime artifact, so the earlier optional trace recommendation remains applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Bun-run updates fail during executor admission before replacing the package.
Reason: The maintainer-authored change restores the existing lock-release contract; the later Bun environment failure is separately disclosed and outside this bug.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current shared SQLite lock-release defect, and no introduced correctness or security bug was found; the required CI gate remains failed.

Priority: P2
Reviewed head: 54c344304391f48ffd16f29a8d0ab4727b35b6ba

Before merge

None.

Findings

None.

Tests

  • Low-value test test/scripts/ci-workflow-planning.test.ts: Remove the added exact command-string assertion: it pins shell spelling rather than execution behavior already covered by the planner contract and Bun CI lane.
  • Missing end-to-end proof: The reported Docker update run has no inspectable terminal trace or linked artifact showing the repaired admission path.
Agent review details

How this fits together

The existing-database helper provides identity-bound rollback-journal snapshots and writer transactions to update handoff, activation, and recovery owners.

flowchart TD
  A[Update command] --> B[Executor lease owner]
  B --> C[Handoff database owner]
  D[Activation and recovery owners] --> E[Existing SQLite helper]
  C --> E
  E --> F[Read snapshot]
  F --> G[Release snapshot lock]
  G --> H[Guarded writer commit]
Loading

Technical review

Best possible solution:

Keep the repair in the shared snapshot owner while preserving journal admission, physical identity checks, and existing writer authority.

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

Current main retains the implicated release sequence, and the independent-writer and Bun executor fixtures target it directly; the author reports baseline failures, while this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs native lock settlement at the existing shared owner without retries, journal-mode changes, or another ownership mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Rollback-journal snapshot release keeps the original intent (0185544: Preserve original recovery authority and refuse unsafe stores while explicitly ending Bun snapshots before writer settlement.)
  • Retained reader lifetime keeps the original intent (8bb889e: Reuse connections to reduce ownership-check CPU cost while ending each observation's snapshot so other writers remain unblocked.)
  • Current admission-fact reuse keeps the original intent (19fe879: Reuse admitted handles and validation facts while preserving per-operation snapshots; the added pragma is a lock-release operation rather than a repeated validation decision.)
  • Bun CI selection keeps the original intent (6a50179: Select protected regression coverage from concrete owner inputs rather than broad PR fallbacks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 8bb889e adds src/infra/sqlite-existing-database.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8bb889e8c841; files: src/infra/sqlite-existing-database.ts)

PR surface

Source +7, Tests +128, Config +3, Other +1. Total +139 across 8 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 1 9 2 +7
Tests 5 128 0 +128
Docs 0 0 0 0
Config 1 3 0 +3
Generated 0 0 0 0
Other 1 2 1 +1
Total 8 142 3 +139

Review metrics

Metric Value Why it matters
Production versus test growth Production +11/-3 lines; tests and test support +128 lines Most growth protects distinct retained-connection and Bun executor contracts through native SQLite.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The defect blocks Bun updater admission and can retain reader locks, with limited runtime scope and no demonstrated data loss.
  • 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.

  • Optionally attach a redacted Docker update trace showing Bun passing executor admission and reaching the separately disclosed candidate-plugins failure; remove IPs, API keys, phone numbers, and non-public endpoints.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-13T02:03:14.348Z sha 54c344304391f48ffd16f29a8d0ab4727b35b6ba :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 10:12 PM ET / October 13, 2026, 02:12 UTC (Revision 2).

@RomneyDa
RomneyDa force-pushed the fix/bun-update-handoff-lock branch from 6d1970c to 721b4e9 Compare October 13, 2026 04:57
@RomneyDa
RomneyDa merged commit 5dbb579 into main Oct 13, 2026
146 checks passed
@RomneyDa
RomneyDa deleted the fix/bun-update-handoff-lock branch October 13, 2026 05:48
steipete added a commit that referenced this pull request Oct 13, 2026
#170519's Bun existing-store regression launches this source helper by
path. Register that exact execution entry in the full-tree Knip audit
so its live update-executor regression is retained without an ignore.

The unchanged opt-in Bun regression and deadcode checker tests pass.
No runtime, update behavior, assertions or timeouts change.
steipete added a commit that referenced this pull request Oct 13, 2026
* fix(test): expose lazy report capture to export analysis

The Vitest 5 migration loads its report-capture constructor through a
CLI file path, which the script export scan cannot resolve. Register
that existing reporter path with a literal lazy import in the redacting
loader, preserving the constructor, options and forwarding lifecycle.

No Knip ignore, eager loading, test suppression or user-visible change.
The original Solid leftovers are covered by #170660; #170680 owns the
separate permission-card export repair.

* test(tooling): register Bun SQLite regression fixture

#170519's Bun existing-store regression launches this source helper by
path. Register that exact execution entry in the full-tree Knip audit
so its live update-executor regression is retained without an ignore.

The unchanged opt-in Bun regression and deadcode checker tests pass.
No runtime, update behavior, assertions or timeouts change.
steipete added a commit that referenced this pull request Oct 13, 2026
## What Problem This Solves

Scheduled main CI reports `src/infra/sqlite-existing-database.bun.test-support.ts` as unused. The helper is live: the Bun regression added by #170519 launches it through a plain path string that Knip cannot connect to the test.

Resolve the actual subprocess argument with `fileURLToPath(new URL(..., import.meta.url))`, following the existing fixture pattern. This makes the dependency visible while preserving the Bun helper, every assertion, the isolated environment, and the existing timeout. No ignore entries or production changes are added.

## Evidence

- Original failure: [scheduled run 38359584345, check-dependencies](https://github.com/openclaw/openclaw/actions/runs/38359584345/job/115170478488). The full-tree unused-file scan reports this one helper; production-file and all unused-export scans passed.
- Culprit: `5dbb5799d2e747d5630f966a72cc576a0049bd83` (#170519), verified against its parent. Launcher and helper blobs on base `cdd0d2df564828ecf9fa01c03ae655af8c952b06` match the failing scheduled head.
- Changed-file oxfmt, oxlint, and `git diff --check` passed.
- One independent Codex review completed scoped-clean at P0–P2.
- The exact full-tree unused-file scan passed on candidate `d79c87980ff41b2218803b907201de9cfa164ff6`: [run 38363318115, job 115182433252](https://github.com/openclaw/openclaw/actions/runs/38363318115/job/115182433252), Knip 6.32.2, unchanged configuration and `--files` arguments, zero diagnostics in 130.2 seconds. Source-preservation verification passed. Ordinary PR CI 38362413570 passed all selected static, type, architecture, security, and required gates. T1 remained 454 to 454, compatibility calls 9 to 9, and dialect groups 0 to 0. No local Knip, typecheck, or runtime test was run under the compute-conservation rule.
- Test LOC: +2/-1; production LOC: 0. No SQL or runtime behavior change.
RomneyDa added a commit that referenced this pull request Oct 13, 2026
…files

Squashed onto current main; keeps #170519's Bun launcher checks alongside the retained-import preload checks.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…acing the package (openclaw#170519)

* fix(update): release the existing-store snapshot lock so Bun updaters can commit

* fix(update): keep the snapshot lock release within the existing pragma budget
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…70701)

* fix(test): expose lazy report capture to export analysis

The Vitest 5 migration loads its report-capture constructor through a
CLI file path, which the script export scan cannot resolve. Register
that existing reporter path with a literal lazy import in the redacting
loader, preserving the constructor, options and forwarding lifecycle.

No Knip ignore, eager loading, test suppression or user-visible change.
The original Solid leftovers are covered by openclaw#170660; openclaw#170680 owns the
separate permission-card export repair.

* test(tooling): register Bun SQLite regression fixture

openclaw#170519's Bun existing-store regression launches this source helper by
path. Register that exact execution entry in the full-tree Knip audit
so its live update-executor regression is retained without an ignore.

The unchanged opt-in Bun regression and deadcode checker tests pass.
No runtime, update behavior, assertions or timeouts change.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
)

## What Problem This Solves

Scheduled main CI reports `src/infra/sqlite-existing-database.bun.test-support.ts` as unused. The helper is live: the Bun regression added by openclaw#170519 launches it through a plain path string that Knip cannot connect to the test.

Resolve the actual subprocess argument with `fileURLToPath(new URL(..., import.meta.url))`, following the existing fixture pattern. This makes the dependency visible while preserving the Bun helper, every assertion, the isolated environment, and the existing timeout. No ignore entries or production changes are added.

## Evidence

- Original failure: [scheduled run 38359584345, check-dependencies](https://github.com/openclaw/openclaw/actions/runs/38359584345/job/115170478488). The full-tree unused-file scan reports this one helper; production-file and all unused-export scans passed.
- Culprit: `d07e31eb2f581fd4147186fbed2045a6dc8f0faf` (openclaw#170519), verified against its parent. Launcher and helper blobs on base `1f32c05dc71dcd8a08761edc3410f6ecad85278b` match the failing scheduled head.
- Changed-file oxfmt, oxlint, and `git diff --check` passed.
- One independent Codex review completed scoped-clean at P0–P2.
- The exact full-tree unused-file scan passed on candidate `d79c87980ff41b2218803b907201de9cfa164ff6`: [run 38363318115, job 115182433252](https://github.com/openclaw/openclaw/actions/runs/38363318115/job/115182433252), Knip 6.32.2, unchanged configuration and `--files` arguments, zero diagnostics in 130.2 seconds. Source-preservation verification passed. Ordinary PR CI 38362413570 passed all selected static, type, architecture, security, and required gates. T1 remained 454 to 454, compatibility calls 9 to 9, and dialect groups 0 to 0. No local Knip, typecheck, or runtime test was run under the compute-conservation rule.
- Test LOC: +2/-1; production LOC: 0. No SQL or runtime behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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.

1 participant