Skip to content

fix: run the installed Leaf when a session's plugin copy has lost its project - #6567

Merged
leaf-agent merged 3 commits into
mainfrom
fix/issue-6562
Nov 20, 2026
Merged

leaf-agent merged 3 commits into
mainfrom
fix/issue-6562

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Once Claude Code deletes an orphaned plugin copy's pyproject.toml, uv run -q --no-dev --project "$root" finds no project. It then runs whatever python the caller has, so the hand-off in session_runtime.hand_off_command never runs. Run from outside a checkout, a bare leaf and every hook fail with No module named leaf. Run from inside a Leaf checkout, they quietly run that checkout's Leaf. When the project is missing, bin/leaf now execs the launcher that installed_plugins.json records for this copy's marketplace, which is the rule installed_launcher follows. It does this in shell, with jq (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-end and LEAF_HOST_LAUNCHER paths, which never use this tree's project, and before every uv run.

Verification:

  • test_an_installed_copy_that_lost_its_project_runs_the_copy_installed_since builds 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.
  • Reproduced by hand with two git archive copies under a fake plugins/cache: after deleting pyproject.toml, leaf --version printed No module named leaf before the change and the newer copy's version after it.

Test changes that go with this:

  • The tests that copy bin/leaf alone now give their project a pyproject.toml.
  • The missing-uv hook test now keeps dirname on PATH. With an empty PATH, 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.py and tests/model/test_interact_layer.py pass.

Worth weighing: the shell now holds a second, smaller copy of how installed_launcher picks a copy. That rule takes the first executable installPath under leaf@<marketplace>.

Closes #6562 — automated triage

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
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The fallback accepts relative installPath entries. installed_launcher requires an absolute path, and the launcher is meant to behave independently of the caller's working directory. Please enforce the same absolute-path rule in the shell fallback and test that it skips a relative record.

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread bin/leaf Resolved
…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.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Done in 70a38d5: the fallback loop now skips any installPath that doesn't start with / before trying it, matching installed_launcher's is_absolute() check. The test runs the orphaned launcher from the cache directory with a record holding only the installed copy's relative name, which resolves from that working directory, and asserts the refusal; without the guard that case ran the relative copy and failed.

@leaf-agent
leaf-agent merged commit 9114f0f into main Nov 20, 2026
7 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-6562 branch November 20, 2026 03:12
max-sixty added a commit that referenced this pull request Nov 20, 2026
…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.
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.

A session's leaf fails with "No module named leaf" once Claude Code cleans up the copy it loaded

2 participants