Skip to content

refactor(state): register worker operations once per domain - #162446

Merged
steipete merged 2 commits into
mainfrom
dbasync/registry
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/registry

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 220 existing tests passed across 16 unchanged files, covering all four domains, worktree retirement/recovery and leases, shared-state preparation, and Gateway Web Push storage scope (179.07 s total wrapper wall time).
  • The new registry test proves that preparation loads only APNs, shares concurrent preparation, leaves unrelated domains unloaded, routes the exact handler and context, and rejects unknown/inherited operation names. 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.
  • Operation-name parity against the pinned base: all 35 names preserved across the four domains, with no additions or omissions.
  • Gateway import-graph proof: findSourceImportBackedges from src/infra/push-web-store.ts reports 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.
  • Full pnpm build passed (17m 24.6s, including all runtime/SDK declarations and UI). node scripts/check-changed.mjs --base c9e66c126df9b48d8b145c6da06569df3bdd14e1 passed: 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-standard SAFETY: marker on two dispatch-correlation comments; those annotations were added and the complete check passed.
  • Codex autoreview is scoped-clean through P2 on both the working candidate and committed branch 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 c7508c3e44c1c845cdec76b0c12f9ea96d640b45 separates 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.ts now 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-fast passed. 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 run 36820391530 independently fails the same core lint diagnostics. The canary line-limit diagnostic retains its separate reproduction from main source.

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.
@clawsweeper

clawsweeper Bot commented Oct 1, 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 agents Agent runtime and tooling fleet size: L labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 2:52 AM ET / 06:52 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: c7508c3e44c1c845cdec76b0c12f9ea96d640b45

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable refactor with preserved store behavior, reported validation, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-admin authorship exempts this internal dispatch refactor from external-contributor runtime proof. Reported tests and build checks are supplemental validation; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts this internal dispatch refactor from external-contributor runtime proof. Reported tests and build checks are supplemental validation; no stored-data contract changes require migration proof.
Evidence reviewed 9 items Pinned introduction reviewed: Reviewed the merge-base-to-head delta across all introduced paths. Domain handlers retain the existing kernel calls, command names, transaction wrappers, binding-error result, and read-only VAPID path.
Preparation and execution boundary: The production SQLite worker awaits command preparation before executing inside actor context. The registry loads handlers without opening a database; existing handlers retain database opening and transaction admission responsibilities. This changes dispatch organization without materially transferring authority.
Current-main necessity: Fetched main still imports the fleet dispatcher and Web Push command guard rather than the new domain registry. The latest release tree also has no worker-operation-registry module; no implemented-on-main closure is established.
Findings None None.
Security None None.

How this fits together

OpenClaw'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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -125, Tests +55. Total -70 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 18 371 496 -125
Tests 1 55 0 +55
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 426 496 -70

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal dispatch cleanup with preserved operation behavior and no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts this internal dispatch refactor from external-contributor runtime proof. Reported tests and build checks are supplemental validation; no stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduction reviewed: Reviewed the merge-base-to-head delta across all introduced paths. Domain handlers retain the existing kernel calls, command names, transaction wrappers, binding-error result, and read-only VAPID path. (src/state/openclaw-state-worker-registry.ts:12, c7508c3e44c1)
  • Preparation and execution boundary: The production SQLite worker awaits command preparation before executing inside actor context. The registry loads handlers without opening a database; existing handlers retain database opening and transaction admission responsibilities. This changes dispatch organization without materially transferring authority. (src/infra/sqlite-store.worker.ts:175, c7508c3e44c1)
  • Current-main necessity: Fetched main still imports the fleet dispatcher and Web Push command guard rather than the new domain registry. The latest release tree also has no worker-operation-registry module; no implemented-on-main closure is established. (src/state/openclaw-state-worker-runtime.ts:44, 10cf91f150e2)
  • Latest-release inspection: The new generic registry path is absent from the supplied latest release tag. (src/state/worker-operation-registry.ts, c074824a27c9)
  • Verified author permission: The live pull endpoint reports CONTRIBUTOR, differing from the supplied MEMBER association. The repository permission endpoint independently confirms steipete has admin permission, supporting trusted-author treatment and the cleanup exemption.
  • Relevant merged history: The APNs cleanup comparison was added in this merged-history commit and remains at line 32 of the reviewed checkout. Raw commit records identify its parent; inspection of the parent source confirms the comparison function was absent there. GitHub commit metadata maps the author to steipete. (src/infra/push-apns-store.worker.ts:32, 8225a328990b)

Likely related people:

  • Peter Steinberger: Raw commit 8225a32 adds src/infra/push-apns-store.worker.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8225a328990b; files: src/infra/push-apns-store.worker.ts)

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 (3 earlier review cycles)
  • reviewed 2026-10-01T05:55:33.687Z sha e2e4a34 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T06:12:31.048Z sha e2e4a34 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T06:35:36.247Z sha c7508c3 :: needs maintainer review before merge. :: none

@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 3f7689e into main Oct 1, 2026
111 of 211 checks passed
@steipete
steipete deleted the dbasync/registry branch October 1, 2026 07:23
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling fleet P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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