Repository navigation
refactor(state): register worker operations once per domain - #162446
Conversation
Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners.
|
🦞👀 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 October 1, 2026, 2:52 AM ET / 06:52 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch derives shared-state worker command types and dispatch from lazy domain handler tables for push notifications, worktrees, and fleet operations. Merge readiness✅ Ready for maintainer review Keep open: the refactor remains useful and is absent from fetched main. The pinned diff has no actionable correctness or security findings; repository-admin authorship also protects it from automatic cleanup. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw's shared-state worker receives database commands from host-side stores. It prepares the requested domain, runs synchronous handlers under the existing database and admission owners, and returns results to callers. flowchart TD
A[Host stores] --> B[Shared state broker]
B --> C[Prepare requested domain]
C --> D[Lazy handler registry]
D --> E[Exact operation dispatch]
E --> F[Existing database and admission owners]
F --> G[Results to callers]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -125, Tests +55. Total -70 across 19 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use the typed domain registry over the existing broker while keeping database lifecycle, admission, and synchronous transaction policy with their current owners. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR reorganizes existing worker dispatch rather than reporting a broken user flow; source inspection supports the stated duplication. Is this the best way to solve the issue? Yes: typed handler tables remove repeated command plumbing while retaining the existing worker preparation and store owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 10cf91f150e2. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…#162446) * refactor(state): register worker operations once per domain Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners. * fix(state): break worker registry type import cycles
What Problem This Solves
Adding a shared-state worker operation requires repeating its name and contract across a type map, command guard, dispatcher, and central runtime routing. Those central edits also collide during parallel domain work. This is a maintainer-requested prototype to reduce that plumbing over the existing broker.
Why This Change Was Made
Register each operation once as a typed handler and derive its input/output contract from the handler signature. A typed namespace-to-loader table prepares only the requested domain through the existing worker preparation hook; synchronous execution then looks up the exact operation name. Host stores consume the inferred contracts through type-only imports.
Migrate 35 operations across Web Push (14), APNs (4), worktree registry reads/retirement/run leases (11), and fleet registry (6). Unmigrated domains retain their existing dispatch paths. Web Push's VAPID read still uses state options without opening a writable handle; subscription-binding errors retain their tagged result. Database handles, transaction/commit admission, schema preparation, and result/receipt ownership remain with the existing owners.
Before: implement the handler, then update the contract map, operation guard, switch, and sometimes central routing/preparation. After: add one entry to an existing domain's handler table; its command and result types and routing follow automatically. Host callers and behavior tests still change as needed. A new domain adds its inferred type and one lazy loader entry to the registry.
User Impact
No user-visible behavior, schema, stored data, retention, permission, update, broker, admission, or settlement change. Existing worker tests remain byte-for-byte unchanged. The direct Web Push dispatcher export remains as a thin table adapter to preserve its existing profile-read test entry point; it contains no operation switch or name list. The worker inventory script and generated inventory are untouched.
Evidence
pnpm test src/state/openclaw-state-worker-registry.test.ts --maxWorkers=1: 2.36 s wrapper wall time, 1.29 s Vitest duration, 50 ms test time. CI timing is not yet available.findSourceImportBackedgesfromsrc/infra/push-web-store.tsreports zero paths to the Web Push worker, shared-state runtime, or either registry module. The inferred contract import is type-only. The same graph check from the shared-state runtime reports zero eager paths to all four migrated worker modules.pnpm buildpassed (17m 24.6s, including all runtime/SDK declarations and UI).node scripts/check-changed.mjs --base c9e66c126df9b48d8b145c6da06569df3bdd14e1passed: core typecheck, all 27 affected test graphs, core lint, formatting, dead-export analysis, database/schema guards, and import/auth boundary guards. Runtime value cycles: zero. The initial check required the repository-standardSAFETY:marker on two dispatch-correlation comments; those annotations were added and the complete check passed.e2e4a34c9828f1230d906567c0eacb7b1e1fe185, against the pinned base. No accepted/actionable findings remain.No blocking design questions remain for this prototype. Further domain migrations and adapting the retained direct Web Push test entry point are follow-up work. The registry API and all operation names, inputs, outputs, and runtime policies remain unchanged after the CI repair.
Landing validation
CI on the original head found two type-import cycles that the runtime-only import check does not include. Commit
c7508c3e44c1c845cdec76b0c12f9ea96d640b45separates fleet record types from the inferred worker contract, takes lease inputs from the existing kernel signatures, and derives the direct Web Push adapter contract locally.check-madge-import-cycles.tsnow reports zero cycles. All 18 focused registry, fleet, and Web Push profile-read tests passed across four files (102.64 s wrapper wall time). The full changed-file check also passed on the repair, including core production types, all 27 test-type graphs, lint, formatting, dead exports, and database/import guards. Fresh Codex autoreview of the full staged candidate is scoped-clean through P2. ClawSweeper completed its review of the repaired head with no actionable or security findings.The original CI run 36821760917 also hit inherited lint failures and cancelled 129 jobs through fail-fast. The same diagnostics occur on main in run 36820391530: missing generated database types, a generic-parameter diagnostic, and two array-sort diagnostics in files outside this PR. Cancelled jobs are not passing coverage. Current-head run 36824809637, attempt 1, contains only two failed lint roots and 96 fail-fast cancellations;
security-fastpassed. Its additional canary-test max-lines diagnostic was independently reproduced from the tested main parent (e304e4ffc6d9951ed6a6848554f98e583e31f014) using that parent's unchanged test and lint config. The native pre-existing-failure admin evidence binds both roots, every cancellation, the tested merge tree, matching source blobs, and saved main failure logs. Cancelled coverage remains unrun.The generated-declaration prerequisite regression was introduced by
6337d159e391(#162288); the owning fix is #162464. Main scheduled run36820391530independently fails the same core lint diagnostics. The canary line-limit diagnostic retains its separate reproduction from main source.