Skip to content

refactor(hosts): run the host update worker as one Bun bundle - #31

Merged
andrebrait merged 3 commits into
mainfrom
host-worker-bundle
Nov 26, 2026
Merged

andrebrait merged 3 commits into
mainfrom
host-worker-bundle

Conversation

@andrebrait

@andrebrait andrebrait commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #23.

The daemon no longer copies the host update worker's sources. Before, copyHostWorkerSources copied update-worker.ts and every module it imports into the attempt directory as rewritten .mts files, and workerRuntime chose at runtime which copy of the lifecycle modules to load. Every tau process runs on Bun now, so:

  • One bundle: buildHostUpdateWorker (lib/hosts/updates.ts) builds one self-contained <attempt>/worker.mjs with Bun.build({ target: "bun" }), mode 0600. This is how self-update.ts already builds the server worker. It imports only builtins, which a test checks. A compiled binary still runs its own copy as host-update-worker and never builds.
  • Static imports: the worker calls upgrade-process and process-identity directly. The runtime module choice, the RUNTIME object and its parameters are gone.
  • Build errors: both workers build with throw: false, so a build failure names its cause instead of Bun's bare "Bundle failed".
  • Pruning: finished attempts drop worker.mjs with the copied runtime.
  • Tests: a test that swapped a lifecycle module beside the copy now swaps it inside the bundle through a build plugin. The plugin reaches the same imports the .mts trick did, including upgrade-process's own ./process-identity.

Review

Review round 1 (full): adversarial

Scope: 09c36b6..439cb6c (whole change). Tool: adversarial-review.

# Severity Location Finding Verdict
1 Low lib/hosts/updates.ts:286 Bun.build throws AggregateError("Bundle failed") by default, so the branch that formats the build logs never runs (also self-update.ts:413). Fixed in d952223: throw: false in both (test: a worker that cannot be bundled fails with the bundler's reason; red without the fix)
2 Low lib/hosts/update-worker.test.mjs:1121 The health-window test passes even if its stand-in never runs. Fixed in d952223: the stand-in writes a marker the test asserts
3 Low lib/hosts/update-worker.test.mjs:1006 No test needs the process-identity stand-in to reach upgrade-process's own import. Rejected: it was already so with the .mts copies; the plugin does reach that import (probe), and only the worker's calls drive these scenarios
4 Low lib/hosts/updates.ts:285 The bundle is built from the on-disk source at launch, so a package replaced without a daemon restart gives new worker code. Rejected: the old copy read the same files at the same moment; not changed here
5 Nit lib/hosts/update-worker.ts:62 RUNTIME, WorkerRuntime and the runtime parameters are leftover indirection. Fixed in d952223
6 Nit lib/hosts/update-worker.test.mjs:731 The import scan would miss an absolute install path baked into the bundle. Fixed in d952223 and e1efa43 (native path and file: URL)

Not checked: Windows and macOS; a real npm-installed package end to end; Bun versions other than 1.4.4.

Review round 1 (full): code review

Scope: 09c36b6..439cb6c (whole change). Tool: /code-review.

# Severity Location Finding Verdict
1 Nit lib/hosts/updates.ts:286 A bundle failure reports only "Bundle failed". Fixed in d952223 (same as adversarial 1)
2 Pre-existing lib/self-update.ts:414 The server worker's build has the same dead check. Fixed in d952223
3 Nit lib/hosts/update-worker.ts:675 Pruning no longer removes .mts copies an older daemon left in a retained attempt. Rejected: tau is pre-alpha with no compatibility promise, and such an attempt is removed whole once a newer one replaces it as the latest
4 Nit lib/hosts/updates.ts:289 The bundle is written with the default mode, then set to 0600. Rejected: the attempt directory is freshly created 0700 (fails on EEXIST), and nothing checks the bundle's mode
5 Nit lib/hosts/update-worker.test.mjs:731 The builtin check misses require("x"). Fixed in d952223 and e1efa43 (__require too)

Not checked: Windows.

Review round 1 (full): simplification

Scope: 09c36b6..439cb6c (whole change). Tool: code-simplification.

# Severity Location Finding Verdict
1 Nit lib/hosts/update-worker.ts:12 Call the lifecycle functions by name instead of through RUNTIME and three runtime parameters. Fixed in d952223
2 Nit lib/hosts/updates.ts:281 buildHostUpdateWorker as written (the plugins test seam, the chmod). No change: neither is speculative
3 Nit lib/self-update.ts:413 Share the build with the server worker? Rejected: one call each, with different entries, messages and modes
4 Nit lib/hosts/update-worker.ts:675 One anchor pair in the prune pattern. Fixed in d952223

Review round 2 (light): code review

Scope: 439cb6c..d952223 (since the last reviewed head). Tool: /code-review.

# Severity Location Finding Verdict
1 Nit lib/hosts/update-worker.test.mjs:732 \brequire never matches __require. Fixed in e1efa43
2 Nit lib/hosts/update-worker.test.mjs:734 The checkout check misses a file: URL. Fixed in e1efa43
3 Nit lib/self-update.ts:413 The server worker's build failure path has no test. Rejected: one argument, the same Bun behaviour the host test pins; a server-worker test needs the whole self-update fixture

Round head d952223; 1 of 3 rounds after the first full review used. e1efa43 changes only a test, so no next round is due.

Summary by CodeRabbit

  • Reliability
    • Host updates now run from a self-contained worker bundle, including when launched through a symlinked directory or as a compiled application.
    • Update workers more consistently handle stop and restart checks, recovery state, and health acknowledgements.
  • Bug Fixes
    • Bundling failures now report the build details, making update errors clearer.

The daemon bundled nothing: copyHostWorkerSources copied update-worker.ts and every module it imports as rewritten
.mts files, and workerRuntime picked the lifecycle modules at runtime. Every tau process runs on Bun now, so the
daemon builds one self-contained worker.mjs with Bun.build (buildHostUpdateWorker), as self-update.ts does for the
server worker, and the worker imports its lifecycle modules statically.

Tests that swapped a lifecycle module beside the copy now swap it in the bundle through a build plugin.

Closes #23
- Bun.build throws a bare "Bundle failed" by default; build with throw: false so the failure names its cause (host and server workers).
- The worker calls its lifecycle functions directly: the RUNTIME object and its parameters only served the runtime module choice.
- Tests: the health-window stand-in proves it ran, and the bundle check also refuses require() and any path into the checkout.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The host update worker now runs from a single Bun-built bundle instead of copied .mts source modules. The worker uses direct lifecycle and process-identity imports. Tests cover bundle creation, launch, pruning, and recovery behavior.

Changes: Host update worker bundling

Layer / File(s) Summary
Bundle and launch the worker
lib/hosts/updates.ts, lib/self-update.ts, lib/hosts/update-worker.test.mjs, AGENTS.md
buildHostUpdateWorker creates a 0600 ESM bundle at worker.mjs, and script-style launches run it. Bundling errors include build logs. Tests verify the bundle and launch behavior. Documentation now describes bundling instead of copying runtime modules.
Run worker lifecycle and recovery
lib/hosts/update-worker.ts, lib/hosts/update-worker.test.mjs
The worker uses direct lifecycle and process-identity imports. Cleanup targets worker.mjs; lifecycle and recovery tests use bundled workers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

  • ompweb-dev/tau#24: Makes Bun the runtime for tau processes, which this worker bundling change assumes.

Suggested reviewers: kahme247

Merge Risk: Minimal · up to e1efa

The host update worker now runs from a single bundled file instead of copied source modules, and the tests cover bundle creation, launch, pruning, and recovery. No concrete defect was found. The only gaps are platform and package-install coverage that was not exercised, so the change looks ready to merge.

Security architecture risk: Minimal · up to e1efa

The host updater is packaged differently, but the reviewed change does not grant it new authority or weaken the checks that govern stopping, replacing, or restoring the host. If the updater cannot be built, the attempt fails before the daemon is stopped.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed execution boundary is the script-installed host being updated: its local daemon, supervisor, and installation files. The handoff uses the existing runtime and detached-launch environment rather than granting a new identity or authority to the worker.

Trust Boundaries and Controls

  • observed — Before replacement, the worker verifies descriptor ownership, validates the approved release pin when present, checks the installation layout and ownership, and verifies control of the daemon's supervisor. Direct imports do not remove those checks.

Resilience and Maintainability Implications

  • observed — A reported bundle failure prevents detached launch. The caller records failure for the matching operation and removes the lock only if it still names that attempt.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "refactor(hosts): run the host update worker as one Bun bundle" matches the main change. The PR replaces copied worker sources and rewritten .mts files with one worker.mjs bundle built by bu…
Linked Issues check Passed [#23] Requirement 1: replace copyHostWorkerSources with one self-contained bundle. The summary shows copyHostWorkerSources removed and buildHostUpdateWorker added in lib/hosts/updates.ts. It calls Bun…
Out of Scope Changes check Passed The changes stay within the host update worker work of #23. AGENTS.md is updated only to describe the new bundling behavior, which is supporting documentation. lib/self-update.ts changes Bun.build to …
Full details: Title check

Explanation

The title "refactor(hosts): run the host update worker as one Bun bundle" matches the main change. The PR replaces copied worker sources and rewritten .mts files with one worker.mjs bundle built by buildHostUpdateWorker using Bun.build. The title is specific, short, and states the primary change.

Full details: Linked Issues check

Explanation

[#23] Requirement 1: replace copyHostWorkerSources with one self-contained bundle. The summary shows copyHostWorkerSources removed and buildHostUpdateWorker added in lib/hosts/updates.ts. It calls Bun.build with target "bun" and writes <attempt>/worker.mjs. The PR description states the bundle imports only builtins, and a test checks this. Requirement 2: follow the lib/self-update.ts approach. self-update.ts already uses Bun.build for the server worker, and the new code follows that pattern. Requirement 3: replace workerRuntime with static imports. The summary shows lib/hosts/update-worker.ts importing upgrade-process and process-identity directly, and the RUNTIME object and runtime parameters removed. Requirement 4: rewrite the .mts fixtures in lib/hosts/update-worker.test.mjs. The summary shows fixtures and pruning assertions moved to worker.mjs, and a build plugin replaces the lifecycle modules inside the bundle. All coding requirements of #23 appear covered by the changes at the reviewed head e1efa43. Evidence comes from the PR description and change summary. No source inspection was made, so exact code details are not independently confirmed.

Full details: Out of Scope Changes check

Explanation

The changes stay within the host update worker work of #23. AGENTS.md is updated only to describe the new bundling behavior, which is supporting documentation. lib/self-update.ts changes Bun.build to throw: false so the server worker reports bundler logs. This is a one-line change to the same build-error handling that #23 cites as the model, and the PR description justifies it as a shared build-error fix. The test changes support the bundle and the static-import refactor. Pruning changes follow from removing the .mts copies. The health-window stand-in and the import-scan tests verify the bundle requirements. No unrelated functional change appears in the summary. Limitation: the self-update.ts change is not covered by a dedicated test, and this was accepted in review.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d07b827d-8932-45f5-a05f-af0f725752ed
Commits

Reviewing files that changed from the base of the PR and between 09c36b6 and e1efa43.

Files selected for processing: 5

  • AGENTS.md
  • lib/hosts/update-worker.test.mjs
  • lib/hosts/update-worker.ts
  • lib/hosts/updates.ts
  • lib/self-update.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@andrebrait
andrebrait merged commit 9fdd123 into main Nov 26, 2026
5 checks passed
@andrebrait
andrebrait deleted the host-worker-bundle branch November 26, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Host update worker: one Bun bundle instead of copied .mts sources

1 participant