Skip to content

Every delivered batch costs a wait restart, so re-arming is easy to forget #70

Closed

Description

@max-sixty

leaf wait prints one batch and exits, so a session holding a page runs wait, reads, acks, replies, and starts another wait, once per batch. A session that forgets one restart goes deaf until something reminds it.

That it is forgettable is already visible in the shape of the docs. The conversation loop has to restate it after the batch, and a whole reference exists for keeping a wait held open across turns, opening: "A Codex watcher keeps a Leaf wait active after the page's task ends its turn."

What I would expect

leaf ack re-arms the wait it just acknowledged, so acknowledging a batch asks for the next one. The two are adjacent in every correct loop, and ack is the step that cannot be skipped.

The exit itself is load-bearing and worth keeping: it is how what the user said reaches a turn-based agent at all. The ask is only that re-arming not be a separate thing to remember.

Seen on leaf 5db3e8f.

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

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. leaf-agent commented on Aug 27, 2026

    @leaf-agent
    Collaborator

    Two things from the code that bear on the shape of this.

    The reminder already exists, but only at a turn boundary. A session that forgets the restart isn't deaf until a human notices — the Stop hook's unattended_pages reports <page>: no watcher. Start `leaf wait` as a background task… for any page this session holds that isn't idle and has nothing listening, and UserPromptSubmit reads the same reasons so the debt opens the next turn too. What it can't do is catch the gap within a turn, and it costs a blocked stop plus a round trip to recover. So the failure is bounded rather than silent, which makes this a cost-and-forgettability argument rather than a correctness one — but the cost is real and paid on every batch.

    Ack's page argument is already the right argument for the wait it would re-arm. Watch.pages() adds a named page to the session's owned set rather than narrowing to it, so cmd_wait(page_dir) called from inside cmd_ack builds the same watch a bare leaf wait builds inside a host session, and the page-scoped watch a bare shell wants outside one. The two grains — per-page ack, session-wide wait — don't actually collide.

    The friction I'd expect is in the exit status. cmd_ack returns nothing today, so exit 0 means the cursor advanced; cmd_wait returns 2 for three unrelated things, and the one an ack would meet most is "an earlier wait of this session's still holds the watch — leave that one running". Folded together, a successful ack reads as a failure whenever a previous wait is still live. What de-risks it is that ack is already monotonic and idempotent (if seq > page.cursor), so retrying after a wait-side non-zero costs nothing — but the two facts still want separate spellings on the way out.

    The other thing that moves is where the wait sits relative to the work. Today it's ack → working → address every event → next wait; re-arming inside ack puts the wait in front of the processing, so a batch can land while the previous one is still being answered, and cmd_wait flips status to working: picking up N updates over whatever the agent set for the work it's mid-way through. On Claude Code a background wait can already complete mid-turn, so it's a widened window rather than a new shape — but the status flip is a second writer to a line the agent just wrote.

    Worth noting that codex-watcher.md step 4 is already literally "run leaf ack <page> <highest-seq>, then start the next wait" — the one place the pair is written down as inseparable, and the one caller that would collapse to a single step.

    Sources
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions