Skip to content

Include Kaimon's env in spawned session JULIA_LOAD_PATH#48

Open
jeffwack wants to merge 1 commit into
kahliburke:mainfrom
jeffwack:spawn-loadpath-includes-kaimon-env
Open

Include Kaimon's env in spawned session JULIA_LOAD_PATH#48
jeffwack wants to merge 1 commit into
kahliburke:mainfrom
jeffwack:spawn-loadpath-includes-kaimon-env

Conversation

@jeffwack
Copy link
Copy Markdown

@jeffwack jeffwack commented May 21, 2026

Claude Code generated this PR - Jeff

Include Kaimon's env in spawned session JULIA_LOAD_PATH

Fixes #47.

Summary

When a target project's Manifest.toml invalidates Kaimon's precompile cache (cache misses: wrong dep version loaded / wrong source / incompatible header), the spawned subprocess rebuilds Kaimon from source in a worker. The previous JULIA_LOAD_PATH='@:@v#.#:@stdlib' override excluded Kaimon's own env from that worker's LOAD_PATH, so resolution of using JSON (and Kaimon's other direct deps) failed against the target project's manifest — and the subprocess died during boot.

Approach

  • Capture Kaimon's load-time env via Base.active_project() at module load (Kaimon._KAIMON_LOAD_ENV).
  • Append it to the spawn-time JULIA_LOAD_PATH so a from-source rebuild of Kaimon can resolve its deps via its own manifest, regardless of how Kaimon was installed (juliaup app, Pkg.dev, plain Pkg.add).
  • Drop the insert!(LOAD_PATH, 1, pkgdir(Kaimon)) line from the boot script. A bare pkgdir is not an env and has no manifest, so Julia uses it to find Kaimon's source but falls back to the active project for dep resolution — which is exactly what causes Spawned session subprocess can't recompile Kaimon when target project's manifest invalidates the precompile cache #47.
  • Factor the env build into _build_session_env() for testability.

Tests

test/session_spawn_loadpath_tests.jl:

  • _KAIMON_LOAD_ENV is captured at module load — non-empty string.
  • _build_session_env() returns JULIA_LOAD_PATH starting with @:@v#.#:@stdlib and ending with the captured env, plus an empty JULIA_PROJECT.
  • _build_session_script no longer emits insert!(LOAD_PATH.
  • Integration (gated behind KAIMON_TEST_SPAWN_INTEGRATION=1, ~30s precompile): build a minimal project with none of Kaimon's deps, call spawn_session!, assert the subprocess does not crash. Pre-fix this dies during boot; post-fix it reaches :running.

Full test suite passes locally (Pkg.test() → 590/590); gated integration test passes with the env var set.

Note on the insert! removal

Worth flagging since the original intent of insert!(LOAD_PATH, 1, pkgdir(Kaimon)) was to let the subprocess find Kaimon even when it isn't a dep of the target project. That role is now filled by appending Kaimon's load env to JULIA_LOAD_PATH — Kaimon is still discoverable, and its manifest is reachable for transitive dep resolution. Re-adding the insert! alongside the env append would shadow the env lookup with the bare pkgdir, reintroducing #47.

Fixes kahliburke#47. When a target project's Manifest.toml invalidates Kaimon's
precompile cache, the spawned subprocess rebuilds Kaimon from source in
a worker. The previous `JULIA_LOAD_PATH='@:@v#.#:@stdlib'` override
excluded Kaimon's own env from that worker's LOAD_PATH, so dep
resolution of `using JSON` (and Kaimon's other direct deps) failed
against the target project's manifest.

- Capture Kaimon's load-time env via `Base.active_project()` at module
  load (`Kaimon._KAIMON_LOAD_ENV`).
- Append it to the spawn-time `JULIA_LOAD_PATH` so a from-source
  rebuild of Kaimon can resolve its own deps via its own manifest.
- Drop the `insert!(LOAD_PATH, 1, pkgdir(Kaimon))` line from the boot
  script: a bare pkgdir is not an env and has no manifest, so it
  shadowed proper env-based dep resolution. Kaimon is now resolved
  via its app env on LOAD_PATH instead.
- Factor the env build into `_build_session_env()` for testability.

Tests in `test/session_spawn_loadpath_tests.jl`. Includes a gated
integration test (`KAIMON_TEST_SPAWN_INTEGRATION=1`) that builds a
minimal project with none of Kaimon's deps and asserts the subprocess
reaches `:running` — pre-fix this crashed during boot.
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.

Spawned session subprocess can't recompile Kaimon when target project's manifest invalidates the precompile cache

1 participant