Repository navigation
Start the detached server and handover reader with python -P, as bin/leaf runs Leaf - #6552
Merged
Merged
Conversation
…ook hands itself back and forth until uv's recursion limit
A Leaf knows itself by its package's location (`own_launcher`), and a hook
hands itself to the session's delivering launcher whenever that differs. A
launcher whose Python imports another tree's `leaf` therefore names itself
as someone else on every hop, and each hop execs the same launcher again
until uv stops the chain:
error: `uv run` was recursively invoked 101 times which exceeds the limit of 100
The one recorded instance, a PostToolBatch hook on 2026-11-04 04:42 UTC,
ran from a session whose working directory was a Leaf worktree's `src/`,
on a launcher from before #5304 added `-P`, so `python -m leaf` imported
the worktree's package. A reproducer with the 4dc2114 tree fails the
same way in 6.6 s (the record: 6.4 s). #5304's `-P` closed the working
directory, but a PYTHONPATH naming another Leaf's `src` still loops on
current main; with `-I` the same hook exits 0 in 0.3 s.
Behavior changes:
- `bin/leaf` runs `python -I -m leaf`, ignoring PYTHON* variables as well
as the working directory.
- Detached children (`detached.starting_detached`) and the handover
reader (`handover_pass`) run `sys.executable -I -m ...`. They ran
without `-P` too: `leaf server start` from a directory holding a
`leaf.py` failed with "the server ... did not start", and now starts.
- `test_claude_code_runs_the_whole_hook_once_its_session_claims` also
puts the stray `leaf.py` on PYTHONPATH, and fails on the `-P` launcher.
uv's `--with-editable` overlay, which the preview worker uses, reaches an
`-I` child through the environment's `.pth`, not PYTHONPATH.
leaf-agent
previously approved these changes
Nov 20, 2026
…leaf runs Leaf Keep the launcher at #5304's `-P` rather than `-I`. A hook inherits Claude Code's environment, so PYTHONPATH reaches one only where Claude Code itself was started with it: no setting, shell profile or running process on the machine sets one, and only dev tooling (the PYTHONPATH A/B bench, one Codex adapter journey test) sets one, for the process it starts. Console scripts, pipx and uv tools respect PYTHONPATH, and so does Leaf. The recorded `uv run` recursion (a PostToolBatch hook, 2026-11-04 04:42 UTC) came from the working directory: Claude Code runs a hook in Claude's current directory, which was a Leaf worktree's `src/`, and that launcher predated `-P`. The two children still ran `python -m` in the caller's working directory: from a directory holding a `leaf.py`, `leaf server start` failed with "did not start", and with `-P` the server comes up.
leaf-agent
approved these changes
Nov 20, 2026
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.
leaf server startspawns the page server, and the server spawns the handover reader, aspython -m leaf…in the caller's working directory, so aleaf.pyorleaf/there stands in for Leaf. From such a directory the server failed with "did not start"; from another Leaf checkout'ssrc/it would run that checkout's code. This gives both spawns the-Pthatbin/leafhas had since #5304.The same cause produced the one
uv runrecursion error on record (a PostToolBatch hook, 2026-11-04 04:42 UTC). Claude Code runs a hook in Claude's current directory, which was a Leaf worktree'ssrc/, on a launcher from before-P: each hop imported that tree'sleaf, took itself for another launcher, and handed the hook on until uv's recursion limit. Leaf uses-Prather than-I, which would also ignore PYTHONPATH, because a hook inherits Claude Code's environment, nothing sets a PYTHONPATH naming a Leaf there, and console scripts respect PYTHONPATH too.Asked by max-sixty, who hasn't read this version. Server start from a directory holding a stray
leaf.pynow comes up; the hook gate, hook registration, launcher dispatch, handover journey and two-install Codex adapter journey tests pass locally.