Skip to content

build: emit the shared worker host graph once - #204087

Merged
obviyus merged 2 commits into
mainfrom
fix/shared-worker-host-chunks
Nov 23, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/shared-worker-host-chunks

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

The installed package tree shrinks by about 758 files. That brings it back under the 47,500-entry installed package budget. The shared worker host, the state reader and the transcript worker now build as one graph, so their common modules ship once.

Part of #204008.

Problem

#202495 ("run lean core workers in one shared host") added infra/shared-worker-host.worker as a standalone runtime process with its own private chunk graph. The host imports the state reader and the session transcript worker, and those two workers also keep their own private graphs. So the package ships the same modules up to three times:

Chunk directory Files on main
infra/shared-worker-host-* 589
state/openclaw-state-read-* 338
config/sessions/transcript-* 404

Scheduled main CI measured 48,070 installed entries against the 47,500 budget (scripts/check-openclaw-installed-package-budget.mts).

Solution

  • standaloneRuntimeProcessBuildGroups (scripts/lib/runtime-process-core-build-entries.mts) returns one build per standalone entry, but puts the three hosted entries in one build. getStandaloneRuntimeProcessOutputOptions gives the three entries the host's chunk directory.
  • tsdown.config.ts and scripts/lib/vitest-worker-compiler.mts both build from those groups, so the package and the test worker generations use the same layout.
  • Each worker keeps its own entry file and loads only the chunks that its own graph reaches. Rolldown puts a module in a chunk only with modules that the same entries reach.
  • The session transcript worker now bundles @openclaw/fs-safe, as the state reader and the host already do. Inside the lean host it already ran with the bundled copy.

Evidence

  • A build of only the grouped config emits 573 files in infra/shared-worker-host-* and none in the state-read or transcript directories (main: 1,331 across the three).
  • test/scripts/runtime-process-build-graph.test.ts passes, including the private-chunk limit and the "out of the Gateway server graph" checks for all three workers.
  • src/infra/shared-worker-host.test.ts and shared-worker-host.unqualified-close.test.ts pass on a freshly compiled worker generation (the host loads the state reader and transcript modules from the shared directory).
  • Gap: the full installed-tree count is not re-measured locally. 48,070 − 758 ≈ 47,312 is an estimate; the package acceptance budget check measures it.

- Build the shared host, state reader and transcript worker as one group; their common modules ship once (~758 fewer installed files).

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 23, 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 scripts Repository scripts size: S labels Nov 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Build the shared host, state reader, and transcript worker together so their common modules are emitted once.

Example: Packaging the three hosted worker entrypoints.

  • Before: The PR reports 1,331 files across three private chunk graphs.
  • After: The grouped build reportedly emits 573 files while retaining all three entrypoints.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, focused build work with reported boundary coverage, but an incomplete fixture cutover causes confirmed CI failures.
Proof confidence 🦐 gold shrimp (3/6) This build-layout change needs no shipped-entry-point demonstration; the body supplies grouped-build counts and reports graph and compiled-worker tests, while explicitly identifying the full installed-tree total as an estimate.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Duplicated worker modules inflate the installed package and exceed its release safety budget.
Reason: The maintainer-authored direction removes measured duplication using existing build owners without adding configuration or runtime policy.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the build deduplication is useful and remains absent from main, but the chunk-name cutover leaves updater fixtures failing in two CI shards.

Priority: P2
Reviewed head: d773070c89b27857534ffa13745ca0d99ea4f015

Before merge

  • Migrate updater fixtures to the grouped chunk namespace (P2) - Changing the state reader's chunk prefix also changes STANDALONE_CHUNK_PREFIXES in update-compat-chunks.mts. The fixtures in update-compat-external-bindings.test.ts:119 and runtime-postbuild.test.ts:853-858 still emit state/openclaw-state-read-* files, so the updater now scans those synthetic private copies as shared runtime code. Exact-head CI consequently reports an ambiguous export in small shard 13 and three extra-inventory assertions in small shard 10. Update both fixtures and their relative imports to infra/shared-worker-host-* while retaining the exclusion and bridge assertions; restoring the retired production prefix is unnecessary.

Findings

  • [P2] Migrate updater fixtures to the grouped chunk namespace — scripts/lib/runtime-process-core-build-entries.mts:115-117
Agent review details

How this fits together

The runtime-process registry supplies entrypoints and chunk settings to production packaging and the Vitest worker compiler; their outputs are executable worker files and private shared chunks.

flowchart TD
  A[Runtime process registry] --> B[Standalone build groups]
  B --> C[Production package builder]
  B --> D[Vitest worker compiler]
  C --> E[Three stable worker entries]
  D --> F[Compiled test workers]
  E --> G[Shared private chunks]
  F --> G
Loading

Technical review

Best possible solution:

Keep the shared registry grouping and complete the cutover by updating updater fixtures to the new private chunk namespace without weakening their assertions.

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

Current-main source independently builds the overlapping graphs, and exact-head CI annotations confirm the fixture failures caused by their renamed output namespace; this read-only review ran no builds or tests.

Is this the best way to solve the issue?

Grouping the entries at their existing registry owner is a small, coherent solution that preserves stable entrypoints and main-graph isolation, but its updater fixture consumers must migrate with it.

Full review comments:

  • [P2] Migrate updater fixtures to the grouped chunk namespace — scripts/lib/runtime-process-core-build-entries.mts:115-117
    Changing the state reader's chunk prefix also changes STANDALONE_CHUNK_PREFIXES in update-compat-chunks.mts. The fixtures in update-compat-external-bindings.test.ts:119 and runtime-postbuild.test.ts:853-858 still emit state/openclaw-state-read-* files, so the updater now scans those synthetic private copies as shared runtime code. Exact-head CI consequently reports an ambiguous export in small shard 13 and three extra-inventory assertions in small shard 10. Update both fixtures and their relative imports to infra/shared-worker-host-* while retaining the exclusion and bridge assertions; restoring the retired production prefix is unnecessary.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Standalone reader isolation keeps the original intent (0873425: Keep optional state readers lazy and outside shared Gateway runtime chunks.)
  • Transcript worker private graph keeps the original intent (516a142: Reduce retained worker memory by preventing host restoration and unrelated application code from entering the reader graph.)
  • Shared host build graph keeps the original intent (da13d2a: Hosted modules must share code within one lean worker isolate.)
  • Selected Vitest worker compilation keeps the original intent (b29f074: Compile only standalone entries selected by the invocation's inventory.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/scripts/update-compat-external-bindings.test.ts test/scripts/runtime-postbuild.test.ts
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.test.root.tooling.json --incremental
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0873425 adds scripts/lib/runtime-process-core-build-entries.mts:59 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0873425a1ef2; files: scripts/lib/runtime-process-core-build-entries.mts)
  • Vincent Koc: Raw commit 3368967 adds scripts/lib/vitest-worker-compiler.mts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 336896733952; files: scripts/lib/vitest-worker-compiler.mts)

PR surface

Other +20. Total +20 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 48 28 +20
Total 3 48 28 +20

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The PR reduces packaging duplication and budget pressure, with a focused fixture repair needed before merging.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The PR reduces packaging duplication and budget pressure, with a focused fixture repair needed before merging.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 23, 2026, 9:09 AM ET / 14:09 UTC.

@obviyus
obviyus merged commit d38fed5 into main Nov 23, 2026
110 checks passed
@obviyus
obviyus deleted the fix/shared-worker-host-chunks branch November 23, 2026 14:28
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
The installed package tree shrinks by about 758 files. That brings it back under the 47,500-entry installed package budget. The shared worker host, the state reader and the transcript worker now build as one graph, so their common modules ship once.

Part of openclaw#204008.

## Problem

openclaw#202495 ("run lean core workers in one shared host") added `infra/shared-worker-host.worker` as a standalone runtime process with its own private chunk graph. The host imports the state reader and the session transcript worker, and those two workers also keep their own private graphs. So the package ships the same modules up to three times:

| Chunk directory | Files on `main` |
|---|---|
| `infra/shared-worker-host-*` | 589 |
| `state/openclaw-state-read-*` | 338 |
| `config/sessions/transcript-*` | 404 |

Scheduled `main` CI measured 48,070 installed entries against the 47,500 budget (`scripts/check-openclaw-installed-package-budget.mts`).

## Solution

- `standaloneRuntimeProcessBuildGroups` (`scripts/lib/runtime-process-core-build-entries.mts`) returns one build per standalone entry, but puts the three hosted entries in one build. `getStandaloneRuntimeProcessOutputOptions` gives the three entries the host's chunk directory.
- `tsdown.config.ts` and `scripts/lib/vitest-worker-compiler.mts` both build from those groups, so the package and the test worker generations use the same layout.
- Each worker keeps its own entry file and loads only the chunks that its own graph reaches. Rolldown puts a module in a chunk only with modules that the same entries reach.
- The session transcript worker now bundles `@openclaw/fs-safe`, as the state reader and the host already do. Inside the lean host it already ran with the bundled copy.

## Evidence

- A build of only the grouped config emits 573 files in `infra/shared-worker-host-*` and none in the state-read or transcript directories (main: 1,331 across the three).
- `test/scripts/runtime-process-build-graph.test.ts` passes, including the private-chunk limit and the "out of the Gateway server graph" checks for all three workers.
- `src/infra/shared-worker-host.test.ts` and `shared-worker-host.unqualified-close.test.ts` pass on a freshly compiled worker generation (the host loads the state reader and transcript modules from the shared directory).
- Gap: the full installed-tree count is not re-measured locally. 48,070 − 758 ≈ 47,312 is an estimate; the package acceptance budget check measures it.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant