Skip to content

improve: defer database feature loading until first use - #152071

Merged
steipete merged 1 commit into
mainfrom
codex/gateway-shared-worker-command-preparation
Sep 19, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/gateway-shared-worker-command-preparation

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A plugin-metadata read loads shared-state handlers for unrelated features. This also affects metadata-only commands such as local openclaw gateway status --no-probe --json with ordinary config and an existing state database.

User Impact

Metadata reads and idle checks can run without loading those handlers. The plain, non-deep status path can finish without requesting the feature runtime. The first command that needs it still pays the deferred import cost. This does not establish a measured status-command speedup. No configuration, schema, durability, retention, or public API changes are required.

Why This Change Was Made

Keep a small shared-state worker entry point and prepare feature code before dispatch. Main's existing worker lifecycle owner holds acquisition and cleanup; module preparation runs inside its release scope. Operations and transaction settlement remain synchronous. FIFO ordering, cancellation, shutdown, current-authority checks, and completed outcomes remain with the existing owners. The production diff adds 66 net lines, including the private preparation contract and entry/runtime split.

Evidence

The PR branch is based on 834f44910010744313f65d4fc86e4909b2c023ab. Fresh independent P2 review passed all seven batches with source integrity verified. The configured F8 Testbox run passed 64 tests across six lifecycle/auth files, formatting and diff checks. Its negative control reproduced the intended coordinator-contention failure when module preparation escaped the release scope, and restored candidate bytes before GREEN. Source, index, dependencies, returned artifacts and joined worker/lease closure were verified. This focused continuation did not repeat a build, compiled graph or full static checks. Added real-broker cases cover rejected preparation releasing lifecycle custody before actor close, cancellation/close during preparation, and original-error preservation through native cleanup failure.

On the producer merge checkout 343db2eca8f7f7f6ac028032957735f9694abffc for PR head 5eaa029b43664e1f8707a017c122a8d7ea5c5323, the original hosted CI run recorded 213 passing cases across 21 relevant auth, worker, coordinator, lease, and runtime-config test files on Linux / Node 24.19.0, with no skips in those target files. This was verified from actual case output in 17 job logs, with shard totals and exit-zero completion checked. The coordinator-delegate file was scheduled twice: its four passing cases are verified in the unit-fast group and counted once; the other scheduled infra placement has no execution evidence. Other files in these jobs have skips.

The Package Acceptance run validated the package from that same 343db2e source checkout using maintained tooling 10b13070c4afb9f4c5ecefab01212ef5511246d3. The npm onboarding/channel/agent lane passed, as did the published [email protected] updater → candidate 2026.9.5 base scenario. The latter used updater installation with manual restart, reported a successful update, and captured the first post-core child exiting 0. Package/source binding and returned onboarding and upgrade-survivor artifacts were verified. These results establish the selected installation and upgrade flows, not startup latency or other upgrade scenarios.

The static import graph of that exact accepted package also passed: metadata remains available in the initial worker graph, while one dynamically imported dispatcher and 144 exclusive chunks (1,283,965 bytes) stay outside it. The audit parsed the packaged modules without executing them; it establishes the packaged lazy boundary, not a latency improvement.

Historical evidence for the preceding candidate, retained separately:

  • Exact 144adb922ad38284b2f30aecd432156866f421f1 candidate passed 114 tests across 14 affected files plus full build, formatting, and diff checks in the configured Testbox run. Its seven-batch independent P2 review passed. These results do not prove the new lifecycle integration on 834.
  • The compiled graph confirmed deferred feature loading. A same-guest compiled ABBA screen, with two fresh-state samples per arm after warmup, measured readiness at 3,092 ms before and 3,104 ms after on Linux / Node 24.19.0. This does not establish an overall startup improvement: plugin planning fell from 206 to 121 ms, while early task-state initialization rose from 5 to 98 ms. The cost appears to move to first domain use. Both builds and all six launches passed. Installed and representative startup performance remain unmeasured.

The single Windows rerun passed on the same 343db2e checkout with the original 81-file test command. It recorded 1,261 passing cases and 359 skips. The maintained Node 24.x selector resolved to Node 24.20.0 for this attempt, versus 24.19.0 in the original failed run. The original watcher timeout remains unexplained; this is not an identical-runtime reproduction or a confirmed flake fix. Required-check verification and native merge gates still apply. Installed startup performance remains unqualified.

