Skip to content

fix: state migration leases target a retired database - #159757

Closed
vincentkoc wants to merge 1 commit into
mainfrom
fix/sqlite-worker-file-incarnation-20260927
Closed

vincentkoc wants to merge 1 commit into
mainfrom
fix/sqlite-worker-file-incarnation-20260927

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: state migrations lose their lease when a retired database's filesystem identity is reused by another database while its lazy worker is still retained.

User Impact

Database operations stop reusing invalidated workers, and a lazy worker refuses a removed or replaced original database instead of recreating it. No schema, configuration, or public API changes are required.

Why This Change Was Made

The database lifecycle already invalidated the old admission, but shared-worker selection checked only the physical file key. Record that canonical lifecycle admission once at worker entry creation, then retire and join the exact stale actor before reuse. Keep it separate from the caller's short-lived schema admission so successive valid schema scopes can share the same worker.

The existing-only backend also checks its captured identity at the first native open. Aliases retain their existing sharing behavior; there is no automatic alias retargeting or fallback.

Known boundary: external same-path, same-inode replacement without canonical lifecycle invalidation remains a separate follow-up. Raw birth timestamps cannot safely establish a universal file generation.

Evidence

  • Exact signed source: 5f623a384410d1f8a00a28413b54ac8655df5354; tree f94140e32e968917dc57a0fcb65b685ea6d0b984.
  • Linux Blacksmith proof: native Testbox run, one worker per file. Node 24.19.0: 129 passed. Maintained Bun 1.4.3, revision a70be26b47560ede9b7646451e66e3f735195672: 127 passed and two pre-existing Node-only topology skips.
  • The unchanged original migration file passed all 23 cases in declaration order on each runtime. Focused coverage includes retained-worker retirement and join, zero/changing file metadata, sequential schema scopes, unexpected-error propagation, lazy missing/replaced locators, aliases, and asynchronous lifecycle behavior.
  • Actual Vitest reporter/fork executable hashes and native worker manifests were verified, including the patched backend input digest 58eb3fb2eddda3435942b05bd4d4fa716459fbd348d602ffa00f38db1ce2a8c3.
  • All six-path changed-file gates passed (1,280.162s), including formatting, core typecheck, all 25 test type graphs, lint (zero warnings/errors), and schema/lifecycle guards. The remote command exited 0; local wrapper cleanup exited 2 after a disk-full receipt write failure. The Testbox was stopped; its local capsule is retained by the native admitted-state guard. This is passing remote proof, not a successful local artifact or cleanup receipt.
  • Independent owner review and installed source review found no remaining actionable finding. Production: +49 net lines for lifecycle ownership and the lazy-open invariant; tests: +220 net lines.

The two Bun skips assume four shared carriers, which does not match Bun's existing dedicated-worker topology; no new skip was added. Dedicated-slot saturation coverage is a separate follow-up. The maintained Bun run's known directory-FD warning is repaired separately in openclaw/bun#16; it did not fail these tests.

Proof cost

One Testbox lease, observed queued at 15:01:43 UTC and stopped at 15:36:32 UTC on 2026-09-27. The passing native command took 28m2.580s; focused file wrappers totaled 5m54.345s and changed gates took 21m20.162s. An earlier pre-test observer assertion incorrectly compared the transport parent to the source branch parent; it failed before tests, was corrected to the receiver-installed transport base, and reused the same immutable source and lease.

@vincentkoc vincentkoc self-assigned this Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 27, 2026, 12:13 PM ET / 16:13 UTC (Revision 2).

ClawSweeper review

What this changes

The branch records each shared SQLite worker’s database admission, retires workers tied to an invalidated database, and prevents a lazy worker from opening a removed or replaced original file.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open. Current main addresses stale-worker reuse, but this branch adds a useful lazy-open safeguard. Its retirement path needs correction before integration.

