Repository navigation
perf(nodes): load only what a worker turn needs - #160442
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 October 2, 2026, 4:33 PM ET / 20:33 UTC (Revision 103). ClawSweeper reviewWhat this changesThe PR splits node-worker code into verified runtime chunks and loads turn-specific code after admission, with matching installation, import-boundary, and test updates. Merge readiness✅ Ready for maintainer review The optimization remains useful on current main. The pinned patch has no actionable correctness or security findings, and its recorded production comparison supports the performance benefit. Priority: P2 Review scores
Verification
How this fits togetherNode workers execute agent turns assigned by the Gateway. Their deployment artifact supplies the runtime, while Gateway admission supplies the current tool policy and execution context. flowchart TD
A[Worker build] --> B[Sealed runtime chunks]
B --> C[Verified node installation]
C --> D[Worker admission]
E[Gateway assignment and tool policy] --> D
D --> F[Load turn runtime]
F --> G[Agent replies and tool results]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -50, Tests -8, Docs +2, Other +48. Total -8 across 68 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Preserve the existing admission, artifact-integrity, and cleanup owners while keeping optional runtime loading off cold worker startup. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance optimization, supported by a controlled comparison through real cold-worker admission and retained turns. Is this the best way to solve the issue? Yes. The patch reuses the existing artifact and lifecycle owners, preserves public exports, and removes superseded loading shims rather than introducing another runtime manager. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5e6982748add. 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 (102 earlier review cycles; latest 8 shown)
|
992d7f3 to
ff4b5e2
Compare
ff4b5e2 to
cc358d2
Compare
|
@clawsweeper re-review Updated head f8c852f8aad05d3e5c247cf400d1390a44fa8f15 incorporates the four verified main repairs and resolves the worker-registry integration. The PR body records fresh complete type lanes, focused/worker suites, full runtime build, import-cycle/sidecar checks, clean final-branch P2 review, and successful retained-node text and tool turns. Current-head CI is running. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Head 1fbd003b4dcb9b4f3eb24d8bb88d71ea9f59b1c6 incorporates the verified main watcher repair e20a820 and preserves the newer Doctor/profile contracts. Fresh type lanes, focused and worker suites, full runtime build, cycle/sidecar checks, full-candidate P2 review, and retained-node text/tool proof pass. The PR body retains the previous-head CI investigations and their uncertainty. Current-head CI is running. |
|
🦞👀 Re-review progress:
|
Preserve and hash every emitted worker chunk in the v1 bundle manifest, including SSH and node installs. Load the turn runtime after admission and retain explicit prewarming. Keep only import-boundary repairs required by splitting, the session type-cycle repair, and lazy MCP OAuth loading.
Move internal raw-target closing into a private lazy runtime so empty cleanup does not load the browser client. Revalidate the selected registration after loading, and preserve cleanup reservation coverage.
|
Merged via squash.
|
|
Follow-up from the native landing of #156307: The complete remote build passed (408.2s), as did production, scripts and root-test type checks, but core lint failed on two current-main files:
Remote run: https://github.com/openclaw/openclaw/actions/runs/37074972322 . It ended exit 1; full tests were not reached, no native gate stamp was produced, and the owned remote lease is completed. Both files and lint configuration are unchanged between the waveform candidate and its main base @steipete could the existing worker-bootstrap owner take the scoped line-cap repair? No limit/baseline relaxation is requested. The portfolio is retaining completed scoped proof and holding further full-gate attempts against these known failing inputs rather than opening a duplicate known-main test/CI PR. |
Landed
Merged through the native maintainer workflow as 4aa24e3a1340 on main.
Refreshed candidate:
d0ab325a9aa39de0d4ce32093833aab32e492651, rebased onto main49135a709150d4b9760146a795bb841d4e2e0e64. The seven PR commits remain patch-identical to the reviewed candidatea68e5db402bf37cb44f2dc1cf9535be34e275e77. ClawSweeper completed its exact-head review at 2026-10-02T19:47:22.911Z with no actionable findings. Exact-head CI run 37055559008 completed successfully on attempt 2 after the single authorized failed-job rerun described below. The PR is merged, and native closeout completed.All three inherited fixture failures from CI run 37041147256 were fixed separately on main in 49135a709150:
session-accessor.identity-projection.test.ts,startup-migration.registry-recovery.test.ts, anddoctor-auth-flat-profiles.test.ts. Their synchronous fixture closes returned before worker-backed database resources had drained. The fixtures now await the existing lifecycle owner before reopening, copying, or directly editing the database; every assertion and the production admission guard remain unchanged.Boundary bisection on one AWS Linux lease identified
d6929f854d2e9: its parent passed all 97 tests, while that commit and unpatched mainc8be3222c262freproduced the five session and two Doctor failures. Each repaired file then passed three repetitions (291 test executions). The original CI owner groups passed 49 files / 632 tests, with one existing benchmark skipped, in 174 s, 150 s, and 62 s. Lease formatting and source-byte verification passed; independent autoreview was scoped-clean at P0. The repair was verified on main and its lease released.The build, typecheck, focused, browser, and live evidence below was captured for the reviewed rewrite before this patch-identical rebase. The refreshed candidate has completed CI and an exact-head ClawSweeper review. The previous database-fixture landing hold is resolved; no main repair was added to this PR's delta.
Fresh CI: one inherited fixture flake, one failed-job rerun
The first exact-head CI run 37055559008 completed with one test-job failure: checks-node-changed-compact-small-8. In
session-accessor.sqlite-metadata-read.test.ts, the native-handle isolation case expected{observedAt: 10, updatedAt: 20}and received{observedAt: 20, updatedAt: 20}. The other cases in that group, including the repaired startup-registry cases, passed; the Doctor group passed as well.Source attribution identifies an existing maintenance race in the fixture. It creates entries with
updatedAt: 1under default enforced 30-day retention, overwrites the transcript fences directly, then awaits another fixture. Automatic stale-entry archival callswriteSessionEntry, which intentionally snapshots the currenttranscript_updated_atintotranscript_observed_at; that is the exact10to20transition. The PR changes none of this fixture, its metadata reader, timestamp writer, maintenance scheduler/store, or retention defaults. Import timing does not make the fixture's unprotected snapshot stable.On unchanged main
4e529baa8f6dc431fd93f8591859a022d29858fb, the full five-case file passed once and the exact failing case passed three further runs. The same original CI group had also passed on Linux during the main-fixture repair proof. These passes do not prove a fix; the source ownership and asynchronous write path identify the intermittent fixture issue. No merged correction exists through main0ef5c30120312cb5ea33fc24a6d4686d6b357971in the relevant owners. No additional main file was changed. Per the bounded landing instruction's proven-unrelated-flake exception, only the failed jobs were rerun once. Attempt 2 completed successfully, including the CI-gate job. This did not repair the fixture race; the original failure and limitation remain recorded here.What Problem This Solves
Cold node workers evaluate optional runtime code before admission, delaying startup and retaining memory that a lightweight turn does not need.
User Impact
Cold worker admission is faster and lightweight retained workers use less memory. In the controlled Linux comparison below, spawn-to-hello fell from 744 ms to 209 ms, and peak RSS after three text turns fell from 426.2 MiB to 243.6 MiB. Warm worker retention is already on main; this change complements it. No operator configuration change is required.
Why This Change Was Made
Split the worker deployment bundle while preserving every emitted chunk in the existing
openclaw-worker-bundle-v1manifest. The build validates every chunk's dependency closure, and Gateway, node, and SSH/npm installation paths hash and verify the same complete artifact. Heavy turn imports begin after accepted admission; explicit prewarming uses the same loader. Remaining production edits are the import-boundary repairs needed by that split build and the lazy MCP OAuth repair.This replaces the sprawling earlier iteration: repeated rebases had accumulated unrelated main repairs and LOC-offset cleanup, making review and integration fragile. The new delta is 51 production files, +321/−323 lines, net −2; 68 files total including tests and documentation. These counts include mechanical import/path updates. No unrelated main repairs or cleanup are included.
The requested backup is a7a19ed344fb, retained locally as
codex/node-parity-l1-sprawl-backup-20261002. That backup object is currently local-only and its GitHub link does not resolve. The previous published head b72ae3174fc0 remains the public reference for the dropped implementation.Evidence
Fresh live comparison: unpatched main
a324281c67173594b56acad3322c9cd1e35b2131versus candidatea68e5db402bf37cb44f2dc1cf9535be34e275e77, on the same AWS Linux lease. Production proof used the exact committed patch; timing markers were applied only inside the lease afterward. The lease-only instrumentation was updated for main's node-launch module move.Same AWS Linux machine and provider configuration, with one cold worker followed by two turns on that retained worker:
Both versions returned all six exact local/node text replies. Two successive turns on one node worker used
execandread, preserved the written file across turns, and settled successfully. These are single controlled observations in Linux process mode, not an end-to-end latency-parity claim.qaRuntimebuild and complete worker-artifact validation passed on the rebased candidate (51.3 s). Both import-cycle checks report zero cycles; sidecar-loader checks pass.1/1stripe with four compiler processes (109.7 s).git diff --checkpassed for that published rewrite.The initial focused run caught obsolete single-file tsdown fixture assumptions. Fixtures now exercise split chunks under the sealed worker directory and distinguish Node built-ins from package dependencies. A separate inherited main type error was reproduced on unpatched main, then resolved by upstream
90897637d32e; that repair is in the base. Main's new maintenance types also exposed a cycle under the required static import boundary; moving those unchanged DTOs into the existing hydration type owner removed it. No exception or baseline was weakened.Production scope and deletion inventory
Resolve the browser static/dynamic import conflicts required by the split build while preserving lazy cleanup (6 files):
extensions/browser/src/browser-tool.ts,extensions/browser/src/browser/client.ts,extensions/browser/src/browser/client-tab-close.runtime.ts,extensions/browser/src/browser/session-tab-registry.ts,extensions/browser/src/gateway/browser-request-tab-scope.ts,extensions/browser/src/gateway/browser-request.ts.Emit, validate, seal, stage, and install every worker chunk (6 files):
scripts/check-cli-bootstrap-imports.mts,scripts/lib/worker-deploy-build-plugin.mts,src/gateway/worker-environments/bootstrap.ts,src/gateway/worker-environments/bundle-staging.ts,src/shared/worker-bundle-hash.ts,tsdown.config.ts.Move bootstrap/model helpers and update callers of moved helpers and types (12 files):
src/agents/bootstrap-files.ts,src/agents/defaults.ts,src/agents/embedded-agent-helpers/bootstrap.ts,src/agents/embedded-agent-runner/run/attempt-bootstrap-prepare.ts,src/agents/embedded-agent-runner/run/model-setup.ts,src/agents/embedded-agent-runner/run/setup.ts,src/agents/harness/workspace-context.ts,src/agents/sessions/session-manager-core.ts,src/agents/sessions/session-manager-suffix-persistence.ts,src/agents/sessions/session-manager-view-types.ts,src/plugin-sdk/agent-harness-runtime.ts,src/worker/embedded-agent.runtime.ts.Keep the MCP OAuth runtime behind the authenticated fetch path (1 file):
src/agents/mcp-oauth-fetch.ts.Load highlighting from a sealed chunk and remove the superseded injection shims (5 files):
src/agents/utils/syntax-highlight.ts,src/worker/worker-deploy-highlight-runtime.cjs,src/worker/worker-deploy-highlight-runtime.d.cts,src/worker/worker-deploy-runtime-registry.ts,src/worker/worker-deploy-runtime.ts.Resolve session-worker import conflicts and keep read contracts independent of runtime readers (17 files):
src/config/sessions/session-accessor.sqlite-active-context.ts,src/config/sessions/session-accessor.sqlite-archive.ts,src/config/sessions/session-accessor.sqlite-artifact-cleanup.ts,src/config/sessions/session-accessor.sqlite-contract.ts,src/config/sessions/session-accessor.sqlite-entry.ts,src/config/sessions/session-accessor.sqlite-exact-read.ts,src/config/sessions/session-accessor.sqlite-history.ts,src/config/sessions/session-accessor.sqlite-lifecycle-state.ts,src/config/sessions/session-accessor.sqlite-page-reclamation.ts,src/config/sessions/session-history-eviction.ts,src/config/sessions/session-transcript-hydration.ts,src/config/sessions/session-transcript-hydration.types.ts,src/config/sessions/session-transcript-maintenance-read.ts,src/config/sessions/session-transcript-reconcile.ts,src/config/sessions/session-transcript-worker-runtime.ts,src/config/sessions/session-transcript-worker.types.ts,src/config/sessions/session-transcript.worker.ts.Admit before loading the turn runtime; remove the superseded admission-preparation callback (4 files):
src/worker/worker-connection-admission.ts,src/worker/worker-connection-contract.ts,src/worker/worker-deploy-entry.ts,src/worker/worker.runtime.ts.Deleted superseded files:
src/worker/worker-deploy-highlight-runtime.cjssrc/worker/worker-deploy-highlight-runtime.d.ctssrc/worker/worker-deploy-runtime-registry.tsThe old admission-preparation callback and its obsolete tests are also removed. Moved helper/type definitions have one owner and their callers move with them.
Changed-test cost
Measured through
pnpm test <selected files> --maxWorkers=1. Values are Vitest file time where emitted, otherwise the sum of reported case times; they exclude shared transform/setup time. The initial mixed selection took 106.2 s including the subsequently corrected fixture failure; the successful six-file completion run took 58.0 s. Hosted CI seconds will be recorded when the exact-head run finishes.src/worker/worker-connection.test.tssrc/worker/worker-deploy-entry.test.tssrc/worker/worker.runtime-imports.test.tstest/scripts/tsdown-config.test.tstest/scripts/worker-deploy-build-plugin.test.tstest/scripts/check-cli-bootstrap-imports.test.tssrc/gateway/worker-environments/bootstrap.test.tssrc/gateway/worker-environments/bundle.test.tssrc/config/sessions/session-transcript-reconcile.readiness.test.tssrc/agents/mcp-http-fetch.test.tsextensions/browser/src/browser/session-tab-registry.test.tsextensions/browser/src/browser/client.test.tsextensions/browser/browser-maintenance.cold.test.tsThe existing 53.8 s worker-deploy integration file compiles the real dependency closure and executes relocated, dependency-free artifacts, including SQLite-backed exec authorization. A mocked helper cannot establish that bundle/install contract. No new sleep, retry, serial configuration, or persistent worker pin was added.