Repository navigation
fix: run the installed Leaf when a session's plugin copy has lost its project - #6567
Conversation
Claude Code marks a running session's older plugin copy orphaned once a newer one is installed, and may delete its files while the session still runs its launcher. Without pyproject.toml, `uv run --project` ran the caller's python, so every bare `leaf` and hook failed with "No module named leaf" (or, from a Leaf checkout's directory, ran that checkout's Leaf). The launcher now runs the copy installed_plugins.json records, and refuses naming the cause where none is recorded. Tests that copy the launcher alone now give it a pyproject.toml, and the missing-uv hook test keeps `dirname` on PATH so it still reaches uv. Closes #6562
|
@leaf-agent The fallback accepts relative
|
leaf-agent
left a comment
There was a problem hiding this comment.
A hook handed off this way loses its payload. The exec sits inside a loop whose stdin is the <<EOF heredoc, so the installed launcher reads the leftover heredoc text instead of the hook's JSON, and leaf hook fails with "hook expects". The issue names hooks as half of the breakage, and the new test only checks argv, so it passes anyway. I checked the redirection with a standalone sh script: piped stdin never reaches the exec'd command.
If the loop reads its candidates from fd 3 (read -r install <&3 … done 3<<EOF), the caller's stdin passes through. The test can then pipe a payload and assert that the installed copy receives it. I'll push that fix.
…ject The candidate loop read its heredoc on stdin, so the exec inside it gave the installed launcher the heredoc instead of the hook's payload. Read candidates from fd 3 instead; the test now pipes a payload and checks it arrives.
The shell fallback now runs only an installed copy recorded at an absolute path, as session_runtime.installed_launcher does, so the launcher never runs a copy found relative to the caller's working directory. The test records a relative path that resolves from the launcher's cwd and asserts the refusal.
|
Done in 70a38d5: the fallback loop now skips any |
…se where none is recorded A removal that stops partway can take a copy's root `.orphaned_at`, which sorts first, and keep its launcher, so the mark alone missed the state #6562 reported: the project gone, and uv left to run the caller's `python`. A copy in Claude Code's cache now reads the record when it is marked or has lost its project, and #6567's refusal comes back for a launcher whose project is gone with no other copy to run, so uv never runs without a project. `session_runtime.replaced` takes the same two checks, so the follower moves on when the launcher would look. Reading the record by parameter expansion rather than `dirname` costs about 4 ms a launch rather than 21; the two checks keep it off the installed copy's launches, which measured the same as main's (63-66 ms for `leaf --version`). The launcher test now fails on main's launcher, on one that skips its own copy, and on one that drops either check; the project stubs the hook tests need for the refusal come back.
Once Claude Code deletes an orphaned plugin copy's
pyproject.toml,uv run -q --no-dev --project "$root"finds no project. It then runs whateverpythonthe caller has, so the hand-off insession_runtime.hand_off_commandnever runs. Run from outside a checkout, a bareleafand every hook fail withNo module named leaf. Run from inside a Leaf checkout, they quietly run that checkout's Leaf. When the project is missing,bin/leafnow execs the launcher thatinstalled_plugins.jsonrecords for this copy's marketplace, which is the ruleinstalled_launcherfollows. It does this in shell, withjq(already a host requirement), because this copy's Python can no longer run. If no other copy is recorded, it exits 1 with a message that names the cause and points to/reload-plugins.The installed launcher receives the caller's stdin unchanged, so a hook keeps its payload.
The check comes after the
session-endandLEAF_HOST_LAUNCHERpaths, which never use this tree's project, and before everyuv run.Verification:
test_an_installed_copy_that_lost_its_project_runs_the_copy_installed_sincebuilds two cache copies. The older one holds only the launcher. The test checks the arguments and the piped stdin arrive. It fails on the old launcher and passes with this change.git archivecopies under a fakeplugins/cache: after deletingpyproject.toml,leaf --versionprintedNo module named leafbefore the change and the newer copy's version after it.Test changes that go with this:
bin/leafalone now give their project apyproject.toml.dirnameonPATH. With an emptyPATH, the launcher's root comes out as/and the new check refuses before uv is reached.tests/model/test_hook_registration.py,tests/process/test_hook_gate.py,test_bridge.py,test_codex_tool.pyandtests/model/test_interact_layer.pypass.Worth weighing: the shell now holds a second, smaller copy of how
installed_launcherpicks a copy. That rule takes the first executableinstallPathunderleaf@<marketplace>.Closes #6562 — automated triage