Repository navigation
refactor(state): share admitted worker write envelopes - #167552
Conversation
Reuse the retained shared-state writer for device auth, restart sentinel, run leases, prepared-pool presence and diagnostic commands. Preserve pre-BEGIN admission, synchronous transaction and commit grants, labels, domain checks and settlement. Remove the superseded lease wrapper and reuse existing test fixtures without deleting scenarios.
Keep custom admission explicit in inline test contexts and update the inventory reference after removing the run-lease wrapper. Preserve all scenarios and assertions.
|
🦞👀 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. What this changesConsolidates repeated database-worker write permission checks into the existing shared-state writer while preserving domain mutations. Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the duplicated envelopes, and the consolidation preserves existing transaction semantics. No actionable introduced defect was found. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDatabase workers persist OpenClaw’s shared state away from the Gateway thread. Domain commands obtain current transaction and commit permission, mutate their owned records, and return settled results. flowchart TD
A[Domain write command] --> B[Shared database worker]
B --> C[Open retained database]
C --> D[Request transaction permission]
D --> E[Run domain mutation]
E --> F[Request commit permission]
F --> G[Commit or roll back]
G --> H[Return settled result]
Technical reviewBest possible solution: Keep the common admitted envelope in the retained worker backend, with domain mutations and specialized admission protocols owned by their existing modules. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR consolidates existing behavior rather than reporting a runtime defect. Is this the best way to solve the issue? Yes: the existing worker backend absorbs repeated transaction plumbing without creating a competing owner or changing domain policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b0c330d27df4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -50, Tests -7, Other 0. Total -57 across 17 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 8, 2026, 10:13 PM ET / October 9, 2026, 02:13 UTC (Revision 3). |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* refactor(state): share admitted worker write envelopes Reuse the retained shared-state writer for device auth, restart sentinel, run leases, prepared-pool presence and diagnostic commands. Preserve pre-BEGIN admission, synchronous transaction and commit grants, labels, domain checks and settlement. Remove the superseded lease wrapper and reuse existing test fixtures without deleting scenarios. * test(state): complete admitted writer test contexts Keep custom admission explicit in inline test contexts and update the inventory reference after removing the run-lease wrapper. Preserve all scenarios and assertions.
What Problem This Solves
Device tokens, restart sentinels, worktree run leases, prepared-pool presence, and diagnostic writes repeat the same worker transaction admission envelope.
User Impact
No user-visible behavior changes. Existing database admission, current-authority checks, physical-store FIFO, rollback, settlement, schemas, and stored data remain unchanged. No migration or operator action is required.
Why This Change Was Made
The shared-state backend already owns the retained writer. Its new
writeAdmittedcapability preserves pre-BEGIN opening, then delegates the synchronous transaction to that writer with the same transaction and commit grants. Domain kernels, row comparisons, return values, and operation labels stay with their current owners; custom admission protocols retain the existingwritepath.Deslop
D1a removes 50 net production lines (67 added, 117 deleted) and 7 net test lines (34 added, 41 deleted), with 0 net support lines (1 added, 1 deleted): 261 changed lines total. It deletes the run-lease envelope module and consolidates six repeated envelopes covering fifteen command registrations. Device-auth tests reuse their existing target fixture and generated database type; all regression names, cases, and assertions remain.
Receipt-producing and custom-protocol callers retain their existing paths. Public SDK contracts are unchanged.
Evidence
Source baseline:
61a5fc58ecce321bc0bb1b224b447f8d446d099e; candidate:11843b1dd7fd542ce4548c9554dc0e1f9ed038ea.Focused real-worker proof passed 268 tests across 19 files, plus all four selected foreign-binding context cases. Coverage includes both admission refusals, rollback, physical-store ordering, unknown native settlement, lost replies, and retained-handle close/reopen behavior. No regression scenario or assertion was deleted.
check-changed, production and all test type graphs, core/script lint, Madge (zero cycles), full Knip, the database-worker ratchet, and fresh isolated P2 review passed. Type checks caught two inline fixture contexts missing the new method; both were fixed before the final passing run. Core lint retains two pre-existing max-lines warnings in untouched files.Test cost: the 19-file focused command with
--maxWorkers=1took 732.96 s including worker preparation.pnpm test src/infra/device-auth-store.test.ts --maxWorkers=1passed 14 tests in 172.16 s wall / 21.30 s test time; imports and worker-cache verification dominate. The four binding-context cases took 108.93 s wall / 3.63 s test time. CI timing is pending publication.Three alternating main/candidate SQL pairs completed on the same host with isolated synthetic state, matching harness hashes, and exact revision receipts. The first pair had later-phase duration skew, so two more pairs were added. Raw all-thread medians (including unassigned statements):
The strict-turn changes satisfy the campaign's <=0.5% untouched-owner noise exception. Native SQL + normalized stack groups reconstruct the representative median samples exactly: first turn +4, warmed ten-turn window +18. Every positive group belongs to unchanged session maintenance/readers, cron maintenance, ACP metadata, auth snapshot inspection, mention/target discovery, read-only freshness/schema probes, or the unchanged upstream-watch read path. No positive group was unresolved or introduced by the migrated envelopes. For example, warmed session-entry reads contribute +26 statements before offsets, ACP reads +6, and an additional upstream-watch read contributes its existing two admission reads plus its query (+3). First-turn session maintenance contributes +26 before offsets and cron maintenance +8. This is timing/cache variability, not a booked SQL performance improvement.
Boot+connect paired sums are main
[2585, 2568, 2608]vs candidate[2727, 2572, 2585](equal medians). Compaction+shutdown paired sums are[1606, 1667, 1610]vs[1605, 1597, 1589](lower in every pair); combining these adjacent windows accounts for shutdown timing skew. All reported gate-window duration ratios are below 1.5. The generic request-origin classifier remains indeterminate without a request census; its conservation check passes exactly, and no unassigned statements are omitted from the raw gate above.Landing verification
The landing review inspected the full diff at
11843b1dd7fd542ce4548c9554dc0e1f9ed038eaand reused the completed P2 review chain, focused worker proof, and three alternating SQL pairs. The migrated paths execute the same admission calls, transaction envelopes, domain SQL, and operation labels. No newOPENCLAW_*names, schema checks, runtime imports, or worker ownership cutovers are introduced.Released-surface inspection against
v2026.10.1-beta.1andv2026.9.9confirms thatexecuteSharedStateCommand,WorkerWriteOperationContext, and the removedworktreeRunLeaseOperationare internal: they are not exposed bysrc/plugin-sdk,api.runtime, or documented plugin subpaths. No released signature changes or compatibility shims are needed. The published-driver planner selects none of the changed paths; existing restart-sentinel and update-result worker coverage passed.ClawSweeper completed its exact-head review with no findings. CI attempt 1 passed all 15 executed Node jobs and the production/test type checks. Its only root failure was the Madge cycle between
src/agents/prepared-model-catalog-fingerprints.tsandsrc/agents/prepared-model-catalog-worker.ts; the aggregate CI gate failed downstream. Main already failed on the identical cycle. Both cycle files and the scanner/config/dependency inputs are byte-identical between the tested main baseline3f76fe021990df309bfcd0905030520bb30f81f4and CI mergeb6c4e43392988697b642e9804aeaecdf0dabee4e. Landing uses the explicitly authorized inherited-failure exception, without representing the failed CI gate as green.The local released SDK comparison (
v2026.10.1-beta.1→11843b1dd7fd542ce4548c9554dc0e1f9ed038ea) rendered both frozen revisions and produced digest962d7fc58d6c3b6f5d4b6f07f9182327c42e1ce095c648ac08ffb8e8684e5b4e: zero entrypoints added or removed. Its 1,187 affected exports include changes since the release baseline and conservative declaration-closure changes; this is not a claim of a globally empty release diff. None of this PR's changed internal function/context names appears in an actual SDK export declaration.writeAdmittedoccurs only in a whole-module*declaration fallback.WorkerOperationsprojects each handler's first argument and result, excluding its changed context argument; the migrated handlers preserve those projected contracts. No released signature is broken by this PR.