Skip to content

Ask the log which drafts were sent, and save leaf.page's drafts when a container stops - #6213

Merged
max-sixty merged 3 commits into
mainfrom
drafts-approach-review
Nov 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
drafts-approach-review

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A review of how Leaf keeps drafts since #6124. The model stays: drafts live on the page's server outside the log, and tabs hear them through the news look. Two places where the drafts store kept a weaker copy of something another part knew change.

  • The log answers which drafts were sent. The store no longer remembers the last 64 sends; it asks the log through event_log.admitted_attempts, an index each server process keeps over the append-only log, about 20 µs a question on any log. The first reading or write after a send settles its draft and moves the drafts version, so admission no longer touches the store, and sent words can't come back however many sends came between or wherever the server stopped. The browser stops walking every event of the session on each draft lookup.
  • leaf.page saves drafts when a container stops. Each page whose drafts moved since its last publication is published from the stop handler, so words typed since the last send survive the 10-minute sleep. The handler closes the listening socket first.

To weigh: a /api/news or /api/drafts read now writes drafts.json once after a send. The drafts and website-publication records move to format 46. A Cancel in one tab can still be undone by another tab's closing write that lands after it, left as too narrow for a mechanism.

Max asked for the review. Codex reviewed twice; its two findings are fixed. Tests: tests/process/test_drafts.py and tests/process/website_server/test_saved_records.py gain a case each, failing before; the drafts browser tests pass.

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

The drafts store kept the last 64 admitted attempts beside the drafts, a bounded copy
of what the log already records, so sent words could come back as a draft when a tab's
late write waited out 64 later sends, or when the server stopped between admitting a
send and settling its draft. The store now asks the log: a generation whose attempt
the log admitted is settled. The first reading or write after a send drops it and moves
the drafts version, so every tab hears it at its next look, and a late write of it
settles it. Admission no longer touches the drafts store (`settle_sent` is gone), so
no stop between the two can leave sent words standing.

`event_log.admitted_attempts` keeps each page's admitted attempts in the server process
and reads only what the log gained since the last question, through the place-in-log
reader `follow_events` now shares (`_Tail`): about 20 µs a question on any log, where
parsing `leaf-dev bench`'s largest log takes 54 ms.

The browser no longer asks the log too (`attemptAccepted`, which walked every event of
the session on each draft lookup): the server's drafts never hold a sent generation.

The drafts record drops `sent`, so its format moves to the current protocol, 46.

Behavior changes: a late write of sent words, or a store left holding them by a
stopped server, settles them however many sends came between. Tests:
`test_the_log_settles_every_generation_it_admitted` replaces the 64-send test and
fails on the previous store; `test_admitting_a_send_settles_the_generation_it_carries`
now also checks that the news version moves.
Drafts change no page reading, so a commit published them only beside a change of its
own: a visitor's words typed since their last send were lost when the container slept
after ten idle minutes with no tab left to give them back, and a tab opened while it
slept showed the drafts as of that send. A container now publishes each page whose
drafts moved since its last publication as it stops (`storage.save_drafts`, from the
stop handler, once serving has ended), so the next container restores them and the
saved answers show them. The handler closes the listening socket first, so a request
arriving during the save is refused at once, as after the process ends, rather than
waiting on a listener nothing serves.

Each publication records the drafts version it carried (`website-publication`, now at
format 46), so a stop publishes only pages whose drafts moved; a page restored with
drafts and not published since is published again, which costs only the stop. Commits
keep publishing on their reading alone, so a draft written during an agent turn adds
no publication to each tool call's transaction.

Behavior change: drafts survive a container's sleep or replacement; a container lost
without a stop, or a page store unreachable at the stop, loses the words typed since
the last save. Test: `test_a_stopping_container_saves_the_drafts_typed_since_the_last_commit`.
@max-sixty
max-sixty merged commit 48ee07f into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the drafts-approach-review branch November 16, 2026 22:45
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