@steipete
steipete marked this pull request as ready for review September 18, 2026 18:55
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Sep 18, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 19, 2026, 8:33 AM ET / 12:33 UTC (Revision 9).

ClawSweeper review

What this changes

Defers shared database feature handlers until their first command, allowing plugin metadata reads and idle checks to use a smaller worker entry point.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/infra/sqlite-store.worker.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

The PR remains useful and has no identified blocking defect. The previous migration-proof blocker does not apply: the patch preserves stored formats and transaction semantics, and the supplied evidence covers selected fresh-install and published-updater flows.

Priority: P2
Reviewed head: 5eaa029b43664e1f8707a017c122a8d7ea5c5323

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused loading refactor with meaningful lifecycle coverage and no identified correctness or compatibility blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this internal refactor from the external-contributor proof gate, and no material authority change activates an exception. The captured evidence connects worker preparation to packaged first-use and upgrade flows; successful job metadata was verified, while detailed artifact logs were inaccessible.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this internal refactor from the external-contributor proof gate, and no material authority change activates an exception. The captured evidence connects worker preparation to packaged first-use and upgrade flows; successful job metadata was verified, while detailed artifact logs were inaccessible.
Evidence reviewed 8 items Introduced change and preserved dispatcher: Compared the pinned merge-base worker against the extracted runtime. Feature dispatch, queries, mutation kernels, and transaction checks are preserved; metadata and idle inspection remain in the entry module. The verified test-merge parents match the supplied base and head.
Preparation remains inside lifecycle cleanup: The asynchronous preparation hook runs inside the coordinator release scope, before synchronous execution and settlement. Existing transaction/commit admission remains in the execution path; preparation receives no actor-scoped reader or authorization context.
Private contract and meaningful regression coverage: The preparation symbol extends an internal backend type; the SDK still exports the original synchronous backend contract. Eight new parameterized preparation cases cover FIFO, framed input, cancellation, shutdown, revoked admission, rejected preparation, and cleanup failure, with persisted-state checks.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared-state worker receives database commands from application features through a serialized broker. This change separates lightweight inspection from feature loading while retaining the existing database, execution, and cleanup owners.

flowchart TD
  A[Application database commands] --> B[Serialized worker broker]
  B --> C{Metadata or idle inspection?}
  C -->|Yes| D[Lightweight worker entry]
  C -->|No| E[Load feature dispatcher once]
  E --> F[Synchronous database operation]
  D --> G[Result and lifecycle cleanup]
  F --> G
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +66, Tests +493. Total +559 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 665 599 +66
Tests 7 507 14 +493
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 1172 613 +559

Review metrics

Metric Value Why it matters
Production versus test growth Production +66 net lines; tests and test support +493 net lines Production growth supports the private preparation hook and entry/runtime split; most added coverage exercises lifecycle and failure invariants.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/infra/sqlite-store.worker.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep metadata inspection lightweight and load the existing feature dispatcher on demand, preserving synchronous mutations and the established lifecycle owner.

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

Not applicable as a correctness-bug reproduction: this is an internal loading improvement. Current-main static imports establish the eager-loading mechanism; no startup-speed improvement was independently measured.

Is this the best way to solve the issue?

Yes. The patch reuses the existing lazy-loader and dispatcher, keeping database ownership and synchronous transaction boundaries intact without adding configuration or a public API.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b39f188eae55.

Labels

Label justifications:

  • P2: This is a bounded database-loading improvement without evidence of an urgent user-facing outage.
  • 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: The supplied MEMBER association exempts this internal refactor from the external-contributor proof gate, and no material authority change activates an exception. The captured evidence connects worker preparation to packaged first-use and upgrade flows; successful job metadata was verified, while detailed artifact logs were inaccessible.

Evidence

What I checked:

  • Introduced change and preserved dispatcher: Compared the pinned merge-base worker against the extracted runtime. Feature dispatch, queries, mutation kernels, and transaction checks are preserved; metadata and idle inspection remain in the entry module. The verified test-merge parents match the supplied base and head. (src/state/openclaw-state-worker-runtime.ts:115, 5eaa029b4366)
  • Preparation remains inside lifecycle cleanup: The asynchronous preparation hook runs inside the coordinator release scope, before synchronous execution and settlement. Existing transaction/commit admission remains in the execution path; preparation receives no actor-scoped reader or authorization context. (src/infra/sqlite-store.worker.ts:251, 5eaa029b4366)
  • Private contract and meaningful regression coverage: The preparation symbol extends an internal backend type; the SDK still exports the original synchronous backend contract. Eight new parameterized preparation cases cover FIFO, framed input, cancellation, shutdown, revoked admission, rejected preparation, and cleanup failure, with persisted-state checks. (src/infra/sqlite-worker-preparation.test.ts:57, 5eaa029b4366)
  • Previous storage blocker reassessed: The storage review checkpoint distinguishes internal lifecycle mechanics from changes to schemas, public contracts, durability, retention, or permissions. This patch changes code loading without introducing a stored-data migration or a competing storage owner. Public docs: docs/reference/database-schemas/storage-changes.md. (docs/reference/database-schemas/storage-changes.md:1002, 5eaa029b4366)
  • Still necessary on main and latest release: The fetched main worker still statically imports the feature handlers, and the relevant production files have no changes from the pinned merge base to fetched main. GitHub source inspection of v2026.9.5 likewise shows eager feature imports. No verified replacement fixing PR was established. (src/state/openclaw-state.worker.ts:1, ec9c1a13db89)
  • Package acceptance and evidence boundaries: The captured PR body binds Package Acceptance to test merge 343db2e and describes successful npm onboarding/channel/agent and published 2026.9.3 updater-to-candidate flows. GitHub independently reports both selected jobs successful in https://github.com/openclaw/openclaw/actions/runs/35438695674. Detailed log access redirected to a blocked artifact host, so those transcripts were not independently reread. The supplied graph audit supports deferred loading, not a latency improvement. (343db2eca8f7)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (8 earlier review cycles)
  • reviewed 2026-09-18T19:03:29.684Z sha 70fdc4b :: blocked before merge. :: none
  • reviewed 2026-09-18T19:58:15.464Z sha a83348a :: blocked before merge. :: none
  • reviewed 2026-09-18T21:24:35.392Z sha 29751d0 :: blocked before merge. :: none
  • reviewed 2026-09-18T21:54:03.742Z sha 29751d0 :: blocked before merge. :: none
  • reviewed 2026-09-18T22:41:00.511Z sha 7f05134 :: blocked before merge. :: none
  • reviewed 2026-09-18T23:27:22.082Z sha 7f05134 :: blocked before merge. :: none
  • reviewed 2026-09-19T10:06:05.736Z sha 5eaa029 :: blocked before merge. :: none
  • reviewed 2026-09-19T12:24:26.997Z sha 5eaa029 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 18, 2026
@steipete
steipete force-pushed the codex/gateway-shared-worker-command-preparation branch from a83348a to 29751d0 Compare September 18, 2026 20:55
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 18, 2026
@steipete
steipete force-pushed the codex/gateway-shared-worker-command-preparation branch from 29751d0 to 7f05134 Compare September 18, 2026 22:29
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final-head CI, canonical Package Acceptance, published-driver upgrade/serving, canonical emitted worker graph, and Windows first use now pass and are linked in the updated body. All nine Windows boots and 18 internal turns passed with clean shutdown. Root independently verified focused terminal logs and all ten source-proof archive members; the artifact-host restriction is a reviewer access limitation. The SQLite table warning is inapplicable: sqlite-store.worker.ts adds a private code-preparation hook, with no DDL or data-model change, and current actor/transaction authority and settlement remain intact. Fresh-state internal turns and upgrade activation/serving remain explicitly separate. No current-head latency claim is made.

@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 18, 2026
@steipete
steipete force-pushed the codex/gateway-shared-worker-command-preparation branch from 7f05134 to 5eaa029 Compare September 19, 2026 09:56
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 19, 2026
@steipete
steipete merged commit 43e41b2 into main Sep 19, 2026
387 of 391 checks passed
@steipete
steipete deleted the codex/gateway-shared-worker-command-preparation branch September 19, 2026 12:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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