Skip to content

Start the detached server and handover reader with python -P, as bin/leaf runs Leaf - #6552

Merged
max-sixty merged 5 commits into
mainfrom
uv-run-recursion
Nov 22, 2026
Merged

max-sixty merged 5 commits into
mainfrom
uv-run-recursion

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

leaf server start spawns the page server, and the server spawns the handover reader, as python -m leaf… in the caller's working directory, so a leaf.py or leaf/ there stands in for Leaf. From such a directory the server failed with "did not start"; from another Leaf checkout's src/ it would run that checkout's code. This gives both spawns the -P that bin/leaf has had since #5304.

The same cause produced the one uv run recursion 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's src/, on a launcher from before -P: each hop imported that tree's leaf, took itself for another launcher, and handed the hook on until uv's recursion limit. Leaf uses -P rather 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.py now comes up; the hook gate, hook registration, launcher dispatch, handover journey and two-install Codex adapter journey tests pass locally.

This was written by Claude Code on behalf of max-sixty

…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
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.
@max-sixty max-sixty changed the title Run Leaf's Python with -I, so no hook hands itself back and forth until uv's recursion limit Start the detached server and handover reader with python -P, as bin/leaf runs Leaf Nov 20, 2026
@max-sixty
max-sixty merged commit d1004fd into main Nov 22, 2026
5 checks passed
@max-sixty
max-sixty deleted the uv-run-recursion branch November 22, 2026 22:04
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.

2 participants