Include Kaimon's env in spawned session JULIA_LOAD_PATH#48
Open
jeffwack wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tomlinvalidates 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 previousJULIA_LOAD_PATH='@:@v#.#:@stdlib'override excluded Kaimon's own env from that worker's LOAD_PATH, so resolution ofusing JSON(and Kaimon's other direct deps) failed against the target project's manifest — and the subprocess died during boot.Approach
Base.active_project()at module load (Kaimon._KAIMON_LOAD_ENV).JULIA_LOAD_PATHso a from-source rebuild of Kaimon can resolve its deps via its own manifest, regardless of how Kaimon was installed (juliaup app,Pkg.dev, plainPkg.add).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._build_session_env()for testability.Tests
test/session_spawn_loadpath_tests.jl:_KAIMON_LOAD_ENVis captured at module load — non-empty string._build_session_env()returnsJULIA_LOAD_PATHstarting with@:@v#.#:@stdliband ending with the captured env, plus an emptyJULIA_PROJECT._build_session_scriptno longer emitsinsert!(LOAD_PATH.KAIMON_TEST_SPAWN_INTEGRATION=1, ~30s precompile): build a minimal project with none of Kaimon's deps, callspawn_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!removalWorth 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 toJULIA_LOAD_PATH— Kaimon is still discoverable, and its manifest is reachable for transitive dep resolution. Re-adding theinsert!alongside the env append would shadow the env lookup with the bare pkgdir, reintroducing #47.