Priority: P2
Reviewed head: 5f623a384410d1f8a00a28413b54ac8655df5354
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful production-boundary proof supports the unique safeguard, but the active-callback self-wait blocks the patch.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The captured PR body reports a Linux Testbox run of the real plugin-state client and SQLite worker under injected inode-key reuse: retirement finished, the replacement write and read succeeded, and the retired path stayed absent. Source tests also check lazy refusal of removed or replaced paths. The linked Actions run ended cancelled after the reported remote command passed, and its raw log was unavailable to this reviewer; active-callback integration and published-updater upgrade remain separate gaps. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured PR body reports a Linux Testbox run of the real plugin-state client and SQLite worker under injected inode-key reuse: retirement finished, the replacement write and read succeeded, and the retired path stayed absent. Source tests also check lazy refusal of removed or replaced paths. The linked Actions run ended cancelled after the reported remote command passed, and its raw log was unavailable to this reviewer; active-callback integration and published-updater upgrade remain separate gaps. No stored-data contract changes.
Evidence reviewed 11 items Introduced retirement wait: The pinned PR patch awaits actor retirement after detecting an invalidated database admission, without checking whether that actor still owns an active callback.
Current-main callback policy: Current main refuses replacement while the stale actor has active operations; its real-worker regression covers a replacement request made from inside the old callback.
Callback regression case: The current-main test explicitly makes a relocated write request from an active old-worker callback and expects immediate admission refusal.
Findings 1 actionable finding [P1] Preserve active-callback refusal before awaiting retirement
Security None None.

How this fits together

OpenClaw routes plugin state, lease, and migration requests through a shared SQLite worker owner. Database admission selects the worker, which then reads or writes the state database.

flowchart LR
  A[Plugin and migration requests] --> B[Database admission]
  B --> C[Shared worker owner]
  C --> D{Original database current?}
  D -->|Yes| E[SQLite worker]
  D -->|No| F[Retire stale worker]
  E --> G[State database result]
  F --> B
Loading

Decision needed

Question Recommendation
Should replacement admission keep current main’s immediate refusal while a stale actor has active callbacks, or change to waiting after a callback-safe design and latency bound are proven? Preserve immediate refusal: Keep main’s active-callback guard while integrating idle-worker retirement and the distinct lazy-open identity check.

Why: Current main deliberately specifies immediate refusal; changing that operator-visible waiting behavior requires the state owner’s intent even after the deadlock is fixed.

Before merge

  • Preserve active-callback refusal before awaiting retirement (P1) - If an old worker callback requests the relocated database after its admission is invalidated, this await retires the actor whose client close waits for that same callback to finish. Both sides then wait indefinitely. Current main refuses this case and has a real-worker regression for it. This is a late discovery on the same reviewed head; retain a callback-safe guard and cover the nested request.
  • Resolve merge risk (P1) - Even after the self-deadlock is repaired, waiting for active stale callbacks would change current main’s immediate-refusal behavior and could stall a replacement request for the callback’s full lifetime.
  • Resolve merge risk (P1) - The published updater followed by this candidate has not been shown against existing operator state, leaving the upgrade effect of the new first-open refusal unverified.
  • Resolve merge risk (P1) - GitHub reports this head as conflicted with its base, so the integrated worker behavior still needs review after conflict resolution.
  • Complete next step (P2) - Resolve the active-callback deadlock and merge conflict, confirm the intended callback policy, then show the published-updater × candidate upgrade on existing state.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve active-callback refusal before awaiting retirement — src/state/openclaw-state-worker-owner.ts:397-400
Agent review details

Security

None.

PR surface

Source +49, Tests +220. Total +269 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 50 1 +49
Tests 3 222 2 +220
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 272 3 +269

Review metrics

Metric Value Why it matters
Production and test growth production +49 net lines, tests +220 net lines Production growth is tied to generation custody and first-open fencing; the test growth exercises the file-identity lifecycle.

Merge-risk options

Maintainer options:

  1. Integrate with main’s callback guard (recommended)
    Resolve the conflict, prevent the self-wait, and demonstrate the published-updater handoff on copied existing state before merge.
  2. Pause this integration
    Keep main’s current protection and revisit the unique lazy-open safeguard if its callback and upgrade behavior cannot be established.

Technical review

Best possible solution:

Keep one lifecycle owner for database-generation fencing, retain the lazy-open identity guard, and preserve callback-safe replacement behavior with a verified upgrade handoff.

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

Yes. Current main’s real-worker test defines a nested active-callback replacement, and the branch’s new wait plus broker settlement show that this scenario would self-deadlock; this read-only review did not execute it.

Is this the best way to solve the issue?

No, not as submitted. The database-generation and lazy-open guards fit the existing owners, but retirement must preserve a callback-safe path before the branch can integrate.

Full review comments:

  • [P1] Preserve active-callback refusal before awaiting retirement — src/state/openclaw-state-worker-owner.ts:397-400
    If an old worker callback requests the relocated database after its admission is invalidated, this await retires the actor whose client close waits for that same callback to finish. Both sides then wait indefinitely. Current main refuses this case and has a real-worker regression for it. This is a late discovery on the same reviewed head; retain a callback-safe guard and cover the nested request.
    Confidence: 0.97
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The branch targets a consequential but narrow database-worker race, while current main already protects the central stale-reuse path.
  • merge-risk: 🚨 compatibility: The candidate changes first-open refusal during state migration without a published-updater upgrade proof on existing state.
  • merge-risk: 🚨 availability: The introduced retirement wait can hang a replacement request issued from an active stale-worker callback.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured PR body reports a Linux Testbox run of the real plugin-state client and SQLite worker under injected inode-key reuse: retirement finished, the replacement write and read succeeded, and the retired path stayed absent. Source tests also check lazy refusal of removed or replaced paths. The linked Actions run ended cancelled after the reported remote command passed, and its raw log was unavailable to this reviewer; active-callback integration and published-updater upgrade remain separate gaps. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body reports a Linux Testbox run of the real plugin-state client and SQLite worker under injected inode-key reuse: retirement finished, the replacement write and read succeeded, and the retired path stayed absent. Source tests also check lazy refusal of removed or replaced paths. The linked Actions run ended cancelled after the reported remote command passed, and its raw log was unavailable to this reviewer; active-callback integration and published-updater upgrade remain separate gaps. No stored-data contract 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)
  • vincentkoc: 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.

  • Preserve current main’s active-callback refusal or prove a callback-safe bounded wait with the nested real-worker scenario.
  • Show a published-updater × candidate run against copied existing state after resolving the merge conflict.

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 (1 earlier review cycle)
  • reviewed 2026-09-27T16:00:18.612Z sha 5f623a3 :: blocked before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

Closing as superseded by the merged replacements:

Rechecked original head 5f623a384410d1f8a00a28413b54ac8655df5354 against main b94e5177a3bb520cf2e4cda709fab5618d68c925. Both replacement commits are ancestors of that main. The inspected production and regression paths are unchanged from the source-review pin.

Main retains independent database-generation admission, callback-safe actor retirement, lexical-scope reuse and unexpected-error propagation. Existing-only factories carry their admitted file identity to native opening, including device identity and the separate existing-schema lease writer.

An independent complete test-coverage comparison found no unique useful regression left behind: retirement and callback admission, lazy removed/replaced paths and surviving hardlinks, and shared-actor ownership cases. Main's consistent same-inode relocation fixtures replace the original synthetic metadata disagreements while retaining the observable protections.

This is a current-source supersession decision, not a new test execution or a claim that the original disk-full cleanup succeeded. Existing branches, checkouts and proof artifacts are retained.

@vincentkoc vincentkoc closed this Oct 1, 2026
@RomneyDa
RomneyDa deleted the fix/sqlite-worker-file-incarnation-20260927 branch October 22, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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