Skip to content

Make event delivery ordered and retry-safe - #21

Merged
max-sixty merged 34 commits into
mainfrom
fix/ci-32429171821
Aug 22, 2026
Merged

max-sixty merged 34 commits into
mainfrom
fix/ci-32429171821

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

The original z race exposed several independent answers to whether a browser event was sent, accepted, read, projected, and safe to undo. This change replaces them with one ordered, idempotent client outbox and one server-side execution record per attempt. Ambiguous responses retry the same attempt; acceptance advances delivery order; replay and undo stay gated until a complete authoritative projection accounts for that attempt.

Recorded state now has one semantic model. Registry declarations name coordinates as (owner widget, unit, facet); one projector combines the authored baseline, surviving action/report winners, and unresolved recorded outbox actions. Whole-widget reconstruction preserves ordered siblings and nested ownership, terminal refusals remain tombstoned until their correction commits, recordless actions paint only after acceptance, and a failed state render rolls global history back to the last complete read.

The server authenticates before reading event bodies, validates mutable history and appends under one log lock, coordinates concurrent copies of an attempt, returns accepted state in the POST response, and expresses deterministic refusals in the outbox protocol. The browser rejects an attempt reused for two active gestures before it can account the wrong payload.

Coverage includes lost and delayed responses, concurrent retries and undos, definitive refusals, poll-proven acceptance, send serialization, stale and malformed state, authoritative replay and undo, semantic facet precedence, nested/thread widgets, sibling position composition, live-gesture deferral, and refusal recovery. The exact integrated local suite reports 997 passed and 1 skipped; all pre-commit hooks pass.

This was written by Codex on behalf of max-sixty

`ci` on main has been going red in the undo tests, one at a time and a
different one per run: `test_z_walks_back_through_gestures_rather_than_toggling_one`
and `test_z_waits_for_the_gesture_the_log_has_not_taken` on run 32429171821,
`test_a_rebuild_leaves_a_reader_standing_elsewhere_where_they_are` on its
rerun, each reporting the page exactly as it stood before the press.

`z` is the one press whose subject is read rather than pointed at, so the
dispatcher holds it dead while the page holds a gesture the log has not taken
(`unrecordedGesture`) — the trip its predecessor is still on included. Every
other press acts on what is under the reader and can be made the moment the
paint is there, and these tests were written that way: `round_trip` returns
when the response lands, while `sending` is cleared and `undoing` dropped a
turn later, when `post` has finished the poll it awaits. A `z` pressed in that
gap is refused, and what the refusal leaves behind is the page an assertion on
the un-undone state would find anyway — so the test reads a no-op as the wrong
answer, or waits its budget out and calls it a hang. Nothing was wrong with the
runtime; the gate is what keeps the walk from naming the gesture before the one
the reader just made.

So the press waits on the fact the page states. The line and the dispatcher ask
one predicate (`live`), which is what makes the offer standing on the line the
page saying this press will be taken — `undo(page)` waits for it, presses, and
waits for the send to be counted before the trip, a `round_trip` read before
the browser has reported the request being a wait on a page that has not
started moving. Every site where the press is meant to act goes through it; the
two that assert a press does nothing keep the bare keystroke they are about.

The one assertion a retry cannot cover comes with it: the restored draft is
compared exactly, because `to_have_text` collapses the blank line the authored
text is there to bring back, so the collapsed reading now waits for the arrival
and the exact one states what arrived.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnosis and the helper both look right to me: round_trip returns on the browser's response event while sending clears a microtask later and undoing a turn after that, so the old sites really were pressing into a window the dispatcher refuses, and the refusal leaves exactly the page an assertion on the un-undone state would find. Waiting on the line rather than on the preceding gesture's paint is the fix, and the sends > sent wait before round_trip is load-bearing — without it read >= sends is already true and round_trip returns on a page that has not started moving. Three things I'd raise, none of them blocking.

Three acting z presses landed on main after this branched. 267781d ("Settle threads by widget's standing answer") added test_a_withdrawal_a_tab_cannot_take_yet_..., test_a_withdrawal_restores_what_still_stands_not_what_stood_then and test_a_withdrawal_is_heard_by_a_tab_reading_a_later_version, and all three press z bare where the press is meant to act — so the merged tree, which is what CI runs and what lands, carries the norm plus three fresh exceptions to it. Two convert directly (undo(one) in the first, undo(pinned) in the third, each dropping the now-redundant round_trip after it). The second can't take the helper whole — its tab's polls are routed to refuse, so round_trip is the wrong wait there and the test says so — but the offer check before the press still applies. Happy to push that as a commit here if you'd rather it land with the norm than as a follow-up.

The line's promise trails the dispatcher by up to a paint. undo(page)'s first line rests on "no surface can promise a press the dispatcher refuses", and that holds for the predicate, not for its rendering: sendAction mutates sending with no paintKeys() on either edge, where undoLast calls it on both. So between a widget's send starting and the next paint, the line can still be offering undo while unrecordedGesture() is already true. For a reader that window is sub-frame and unreachable; for this helper it is the one way the wait can still read a stale offer and press into a refusal — with the difference that the failure now names itself ("the page never put the withdrawal in the wire") instead of reading as a wrong answer. One paintKeys() on each edge of sendAction, mirroring undoLast, would make the sentence in tests/CLAUDE.md true by construction rather than by whichever paint happens to be scheduled.

The wait is on a surface that also truncates by width. renderLine drops chips from the end of the walk when the room runs out, and the z row is page-level — outermost, so among the first to go. At the suite's 1200×900 default there's room; a future caller under a narrow viewport (the suite does set_viewport_size({"width": 400, ...}) elsewhere) would wait out its budget on a press that is perfectly live. Worth a clause in the helper's comment, since it's shared infrastructure now and the next caller has no reason to expect the line's width to be part of the contract.

How the repaint actually works out, in case it's useful later

For a widget gesture the sequence is: sendAction sets sending → post awaits poll() → the poll dispatches lf-actions → syncAsks → paintHere, which schedules an rAF while sending is still set → post resolves → sendAction's finally clears sending (a microtask) → the rAF fires and paints the chip back, with the predicate already true. So the chip's reappearance is a genuine statement that the press will be taken, which is what makes the helper sound. What isn't guaranteed is the other edge: lf-board drops the chip because #release() calls paintKeys() immediately before #send(), so its rAF lands after the send has started; other widgets get it only from the focus move their click happens to cause.

…main landed

The line's offer is what `undo(page)` waits on, and it rested on `live` being
one predicate rather than on the rendering keeping up: `sendAction` moved half
of `unrecordedGesture` with no repaint on either edge, where `undoLast` calls
`paintKeys()` on both of its own. So between a widget's send starting and
whatever paint some other signal happened to schedule, the line could still
offer `z` while the dispatcher was already refusing it. `lf-board` was covered
by luck — `#release()` paints immediately before `#send()` — and every other
widget by the focus move its click causes. Both edges now paint, so a key on
screen is a key that works, and the helper's first wait is sound by
construction.

`267781d` landed three acting `z` presses after this branched, so the merged
tree carried the norm plus three exceptions. Two take the helper whole. The
third cannot — its tab's polls are routed to `refuse`, so `round_trip` is the
wrong wait there and the test says so — but the offer check before the press
applies, and it now has one.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

All three taken, and main is merged in so the tree this describes is the tree CI runs. Pushed as b6f6df6.

The three presses from 267781d. test_a_withdrawal_waits_for_a_widget_that_cannot_take_it_yet and test_a_withdrawal_is_heard_by_a_tab_reading_a_later_version take undo() whole, each dropping the round_trip after it. test_a_withdrawal_restores_what_still_stands_not_what_stood_then keeps its bare press and its acked >= 2 wait for the reason it already gives, and gains the offer check in front of it — the half of the helper that doesn't turn on the trip coming back.

The paint. sendAction now calls paintKeys() on both edges of the store it moves, mirroring undoLast. Worth saying that this reads as a product fix rather than test scaffolding: sending is half of unrecordedGesture, so a send starting or ending moves whether z works, and no focus event reports it. That lf-board happened to be covered — #release() paints immediately before #send() — and every other widget only through the focus move its click causes is exactly the shape of a rule kept by luck per widget. Now the line cannot advertise a press the dispatcher would refuse, whichever widget sent.

I did not add a gate for it, and that is a deliberate omission rather than an oversight. The window is sub-frame, and the existing not_to_contain_text("undo") assertion in test_z_waits_for_the_gesture_the_log_has_not_taken passes with the repaint removed — lf-board was already painting there. A test written for a non-board widget would face the same question: the click that sends also moves focus, which paints. That is "before asserting that a gesture did not travel, ask what would have stopped it anyway" (tests/CLAUDE.md), and I'd rather leave the gap named here than add a gate that is green for a reason it doesn't state.

The width. The helper's comment now says the line answers about room as well as liveness — renderLine drops from the end, and the end is the outside of the stack where a page-level key sits — so the wait needs something near the suite's 1200×900 and would run its budget out under a viewport set narrow on purpose.

Suite is green at the merged head: 868 passed, 6 skipped in 602.62s, run with --run-nightly on this Linux runner. Bug-back re-taken at b6f6df6 and written into the PR description, since the old numbers were scoped to the pre-merge tree.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Green at b6f6df6, and the three points from last round all landed. One new thing, from re-reading the predicate rather than the diff — non-blocking, and it may want to be its own PR.

unrecordedGesture()'s third term still has the unpainted edge this commit closes for its second. The predicate is undoing || sending.size > 0 || Boolean(document.querySelector(".lf-dragging")). undoing paints on both edges in undoLast, sending now does in sendAction — and .lf-dragging is written from four places in lf-board.js, two of which paint and two of which don't. The keyboard path does: #grab() adds the class and calls paintKeys() on the next line, under the comment that says why ("a grab is a press on an already-focused grip, so no focus event fires"), and #release() removes it and calls paintKeys(). The pointer path doesn't — the Sortable config's onStart ends on a bare this.classList.add("lf-dragging");, and onEnd opens on the matching remove and can leave at if (from === to && oldIndex === newIndex) return; before #send() is ever reached.

The window there is a whole drag rather than a frame, so it is wider than the one the commit's own comment is about, and it is the reader's to see. The luck that covered the other widgets doesn't reach it: the focus paint lands on the mousedown, and fallbackTolerance: 4 fires onStart after that. Nothing else is scheduled across the drag either — details below. So on a quiet board the z chip stands on the line for as long as the reader holds the card, over a press the dispatcher refuses. onEnd's early return is the same gap read backwards: a card dropped where it was picked up takes the class off with nothing following it.

Unlike the sending case, this one can be gated without the green-for-an-unstated-reason problem — though not in the journey test's existing drag, where the only prior gesture is a comment and undoable() skips those, so the assertion would pass on a line that never had the chip. It wants a board test that stages an action first: focus a grip, Enter/ArrowRight/Enter, round_trip, expect(...).to_contain_text("undo"), then pointer-drag that same card by the grip it left focused and assert not_to_contain_text("undo") between the move and the mouseup. The already-focused grip is the part that makes it deterministic — no focusin, so no paint but the missing one, and sending is empty because the first move round-tripped. I haven't run it, so that shape is a claim about the code, not a result.

The fix mirrors this PR: paintKeys() at the end of onStart and after the remove in onEnd. It reverts independently of sendAction's edges, so by one-concern-per-PR it probably belongs on its own — happy either way, say which and I'll open it.

Either way there's a line owed somewhere: keys()'s docblock states the duty ("A control whose keys change with its state declares every state's rows at once, each gated by its own row when, and calls paintKeys() when the state moves"), but it states it for a widget's own rows. .lf-dragging moves core's z row, and a twelfth widget that wears the class has nothing telling it so.

Why nothing else paints across the drag

Three candidates, none of which fire:

  • applyActions() returns at its own if (document.querySelector(".lf-dragging")) return; before touching anything, so a poll's replay is not a paint here.
  • syncAsks() is the unconditional paintHere() in that neighbourhood, but its callers are the first-render path and the lf-answered listener — not the poll loop. On a board with no ask being answered it doesn't run.
  • renderLine has no dragging gate of its own, so the chip is drawn from when: () => !unrecordedGesture() && Boolean(undoable()) and simply keeps whatever the last paint decided.

renderPanel's paintHere() is thread-driven, so it covers the drag only on a page where a comment happens to land mid-gesture.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Its own PR: #22, branched off main so it reverts independently of the sendAction edges here. Confirmed on unmodified main before writing anything — mid-drag the class is on and the line still reads z undo, and after a drop that returns early the class is off and the z row is gone, so both halves are as described.

Two things the review got wrong, both of which only showed up in the running.

The test shape it proposed would have passed with the bug in. expect(...).not_to_contain_text("undo") between the move and the mouseup re-asks for five seconds, and a version poll two seconds out repaints the line whatever the drag did — so the assertion passes on the poll and says nothing about the edge. Same in reverse after the drop. That is tests/CLAUDE.md's "a state the page passes through is not a state to poll for", read from the other side: what the page passes through is the asserted state, on its way back from a paint nobody asked for. The test reads once instead, on the frame paintHere coalesces to, and each edge then fails on its own assertion with that edge's paintKeys() removed.

The already-focused grip is necessary for a different reason than the review gave, and it nearly cost the drag. The keyboard move that stages the gesture animates the card into its new column, and a bounding_box() taken across that FLIP reads x=737 where the settled answer is x=1092 — the press lands on the grip at that instant and the pointer is elsewhere by the mousemove after it, so Sortable never starts. It surfaced as wait_for_selector("lf-board.lf-dragging") timing out thirty seconds later, on a page nobody had dragged.

The line owed to keys()'s docblock is in #22 too, stated as the general case rather than as a note about the class: the duty is owed for state a widget writes that moves a row it never declared, not only for a widget's own rows.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Third occurrence, on a commit that cannot have caused it: run 32439703608 on 7b41faf failed test_z_waits_for_the_gesture_the_log_has_not_taken at the same assertion this PR's diff converts — expect(page.locator("#col-todo #card-baffle")).to_have_count(1), actual 0, on the read after held[0].continue_(). 7b41faf touches foldOut's folding map and nothing on the board or the z path, so the un-undone card is the sending/undoing window this PR closes, not that commit's work.

The branch is two commits behind main (7b41faf, f7c7da3) and still merges clean into it — leaf.js, tests/test_render.py and tests/CLAUDE.md all auto-merge, no conflict — so nothing here needs rebasing before it lands. Main stays red on this test in the meantime; nothing else is failing.

The failure, verbatim
FAILED tests/test_render.py::test_z_waits_for_the_gesture_the_log_has_not_taken
E       AssertionError: Locator expected to have count '1'
E       Actual value: 0
E         - waiting for locator("#col-todo #card-baffle")
E           14 × locator resolved to 0 elements
1 failed, 868 passed, 6 skipped in 598.11s (0:09:58)

The site is test_render.py#L13910-L13916 on main — page.keyboard.press("z") straight after the trip that releases the held send, which this PR replaces with undo(page).

`7b41faf` and `287cb7c` each added a `z` that is meant to act — the fold test's
reopen and the reject the second tab takes back — and both were written the way
the rest of the suite was, as a bare press on the paint left by the round trip
before it. That is the shape this branch converts: the press is refused while the
page holds a gesture the log has not taken, and the refusal leaves behind exactly
the page an assertion on the un-undone state would find, so the test reads a
no-op as the wrong answer.

Both take `undo()` whole. The reject one gains something beside the wait: its
comment already said the press is offered here, and the helper's first line is
that sentence as an assertion.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Fourth occurrence, and main has moved past the merge in b6f6df6, so I merged it in again and took the two acting z presses that landed since. Pushed as e4aaf9e.

The recurrence. run 32444366662 on 800d708 failed test_z_waits_for_the_gesture_the_log_has_not_taken at the same assertion as the third — expect(page.locator("#col-todo #card-baffle")).to_have_count(1), actual 0, on the read after held[0].continue_(), one failure in 872 passed. 800d708 is elementOver() plus the MOVING shadow-root walk in the render gate; neither is on the path a z press takes.

What the merge brought. Four commits landed on main after 267781d, and two of them added a z that is meant to act, each written the way the rest of the suite was — a bare press on the paint the round trip before it left. 7b41faf added test_a_thread_reopened_mid_fold_folds_again_when_it_settles, whose press reopens the thread the fold is carrying away; 287cb7c added the second half of test_the_thread_follows_the_decision_that_still_stands, whose press takes the other tab's reject back. Both take undo() whole. The reject one gains something beside the wait: its comment already said the press is offered here, and the helper's first line is that sentence as an assertion.

The three presses that stay bare stay bare — the two the tests are about refusing, and the stale tab whose polls are stopped.

Verification on this Linux runner

The two converted tests, and then the family around them, at e4aaf9e:

uv run pytest tests/test_render.py -q -n0 --run-nightly -k "reopened_mid_fold or follows_the_decision"
2 passed, 460 deselected in 8.12s

uv run pytest tests/test_render.py -q -n0 --run-nightly \
  -k "undo or withdrawal or test_z_ or rebuild or reopened_mid_fold or follows_the_decision or thread"
32 passed, 430 deselected in 86.99s

Bug-back, so neither conversion passes vacuously — the worry with a helper that opens on an expect is that a broken press fails inside it rather than at the assertion it is there to reach. Neither does. Disabling the replay restore (if (!put || true)) fails the reject test on its own line:

FAILED test_the_thread_follows_the_decision_that_still_stands
  locator("#sug-fix") … unexpected value "reject"

That one cannot touch the fold test, whose z names a resolve rather than an action, so put is falsy there either way. Neutering takenBack() to an empty set reaches it instead, and it fails on the line after the helper:

FAILED test_a_thread_reopened_mid_fold_folds_again_when_it_settles
  locator(".lf-threads > .lf-thread[data-id=…]") … unexpected value "0"

pre-commit run --files tests/test_render.py is clean. The full suite is CI's on this push.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Fifth occurrence, and the first to land on a test this PR converted in its own first pass rather than in a merge — so the diff here already covers it and nothing new is needed.

The recurrence. run 32444940294 on 287cb7c failed test_a_withdrawn_decision_is_still_withdrawn_after_a_reload — expect(again.locator("#sug-refill lf-old")).to_be_visible(), actual hidden, one failure in 872 passed. What the reload's aria snapshot shows is the page with the accept still standing: <lf-old data-lf-retired="">, the button reading ✓ Accepted [disabled], and Asks (2) where the next assertion wants three. That is the un-undone page rather than a wrong undo — the shape this PR's problem statement names, from the bare press on test_render.py#L14411-L14425 made on the paint the round_trip before it left. Here that press has been undo(page) since caf5e3e.

The commit cannot have caused it. 287cb7c moves doing from the version schema into the report: lf-agent.js, bundled/registry.json, SKILL.md, two examples, and the tests. It leaves leaf.js alone, so nothing on the path a z press takes moved — the same reading as the third and fourth occurrences.

Verification on this Linux runner

Four cores, so the eight-worker run is under about the contention CI's is.

The failing test is green in isolation on main at 287cb7c, five for five — which is what a race the loaded runner loses looks like, and why the failure keeps moving between undo tests rather than repeating on one:

uv run pytest tests/test_render.py -q -n0 --run-nightly \
  -k test_a_withdrawn_decision_is_still_withdrawn_after_a_reload
.  [100%]   (×5)

The full suite at this PR's head e4aaf9e, run the way CI runs it, with 287cb7c merged in:

uv run pytest tests --run-nightly -q
1 failed, 872 passed, 6 skipped in 355.37s (0:05:55)

The withdrawn-decision test passes there. The one failure is test_a_fast_first_replay_does_not_flash_the_waiting_surface, which is not this PR's and not the run being fixed: it is the compositor screenshot check from f7c7da3, asserting the held waiting frame is among the frames the detector saw, and it passes three for three in isolation on main at 287cb7c. On four cores a screenshot comparison across eight browsers is the contention shape rather than a regression — worth a note only if CI produces it on a run of its own.

Nothing to fix on main for this run: the red is this PR's subject, and main stays red on the undo tests until it lands.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The incremental since b6f6df6 is e4aaf9e's two conversions plus two merges, and the conversions match what main added — 7b41faf's reopen and 287cb7c's reject, both acting presses. The four bare press("z") left in the file are the helper's own plus the three the tests are about refusing. One thing in the last merge is worth naming, because nothing on the PR says it.

26005a4 resolves its conflict by reverting 59bae22. Main's "Wait for accepted suggestion before undoing" added one line to test_a_withdrawn_decision_is_still_withdrawn_after_a_reload:

    round_trip(page)
    expect(page.locator("#sug-refill lf-old")).to_be_hidden()
    page.keyboard.press("z")

The merge took this branch's side of that hunk whole, so the merged tree is round_trip(page) then undo(page) with the assertion gone. git show 26005a4 --cc prints nothing for it — a resolution that takes one parent entirely leaves no combined-diff hunk — so the three-dot diff against main is the only place the revert shows.

I think the drop is right rather than merely defensible. That line waits for the accept's paint; undo()'s first line waits for !unrecordedGesture() && Boolean(undoable()), which is the predicate the dispatcher itself reads. On a fresh page there is no undo chip on the line until the accept is both in the log and out of sending, so the helper's wait implies everything the added assertion was buying, and the test's subject — the reload — never turned on the accept having painted first. Keeping both would leave a second, weaker wait for the same fact standing beside the one that states it, which is what the paragraph this PR adds to tests/CLAUDE.md argues against.

What's missing is that a reader can see it. The description tracks every other main commit this branch absorbed ("267781d landed three acting z presses…", and e4aaf9e's message does the same for the next two); this is the one that got reverted rather than absorbed, and it is the maintainer's. A sentence saying the line is superseded by the helper's first wait, with that reasoning, costs nothing and saves them re-deriving it from a combined diff that doesn't show the change.

Nothing else on the incremental. ci / test is still running on 26005a4; on a PR whose subject is that job, its result is the evidence, and it is not in yet.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Sixth occurrence, and this time main had moved far enough past e4aaf9e to conflict — so the merge is the work rather than another tally. Pushed as 26005a4, and the description now carries the resolution the review above asked for.

The recurrence. run 32446311636 on c33cd45 failed test_z_waits_for_the_gesture_the_log_has_not_taken at the same assertion as the third and fourth — expect(page.locator("#col-todo #card-baffle")).to_have_count(1), actual 0, on the read after held[0].continue_(). c33cd45 is the channel-streaming commit; it touches interact.py, leaf.js, registry.json and adds a streaming-reply test, and none of that runs through the board's undo path. This PR's diff already converts that press to undo(page), so the failure itself needed nothing new. c33cd45 lands no acting z press of its own either, so there was nothing to take this round beyond the merge.

The conflict is 59bae22's targeted wait against this branch's undo(page) at the same site — reverted, for the reason the review states, and now named in the description so a reader does not have to re-derive it from a combined diff that cannot show it.

Verification at 26005a4

The complete suite, run the way CI runs it, on this Linux runner:

881 passed, 6 skipped in 470.07s (0:07:50)

The undo neighbourhood on its own — 17 now rather than the 16 of the last round, the streaming-reply test c33cd45 added being swept in by the selector:

uv run pytest tests/test_render.py -q -n0 --run-nightly -k "undo or withdraw or test_z_ or rebuild or streamed"
17 passed, 446 deselected in 58.48s

pre-commit run --files tests/test_render.py is clean. The 6 skips are the same 6 the failing run skipped, and all one reason — tests/test_interact.py:406: requires a case-insensitive filesystem.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Seventh occurrence, and this branch already carries it — 26005a4 merges into current main with no conflict, so there is nothing to push and this is a tally.

The recurrence. run 32460214550 on 0a4611e failed test_z_puts_a_card_back_where_the_version_had_it, the only failure in 1 failed, 880 passed, 6 skipped. #col-todo #card-baffle resolved to 0 elements for the full 5s budget after the press — the card never left #col-done, which is the refusal shape rather than a misplaced restore: a restore that put the card back at the wrong index would still count 1. That is the site this PR converts to undo(page) in its own first pass (test_render.py), same as the fifth.

The triggering commit cannot have caused it. 0a4611e is a refactor of the note-floor fold and two lf-board announce strings, and neither reaches the board's placement or the undo restore.

What I checked on `0a4611e`

answeredReports changed return type — a Set of ids became the Map that noteFloors returns. Both call sites read it only through .has() (applyActions, reportFold), which Map answers the same way, and the extra values it now carries are never read. The memo key gained the field name, so the two channels can no longer collide on one cached fold.

In lf-board.js the two hunks hoist cards.indexOf(card) and this.#cards(now) out of the announce template — the same array, read once instead of twice. No behaviour rides on either.

The rest of the diff is interact.py and lf-agent.js; this test runs through neither.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Eighth occurrence, on a test this PR's own first pass converts, and 26005a4 still merges into current main cleanly — so there is nothing to push and this is a tally.

The recurrence. run 32507562319 on bbaa98f failed test_a_rebuild_keeps_what_the_reader_did_inside_the_change, the only failure in 1 failed, 880 passed, 6 skipped. The assertion is the accept pill after the press — expect(page.locator("[data-lf-for='sug-thistle'] .lf-sug-accept")).to_have_text("✓ Accept"), actual ✓ Accepted, with the pill still aria-disabled="true" in the resolved node the call log prints. The count assertion above it passes either way (the accept retires lf-old, so one slot stands whether or not the undo landed), so the pill is the first read that can tell, and what it reports is the page exactly as it stood before z — the refusal shape, not a wrong undo. This diff already converts that site to undo(page).

bbaa98f cannot have caused it. It moves the widget/verb/unit lookup in standing_reports, state_fold and report_errors into one declared_events generator. The reordering it introduces is the unit resolution moving ahead of the withdrawn/action_retracted skip in state_fold and ahead of the absorbed filter in the other two — all three are pure reads, and the generator's isinstance(unit, str) gate is the same one each caller had at its tail. Undo folds identically, and every other undo test in the run is green.

The six recurrences since this PR opened
32439703608  7b41faf  test_z_waits_for_the_gesture_the_log_has_not_taken
32444366662  800d708  test_z_waits_for_the_gesture_the_log_has_not_taken
32444940294  287cb7c  test_a_withdrawn_decision_is_still_withdrawn_after_a_reload
32446311636  c33cd45  test_z_waits_for_the_gesture_the_log_has_not_taken
32460214550  0a4611e  test_z_puts_a_card_back_where_the_version_had_it
32507562319  bbaa98f  test_a_rebuild_keeps_what_the_reader_did_inside_the_change

Four distinct tests over six red runs on six consecutive commits, each one a bare press("z") site this diff converts, each run carrying exactly one failure out of ~886. main has now been red on every push since 7b41faf except 59bae22.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Ninth occurrence, on the same site as the eighth, and 26005a4 still merges into current main cleanly — so there is nothing to push and this is a tally.

The recurrence. run 32514547746 on bb3b527 failed test_a_rebuild_keeps_what_the_reader_did_inside_the_change, the only failure in 1 failed, 891 passed, 6 skipped. The assertion is the one the eighth reports: the accept pill reads ✓ Accepted where ✓ Accept is expected, aria-disabled="true" still on the resolved node the call log prints — the page exactly as it stood before the press, the refusal shape rather than a wrong undo. This diff converts that site to undo(page).

bb3b527 cannot have caused it, and it is the first of the nine that touches leaf.js at all, so it is worth ruling out rather than asserting. Its runtime edits are three: the edge-board and comment-panel restore moving to the foot of the module, the stored().where() accessor the gate seeds a store through, and the ARRANGEMENTS export. None of them is near the key dispatcher, sendAction or the suggestion module, and none is even reached by this test — a fresh context holds neither store, so the restore reads nothing and the page is a first visit. Its tests/test_render.py hunks are the new arrival_findings reading at line 1004 and a trailing comment at line 1230; the failing test at line 14652 and the round_trip and open_page helpers it drives are untouched.

The seven recurrences since this PR opened
32439703608  7b41faf  test_z_waits_for_the_gesture_the_log_has_not_taken
32444366662  800d708  test_z_waits_for_the_gesture_the_log_has_not_taken
32444940294  287cb7c  test_a_withdrawn_decision_is_still_withdrawn_after_a_reload
32446311636  c33cd45  test_z_waits_for_the_gesture_the_log_has_not_taken
32460214550  0a4611e  test_z_puts_a_card_back_where_the_version_had_it
32507562319  bbaa98f  test_a_rebuild_keeps_what_the_reader_did_inside_the_change
32514547746  bb3b527  test_a_rebuild_keeps_what_the_reader_did_inside_the_change

Four distinct tests over seven red runs on seven consecutive commits, each one a bare press("z") site this diff converts, each run carrying exactly one failure out of ~890. main has been red on every push since 7b41faf except 59bae22, and this branch is green (test, lint, review all pass at 26005a4) with no open request for changes on it.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Tenth occurrence, on the site this PR's own first pass converts, and 26005a4 still merges into current main cleanly (git merge-tree --write-tree origin/main 26005a4 returns a tree, no conflict) — so there is nothing to push. Rather than another narrative tally, the one fact these nine comments have not stated: the rate.

run 32525588277 on 9c73cc1 failed test_z_waits_for_the_gesture_the_log_has_not_taken, the only failure in 1 failed, 892 passed, 6 skipped, at expect(page.locator("#col-todo #card-baffle")).to_have_count(1) — actual 0, on the read after held[0].continue_(). That is the assertion the hunk at test_render.py:14114 converts, swapping the bare page.keyboard.press("z"); round_trip(page) for undo(page). 9c73cc1 touches registry.json, lf-suggestion.js, the suggestion tests, one interact.py line, and itemWord in leaf.js — a naming read. Nothing in it runs through the board's drag, the send, or the key line.

Every red ci on main since this PR opened has been this one cause. Ten pushes, eight red, and all eight are occurrences already tallied here:

run commit test
32439703608 7b41faf test_z_waits_for_the_gesture_the_log_has_not_taken
32444366662 800d708 test_z_waits_for_the_gesture_the_log_has_not_taken
32444940294 287cb7c test_a_withdrawn_decision_is_still_withdrawn_after_a_reload
32446311636 c33cd45 test_z_waits_for_the_gesture_the_log_has_not_taken
32460214550 0a4611e test_z_puts_a_card_back_where_the_version_had_it
32507562319 bbaa98f test_a_rebuild_keeps_what_the_reader_did_inside_the_change
32514547746 bb3b527 test_a_rebuild_keeps_what_the_reader_did_inside_the_change
32525588277 9c73cc1 test_z_waits_for_the_gesture_the_log_has_not_taken

The two green runs in that window are f7c7da3 and 59bae22 — the race lost, not a different code path. running-tend says a red ci on main is live here because nothing gates a change before it lands, so the standing cost of this PR waiting is that four pushes in five leave main red for whoever pulls next.

I will stop tallying: further occurrences add nothing this comment does not already say, and each one costs a notification. If a later run fails on a site the diff here does not convert, that is new information and I will say so.

@max-sixty max-sixty changed the title Press z from the moment the line offers it Make event delivery ordered and retry-safe Aug 21, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9002594 replaces what the earlier commits on this branch were about, so this is a fresh read of the outbox rather than a follow-up on the undo() helper. The shape is right: one ordered list is a better answer than a promise chain plus a pending map that had to be reconciled through a later poll, and folding the read into the POST answer removes the "append succeeded, then a GET happened to see it" split the old round_trip had to model. Three things, the first of which I think is a real gap.

final is the only word that ends a retry, and it is spoken in one place while the door refuses in ten. deliver() retries forever unless it gets ok: false + final: true + a matching attempt, and only event_rejection writes that shape. Every other refusal /api/event can produce answers with a bare {"error": …}: the key gate in _answer (403 NO_KEY), the preview server's 403, and each shape gate in _post — unknown kind, unexpected fields, wrong field types, a bad comment anchor, a malformed attempt. All of them are deterministic, and all of them now put the page into a permanent 2-second POST loop. Inline below for the reachable one and what the fix looks like.

An accepted answer that fails to render is re-sent. The old post() carried a comment saying a fault in the render pipeline "is its own news and must not claim the send failed"; deliver()'s catch around receiveState now retries the POST instead. Suggestion inline.

retry: True on the 500 answer is read by nobody — neither deliver() nor Traffic._responded looks at it, and the field isn't in the registry's $events. Inline.

Nothing here blocks the design; I'd take all three as follow-ups on this branch rather than a separate PR, and I'm happy to push them if you'd rather not hand-apply. Two notes that aren't findings: ci / test is still running on this head, so the suite is not evidence yet, and #22 (the .lf-dragging edges) still stands after this — unrecordedGesture() keeps that third term — but its leaf.js hunk sits in the comment block this commit rewrote, so it will want a rebase.

Comment thread plugins/leaf/skills/leaf/assets/leaf.js Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The suite on 9002594 has come back — the one thing my last read said wasn't evidence yet — and it is red, on a test this branch adds.

run 32530249359: 1 failed, 898 passed, 6 skipped, test_an_answer_carrying_an_older_pick_cannot_undo_a_newer_one, IndexError: list index out of range at first_route, answer = first_answer[0].

The wait above it names the fact it wants and reads a different one. _until(page, lambda traffic: traffic.sends == 1, "held the first pick's answer") counts through Traffic._out, which fires on the browser's request event — the moment the route is intercepted, not the moment route.fetch()'s round trip returns and first_answer gets its entry. Nothing else fills the list in that window either, and the outbox is why: one send at a time means the second click queues behind the unresolved first rather than reaching the wire, so no second handler runs to append. On a loaded runner the main thread's click and count read finish first, and the list is empty at that line.

Confirmed rather than inferred: with time.sleep(0.3) between route.fetch() and the append, the test fails with exactly that IndexError here; with the delay still in and the wait changed to the fact it names — _until(page, lambda _: bool(first_answer), "held the first pick's answer") — it passes three runs over. Same offer as the three findings in the review: happy to push it, or leave it to you.

main is still red on the cause this branch fixes

run 32530833631 on 8553641 failed test_z_waits_for_the_gesture_the_log_has_not_taken at expect(page.locator("#col-todo #card-baffle")).to_have_count(1), actual 0 — the site this branch converts to undo(page), and the only failure in 1 failed, 906 passed, 6 skipped. 8553641 cannot have caused it: its one leaf.js hunk changes a comment about the claimant pid and nothing else. Eleventh occurrence, left at one line per the tenth.

`final` is the only word that ends a retry, and it was spoken in one place
while the door refused in ten. `event_rejection` covered the refusals that
reach `coordinate_event`; the key gate, the preview server's 403 and each
shape gate in `_post` answered with a bare `{"error": ...}`, which the
outbox reads as an incomplete answer — so a deterministic refusal became a
POST every `POLL_MS` for the life of the tab. The reachable one is the key:
`KEY_COOKIE` carries no `Max-Age` and the runtime navigates to the bare
version URL, so a tab restored after a browser restart has no key and every
widget is still live. Finality is now a property of the door having refused
rather than of the branch that decided it: the POSTed body is read in
`do_POST`, ahead of the one gate the door does not produce itself, and
`_refuse` writes every refusal through `event_rejection`.

An accepted answer that fails to render is no longer re-sent. The send
succeeded the moment the answer named the accepted event, so a fault in
`receiveState` is its own news; the comment `post()` used to carry said so
and the outbox dropped it along with the code.

`retry: True` on the 500 answer is gone. Nothing read it, and withholding
`final` already says retryable — a second word for one fact, free to
disagree with the one the browser reads.

`test_an_answer_carrying_an_older_pick_cannot_undo_a_newer_one` held its
first route by fetching the answer inside the handler, so the handler was
still inside that call when `Traffic.sends == 1` and the release reached for
a route the list hadn't got (CI run 32530249359). The hold keeps the request
in the wire instead, which is the arrangement `tests/CLAUDE.md` names, and
the answer it carries is the same one: the second pick cannot reach the
server behind an unresolved first.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

All three taken, plus the red test the tally above named. Pushed as d541c04; each finding is answered inline where it was raised.

The refusal shape. The fix is the one the review preferred rather than the second-best: the POSTed body is read in do_POST, ahead of the key gate — the one refusal at this door the door does not produce itself — and _refuse writes every refusal at /api/event through event_rejection. _answer keeps its single key gate, so nothing re-opens the hazard its docstring is written around, and the 500 it answers with stays non-final on purpose: a fault may have landed either side of the append. test_every_refusal_at_the_event_door_is_final_and_names_the_attempt is the gate, checked by putting the bug back.

The re-sent render fault. Applied as suggested. The path the review named isn't the way in — loadMarked catches its own import rejection and clears markedReady for a later poll, so receiveState doesn't throw there — which leaves no fault the suite can arrange from outside the page, and this one lands ungated. Detail inline.

retry: True. Gone.

The red suite. Same diagnosis as the tally: the handler was still inside route.fetch() when Traffic.sends counted the request out, so the release reached for a route the list hadn't got. The fix is the other of the two shapes tests/CLAUDE.md sanctions — the handler holds the request in the wire and does nothing else, so an unconditional release with Traffic counting in front of it is sound again. Holding rather than fetching costs the test nothing: the outbox sends one at a time, so the second pick cannot reach the server behind an unresolved first, and the state the released answer carries is the same older snapshot either way.

Local run of uv run pytest tests --run-nightly: 899 passed, 6 skipped, and all pre-commit hooks pass. The two installed-Chrome tests are among the skips — this container can't install Chrome — so CI is the first place they run.

What changed, by file
  • interact.py — event_rejection says it is the door's one refusal shape; do_POST reads the body through _read_posted; _refuse shapes a refusal by the door it came through; _post's gates and _answer's key gate go through it; retry dropped from the 500 receipt.
  • leaf.js — deliver()'s accepted branch returns the minted event whether or not receiveState threw.
  • test_interact.py — the new door gate, over key, preview server, and each shape gate.
  • test_render.py — the hold keeps the first pick in the wire instead of fetching its answer.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shape is what the last round asked for, and it is better than the second-best I named: final is now a property of the door having refused, _refuse is the one writer, and test_every_refusal_at_the_event_door_is_final_and_names_the_attempt reads the loop against the unlive-version case that could never have failed it. The retry removal and the render-fault return both land as described — I checked that nothing reads retry (deliver(), Traffic._responded, $events), and the announced/retryPause machinery is still live on the three branches that keep it. The test_render.py hold is the right correction too: route.continue_() leaves the request in the wire where route.fetch() kept the handler inside its own call, and the new sends == 1 assertion states the thing the test was resting on silently.

One finding, and it is the same failure this commit exists to close — reintroduced by where the body read moved to. Inline below, with a suggestion.

Reading the body in do_POST put it outside _answer's boundary, and one input escapes. _answer's docstring is explicit about what that boundary is for — "Unanswered, a fault drops the socket, socketserver buries the traceback in stderr nothing reads, and the banner says 'Server offline' about a server that is up". _read_posted now runs before it, and its except json.JSONDecodeError does not cover the one thing json.loads raises on bytes before the parse is reached: a body that is not UTF-8 gives UnicodeDecodeError, a ValueError but not a JSONDecodeError. handle() catches ConnectionError and nothing else, so it propagates out unanswered. I ran both sides of the commit against the same POST:

9002594: STATUS 500 b'{"error": "UnicodeDecodeError: \'utf-16-le\' codec can\'t decode byte 0x63 in position 4: truncated data"}'
d541c04: NO ANSWER: RemoteDisconnected: Remote end closed connection without response

A dropped socket is read by deliver() as postEvent throwing, which is "Connection lost — retrying your change…" and a POST every POLL_MS forever — the same permanent loop, on a deterministic input, arrived at from the other side. No browser sends it (postEvent stringifies an object), so this is a hand-written or a broken client rather than a reader; what makes it worth the line is that the old bare-{"error": …} answer was at least an answer, and this one is not.

The two refusals _read_posted does produce are the corner the new test doesn't reach. invalid JSON and event must be a JSON object go through _refuse with self.posted == {}, so event_rejection's if event.get("attempt") omits the attempt — and deliver() requires answer.attempt === event.attempt before it will treat a final as leave to put the gesture back, so those two land in the "Server answer was incomplete" retry too. That is inherent rather than a bug: there is no attempt to name in a body that wouldn't parse. But it is the one place the test's title isn't true of the door, and the eight cases in its list are all bodies that parse — which is why nothing in the gate had a chance to see the escape above. Worth a case for each, even if the assertion on them is weaker than the other eight.

Happy to push both if you'd rather they land here than as a follow-up. ci / test is still running on this head, so the suite isn't evidence yet; the new door test passes on its own here (3 passed).

`json.loads` decodes bytes before it parses, so a body that is not UTF-8
raises UnicodeDecodeError — a ValueError, never a JSONDecodeError. While
the read lived in `_post`, `_answer`'s boundary caught it and answered
500; reading it in `do_POST` moved it in front of that boundary, and
`handle()` catches only ConnectionError, so the request went unanswered.
The outbox reads a dropped socket as a lost connection and re-posts the
same attempt every poll for the life of the tab — the permanent loop this
commit's predecessor exists to close, reached from the other side.

Widening the clause to ValueError covers both and keeps the message
honest: a body that cannot be decoded is not valid JSON either.

`test_every_refusal_at_the_event_door_is_final_and_names_the_attempt`
gains the three refusals decided before the body is a dict at all, which
its eight cases could not reach — every one of those parses. They assert
the door's shape minus the attempt, there being nothing in an unreadable
body to read one out of.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 1a5169a on top of 362023c, and ci / test, lint and review are green on it. I started this round from the receipt-lifetime question and reached the same answer independently — drop the != 400 — so c816b99 and my own commit were the same edit twice. I dropped mine and kept only the two parts it did not already carry.

The reachable asker got a test, and moved out of the fold. The 02:35 review worked out the shared-draft case in a <details> block; nothing pinned it, and the code comment beside the release still read "a delivered final refusal is never retried", which the same case falsifies. test_a_refused_attempt_is_re_read_against_the_page_that_refused_it now drives it through the real door: refuse an attempt on a version that is not live, publish, press the same stored attempt again. With if result[0] != 400: put back it fails at that second press — the receipt answers the stale 400 — and it fails a second way on the payload the reload moved on, 409 already belongs to another event over an event that does not exist. The reasoning is now in coordinate_event's finally and in the layer norm rather than only in a review body.

The rest of the wrapping. The two suggestions were the two widest paragraphs, not all of them: the paragraph above the first ran to 84 and the whole section below sat at 85–92 in a file wrapped at ~80. Same words, re-wrapped together.

The correction that landed while I was polling is right, and I have not acted on it. Review 4998856212 points out that published_versions only ever grows, so "refused for naming a version the page has since retired" describes a direction the code cannot take — the test builds the mirror, and my prose narrates the unreachable half in three places. I checked the two wrapping strandings it names as well: actions. The is a 12-character line at line 82, a join my own re-wrap created. Both are follow-ups, and I have left them to the run that review dispatches rather than racing it.

What I verified locally
  • pre-commit run --all-files: clean.
  • uv run pytest tests/test_interact.py: 427 passed, 6 skipped.
  • Bug-back on both directions of the gate, per tests/CLAUDE.md: with the != 400 condition restored, test_a_refused_attempt_is_re_read_against_the_page_that_refused_it fails at assert status == 200 and test_concurrent_retries_share_one_attempt_execution fails at assert calls == 2. Released, both pass.
  • uv run pytest tests --run-nightly on the pre-rebase tree: 956 passed, 1 failed, 6 skipped. The failure was test_an_open_tab_reloads_before_posting_through_a_revendored_layer, in told(page) waiting for a poll — the layer-mismatch reply returns from _post before coordinate_event is reached, so the change cannot touch it. It passed four times alone afterwards, and ci / test is green on the pushed head.

The absent-receipt prose named "a version the page has since retired" in three
places, and publishing cannot produce that: `published_versions` filters
`list_versions`, version files are immutable and never removed, so the live set
only grows. A version a tab was served stays live for the life of the page.

So the prose names the reachable refusals instead — a reply refused for an
unknown parent its tab had not read yet, an action refused by a registry the
page has since re-vendored — and the regression's docstring says outright that
it drives the mirror of the reader's case, a version refused before it was
published and re-pressed after, because that is the gate a test can walk the
door through directly.

`execute_event`'s own comment carried the same unreachable reading in the other
direction. Its example is now one the log really does produce: a retried undo
the first request already appended, which `undo_error` would refuse as a gesture
already taken back.

Also the two mid-paragraph strandings the re-wrap left at its joins, reflowed
with the words unchanged.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4561bdb replaces the unreachable retirement reading in all three places, and the two examples it puts there hold at the door. execute_event's is now something the log really produces: the first request appends the undo, so taken_back holds its target and a retry would earn has already been taken back — which is exactly what the accepted-attempt lookup above it is there to outrank. Both re-wraps landed with the word sequence unchanged (checked by token diff, not by eye).

One clause is left over from the old reading. The framing is "the ground a refusal stood on moves as the log grows", and the second example named under it — an action refused by a registry the page has since re-vendored — is not the log growing: action_contract_error takes its registry from load_registry(self.page_dir), so what moved is the page directory. It is reachable, for a reason worth having written down somewhere: handler_for captures layer once at construction, so after a re-vendor a live server still answers with the pre-re-vendor generation, _post's Leaf-Layer comparison passes, and the same request then reads the fresh registry off disk. The clause sits in three places — CLAUDE.md, the coordinate_event comment, and the regression's docstring, which states it most flatly as "the refusals whose ground the log really does move under (… action_contract_error behind a re-vendor)".

Two ways out, and the suggestions inline take the cheaper one — "moves under it", which covers both examples and leaves the examples alone. The other is to keep "as the log grows" and swap the example for the branch of that same function which is one: action_widget_tags folds each message's markup into the id→tag map, so unknown action widget flips to accepted the moment a thread's markup carrying that widget reaches the log. Either way the docstring's parenthetical wants the same edit.

Comment thread plugins/leaf/skills/leaf/CLAUDE.md Resolved
"The ground a refusal stood on moves as the log grows" was written for the
`unknown parent` example and does not cover the one beside it: a re-vendored
registry moves the page directory, not the log. `load_registry` reads it off
disk on every request while `handler_for` captured `layer` once, so the same
request passes the generation check and then meets a fresher contract.

"Moves under it" is true of both, and leaves the examples alone.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 4561bdb and f4cf5d6; ci / test, lint and review are green on the head. Each finding is answered inline where it was raised.

The retirement reading is gone from all four places, not three. 4561bdb replaces it in coordinate_event's finally, in the layer norm, and in the regression's docstring, and takes execute_event's inherited copy with them — that one is on main already, so it is the one edit here outside this PR's own diff. Its replacement is a flip the log genuinely produces: a retried undo the first request appended, which undo_error refuses as has already been taken back, which is precisely what the accepted-attempt lookup above it exists to outrank. The norm and the docstring now also say outright what the direction the door cannot take is, and why — published_versions filters list_versions, version files are immutable and never removed, so the live set only grows.

The clause I put the examples under was too narrow, and f4cf5d6 widens it. "The ground a refusal stood on moves as the log grows" was written for unknown parent and does not describe a re-vendored registry at all; "moves under it" covers both and leaves the examples alone.

This branch no longer merges into main, and main is red on the test this PR converts. git merge-tree against cf35cb0 conflicts in five files — CLAUDE.md, leaf.js, registry.json, interact.py, tests/test_render.py — with the two refactors that landed since 1a5169a ("Refactor state coordination to use semantic facets", "Refactor parallel workstreams as workstream tabs"). I have not merged, because ci on cf35cb0 failed on test_z_walks_back_through_gestures_rather_than_toggling_one — a twelfth occurrence of the failure this branch exists to fix, and the same test this PR converts to undo(page) — so merging now would pull a red suite onto a green head and put this PR's own subject back in front of its CI. Worth a maintainer's call on the order: land this, then let main inherit the conversion, or merge first and carry the noise.

What I verified locally
  • pre-commit run --all-files: clean, on both commits.
  • uv run pytest tests/test_interact.py: 427 passed, 6 skipped on 4561bdb; the focused -k refused_attempt row passes on f4cf5d6.
  • The changes are comments, a docstring and prose only — no runtime behaviour — so the browser suite is CI's, and it is green on f4cf5d6.
  • published_versions growth, read at versions_live: the non-preview branch is published_versions(self.page_dir, events), and nothing in the script removes a file from versions/.
  • undo_error's has already been taken back branch, which the new execute_event example names: interact.py#L1156.
  • Conflict list from git merge-tree --write-tree HEAD origin/main at cf35cb0.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f4cf5d6 is both suggestions applied verbatim, and 451eae0's release-then-unroute is placed right: deliver() races postEvent against entry.read, so once the poll wins, the POST answer is abandoned before res.json() is ever called — fulfilling after the verdict cannot paint, and asserting after it would be green by construction. I scanned the rest of the file too: every other held.append(route) test releases through continue_, fulfill, abort, or refuse, so these five were the only strands left.

The hang 451eae0 is written against is not the hang the suite has. I ran uv run pytest tests --run-nightly on this head. It reached ~98% and then deadlocked for twenty minutes with no browser process alive, in test_a_claim_transfer_stops_a_waiter_already_inside_a_poll — a launcher test that never opens a page. /proc/locks named both sides: the leaf wait watcher held the write flock on page-locks/<hash>.claim.lock while blocked in a pipe read on the test's status.json FIFO, and the pytest worker was queued behind it on that same lock, inside interact.claim_page(page).

The mechanism is the two reads of status.json in PageWatch. tick takes the first one outside the lock as observed, and that is the read the test means to hold — but _read reads it again inside flocked(claim_lock(page_dir)), and the FIFO's open rendezvous takes whichever read gets there first. Caught on the inner one, the watcher holds the claim lock until the test writes the FIFO, which it only does after claim_page returns — so the two wait on each other with nothing to break the tie. Nothing between claim_lock and _read changes in fa59396..451eae0, so this is a race on main that the branch is meeting, not one it introduced.

That matters for the paragraph 451eae0 adds to tests/CLAUDE.md, because the branch's own history contradicts its causal sentence. All five stranded holds were already present at e0ee8bf, whose ci / test went green in 8m16s; the hangs start at the very next commit, cc1d561, and every ci / test since has been stuck in the suite step. So "Leaving it there stranded Chromium during the Linux worker's session teardown" is the one clause I can't ground — the release is still worth keeping on its own terms, but as written the norm sends the next reader to the wrong subsystem. Naming what the hold actually is (a live route handler the test no longer needs) without claiming the teardown symptom would keep the paragraph and drop the part that isn't evidence.

This head has no ci run. 451eae0, f4cf5d6, 4561bdb, and 1a5169a each produced a tend-review run and no ci run at all; the last ci to start on this branch was 362023c's, which was cancelled. The three before it were the hung ones — I cancelled them, since they had been sitting in the test step for three hours and are the likeliest thing holding the branch's runner slots. Worth confirming a fresh ci fires before treating any of this as verified; nothing on this head has been through the gate.

One other thing a reader of the merged tree will hit: main is red independently of this PR, on test_z_walks_back_through_gestures_rather_than_toggling_one (tests/test_render.py:15060, assert 'Rewritten.' == 'First line o... of the note.') in run 32549479170.

Reproduction notes

Environment: this runner (4 cores), uv sync --frozen plus the pinned Chromium headless shell, on 451eae0.

The deadlock evidence, read live while the run was stuck:

/proc/locks
23: FLOCK  ADVISORY  WRITE 54595 08:01:9476083 0 EOF
23: -> FLOCK  ADVISORY  WRITE 53375 08:01:9476083 0 EOF

54595  interact.py wait .../test_a_claim_transfer_stops_a_0/codex-page
       wchan=anon_pipe_read
       fd 5 -> .../page-locks/3a4aeae22b0b71f320e4624896d497a6.claim.lock
       fd 8 -> .../test_a_claim_transfer_stops_a_0/codex-page/status.json   (the FIFO)

53375  pytest worker gw5
       wchan=locks_lock_inode_wait
       fd 16 -> .../page-locks/3a4aeae22b0b71f320e4624896d497a6.claim.lock

Seven of the eight xdist workers were parked in futex_do_wait with no headless_shell process anywhere, which is what ruled the browser layer out before I looked at the locks.

It is a race, not a certainty: the test passes in 2–4s on its own, and twelve consecutive isolated runs with four CPU burners loading the box did not reproduce it. It needs the FIFO's open to land on the in-lock read, which is why the full suite reaches it and a focused run does not.

The commits I checked the five held routes against:

  • e0ee8bf — all five strands present, ci / test success in 8m16s (run 32543990152).
  • cc1d561, c816b99, e3c795a — first three hangs, all stuck in 🧪 Test suite (lint green on each).

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this branch had no CI for five commits — and what cleared it. pull_request-triggered workflows only dispatch once GitHub can compute refs/pull/N/merge. From 362023c onward the PR was mergeable: false / "dirty", so that ref froze at 278d3e7 (the merge of 362023c into fa59396, 02:44) and ci simply never fired on 1a5169a, 4561bdb, f4cf5d6, 451eae0, or 75cced9 — no run, no red, nothing on the PR to say the gate was missing. 75cced9 didn't fix it, because main had moved to 871edb2 and conflicted again. a987440 does: the PR is mergeable: true, the merge ref recomputed to 681253e, and ci started on it at 06:03 — the first run on this branch since 02:44. Worth recognising the shape next time, since the symptom is silence rather than failure.

Same cause, second effect: every tend-review run in that window checked out the frozen refs/pull/21/merge, so each one read the tree from 02:44 rather than the commit it was reviewing. I read the head commits directly instead.

What I checked while the gate was down. On 75cced9 — the head when this run started, carrying the 29-hunk resolution against cf35cb0 — pre-commit run --all-files was green, tests/test_interact.py gave 447 passed, and tests/test_render.py --run-nightly gave 511 passed, including test_z_walks_back_through_gestures_rather_than_toggling_one, which is what cf35cb0's own ci went red on. On the current a987440, tests/test_interact.py gives 456 passed; the browser suite there is the running ci's to answer. The resolution reads sound in the places the two designs actually collided — execute_event folding _matching_attempt into the held append lock in place of the standalone accepted_attempt, and main's StateProjection facet model displacing BROWSER_EVENT_FIELDS — and 09a40d6 only had five hunks to settle against 871edb2, against 29 the merge before it.

One thing the resolution kept twice — inline on interact.py.

Evidence and notes

Environment: this runner (4 cores), uv sync --frozen, pinned Chromium headless shell.

The dispatch mechanism. gh api repos/max-sixty/leaf/pulls/21 at 75cced9 → {"mergeable": false, "mergeable_state": "dirty"}; git ls-remote origin 'refs/pull/21/*' → refs/pull/21/merge 278d3e7…, and git log -1 278d3e7 → Merge 362023c into fa59396. gh api .../workflows/ci.yaml/runs?branch=fix/ci-32429171821 listed 362023c (cancelled, 02:44) as the newest and nothing after it, while tend-review — pull_request_target, which needs no merge ref — ran on all five later commits. After a987440: {"mergeable": true}, refs/pull/21/merge 681253e…, and an in_progress ci run on a987440.

Runs. 75cced9: pytest tests/test_interact.py -q → 447 passed, 6 skipped; pytest tests/test_render.py -q --run-nightly -n4 → 511 passed in 8m39s; pre-commit run --all-files → all 11 hooks passed. a987440: pytest tests/test_interact.py -q → 456 passed, 6 skipped.

One local failure that was never this PR's. On 75cced9, test_demo_recording_drives_the_browser_journey failed for me whenever test_product_page.py and test_site.py ran together under -n4 (could not select 'Backfill history' in #p2). It failed identically on both merge parents, passed inside cf35cb0's own 8-worker CI run, and is fixed on main by waiting for all three readiness stamps rather than lfUpgraded alone in scripts/record-demo.py. a987440 carries that fix, so it is moot now — noting it only so a later reader doesn't re-chase it.

The claim-lock deadlock from the last review did not recur across these runs, but it is a race and a clean run is weak evidence either way.

@max-sixty
max-sixty merged commit 85631b3 into main Aug 22, 2026
10 checks passed
@max-sixty
max-sixty deleted the fix/ci-32429171821 branch August 22, 2026 06:30
leaf-agent added a commit that referenced this pull request Aug 22, 2026
The four `**/api/state*` unroutes still in the file arrived with main's
merge — #21's own new tests — so the comment saying the `**/api/event`
unroutes are the boundary was true of what this branch converted and
false of the file it left. Convert them rather than write the exception
down: the norm is absolute, and a survivor reads as one that was checked
and found safe.

Two are the converted shape exactly — refuse, lift, refuse again — which
`CutOff` could not express because `restore` is one-way. `cut()` is the
other half of that switch. Two lift a handler that answers as well as
refuses, so the switch is a flag the handler reads at its top and
continues on, written where the answers are.
max-sixty pushed a commit that referenced this pull request Aug 24, 2026
## Problem

`.lf-dragging` is half of
[`unaccountedGesture()`](https://github.com/max-sixty/leaf/blob/85631b307072a9fb7135c4b01e9e66820d47a4b1/plugins/leaf/skills/leaf/assets/leaf.js#L10031),
so a widget wearing it moves core's `z` row — and `lf-board` wrote the
class from four places, of which only the two on the keyboard path
painted. `#grab` added it and called `paintKeys()` on the next line,
under the comment that says why; `#release` removed it and called
`paintKeys()`. The pointer path did neither: Sortable's `onStart` ended
on a bare `classList.add`, and `onEnd` opened on the matching `remove`
and could leave at its `from === to && oldIndex === newIndex` early
return before `#send` was ever reached.

The window on the first edge is a whole gesture rather than a frame, and
nothing else covers it: the focus paint lands on the mousedown and
`fallbackTolerance: 4` fires `onStart` after it, `reconcileState()`
returns at its own `.lf-dragging` gate so a poll's replay is not a
paint, and `syncAsks()` is not in the poll loop. So on a quiet board the
line went on offering `undo` for as long as the reader held the card,
over a press the dispatcher was already refusing. `onEnd` is the same
gap read backwards: a card dropped where it was picked up takes the
class off with nothing following it, so the offer stayed withheld from a
press that was live.

## Solution

The paint moves to the class, in core: `dragging(el, on)` toggles
`.lf-dragging` and calls `paintKeys()`, and `lf-board`'s four sites
become `dragging(this, true/false)` — the two that already painted along
with the two that didn't.

Core owning the writer is what closes the gap for the widget after this
one. The class is core's own vocabulary and core is its only reader
(`unaccountedGesture`, and the replay gate in `reconcileState`), so a
duty stated in prose — "whoever moves the state paints" — would leave
the twelfth widget to learn it from a docblock or not at all, with a
paint that never happened as the symptom: invisible to the file lint,
which doesn't read modules, and to `version check --render`, which has
no wrong artifact to compare against. That is the shape `CLAUDE.md`
names under **The widget list is never closed** ("Before gating an
obligation every adopter must remember, ask whether the declaration
already states enough for the layer to do it once"), and the resolution
the `data-lf-state` mark already took. Here it needs no declaration at
all, because the class is already the layer's.

The paint coalesces to a frame, which is what lets one call stand for
everything else the same gesture moved: the widget's own rows in
`#grab`, where the grab is a press on an already-focused grip and no
focus event fires, and — on the drop that does send — a frame landing
after `#send` has stated what is in flight, so it still reads as a
gesture the log has not taken. `onEnd` keeps the call ahead of its
branches, because the branch that returns early is the one with no send
behind it.

## Testing

`test_a_pointer_drag_stops_the_line_offering_the_press_it_refuses`
stages a keyboard move so there is a gesture to take back, then
pointer-drags that same card by the grip the move left focused — so the
mousedown lands on an already-focused control and fires no focusin,
leaving the paint under test as the only one that could clear the offer.
It reads the line once at each edge, and each read fails on its own edge
with that edge's paint removed.

<details><summary>Two ways this test passed while proving nothing, and
what fixed each</summary>

**The read has to be once, not `expect`.** Written as
`expect(...).not_to_contain_text("undo")`, the mid-drag assertion passed
with the fix removed — and so did the assertion after the drop. A probe
against unmodified `main` shows why: mid-drag the class is on and the
line still says `z undo`, for the whole 0.9s the probe watched, so the
defect is real — but `expect` re-asks for five seconds, and a version
poll two seconds out repaints the line whatever the drag did. That is
`tests/CLAUDE.md`'s "a state the page passes through is not a state to
poll for", read the other way round: the page passes through the
*asserted* state on its way back from a paint nobody asked for.
`_painted_line` consumes the frame `paintHere` coalesces to and reads
once.

```
main, mid-drag:  ['lf-dragging', '⏎ / space grab the card … z undo … esc let go …']
main, after drop: ['',           '⏎ / space press it … esc let go …']   ← no undo row
```

**A box measured across the FLIP is a box the card has left.** The
keyboard move animates the card into its new column, and
`bounding_box()` taken across that read x=737 where the settled answer
was x=1092. The press lands on the grip at that instant and the pointer
is somewhere else by the mousemove after it, so Sortable never starts
the drag — and the failure arrives as
`wait_for_selector("lf-board.lf-dragging")` timing out on a page nobody
dragged, thirty seconds later and nowhere near the cause. The test waits
for the card's own animations to empty first.

**Bug-back.** Each edge on its own at `dbb520f`, when the paint sat in
`lf-board`:

```
onStart paint removed:
  AssertionError: the line offered a press the dispatcher refuses for the length of a drag
onEnd paint removed:
  AssertionError: the drop that sent nothing left the line refusing a press that is live
```

And with the paint now in one place, dropping `paintKeys()` from
`dragging` takes out the same assertion (`1 failed, 24 passed` over `-k
"board or dragging or pointer_drag"`).

**The suite**, run the way CI runs it on this Linux runner: `869 passed,
6 skipped in 590.59s`. `pre-commit` is clean on both changed files. One
run in between failed
`test_a_withdrawn_decision_is_still_withdrawn_after_a_reload`, which
passes alone and passed on the unmodified branch head under the same
load — a contention failure on a page this branch does not touch.

</details>

Found reviewing #21, which closes the same shape of gap for `sending` —
the other term of the same predicate. This one reverts independently of
that, so it is on its own branch off `main`; the two touch `leaf.js` in
different places.


Merged with `main` at #21, which renamed `unrecordedGesture` to
`unaccountedGesture` and moved the `.lf-dragging` replay gate into
`reconcileState` — the names above are the post-#21 ones, and the
mechanism is unchanged under them.

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Aug 24, 2026
## Problem

[Run
32553975712](https://github.com/max-sixty/leaf/actions/runs/32553975712)
failed
`test_a_decision_travels_between_tabs_and_the_log_has_the_last_word` —
`expect(tab.locator("#sug-thistle lf-new")).to_be_hidden()`, actual
`visible` — with the log holding the reject the assertion is about. The
cause is the test's own instrument: `page.unroute` drops its handler
while a request is in its hands, and that request is then neither
continued nor refused. It never comes back, and nothing in the page
times it out.

The lost poll is not the cost. A send ends in a poll of its own, so a
lift landing inside that poll leaves `post` awaiting forever — the
widget the gesture was made on stays in `sending`, `reconcileState`
skips it for the rest of the tab's life, and the page sits at
`aria-busy` disagreeing with the log about a decision the log has taken.
Here the cut-off tab rejects a suggestion the log already holds an
accept for, `third.unroute("**/api/state")` lands inside the reject's
own poll, and that tab never folds again.

## Solution

A refusal stays on the page for its whole life and answers every request
it receives; lifting changes which answer, not whether there is one.
`CutOff` keeps that handler installed and switches polling between
refusal and continuation. On current `main`, eleven of the twelve
polling-route lifts now use this pattern. The remaining `arrive()`
unroute is safe because no send or later wait depends on that page, and
the next call navigates away.

## Testing

The original failure reproduced four times in 48 loaded runs; the fix
passed the same 48 runs. The current-main merge passed 13 affected
browser tests. After the final conversion and simplification, the three
directly changed tests passed and `pre-commit` was clean.

<details><summary>The reading that named it</summary>

Three tabs, `third` being the one cut off. `polls` counts entries to
`poll()`, `asked`/`heard` are `Traffic`'s counts of what the browser
reported:

```
DIAG traffic third {'sends': 1, 'acked': 1, 'asked': 6, 'heard': 6, 'read': 1}
DIAG third {"state": null, "busy": "true", "stage": "minted",
            "polls": [{"n": 1, "stage": "json"}, {"n": 2, "stage": "json"},
                      {"n": 3, "at": 3664, "stage": "fetch"},   <-- never returns
                      {"n": 4, "stage": "json"}, {"n": 5, "stage": "json"},
                      {"n": 6, "stage": "json"}, {"n": 7, "stage": "json"}]}
DIAG first  {"state": "reject", "busy": null, "stage": "polled"}
DIAG second {"state": "reject", "busy": null, "stage": null}
DIAG log: [note, sug-refill accept, sug-thistle accept, sug-thistle reject]
```

Seven polls, six requests: the third one's `fetch` was never issued to
the network the browser reports on, and never settled. `post` therefore
never reached its `return minted`, `sendAction`'s `finally` never ran,
and `sending` kept `sug-thistle` out of every later reconciliation — the
timer polls beside it kept working the whole time, which is why
`told(third)` returned and only the widget was wrong.

</details>

<details><summary>What this does not change</summary>

The runtime's own behaviour under a poll that never returns is
untouched: a stalled connection would pin a widget the same way, since
`post` awaits the read it ends with and `sending` is released only
behind it. That is reachable without any instrument, and #21 is already
reworking that path, so it is left alone here rather than changed
underneath it.

</details>

---

Automated fix for [failed
run](https://github.com/max-sixty/leaf/actions/runs/32553975712)

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
max-sixty pushed a commit that referenced this pull request Sep 18, 2026
`notes/workspace-followups.md` has been presenting finished work as the
plan since 9 September. It opens with "Start #2, #3 and #4 as one
coordinated contract batch; run the review-queue simplification #8
alongside it" — all four of those shipped that week — and carries
thirteen briefs, each with a live "Next task" and "Done when", for work
`TODO.md` dropped as complete. This removes them and leaves the six
`TODO.md` still links: #11, #14, #19, #20, #22 and #23.

The trim follows the convention #666 set and the reason `CLAUDE.md`
gives for it: a note is never a second specification for shipped
behavior. #666 removed #6, #7, #16 and #17 the same way, rewriting the
two `Owner / dependencies` lines in surviving briefs that named them; it
simply did not reach the rest.

Each removal is evidenced by the commit that took the item out of
`TODO.md`, not by a reading of the current code:

| Brief | Removed from `TODO.md` by |
| --- | --- |
| #1, #3, #5 |
[`0f7f06a6`](0f7f06a)
— "Completed workspace items #1, #3, and #5 are removed from `TODO.md`"
|
| #2, #4, #8, #9 |
[`28b5da99`](28b5da9)
— "the completed #2, #4, #6, #8, #9, and #17 backlog entries are removed
while preserving the deferred evaluation work" |
| #13, #15 |
[`6df40353`](6df4035)
— "closes three bounded workspace follow-ups" |
| #10, #12 |
[`c9eaa2c6`](c9eaa2c)
— the continuation cue and the adaptive Threads placement |
| #18, #21 |
[`e46c8b93`](e46c8b9)
— the monitoring workspace and its package-owned root |

Alongside the briefs, three group headings are now empty and go; the
`Suggested work packages` table loses the rows whose whole scope landed;
and four cross-references that named a removed ID are rewritten — #14's
dependency on the Threads-placement experiment, #20's ordering behind
#8, and the two sentences in `Reproduction record` and `Browser
evidence` that pointed at briefs no longer here.

#14 needed more than a rewritten pointer. The experiment it waited on
was settled in two steps, and only the first removed an ID: [PR
#520](#520) kept the adaptive
placement and deferred the modal-focus work to #24, which landed in [PR
#536](#536) as inertness, dialog
semantics and focus containment for a covering workspace. That is the
surface #14 exists to verify, so its `Done when` — "Avoid imposing a
modal focus trap on a nonmodal panel" — described the containment #536
shipped as the defect to avoid. It now states the containment the
shipped modality requires, and the dependency line names both
settlements.

The dated evidence sections themselves stay. They are the record of what
was read in a browser on 8 September, not a plan, and the note's own
header scopes them to that date.

No test covers `notes/`, and this changes no behavior, so there is
nothing to regress. `pre-commit` passes on the file; the `TODO.md` →
note anchors all still resolve, and no surviving text references a
removed ID.

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Oct 12, 2026
…output (#2500)

The Worker, its container (`worker/leaf_website`) and the site build
(`dev/leaf_dev/site.py`) are Leaf's own code, ship in one release, and
`leaf-dev verify-site website-worker` drives them together on every PR
and before each deploy. Several checks on that path validated values one
of them produced for another, as if it came from the internet. They go;
validation of what does come from the internet (startup reports,
interaction batches, request cookies, sample ids, page-fault bodies)
stays. Part of the complication-weight sweep (#26 there, and the dev
half of #21).

**Removed**
- **Site manifest:** the Zod schemas and `parseSiteManifest` in
`worker/src/routing.ts` become TypeScript interfaces. `site.py`
constructs every field the schema checked (the asset path from the
release, the state from the current revision, the image from a media
file `check_links` proves resolves, title and description refused at
build).
- **Agent start/fail protocol:** no longer validated at both ends. The
Worker's failure code is typed `WorkerFailure = "rate_limited" |
"startup_failed"`, so "only the container writes `turn_failed`" is a
type on the one producer; `askContainer` reduces to ok → `json()`. The
container reads `posted["event"]` and `posted["failure"]` directly; an
unknown code still fails at `FAILURE_RECEIPTS[failure]` and an unknown
event at admission. No public path reaches these routes: the Worker 404s
every `/_leaf/` path, `pageRoute` forwards only API, layer, session and
vendored-file paths, and the container matches routes exactly.
- **`OPENAI_API_KEY` runtime check:** `wrangler.toml` requires the
secret, so deploy refuses without it.
- The shape check on the sample URL the container returns, three routing
guards on values already checked or freshly generated, `_finish_turn`'s
stderr line repeating `turn_stream_completed`, and `_select_page`'s
`events.jsonl` check.
- **Dev catalog readers:** `example_data.py` and `site.py` stop
explaining dead example routes and missing captions, which `check_links`
refuses or a `None` access reports; `example_previews.py`'s fallback is
`min(glob)`.

**Behavior change:** a build or container bug in these fields now fails
as a routing or Python error in `verify-site` instead of a named
validation error. The container's private `/_leaf/agent/fail` route
would accept `turn_failed` if something posted it; only the Worker's
type and the route's unreachability rule that out.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 12, 2026
… a reply to a withdrawn message (#2507)

Python code that restated a rule a stronger mechanism already enforces,
explained malformed agent input the agent would fix from a plain
refusal, or recovered from states no Leaf writer produces. It goes; what
stops bad input passing silently into admitted events, stored decisions
or anchors stays. One confirmed bug is fixed on the way. Part of the
complication-weight sweep (#19–#24 and #30 there).

**Bug: a reply to a withdrawn message opened a phantom thread.**
Admission checked a reply's `parent` against every message in the log,
withdrawn ones included, while the thread fold drops withdrawn ones; so
a reply to a reaction the user took back was admitted and landed in a
second thread named after the withdrawn reaction. `_parent_error` now
refuses a withdrawn parent, and `UndoReading` counts any child, a
reaction included, as standing on a reaction, so every standing
message's parent stands. The fold reached the phantom through recovery
written for a torn opening line, which the writer cannot produce (it
fsyncs before returning an id and repairs a torn tail before the next
append); that recovery goes from `build_threads`, `seat_root`,
`thread_context` and `logged_id`, with its two tests.

**Restated rules (#19):** the start line's one-line rule now lives once
in the kernel registry, including a progress reply's `start`;
`record_pickup`'s phase, `cmd_wait`'s argument pair, `deferred_value`'s
re-checks, the `Unresolvable` catch, the JSX refusal (the browser check
reports it), the `check_app_server_endpoint` alias, the
entries-are-dicts check and the `user_views` JSON round trip (now
`deepcopy`) go.

**#20:** the `fcntl` ImportError fallback goes; Leaf runs only on POSIX
and a plain import fails as early.

**#21:** `capture_anchor` refuses a missing quote with one message
instead of diagnosing fences, removed words and data bodies (the
retired- and gone-section refusals stay); `leaf data set` no longer
explains empty stdin; `task open` no longer explains a thread subject
the schema refuses.

**#22, #24:** `activity._moment` stops tolerating timestamps no Leaf
writer produces; the interaction log stops re-validating on read what it
validated on write: it skips a torn line, and marks a split record whose
parts don't join into the entry they name as `interaction_unreadable`
(ingress checks each part, not the whole).

**Rules moved to their owners (#30):** the layer's `$` fact shapes are
one `LAYER_FACTS_SCHEMA`, leaving only cross-references and what a
schema can't say in code; `delivery.pending_batches` is gone for
`hook_transport.read_plans`; `codex run --handshake` is required; the
`RANK` pattern and identity fields' non-emptiness are in
`detail_schema`. Patterns that replaced a `fullmatch` end with
`(?![\s\S])`, because Python's `re` lets `$` match before a final
newline. `lf-suggestion`'s rules stay in Python: no existing declaration
can say how many slots it holds or that it can't nest.

**Behavior changes:** a reply or reaction to a withdrawn message is
refused; a reaction to a reaction blocks undoing the parent reaction;
refusals read as the schema's or parser's message; a log that already
holds an orphaned message (possible only from the bug above) now fails
to read instead of showing a phantom thread.

The browser runtime's half of #23 is in the runtime cuts PR, which
follows this one.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Nov 6, 2026
…is HTML's phrasing less what draws its own box; shipped chips gain their spaces

Where words are read (#21). The runtime found the element a run of words is read in
after the walk, by climbing each text node's parents past inline tags, so a staged
widget's top-level `<span>` climbed to its shadow root and stopped there: two widgets
side by side under a `<div>`, each holding a `<span>`, read "alpha beta" before they
staged and "alphabeta" after, where the file's reading kept "alpha beta". The reading
walk now carries that element in its context (`enter`, `words`), as passages.py
carries each element's block, across shadow roots as across the light tree, and a
slot's words are read among the words where the slot draws them. Each segment carries
it; a space stands between two runs read in different elements or across a line break
(`spacedFrom`), in the raw reading as in `quoteFrom`. `segmentTextBlock` and its climb
go.

Which elements join words (#20). `$passages.inline` listed 28 tags and missed
`<output>`, so `alpha<output>beta</output>gamma`, drawn and found by both browsers as
one word, read "alpha beta gamma". It goes. `$passages.phrasing` comes in as on
link-previews (4b056fc), JSON and `why-` text alike, so that merge is trivial, with
`$passages.apart`: the phrasing elements drawn as boxes of their own, each with its
reason, from the review's table of what each engine draws and finds (controls:
button, select, datalist, textarea, meter, progress; embedded content: audio, video,
canvas, iframe, object, picture, svg). Every other phrasing element, and a widget
declared `x-inline`, runs into the words beside it: output, label, slot and a ruby's
base among them. Both readings derive the set from the two facts (`JOINS_WORDS`,
`JOINS_WORDS_TAGS`). An element outside the set, a text block or a widget among them,
reads its words apart, inside a text block too: `alpha<button>beta</button>gamma` in a
`<p>` now reads "alpha beta gamma" in both. The file's reading no longer reads text
blocks at all, so `why-blocks` stops claiming they decide spacing. link-previews'
`why-phrasing` says only the browser reads the list; that sentence changes at the
merge, since the file's reading now reads it too.

Said values. An `x-says` value is drawn as its element's caption (lf-sample), label
(lf-column) or popover (lf-gloss), never among the element's words. The file's
reading read one apart only outside a text block and the browser's never did, so a
label beside its element's own words read "Headbody" in the browser and "Head body"
in the file, and a gloss's tip in a paragraph "glossTip" in both. Both now read every
said value apart (`enter`'s `SAID`, `_said`).

Shipped chips (#19). The option chips in examples/heat-loss.html, adjacent `<small>`
elements with nothing between them, draw as separate boxes but read
"£180one afternoon", so search for "£180 one afternoon" found them on main and not
here. They now have whitespace between them, as do the same chips in three of
packages/default/registry.json's `x-example`s, the site nav's example in
docs/package/registry.json, and four figure captions in docs/ui.html whose label is a
block by CSS alone. No other adjacent chips stand in examples/, docs/, packages/ or
skills/.

tests/quote_cases.json gains an output, a ruby's base, a widget's slot drawing two
spans, a button's label in a text block, two staged widgets side by side, as one word
and as two, and a said label and a said tip; its browser side renders said values.
Both runtimes answer all 27. A runtime test holds that a slot's words run into the
shadow tree's words around it.

Tests, each failing on c8bddac in Chromium and Firefox:
- test_page_search_finds_words_an_output_runs_into (#20);
- test_page_search_reads_two_staged_widgets_side_by_side_apart (#21), with the shared
  staged cases failing in the browser's runtime test on c8bddac and passing in
  Python there and here;
- test_page_search_reads_a_said_label_apart_from_its_elements_words.
max-sixty added a commit that referenced this pull request Nov 16, 2026
…ed glide's scroll at its last frame (#6116)

Two browser timers decided what the reader saw by how fast the machine
ran. This change ends each of them on an event instead.

**Holding the reading place (`SETTLING_MS`, version.js).** After a
layout shift, such as a width change, the runtime puts the reader's
place back each time late widget layout lands, and it stopped doing so
after 1 s whatever was still preparing. In a probe in Chromium and
Firefox, a widget that prepared for 1.5 s moved the line being read by
200 px. The window now closes after the last widget preparation has
landed and one quiet rendering update has passed, when the reader's
input ends the last hold, or on a revision. The 1 s cap runs only while
nothing is preparing, for a page that never settles, such as an animated
chart. Preparations of 1.5 s and 4 s now keep the line in place.

**Scroll-end fallback (80 ms and two frames, arrivals.js).** `scrollend`
already ends every scroll that moves the box, in Chromium, Firefox and
WebKit. The fallback decides only scrolls that get none, mostly Leaf's
own glides, whose last frames move less than a pixel. A glide whose last
write moves nothing now ends right there, so the scroll a `d` press
makes ends in about 145 ms instead of about 230 ms in Chromium and
Firefox. WebKit's last glide frame still moves the box, so it is
unchanged.

What to weigh:
- A widget preparation that never ends keeps the window open, though
with no per-frame work, until the reader acts, a revision arrives or 12
size changes land.
- A CPU-starved Firefox still loses a key pressed during a scroll: it
applied the key's scroll up to 800 ms late, so the 80 ms ended the
reader's scroll before it moved (10 of 10 under heavy background load, 0
of 8 at normal priority). No event says a scroll won't come. Ending on
`scrollend` alone would need a backstop of about 8 s and rules
predicting which inputs move nothing, so the 80 ms stays.
- The controller now subscribes to preparations once, when it starts. A
subscription per window missed a preparation that began just before the
window opened, so the window stayed open and put back a later, unrelated
change.
- No browser test covers a slow preparation, because tests can't reach
`holdRendering`. The evidence for it is the probes.

Max asked for this ("research #21") in a review of timers that race a
slow machine. Codex reviewed it three times. It found a frame pause over
1 s that still closed the window early, a per-frame loop left running
after the last hold ended, and an expired cap's queued close racing a
preparation that began within it. Each is fixed, with a probe showing
the line move before the fix and hold after it.

Tests: `pnpm run test:runtime` (992), including a new arrivals assertion
that fails on main; `check:browser`; seven reading-place browser tests,
including the never-settles one; four scroll tests, two in Firefox.

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