Repository navigation
fix(state): retire stale workers before replacement admission - #159944
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 8:28 PM ET / September 28, 2026, 00:28 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch makes OpenClaw retire a stale shared SQLite worker before admitting replacement database work and makes a lazy worker refuse a removed or replaced original file. Merge readiness✅ Ready for maintainer review Current main still lacks the database-generation check, and this PR supplies a focused fix with regression evidence. No actionable patch defect emerged from the reviewed head. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw sends shared-state database operations through a worker owner that selects a SQLite worker and retains it across calls. Database lifecycle admission and file identity determine whether that worker can serve a later operation or must retire first. flowchart LR
A[State operation] --> B[Database admission]
B --> C[Shared worker owner]
C --> D{Original generation current?}
D -->|Yes| E[SQLite worker result]
D -->|No| F[Retire worker or refuse active callback]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +52, Tests +307. Total +359 across 7 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep database-generation custody with the existing worker owner, settle the old actor before replacement work, and preserve refusal when an active callback or changed file makes reuse unsafe. Do we have a high-confidence way to reproduce the issue? Yes. The added real-file rename scenario reaches the plugin-state client and shared worker owner, and the PR reports clean-main failures for that path; this reviewer did not execute it. Is this the best way to solve the issue? Yes. Capturing canonical database admission in the existing worker owner and checking the original file at lazy open repairs the stated invariant without a new store, schema, or public API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e205c9d6fced. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
70615a3 to
e22489a
Compare
…aw#159944) * fix(state): retire workers after database admission invalidation * fix(state): refuse stale actor replacement during active callbacks --------- Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Builds on Vincent Koc’s #159757, preserving his original commit attribution and adding actor-wide active-callback refusal.
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. If any callback still holds the stale actor, reject replacement immediately; joining its retirement from that callback would wait on itself. Once those callbacks settle, replacement joins retirement before using the new database.
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
Merged as
50864f52176af234dcf4baea0af7640421f67e79; CI 36361602386 passed on exact heade22489aeddb7b0a687e08d8a8ad0d75847a9cd6e. Main ancestry and Vincent Koc’s merge attribution are verified. All task-owned Testbox leases are stopped. The source-pinned proof and intermediate investigations below remain historical evidence.5f623a384410d1f8a00a28413b54ac8655df5354; treef94140e32e968917dc57a0fcb65b685ea6d0b984.a70be26b47560ede9b7646451e66e3f735195672: 127 passed and two pre-existing Node-only topology skips.58eb3fb2eddda3435942b05bd4d4fa716459fbd348d602ffa00f38db1ce2a8c3.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.
Integration for the migration CI failure
The migration
completed/refusedfailure blocking #159481 was traced to a revoked worker selected after inode reuse, writing lease rows into the previous fixture database. The initially landed repairse52420and601bb5were reverted. This replacement retains canonical database-generation admission independently of a caller's lexical schema scope; it does not reclassify ended schema authority as a cache miss.The active-callback behavior is now explicit: replacement rethrows the original invalidation while any callback retains that actor. This preserves accepted-work custody and avoids a callback waiting for its own close. The check uses the existing actor-wide operation owner, including other maintenance scopes. Idle stale actors still retire and join before replacement admission. No write is replayed, and no durable data, schema, retention, permission, config or public SDK contract changes. Existing-only lazy workers refuse a removed/replaced original locator instead of creating or adopting another file. Existing installations need no migration or update action.
Two additional regression cases keep a callback active through a real filesystem rename, then request replacement in the same scope or another maintenance scope. A pass-through observation of real retirement lets the old implementation report
retiringand settle naturally. On providerblacksmith-testbox, leasetbx_01m3j6nby3jq9g0et6qshevs88, run 36345784969, both cases failed for that exact reason on the original PR head in 16.387 s; neither timed out. The receipt classifier additionally expected the labelAssertionError, while Vitest's resolves wrapper reportedError. That harness rejection is retained; direct inspection verified the exact expected failures, and the negative was not rerun. The corrected implementation passed the full admission file: 13 tests in 20.808 s. Assertions, retry counts, timeouts and mock scope were not weakened.Current-source proof: provider
blacksmith-testbox, leasetbx_01m3jg140mvzve7v6rafdhdy94, run 36355707484, tested head9c2d0b4e8dce5c1d922491711d81a95ebf412802, tree8abd8f5e3d3a598a443f1aa005af3c07ad099b1aon basee74690a70ca826da3c40e745099482e8c9401da6. The matching class32 runner exposed eight logical CPUs and 33,229,729,792 bytes RAM; actual Node 24.19.0 and pnpm 12.5.0 were recorded.The clean-main negative, with only the final tests applied, failed six regressions in 21.478 s: three stale-worker replacements bypassed retirement, two active-callback replacements wrote instead of refusing, and one recorded admission error was ignored. The receipt checker expected only the three stale-retirement failures; its rejection is retained. Direct inspection confirmed that all six failures express the missing canonical-admission check. No negative was rerun and no assertions or matcher were changed.
The full candidate passed all 67 focused cases using
node scripts/run-vitest.mjs <file> --maxWorkers=1: admission 13/25.408 s; worker lease 7/17.909 s; settlement 6/33.432 s; resident subagent state 39/28.502 s; existing-schema 2/21.248 s. The latter two protect the ended-schema semantics involved in the reverted repair.python3 run-repro.py mcp-small16 <candidate-checkout>replayed the original first infra CI group with the same environment, two-worker setting, class32 machine and surviving file order: 436 passed, two existing skips, 183.835 s. Four of the original 46 paths were deleted by the separately landed Tasks removal; all 42 surviving paths were supplied. The later Gateway groups cannot influence the earlier infra failure and were not rerun.node scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core","core-test-state-logging"]' --concurrency 2passed in 42.506 s;node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <six changed files> --threads=1passed in 21.835 s.An earlier integrated attempt lost its transport during the network outage (exit 255, empty output, no phase receipts). Its expired lease could not return evidence, so no result was claimed for that attempt. Only those unproven phases were resumed on the fresh lease; the completed original-head controls were retained.
Publication head
70615a358655ef2095da3741f037041e84146674is a patch-identical rebase onto main4994ec450134ed826e6e4fb63f6a277aee53d4a1. GitHub's enforced checks gate its exact-head auto-merge.Deslop and fresh isolated Codex review through P2 are clean. The complete replacement and active-callback addition were rebased onto current main with both commits patch-identical. Full PR LOC: production +53/-1/net +52; tests +316/-9/net +307; docs +0/-0/net 0. The additional production delta beyond the original PR is +4/-1/net +3; the added regression coverage is +76/-1/net +75.
Native-handle fixture correction after CI
Run 36357143646, job
108727843346, exposed fourENOENTfailures inopenclaw-state.worker.summary.test.ts. These direct-backend fixtures constructed an existing-only backend with no file, then expected its first write to create the database. The real broker rejects an absent existing-only path before worker dispatch. Its existing missing-path/no-dispatch regression is unchanged.The fixture now supplies admitted input: KV cases use an empty existing file, while health/diagnostic cases initialize the canonical schema through the database owner and fully close it before capturing admission. Read assertions compare exact bytes before and after. Every transaction-grant, promotion, shared-handle, survivor, close, and durable-reopen assertion remains. The ordinary-creation case still begins with an absent path. Production and the identity guards are unchanged.
On the same
blacksmith-testboxleasetbx_01m3jg140mvzve7v6rafdhdy94/ run36355707484, the historical CI merge69491cd90bbc298eeaea8d10688e1008e5cdb673reproduced all four failures in the exact exercised prefix: 50 Gateway inputs followed by 80 unit inputs, original environment and worker settings, 124.453 s. The first attempt stopped before the target group because Bun was absent; it is recorded as a prerequisite failure. CI's exact pinned Bun binary (1.4.3-canary.1+ddfce5d01) was installed with the action's archive and binary checksum checks, then that complete environment was used.The first fixture candidate passed three cases but exposed missing-schema errors in the two health cases. The final setup uses the actual canonical schema for those cases; no baseline was rerun.
pnpm test src/state/openclaw-state.worker.summary.test.ts --maxWorkers=1passed all five tests in 18.060 s. The same two-group prefix passed all 1,715 tests across 130 files in 109.120 s (705 Gateway Node, 20 Gateway Bun, 990 unit tests). Summary-only typed lint passed in 19.512 s. The tested combined fixture tree was434c7be6fe1ab1092003264e46799bd74c385291; source hashes were verified. Both fixture refinements have clean isolated Codex P2 reviews and deslop.Current head
e22489aeddb7b0a687e08d8a8ad0d75847a9cd6erebases all four commits unchanged onto main1fea5ee10891ea6105f8757ec8695f9583a134ca. Exact-head auto-merge is re-armed; required GitHub CI remains the merge gate. The cumulative fixture delta is tests +18/-6/net +12, with no production change.