Skip to content

Wake a session no watch follows when a line turn lapses, however its line fork fares - #6592

Merged
max-sixty merged 2 commits into
mainfrom
wake-on-late-line
Nov 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
wake-on-late-line

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A thread message Leaf keeps back for a line fork goes to the main session when the line turn ends. When the line fork answers within 30 s, the hand-over nudges a session no watch follows; when it answers later or never, the line turn lapses, which writes nothing, and nothing nudged. A session whose turn its Stop hook closed and whose watch had gone (failed, or past its hook's timeout) then kept the message until its next prompt. An interrupted session was already woken at the lapse by the page server's interrupt nudge.

The page server's row producer already wakes at each transition the activity fold names, a line turn's lapse included. It now nudges at a transition whether the main turn was interrupted or closed (presence.nudge_interrupted becomes presence.nudge_left). nudge_unwatched still sends nothing to a session a watch follows, and at most one nudge per turn ending.

Worth weighing: this reverses a cost #6156 accepted ("A line turn that lapses nudges no one"). A transition that falls between a Stop and its watch taking the lease wakes the session twice, as input admitted in that moment already does.

Asked for in Max's session after a Codex review of #6574 found the gap; Codex also reviewed this diff.

Tests: a new model test fails on main and passes here; the in-time hand-over still nudges once; focused model and process suites pass.

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

…line fork fares

A thread message Leaf keeps back for a line fork reaches the main session when the line turn ends: by `forks._hand_over`, which nudges a session no watch follows, when the line fork answers within `activity.STARTING_GRACE` (30 s), or by the line turn lapsing. A lapse writes nothing and nothing nudged at it, so a session whose turn its Stop hook closed and whose watch had gone (failed, or past its hook's timeout) kept the message undelivered until its next prompt, whether the line fork answered late (`route` records `dropped`, "its line turn no longer runs") or never. This reverses a cost #6156 accepted with the log-held design, which the `forks.py` header recorded as "A line turn that lapses nudges no one".

The page's server now nudges at the lapse. Its row producer already wakes at each transition the activity fold names (`next_transition_at`), a line turn's lapse included, and already messaged an interrupted session for the input its turn left (`presence.nudge_interrupted`), which is why an interrupted session no watch follows was woken at the lapse before this change. That function becomes `presence.nudge_left(page_dir, at_transition=...)`: at a transition it nudges whether the main turn was interrupted or closed, where before it left a closed turn to the watch its Stop hook starts. `nudge_unwatched` still gates every send on no watch holding the lease and on one nudge per turn ending, so a watched session, and one the hand-over already nudged, hears nothing more. The producer skips the check on a page no live session claims. The line fork's own path is unchanged: in time, it posts the line and the hand-over nudges.

Accepted with it: a transition that falls between a Stop hook closing the turn and its new watch taking the lease wakes the session twice, as input admitted in that moment already does, since the watch doesn't read the nudge mark (a session may hold a nudge unread). Codex's review reproduced that ordering.

Designs weighed and rejected: a nudge in `route`'s late-answer branch, which misses a line fork that never answers, as after its module reloads mid-fork; a bound in the pages follower, the `BOUND_S` nudge #6156 removed, which would be a second clock beside the fold's; admission nudging a kept-back message at once, which wakes a main turn that finds nothing to deliver, then wakes it again at the hand-over; and delivering the message at once beside the line fork, which drops the keep-back #6574 kept.

On this machine, `fork_outcome` records show line forks dropped as "its line turn no longer runs" after 32.7 s, 52.4 s and 486.8 s.

Tests: `test_a_lapsing_line_turn_wakes_the_session_and_its_late_answer_writes_nothing` fails on main (no nudge at the lapse) and passes here; `test_a_line_hands_the_thread_to_the_session` now also checks that the in-time path nudges once, with the server's later transition sending nothing more. Focused model and process suites pass (forks, hooks, claims, wait, server lifetime, activity, clerk, and the Claude Code module and server process tests).
@max-sixty
max-sixty merged commit 3965c28 into main Nov 20, 2026
6 checks passed
@max-sixty
max-sixty deleted the wake-on-late-line branch November 20, 2026 17:24
max-sixty added a commit that referenced this pull request Nov 20, 2026
…de it (#6616)

A Claude Code thread message now reaches the main session at once,
delivered and nudged as any input is, as in Codex and Pi. The line fork
runs beside the delivery and posts the agent's working line when it
answers. Until now Leaf held the message from the session while the line
fork wrote, for up to 30 s.

Max chose this on 20 Nov 2026. The hold came with #6156, when the line
fork also judged whether a working fork should take the message, and the
session had to wait for that judgment. #6574 removed the judgment, which
left the hold buying only that the line went in before the session's own
words. This reverses the decision `forks.py`'s header recorded, and
deletes the hold and everything that existed only for it.

## What holds now

- **Which messages get a line fork.** The pages follower lists one for
each *round*: an open thread whose waiting messages have nothing of the
agent's after the oldest of them, read as the round stood when its
newest message arrived. A message that joins a round before its line
gets a line fork about all of them. One that joins after the agent spoke
in the thread gets none. The follower lists only rounds newer than its
first look at a page, and the module runs each id once, so a round gets
at most one line fork, across a module reload too.
- **When the line goes in.** Only while its round still awaits it: the
thread's waiting messages are the ones the line fork read, and the agent
has said nothing there since, by a message or a rewrite. Leaf checks
this under the lock the append takes (`thread.Receipt`'s `fence`), so a
line never lands after the session's words, nor speaks for a round a
later message joined. A line that fails the check is recorded as
`dropped`.
- **On it.** Waiting messages read On it once the line stands, until the
session answers, as before. Before the line lands they read as their
delivery does: Queued, then Delivered.
- **The summary fork** still runs beside each listed round, even where
the agent spoke first. A delivery leaves the summary hint to it by the
same reading.

## Deleted

`holding.py`, line turns (`state.AGENT_TURNS` and its helpers), the
`held` pickup phase, `activity.STARTING_GRACE` and the lapse, #6592's
lapse nudge, admission's keep-back, the hand-over, the follow-up that
replaced a line turn, delivery's branch for input a line turn kept past
the cursor, `fork-holds-thread`, and `leaf page state`'s `holder`.
Production code nets −1,079 lines, tests −874, `leaf-dev` −119.

## To weigh

- The page protocol moves to 53, because the pickup's phases lose
`held`.
- For the second or two before the line lands, a message reads Queued or
Delivered rather than On it.
- A message the user sends before the pages follower first reads the
page gets no line. As before, the session gets it anyway.
- Whether a delivery carries the summary hint now turns on whether the
follower holds the session's lane when the delivery is built
(`forks.lane_up`), rather than on a record in the log.
- `leaf-dev eval run 'line-fork*' --base` can't compare across this
change, since its scripts call the new `forks.look` under the base arm's
Leaf too.

How it works' Forks tab describes the new flow, and its "Anatomy of a
fork journey" is re-recorded from the journey run on this branch.

Also fixes two tests #6573 left failing on main: the third delivery that
`evals/beside-work-goes-to-a-fork` pastes moves to `leaf-delivery/52`,
and
`test_an_agent_reply_can_remove_a_subject_and_detach_its_open_thread`
expects the thread's new `rewritten_from`.

Tests: model and process suites for the touched modules pass. New tests
cover delivery at once, a joining message, the agent speaking first
(answer, message, progress, rewrite), the race under the lock, a
repeated step, and the summary fork's ownership. Each new guarantee has
a test that fails without its fix. `pnpm run check` passes. `leaf-dev
journey run claude-code` passed all 14 steps on the final code. The line
was in the thread 1.6–2.0 s after each message (the line fork itself
took 1.3–2.0 s), and an idle session's prompt took a message 0.2–0.4 s
after it was sent. Before this change it waited for the line. Codex
reviewed the change and then its fixes. It found three gaps, each fixed
with a test that fails without the fix: a rewrite of the agent's own
answer didn't stop a late line, the agent's progress could leave a long
thread's summary with no owner, and a second rewrite could list a round
again.

> _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.

2 participants