Skip to content

fix: stop retaining native watchers for server maintenance - #4813

Merged
leaf-agent merged 2 commits into
mainfrom
fix/issue-4812
Oct 31, 2026
Merged

leaf-agent merged 2 commits into
mainfrom
fix/issue-4812

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Page servers held one or two native filesystem subscriptions for their whole lifetime, including after a background job finished. Server retirement, neighbor-row publication and the Claude Code prompt's page-list follower now use their existing liveness timers alone. A live Linux probe of a server with data/ found zero inotify instances; applying this change to the process mix in #4812 would remove the 50 server instances and 16 page-list instances reported there.

The tradeoff is update latency: neighbor rows and the prompt list now notice file changes on their two-second presence intervals (a row change reaching the prompt can cross both intervals). Server retirement still checks session ownership every second, and activity deadlines still shorten row waits. Between-turn delivery and explicit event followers retain native subscriptions. Background-job pages remain served and resumable.

Validation: both new regression tests failed before the fix and pass afterward, covering row updates, service withdrawal and claim retirement without allocating a native watcher. The 39 focused tests covering native delivery, server lifetimes, row publication and the Claude Code prompt band pass. Ruff and Python compilation pass. The live Pi journey passed setup, release/reply, mid-turn delivery, Escape, held Escape and quit. The live Claude Code journey could not run because its executable is absent, and both Codex journeys report that codex is absent from PATH.

Closes #4812 — automated triage

Use the existing liveness timers for row publication, server retirement and the harness page list. A retained page server consumes no native subscription; between-turn delivery and explicit event followers keep theirs. Neighbor rows and the prompt band now notice file writes on their two-second presence intervals, while activity deadlines still shorten row waits.

Regression checks prohibit watcher allocation while exercising row updates, service withdrawal and claim retirement. Both failed before the change. Update the reaper fixture to advance its timer rather than a subscription wait.

Closes #4812
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Fixed the ty failure in 920493a by asserting that the maintenance test's row and service records exist before reading them. The nine diagnostics reproduced before the fix; uv run ty check now passes. The maintenance regression test, Ruff checks and Python compilation also pass.

The pushed head is recorded for the queued review and landing workflows; this continuation leaves CI waiting to them under await_ci: false.

@leaf-agent
leaf-agent merged commit c5e6fb7 into main Oct 31, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-4812 branch October 31, 2026 05:41
max-sixty added a commit that referenced this pull request Nov 14, 2026
…ude -p` (#5835)

Thread titles and widget `generate` on a Claude Code page no longer
shell out to `claude -p` from the page server. The page server writes
the request into the claimant session's files in the state home
(`src/leaf/completions.py`). The session's pages follower lists it,
Leaf's hooks module runs `$.model.complete` with the session's own
client, and the reply comes back through `leaf hook --fork`. Titles get
faster. On the same 60 real thread requests, sent four at a time in one
window:

| | median | p90 | input tokens |
|---|---|---|---|
| `claude -p --json-schema` (main) | 3.1 s | 4.8 s | ~2,000 |
| `claude -p`, schema in the prompt | 2.1 s | 3.5 s | ~1,600 |
| `$.model.complete` through the module | 1.3 s | 1.4 s | ~300 |

The module row leaves out the relay through the follower. End to end,
the claude-code journey titled each thread in 1.2–2.6 s.
`$.model.complete` takes no answer schema, so the schema goes at the end
of the system prompt, and Python validates the answer. Haiku returned
valid JSON for every one of 452 title requests. On the widget builder,
every completed answer in the HTML arm parsed: 14 of 14, plus 1 request
that hit the time limit. The Leaf-catalog arm uses a nested `$defs`
schema, and there 57 of 60 parsed. The three failures dropped a key,
left a bracket unclosed, and repeated the whole object. Each of these
rejects `generate` rather than reaching the widget.

Things to weigh:
- **The follower's output is now `{"pages": [...], "completions":
[...]}`.** A running session's module stays at the version it loaded,
while its follower moves to the new Leaf. So after this lands, each live
session shows an error at every follower start, and its band and forks
stop, until `/reload-plugins`. A new session that selects a pre-change
checkout hits the same error the other way round. Listing completions
per page avoids that, but loses titles on a page the agent closed.
Leaf's Stage rule chose the new shape. Any session that doesn't reload
also loses its titles, since its module makes no completions.
- **A Claude Code title or `generate` now needs the claimant's Claude
Code process running.** Without one, the request fails after 60 s. An
active claim doesn't guarantee a process. The desktop app stops its
sessions to install an update after ten unfocused minutes, so those
sessions get no titles until the user reopens them; meanwhile each
thread shows its opening words, and `generate` rejects. A background job
retires its worker after an hour idle. The comment's wake probably
brings the job back inside the 60 s, but I haven't measured that. Max
kept the module and accepted this gap. The alternative was `claude -p`
alone with the schema in the prompt (the table's middle row), which
keeps working while a session is stopped and needs no relay. A fallback
that keeps both transports would cost more than either.
- A follower without forks now holds one native subscription, on
`sessions/`. It still holds none per page (#4813).

Two follow-ups are filed: #5954 asks whether a fork of the session
should title threads, and #5955 constrains the reply to the schema once
`$.model.complete` takes one.

Max asked for this. An independent reviewer read it twice, and its
findings are fixed in this branch. Focused tests pass, including the
module end to end through a 429 and a retry, and so does the real
`leaf-dev journey claude-code`.

> _This was written by Claude Code on behalf of max-sixty_
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.

Leaf holds most of a user's inotify instances, so other programs get EMFILE

1 participant