Skip to content

build: make Bun the primary runtime - #1970

Open
sethkarten wants to merge 36 commits into
mainfrom
feat/bun-primary-runtime
Open

build: make Bun the primary runtime#1970
sethkarten wants to merge 36 commits into
mainfrom
feat/bun-primary-runtime

Conversation

@sethkarten

@sethkarten sethkarten commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Linear: https://linear.app/primeintellect/issue/RES-1242/make-bun-the-primary-prime-agent-runtime

Summary

  • Pin Rust-based Bun 1.4.0 exactly and make it the primary installer, package manager, development runtime, test runner, bundler, compiler, and CI/release tool.
  • Preserve TypeScript checks and declarations, registry package publication through Bun, existing exports, daemon behavior, extensions, providers, skills, and CPython/Cython execution.
  • Build standalone macOS and Linux executables with the required runtime assets as flat sidecars.
  • Make verified compiled Bun binaries the only supported Prime Agent install and update path.

Runtime and test migration

  • Replace npm, npx, tsx, shx, Vitest, Vite, and esbuild execution with Bun-native scripts and Bun.build.
  • Run Bun tests in isolated modules and separate file processes to prevent mock and handle leakage.
  • Keep the existing Vitest-style test surface through type-only compatibility declarations rather than restoring the Vitest runtime.
  • Sanitize internal orchestration environment state before test subprocesses start.
  • Preserve dedicated process-stress, kernel-heavy, Python-runtime, and compiled-artifact lanes.

Binary and installer safety

  • Verify SHA-256 checksums before activation.
  • Smoke-test new binaries before switching the active version.
  • Install into immutable version directories and switch atomically with rollback support.
  • Keep application files separate from ~/.prime user state.
  • Reject archives with missing sidecars or dependency/cache directories.
  • Keep registry package publication on Bun while compiled artifacts install and run without Node or npm.

Release behavior

  • Preserve stable release detection on version changes, tags, and manual retries.
  • Preserve beta publication from main.
  • Compile and smoke-test darwin-arm64, darwin-x64, linux-arm64, and linux-x64 release layouts.
  • Preserve concurrency.queue: max so release runs remain FIFO-serialized.

Validation

  • Frozen Bun install, Biome, tsgo --noEmit, installer rendering, and browser smoke: passed.
  • Agent package: 70 passed.
  • AI package: 341 passed, 726 expected provider skips.
  • TUI package: 766 passed.
  • Coding-agent tests: all isolated file partitions passed after focused reruns of the two corrected fixtures.
  • Process-stress lane: 19 passed.
  • Kernel-heavy lane: 23 passed.
  • Python runtime: 269 passed.
  • Daemon supervisor monitor: 100 passed.
  • Hermetic bundle suite: 16 passed.
  • Worker recovery regression: 4 passed.
  • Committed-state native artifact smoke: 5 passed, including empty-PATH --version and --help.
  • Focused binary installer and release archive suites: 33 passed.
  • Registry publication dry run through Bun: all four workspace packages at 0.9.1 passed manifest, tarball, and entry-point checks.

All process-heavy validation ran in Docker with isolated writable dependency volumes.

Paired Docker benchmark

Linux arm64, 4 CPUs, 8 GB RAM. Baseline: origin/main@81ae3cb34d, Node 22.23.2/npm 10.9.8. Bun: 1.4.0+34cbb9a40 with minification, bytecode, and lazy Bedrock loading.

End-user installation

Five real installer trials used a controlled local release server. Node was already installed and npm's third-party cache was warm, which favors npm. Bun ran checksum verification, extraction, smoke testing, and atomic activation.

Operation npm / Node Bun 1.4 Result
Fresh install 4.19 s 0.89 s Bun 4.7× faster
Reinstall 4.39 s 0.13 s Bun 34.5× faster
Installed CLI --help 128 ms 57 ms Bun 56% faster
CLI startup CPU time 145 ms 70 ms Bun 52% lower
Daemon socket ready 137 ms 61 ms Bun 55% faster
Installed footprint 245 MiB 161 MiB Bun 34% smaller
Release transfer 10.8 MB 59.3 MB Bun 5.5× larger
Peak CLI RSS 127 MiB 150 MiB Bun 18% higher

Developer loop

Operation npm / Node Bun 1.4 Result
Fresh dependencies, warm cache 3.485 s 0.436 s Bun 8.0× faster
Repeat dependency check 3.666 s 0.016 s Bun 223× faster
Full build 3.584 s 1.436 s Bun 2.5× faster
node_modules 492.7 MiB 421.3 MiB Bun 14% smaller

Model latency and subagent completion time were not measured.


Note

High Risk
This changes the end-user install/update path, release artifact format, and entire CI/release pipeline; mistakes could break downloads, upgrades, or production publishes.

Overview
Makes Bun 1.4.0 the repo-wide toolchain by adding .bun-version, bun.lock, and bunfig.toml (7-day minimumReleaseAge replaces .npmrc), and switching Husky, AGENTS.md, and all GitHub Actions from Node/npm to oven-sh/setup-bun, bun install --frozen-lockfile, and bun run (including check:bun-version). CI splits former matrix extras into dedicated process-stress, kernel-heavy, runtime-python, and artifact-smoke jobs; uv is pinned via setup-uv@0.12.4.

Release and distribution move from npm tarballs to Bun-compiled artifacts. The build workflow cross-compiles packages/coding-agent for darwin-arm64, darwin-x64, linux-arm64, and linux-x64, copies binary sidecar assets, packs with bun run release:pack, smoke-tests by extracting the host *.tar.gz and running --version, and publishes *.tar.gz to R2 instead of *.tgz. The npm 12 installer smoke test is removed.

install.sh is rewritten for binary-only installs: downloads platform prime-agent-{version}-{platform}.tar.gz, verifies SHA256SUMS, installs into immutable version directories under XDG paths, activates via atomic symlinks with install locks and rollback, supports --update, rejects --method, and drops Node/npm bootstrap, kernel-on-install prompts, and global npm install -g. PATH setup targets ~/.local/bin instead of npm’s global bin.

Reviewed by Cursor Bugbot for commit 5259609. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Replace Node/npm/tsx with Bun as the primary runtime

  • Migrates all build, test, release, and development scripts from npm/tsx/Node to Bun 1.4.0, adds bun.lock and bunfig.toml, and pins Bun version via .bun-version.
  • Rewrites install.sh from an npm-package installer to a compiled-binary installer that downloads, verifies, and atomically activates platform-specific Bun-compiled archives with rollback support; removes all Node.js/npm installation logic and the --method flag.
  • Migrates the entire test suite from Vitest to bun:test with a preload compatibility shim (bun-test-preload.ts) providing fake timers, waitFor, expect.poll, and module mocking via createRequire; converts vi.mock factories to synchronous createRequire-based mocks across all test files.
  • Reworks release packaging to compile four Unix Bun binaries (darwin x64/arm64, linux x64/arm64) with sidecar assets instead of npm tarballs; removes Windows from build targets.
  • Introduces createCliSubprocessLaunchSpec to centralize subprocess launch logic for compiled binaries, installed launchers, and direct runtime execution; replaces tsx-based CLI launches throughout.
  • Behavioral Change: install.sh rejects --method, musl Linux, and Windows; daemon sockets now flush before close with a 1-second forced-destroy timeout; console.log/info/debug redirect to stderr during stdout takeover in Bun; detectInstallMethod no longer classifies all Bun runs as bun-binary; assertNodeVersion no longer skips validation for Bun runtimes; defaultDaemonSocketDir honors TMPDIR/TMP/TEMP.

Changes since #1970 opened

  • Introduced safe binary publication mechanism avoiding destructive operations on pre-existing paths [5259609]
  • Refactored fresh install and update flows to use claimed staging paths and safer activation with rollback support [5259609]
  • Reworked atomic symlink creation with non-clobbering temp links, directory target rejection, and post-placement verification [5259609]
  • Added error handling to install paths persistence and symlink validation in rollback [5259609]
  • Added end-to-end test coverage for installer safety mechanisms and edge cases [5259609]
  • Refactored atomic symlink unit test to use dedicated shell helper script [5259609]

Macroscope summarized 7163e9c.

Comment thread install.sh Outdated
Comment thread install.sh
Comment thread packages/coding-agent/docs/quickstart.md
Comment thread packages/coding-agent/scripts/copy-assets.ts
Comment thread scripts/assemble-release-archives.mjs Outdated
Comment thread scripts/assemble-release-archives.mjs
Comment thread scripts/assemble-release-archives.mjs
Comment thread .github/workflows/ci.yml Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/scripts/copy-assets.ts Outdated
Comment thread install.sh
Comment thread install.sh
Comment thread scripts/pack-prime-agent-release.mjs Outdated
Comment thread install.sh Outdated
Comment thread scripts/assemble-release-archives.mjs Outdated
Comment thread scripts/pack-prime-agent-release.mjs Outdated
Comment thread scripts/pack-prime-agent-release.mjs Outdated
Comment thread install.sh Outdated
Comment thread scripts/assemble-release-archives.mjs Outdated
Comment thread packages/coding-agent/test/bun-installer-e2e.test.ts
Comment thread install.sh
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh
Comment thread install.sh
Comment thread install.sh
Comment thread install.sh
Comment thread install.sh Outdated
Comment thread install.sh Outdated
Comment thread install.sh
Comment thread install.sh
Comment thread packages/ai/src/providers/register-builtins.ts
Comment thread packages/coding-agent/src/modes/interactive/interactive-mode.ts
Comment thread scripts/assemble-release-archives.mjs
Comment thread .github/workflows/build-binaries.yml
Comment thread install.sh Outdated
Comment thread packages/coding-agent/src/cli/daemon-update-restart.ts
Comment thread packages/coding-agent/package.json
Comment thread install.sh
@sethkarten
sethkarten force-pushed the feat/bun-primary-runtime branch from 50b4919 to caec73c Compare September 2, 2026 21:58
@sethkarten

Copy link
Copy Markdown
Contributor Author

Rebased onto current main at cd10724fe and force-pushed with lease. The branch is now 0 commits behind main.

Conflict resolution:

  • Kept the compiled Bun-only release workflow over main's npm 12 installer smoke path.
  • Kept the compiled binary installer over main's npm installer policy functions.
  • Preserved main's unrelated package and daemon changes.
  • Removed the superseded npm 12 installer changelog and restored the compiled-installer render check path.

Post-rebase Bun 1.4.0 validation passed in clean Docker: static/build checks, all three official coding-agent shards, process stress 19/19, kernel-heavy 23/23, CPython 269/269, AI/TUI/agent packages, and compiled artifact smoke 5/5. An independent rebase audit found no actionable integration issues.

The prior review-fix commit 50b4919f1 is now 3cc8bd061 after rebase. The reconciliation tip is caec73c2c. Hosted checks are restarting now.

@macroscopeapp

macroscopeapp Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Macroscope skipped reviewing this pull request. Per-review cost limit exceeded (workspace setting).

This review would cost an estimated $10.85, which exceeds your per-review limit of $10.00.

The top 3 files driving up this estimate:

File Diff Size Estimate
install.sh 64.50KB $3.23
scripts/pack-prime-agent-release.mjs 15.48KB $0.77
scripts/assemble-release-archives.mjs 12.60KB $0.63

Tip

To get this pull request reviewed, you can:

  1. Comment @macroscope-app on this PR to request a manual review (monthly spend limits still apply).
  2. Exclude the file(s) above from review by adding a pattern to your .macroscope/ignore.md — note that creating this file replaces Macroscope's built-in default ignores rather than extending them.
  3. Raise your cost limit in your workspace billing settings.

Turn off this reminder going forward

Comment thread install.sh
Comment thread install.sh Outdated
@sethkarten

Copy link
Copy Markdown
Contributor Author

Addressed both post-rebase Cursor findings in 3125a8618:

  • Bundled installer sidecars can repair missing or safely-shaped broken activation symlinks while retaining physical-root, absolute-path, and symlink-escape validation.
  • Explicit-path installs without HOME no longer exit after successful activation when shell-profile detection is unavailable.

Validation: root checks passed; installer suite passed 23/23 locally and in clean Bun 1.4.0 Linux Docker. Both threads have evidence replies and are resolved. Hosted checks are restarting.

# Conflicts:
#	packages/coding-agent/test/suite/agent-session-compaction.test.ts
- semantic-edges: replace vi.spyOn(accessor) with Object.defineProperty +
  Reflect.deleteProperty restoration (Bun does not support getter spy)
- bun-installer: use realpathSync(tmp) instead of shell spawn for
  /var -> /private/var canonicalization
- session-lease: create guard directory with future mtime to prevent
  proper-lockfile stale-reclaim during Bun's slow Atomics.wait
Comment thread packages/coding-agent/test/bun-installer.test.ts Fixed
Comment thread install.sh Outdated
…injection

Never rm -rf any pre-existing final path entity (file, symlink, or directory)
in fresh install or update. Check with `-e` and `-L` before any operation.
Reuse a healthy existing target after layout+smoke validation.
Stage to a collision-checked repair directory (bounded deterministic counter,
no RANDOM) when existing target is unhealthy. Never pre-delete destination;
fail closed on collision. Track owned paths via _owned_dest for cleanup;
delete only what this invocation staged (not pre-existing paths).
Rewrite atomic symlink test to use execFileSync argv (CodeQL fix).
Add 14 tests: healthy reuse, unhealthy repair, active repair, collision retry,
symlink/file collision, bounded failure, activation failure recycling old target,
and no pre-existing dir deletion for both install and update.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5259609. Configure here.

Comment thread install.sh
}
_owned_dest="$_repair_dir"
prime_agent_binary_repair_copy "$_repair_dir"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Owned dest survives install interrupt

Medium Severity

_owned_dest is cleaned only on the explicit activation-failure paths. The EXIT trap still tracks only staging and download. An interrupt during prime_agent_binary_repair_copy leaves a half-written directory that this publisher will never replace, so later same-version installs are forced onto new repair paths and the canonical slot stays broken.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5259609. Configure here.

@sethkarten

Copy link
Copy Markdown
Contributor Author

Installer hardening is now complete in 52596093f. Both actionable review findings were fixed, answered, and resolved. Local validation passed the focused installer suites (62/62) and the complete 357-file coding-agent suite. All 22 applicable hosted checks are green. This PR is ready for human review.

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.

3 participants