Skip to content

Pages follower opens an inotify watcher for a session that owns no page, and dies when the user has none left #3490

Closed

Description

@max-sixty

What happens

The pages follower (leaf hook --harness claude-code --if-claimed --pages) exited 1 at the end of a turn with watchfiles' error Error creating recommended watcher: Too many open files (os error 24). Claude Code showed a notice beginning "Leaf: the pages follower exited with code 1:", followed by the traceback. It happened on a Linux host where the user's inotify instances had run out. The kernel caps them per user (fs.inotify.max_user_instances, 128 by default), and each watchfiles watcher takes one. More than 100 concurrent Claude Code sessions of the same user, plus Leaf's own page servers and watches, had taken all of them.

The session owned no page (owned_pages was empty). It held only kept claims, from a generation that had ended. The launcher's --if-claimed gate still passes, because holds_claims counts kept claims, which the prompt and resume hooks read for reconnect notices. So the follower starts. cmd_pages then subscribes to rows/ and the session's claims directory before it reads which pages the session owns. Had the subscription succeeded, the follower would have printed [] and exited. cmd_watch already checks owned_pages before it subscribes.

A session left holding only kept claims therefore starts uv and opens an inotify instance at its start, at every turn start and turn end, and after every leaf Bash call. Each of those runs fails while the user's instances are exhausted.

Expected

cmd_pages reads the session's owned pages first, and prints [] and returns without a watcher when there are none. Separately, the launcher could gate the follower on active claims only. The prompt and resume hooks need the current gate, because they read kept claims to send reconnect notices.

Repro

On Linux, from the plugin root:

  1. Take a Claude Code session that holds only kept claims. Mine was a Claude Code background job. Its lifecycle record holds a new generation with "lifetime": {}, which prompt_turn writes after a generation ends. SessionEnd keeps a generation whose lifetime names a job (state.end_harness_instance), so this one was probably recorded without the job. I haven't confirmed that, and it may be a separate bug. session-lifetime.md ("Turns and generations") describes one way to reach this state, a resumed process-backed session; I haven't tried it.
  2. Pipe {"session_id": "<that session>", "hook_event_name": "Stop"} to .venv/bin/python -S skills/leaf/scripts/leaf/state.py hook-gate. It exits 0.
  3. Pipe the same payload to .venv/bin/python -m leaf hook --harness claude-code --if-claimed --pages under strace -f -e trace=inotify_init1. It calls inotify_init1 once, prints [] and exits 0.
  4. Run step 3 while the user's inotify instances are exhausted. It exits 1 with the error above.

I ran steps 2 and 3. I didn't run step 4: the failure above came when the hooks module started the follower at a turn end while the user's instances were exhausted.

Seen on leaf a69bf53, installed 2026-10-20T18:07:46-07:00.

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

Activity

  1. added
    bug
    on Oct 21, 2026
  2. leaf-agent commented on Oct 21, 2026

    @leaf-agent
    Collaborator

    The regression is fixed in #3492. A session holding only kept claims now prints [] without opening a watcher. The new test reproduced the watcher construction on the previous code and passes with the fix; the PR's checks are green on the pushed commit. Tend's landing run is handling the merge decision.

  3. added a commit that references this issue on Oct 21, 2026
    c060d6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions