Skip to content

fail kernel bootstrap fast when the bundled runtime source is missing - #2203

Open
kevinjosethomas wants to merge 1 commit into
mainfrom
fix/kernel-bootstrap-missing-runtime-source
Open

fail kernel bootstrap fast when the bundled runtime source is missing#2203
kevinjosethomas wants to merge 1 commit into
mainfrom
fix/kernel-bootstrap-missing-runtime-source

Conversation

@kevinjosethomas

@kevinjosethomas kevinjosethomas commented Sep 10, 2026

Copy link
Copy Markdown
Member
  • a session that outlived its deleted worktree could no longer find the bundled runtime source, fell back to installing an unpublished package name, and wiped the shared kernel venv that every other session was using before the reinstall failed with a bare exit code.
  • bootstrap now resolves the runtime source before looking at the venv and fails with a clear message naming the searched paths and the recovery steps, leaving the existing venv untouched; the registry fallback is gone since the runtime is always installed from a local checkout.
  • uv and python helper failures now carry the tail of their stderr, and a new runtime source override lets you install from an explicit checkout and doubles as the test seam for the missing-source path.

Note

Medium Risk
Changes shared kernel venv bootstrap ordering and install path resolution; incorrect behavior could still break multi-session Python kernel setup, though the intent is to reduce collateral damage when installs go missing.

Overview
Kernel bootstrap no longer destroys the shared venv when the bundled prime-agent-runtime checkout is gone (e.g. a long-lived session after its worktree was removed). Bootstrap resolves the runtime source directory before comparing or rebuilding ~/.prime/agent/kernel-venv, and drops the old registry-name fallback—installs always come from a local path with a content hash identity.

When no source is found, bootstrap fails immediately with searched paths, recovery hints (PRIME_AGENT_RUNTIME_SOURCE, restart from a valid install, or PRIME_AGENT_KERNEL_PYTHON), and an explicit note that the existing venv was left untouched.

PRIME_AGENT_RUNTIME_SOURCE lets devs point bootstrap at a specific runtime checkout (also wired into the bootstrap cache key). uv/python helper failures now append a bounded stderr tail instead of only an exit code.

Docs add the env var and a new RLM failure-mode row; tests cover override install, missing-source safety, and stderr propagation (Windows spawn expectations updated for stderr piping).

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

Note

Fail kernel bootstrap fast when bundled runtime source is missing

  • Kernel bootstrap now resolves and hashes the local runtime source before touching the shared venv. If no source is found, it throws a structured error listing searched paths and leaves the existing venv untouched.
  • Adds PRIME_AGENT_RUNTIME_SOURCE env var so callers can point bootstrap at a specific runtime checkout; when set, it is the sole candidate and the cache key changes accordingly.
  • Removes the registry-package fallback from bootstrapVenv; installs always use the resolved local source directory.
  • Subprocess helper run now captures stderr (up to a fixed tail) and appends it to failure errors instead of reporting only the exit code.
  • Risk: resolveRuntimeIdentity no longer returns a package-name fallback identity — any out-of-tree caller relying on that fallback will now fail when the local source is absent. Bootstrap subprocess spawn options changed to pipe stderr, so tests asserting stdio config in kernel-windows-process.test.ts were updated.
📊 Macroscope summarized 147fc29. 4 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted

🗂️ Filtered Issues

Incident: a long-running prime-agent session kept running after the Codex
worktree it was launched from was deleted. On the next kernel start the
bootstrap could not find prime-agent-runtime/pyproject.toml, fell back to the
bare registry name "prime-agent-runtime" (which is not published anywhere),
treated the healthy shared ~/.prime/agent/kernel-venv as stale because its
recorded identity differed, deleted it, and then failed the reinstall with a
bare "failed with exit code 1" because uv's stderr was discarded. Every other
session sharing that venv lost its kernel too.

Changes:
- Resolve the runtime source before looking at the venv and throw a
  descriptive error (paths searched, likely cause, how to recover) when it is
  missing. The venv is never touched in that case. The registry fallback is
  gone: the runtime is always installed from a local source directory.
- Capture the last 8 KB of stderr from uv/python helper invocations and
  include it in bootstrap errors, so the real reason is visible.
- Add PRIME_AGENT_RUNTIME_SOURCE to install the runtime from an explicit
  checkout; it is also the test seam for the missing-source path.
- Tests for the missing-source fail-fast (stale venv survives, uv never
  runs), the source override, and stderr propagation; Windows stdio
  expectations updated for the piped stderr.
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

Prime Agent performance — completed

PR 147fc295 compared with main 4f4d51c5.

Overall: 0 regressed · 0 improved · 17 no clear change.

Metric Main This PR Change
Cold startup 2,828.8 ms 2,891.9 ms ≈ +63.1 ms (+2.23%)
Warm startup 1,619.0 ms 1,697.3 ms ≈ +78.2 ms (+4.83%)
Installation 26.28 s 28.00 s ≈ +1.72 s (+6.53%)
Compressed release artifacts 11.11 MB 11.11 MB ≈ +0.0013 MB (+0.01%)
Installed footprint 597.44 MB 597.45 MB ≈ +0.01 MB (+0.00%)
Idle memory, summed RSS 1,038.14 MB 1,032.41 MB ≈ -5.73 MB (-0.55%)

Python runtime

Metric Main This PR Change
Python kernel startup 132.6 ms 127.0 ms ≈ -5.6 ms (-4.25%)
Python cell round trip 0.577 ms 0.551 ms ≈ -0.027 ms (-4.62%)
Empty bash command 11.8 ms 11.6 ms ≈ -0.2 ms (-1.97%)
Bash git status 17.6 ms 17.4 ms ≈ -0.2 ms (-1.11%)
Bash 32 KiB output 11.9 ms 11.8 ms ≈ -0.1 ms (-0.95%)
35 cells / 9 shell calls 173.8 ms 170.3 ms ≈ -3.5 ms (-2.01%)
Python interrupt to done 1.613 ms 1.677 ms ≈ +0.063 ms (+3.93%)
Python state snapshot 27.0 ms 26.4 ms ≈ -0.6 ms (-2.11%)
Python state restore 373.1 ms 333.2 ms ≈ -39.9 ms (-10.71%)
Python idle RSS 35.65 MB 34.26 MB ≈ -1.39 MB (-3.90%)
Python RSS after pandas workload 97.69 MB 96.41 MB ≈ -1.27 MB (-1.30%)

Sandbox cost: ~$0.0867 — no inference calls.
Run, logs, and downloadable raw results

Methodology and samples

Main resolved at 2026-09-10T19:40:58.749480+00:00. Harness 4f4d51c5.
Linux x64, 4 vCPU, 8 GB RAM, 20 GB disk; region us.
Image: node:24-bookworm@sha256:be23f54a88d34e8824c741b19b91064094f92c1c97b194144bfc8b50d67258e2.
Stock tools, skills, daemon, and Python bootstrap enabled; fresh homes and a fixed Git fixture.
Onboarding is dismissed; the editor starts without a selected model or submitted prompt.
Medians shown. Arrows require a 20% timing/memory change plus absolute floors and IQR.
These practical noise floors are not a statistical significance test.
Cold means stopped Prime processes; OS filesystem caches are not flushed.
No model requests or credentials. Installation excludes build/setup time.
Installer tarballs use loopback; npm/Python downloads use the network with fresh caches.
Artifact size counts release tarballs; footprint after first use includes registry packages.
MB is decimal. Summed RSS can double-count shared pages; PSS is recorded when available.
Provisioning, setup, and build durations are recorded separately in the raw results.
Kernel probes use the installed JSONL runtime, outside the TUI/TypeScript host.
Per trial: 50 Python cells, 5 calls per shell case, and one 35-cell mix (9 git status calls).
Cell/shell values are batch means; other runtime timings are single operations.
State fixture: a 10,000-row × 8-column integer DataFrame and a 10,000-integer list.
Restore runs in a fresh kernel, including pandas imports; kernel startup is excluded.
Kernel RSS covers the isolated Python process; loaded RSS follows the pandas workload.
Costs estimate full sandbox lifetimes at configured rates, including setup and build.
Budget target: $1; not a billing cap. Checks are informational.

Metric Main successful/attempted PR successful/attempted Main spread PR spread
Cold startup 10/10 10/10 IQR 62.6 ms IQR 66.9 ms
Warm startup 10/10 10/10 IQR 68.1 ms IQR 22.8 ms
Installation 3/3 3/3 range 0.52 s range 1.71 s
Compressed release artifacts 1/1 1/1
Installed footprint 1/1 1/1
Idle memory, summed RSS 10/10 10/10 IQR 94.61 MB IQR 92.28 MB
Python kernel startup 10/10 10/10 IQR 3.9 ms IQR 3.4 ms
Python cell round trip 10/10 10/10 IQR 0.053 ms IQR 0.080 ms
Empty bash command 10/10 10/10 IQR 0.4 ms IQR 0.4 ms
Bash git status 10/10 10/10 IQR 1.0 ms IQR 0.5 ms
Bash 32 KiB output 10/10 10/10 IQR 1.1 ms IQR 0.5 ms
35 cells / 9 shell calls 10/10 10/10 IQR 11.8 ms IQR 5.8 ms
Python interrupt to done 10/10 10/10 IQR 0.223 ms IQR 0.202 ms
Python state snapshot 10/10 10/10 IQR 2.0 ms IQR 2.2 ms
Python state restore 10/10 10/10 IQR 11.9 ms IQR 20.3 ms
Python idle RSS 10/10 10/10 IQR 2.69 MB IQR 4.08 MB
Python RSS after pandas workload 10/10 10/10 IQR 4.13 MB IQR 4.52 MB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟠 High

const hadVenv = existsSync(venv);

When runtimeSourceDir is deleted while acquireBootstrapLock waits, this function still removes the shared venv, and bootstrapVenv then fails because the source path no longer exists. Revalidate the runtime source inside the lock immediately before teardown, and use the refreshed path for the rebuild.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/coding-agent/src/core/kernel/bootstrap.ts around line 971:

When `runtimeSourceDir` is deleted while `acquireBootstrapLock` waits, this function still removes the shared `venv`, and `bootstrapVenv` then fails because the source path no longer exists. Revalidate the runtime source inside the lock immediately before teardown, and use the refreshed path for the rebuild.

Evidence trail:
packages/coding-agent/src/core/kernel/bootstrap.ts:787-808, 890-907, 957-983; commit 147fc295

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.

1 participant