Repository navigation
Lift a refusal by a switch rather than by taking the route away - #26
Conversation
`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 poll lost 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. The assertion is what runs out, since nothing else does. That is the cross-tab settlement test's red on CI: the tab cut off from the log rejects a suggestion the log already holds an accept for, and the lift of its refusal lands inside the reject's own poll about one run in ten under load. Four of forty-eight loaded runs failed with the runtime's stage stuck at the minted event, the tab's poll counter one ahead of the requests the browser reported, and `data-lf-state` unwritten while the two live tabs had both folded to reject. So a refusal stays on the page for its whole life and answers every request it is handed; lifting changes which answer, not whether there is one. `CutOff` is that one handler, `held_stale` is it with the stamping poll let through, and the six sites that stopped a page's polls and started them again go through it. The seventh unroute is left with the reason it is safe: it holds and continues rather than refusing, its arrival is over, and the next one navigates away. Forty-eight loaded runs of the cross-tab test pass where the same load failed four, and twenty-four loaded runs of all seven converted tests pass. The complete suite reports 956 passed with `test_z_walks_back_through_gestures_ rather_than_toggling_one` red — the shape PR #24 is open for, red on main before this change and green alone here.
leaf-agent
left a comment
There was a problem hiding this comment.
Self-review. The diagnosis holds up and the conversion is faithful: every converted site keeps the same answer before the lift (lets_through=1 reproduces held_stale's old next(polls) == 0, lets_through=0 reproduces the bare refuse), and the two sites whose pattern widened from **/api/state to **/api/state* match the same request, since the runtime's only poll is fetch("/api/state") with no query. The arrive() exemption checks out too — the runtime schedules polls with setInterval, not chained off the previous one, so a stranded poll there costs that page nothing later.
Scoping the fix to /api/state and leaving the **/api/event unroutes alone is the right line, and the reason is worth having in the comment: /api/event is only ever requested by a gesture the test makes (or by reportPageError, which nothing awaits), so those unroutes never land on a request nobody asked for — where a timer's poll is exactly that. As written, the comment names the mechanism generally and then converts only the state sites, which reads as an oversight rather than a boundary.
One thing to drop below.
The pattern parameter had no caller and read as though the class were generic over any route; it only makes sense for the timer's poll, which is the request a lift can land in the middle of. Inlined, and the comment now states the boundary it had left implicit: an event is posted only by a gesture the test just made, so the api/event unroutes are where the mechanism stops applying rather than sites left unconverted.
|
Both actioned in b55a4d7. The
|
leaf-agent
left a comment
There was a problem hiding this comment.
Self-review of b55a4d7. The pattern inlining is right and every .hold(...) call site passes only page, so nothing breaks.
The new paragraph is the problem: it names **/api/event as the boundary, and that is not where the mechanism actually stops. Four page.unroute("**/api/state*") calls survive in the file, each dropping a live **/api/state* handler whose poll branch is refuse — the exact shape the header two paragraphs above forbids absolutely ("A refusal is lifted by a switch the handler reads, never by taking the route away"). Detail inline.
The PR description undercounts the same way: tests/test_render.py carries eleven unroute("**/api/state…") calls at the merge base, not seven. Six go through CutOff, one (arrive) gets the exemption comment, and four are unaccounted for. Worth correcting there too, since the description is what a reader checks the conversion against.
|
The four surviving |
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.
leaf-agent
left a comment
There was a problem hiding this comment.
Self-review of the increment (16e68bf, b81fcfd). The conversion is complete and correct: **/api/state* now has exactly one surviving unroute, the exempt one in arrive(), and the four sites the last review named are converted. cut() reads right — with _live true the or short-circuits, so the count is never advanced by a live poll and a second cut restores the refusal without rewinding lets_through (I ran the switch table for lets_through 0 and 1 to confirm). The two hand-rolled lifted flags are sound too: rebinding a name the nested handler closes over is read at call time, so lifted = True reaches hold_older_state and malformed_poll_state, and both check the flag before the branch that would otherwise refuse or hold.
One thing, on what survives the merge. b81fcfd deleted the sentence that stated the norm — "A refusal is lifted by a switch the handler reads, never by taking the route away" — and it now exists nowhere in the repo. What remains is a three-line comment above one class in a 26k-line file, while tests/CLAUDE.md, which the root CLAUDE.md names as the owner of test rules, still says the opposite in the paragraph beginning "Every hold has a release path": "…continue or fulfill the route, wait for the handler to finish, remove the route, and only then close the page… Put release and unroute in cleanup that also runs when the assertion fails."
That paragraph is about a hold rather than a refusal, but it is the only place the mechanics file speaks about taking a route away, and **/api/state* still carries ~20 live route(…, refuse) registrations. The next test that needs to stop a page's polls and start them again reads that paragraph, reaches for unroute, and reopens the window this PR closed — with no gate anywhere to catch it, since the failure is a one-in-ten flake in an unrelated assertion. The fix this PR makes is durable in the file; the reason it was made is not.
A sentence in that paragraph would carry it — something like: a poll route is the exception, since the timer issues it whenever it comes round and a lift is free to land mid-request; switch its handler between refusal and continuation (CutOff) rather than removing it. Happy to push that as a commit if you want it, but the prose is yours — you just trimmed this material deliberately, so I'd rather ask than write over the call.
lint is green on 6fde164. test was still running when my poll cap expired, so I haven't verified it.
|
Merged before On the doc question, leaving it as your call and not pushing over it. The merged file keeps the mechanism in the comment above |
The Lit application arc between 2026-09-13 and 2026-09-17 closed #1 and #3 without the list recording it: `semantic-state.js` is 77 lines over one publisher and `application.js` holds no DOM reference, while `version.js` activates through one door returning one result that `state-application.js` adopts atomically. Both leave for git history. The largest remaining duplication was not on the list. `scripts/browser/application.ts` re-derives the Ask inventory, the winner resolution and each thread's `awaits_reader` from a wire that already carries all three, roughly 750 lines that arrived in #746; the two copies of the `when` predicate already disagree on an attribute recorded as `null`, and nothing compares them. That inverts #4, which asked for a corpus proving parity between the two implementations — built first it would police one that should go — so #4 now names the deletion and the corpus follows it. Three items are new. #25 is the Worker's second App Server client, whose reconnect backoff is written four times and has already drifted. #26 is the generated-hint machine that `go-to-sequence.js` and `target-chooser.js` each build. #27 is admission: six of the nine `append_event` callers check no contract, and of the three that do, `cmd_receipt` uses a validator `requests.py` defines itself, so the rules sit in two homes and the gate in three against a stated boundary of validating once at the edge. They take ids above #23 because `notes/workspace-followups.md` numbers its research #1 to #23 and the workspace section here draws from it, so #9 and #10 were already spoken for. The section now says where its ids come from rather than leaving the next writer to rediscover it. The items that stay keep their numbers and gain what the survey measured: how much of `margin-projection.js` is already free of the DOM, what fraction of the render suite drives no input, and the 53 capabilities `page.js` and `leaf.js` both name. #8 stops waiting for a change to prove the need, which has happened. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`g`'s map of visible page targets and `s`'s map of addressable elements were one interaction implemented twice: arming, opaque prefix-free codes, a typed prefix that narrows, an audible Tab walk, Enter to take the one just heard, Escape to give a letter back, a scroll freeze, and a keyed chip layer — written out in full in each owner, sharing only three helpers from `keyboard/hints.js` before rebuilding everything above them. `hints.js` now owns that interaction as `createHintSession`, and each owner declares what its scene holds, what a chip says, what taking one does, and the words it speaks. This is TODO #26. The session separates the two readings the old copies mixed. `read` answers which members the map holds and what codes name them, and is held until something invalidates it. `layout` answers where those members are, and runs every paint over the whole standing set from one `scene` reading — because a chip's place among its neighbours and its own box are the same measurement, and derived from different readings they put the chip where neither reading said. ## What changes for the reader **The target chooser gains a scroll settle.** `scrollend` does not arrive for a programmatic scroll written a frame at a time, nor for the scroll a replaced scene restores, which is why Go-to carried an 80ms timer and why [the dependency survey](notes/dependency-survey.md) rejects `scrollend` alone. The chooser had only the event, so a scroll that never ended left its hint membership frozen until the next resize. **A letter naming no hint leaves the chooser's typed prefix standing**, rather than throwing away the letters the reader had already got right. Go-to has always reported the miss and kept them. Two smaller unifications come with it: the chooser now revalidates a candidate against a fresh reading before taking it, and an invalid letter no longer clears the audible walk position. **The chooser's codes survive a page change.** It used to re-read the whole scene on every paint, which reassigns codes: a page change under a standing map moved `a` from one target to another, so the letter the reader had just read took them somewhere else. Membership is now held until something invalidates it, which is how the Go-to map has always behaved. ## The geometry underneath What the reader can see of a target, net of fixed chrome, was answered twice. `clippedRect` meant two different things in two files, `overlaps` had four copies, and `fixedChromeBoxes` was a second name for `bottomChromeBoxes` — which is why the chooser could not use `keyBadgePlacement` and rebuilt everything above it. That reading now has one owner, with the two answers that genuinely differ named beside each other: `badgeBox` starts at a member's corner and clamps it to the banner, `visibleBounds` cuts the bottom chrome's lanes out of its whole box. So Go-to and the chooser still disagree about a target the shortcut bar's lane covers: Go-to keeps its route and spreads the chip clear, the chooser drops it. That is a product question about what "visible" promises rather than a difference in the geometry, and it is now one edit rather than two. ## Evidence The first two changes above are fixes to shipped behaviour, and their tests fail on the merge base. Two further tests guard the extraction rather than fixing anything on `main`. Review of the session found that the first commit had broken both and the third repairs them: an open page search's mark stopped following the page when slash was pressed from the page rather than from the map, because the map's door had become the only one and a direct slash arms no map; and a chip's step past an enclosing box was measured a paint apart from the box it starts from. Both were reproduced by comparison with the merge base, where the mark tracks and the step is re-derived. Every new and changed behaviour is pinned by a test that fails when its own fix is reverted. Complete suite green at 2721. Baseline (`d2fefc94`) and candidate previews of `examples/ship-review.html` at 1280×900, `g` and `s` armed: identical chip counts, codes, pixel seats and live-region text, and no console errors on either side. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
…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]>
… connection, and choose Page Map receipts in the model (#2504) Follow-up to #2349, from the review of the Lit survey PRs (items #25, #26 and #27 in that review's numbering, not GitHub issues). **#25: `said` deleted; one factory for element directives.** `said` had one caller, which passed the constant `false`. Every other template writes the label markers as static attributes, and that is now the only form: thread-card's resolved summary writes `data-lf-gen="1"` again, and `module-authoring.md` and the `relabel` comment now describe the static markers. The `said` export, its test and its authoring line are gone. `offered`, `contributionHost` and `contributionReceipts` each repeated the same element-part skeleton; `elementDirective(name, write)` in `widget-elements.js` now builds all three. Rendered markup is unchanged. **#26: `commandsOn` attaches once per connection.** Before this change, every render re-attached the scope, which meant re-validating it, re-wiring its buttons and running `paintKeys()`. That made the next frame re-read the shortcut attributes of every scoped element on the page. Now a re-render puts a fresh scope with the latest declaration (title, rows, callbacks, `when`) in place of the last one (`standScope`). It then queues one reading of that element alone, the same reading any new declaration gets on its first paint, without the page-wide pass. As before, a row whose `when` turns false loses its `aria-keyshortcuts` on the next frame. The scope is replaced rather than changed because its contextual aliases are built from it once. Measured with the reviewer's probe (20 template rows beside 300 other scoped elements), an unchanged re-render now costs 120 attribute reads instead of 2,040. `detachScope(element, scope)` is now the one way an element's own declaration is withdrawn: when the directive leaves, and when a first reading refuses the declaration. It re-reads the element from whatever scopes remain. That also fixes a bug `main` already had: a declaration refused on re-render kept its stale `aria-keyshortcuts`, and because the element then left the reference's list, nothing ever cleared it. `forgetScopedElement` now itself checks that nothing else declares on the element, which removes the same check from its three callers. The never-passed `validateAtPaint` option is gone. **#27: the Page Map's receipt choice moves into the model.** `marginMapGroups` gives every row an `action.receipt` (and `awaitsUser`). A control row gets the target's receipt when the margin shows that receipt on the same control (`workflowCarrier`), and otherwise its own record's receipt. Item rows and control rows now both bind `contributionReceipts(action.receipt, action.awaitsUser)`. `contributionHost(source, surface, record, options)` tracks the host on its surface itself, as `materializeContributionControls` does for every host it presents, and the `paint` callback is gone. The test that asserted the callback received the control now asserts that the template host matches the imperative host and that the host is found on its surface. A new `margin-model` assertion covers which receipt each row gets. Line deltas (hand-written source excludes tests and Markdown): | | source | tests | |---|---|---| | #25 (`widget-elements`, `thread-card`, `widget-api`, the directive half of `contribution-controls`) | about −43 | −23 | | #26 (`keyboard/scopes.js`) | +20 | +89 | | #27 (`page-map-dialog`, `margin-map-model`, the host half of `contribution-controls`) | about −5 | +13 | | total | −28 (+132 −160) | +79 (+111 −32) | Checks: the `command-controls`, `margin-workflow`, `margin-model`, `passage-boundaries` and `indication` runtime tests. The two new `command-controls` cases fail on `main`. In one, an unchanged re-render reads an unrelated scoped element 3 times. In the other, a refused re-render leaves `aria-keyshortcuts` behind. Browser: two Page Map cases (`test_open_page_map_uses_the_canonical_margin_entry_record_and_live_state`, `test_unit_claim_arrivals_share_one_window_with_the_open_page_map`) and three `commandsOn` journeys (quoted passage, Questions panel, a thread Question's Done). > _This was written by Claude Code on behalf of max-sixty_
…s from TODO (#2525) TODO.md gave #6 and #7 to items that notes/comparisons.md numbers differently, so a bare id could mean either; TODO's two items are now #26 and #27, the unfindable "#7 in the simplification audit" label is gone, and the header says an id names one item across TODO.md and notes/. Nothing outside TODO.md referred to the old ids. notes/prose-review.md was mostly a record of landed phases, so it is now notes/site-structure.md and holds only the open site-route proposal and its two decisions, noting that the proposal predates /threads/ and /website/ and that removing /registry/ has to re-home the `x-` key index `leaf-dev keydocs` writes there. The stale "Rewrite Leaf's prose" Now item, which still said the maintainer rewrite awaited review and cited five decisions, becomes an Etc item triggered by preparing a release, as the note itself deferred both decisions. Three notes no TODO item linked now have one: undo-reach/ as a Next item waiting on the user's pick, and datastore-review.md and named-widget-interfaces.md (#16) as Etc items with their triggers; named-widget-interfaces.md now counts the diff package's typed reference (`lf-call-diff` through `$diff.widgets`), and #16's trigger names the command `goal` and `readings` interfaces. The rust-sort item now links the workspace decision in chrome-and-covers.md instead of calling that note its plan. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…the undo pick (#3493) Applies the answers given so far on the TODO and notes decisions page. Prose only: no code, tests or instructions change. - **Five finished TODO items go**: tabbed sections (`lf-tabs` placement covers them), #27 runtime fold tests (`tests/AGENTS.md` states the practice), the favicon count, `leaf-dev` charts (`journey-chart --replies` adopted it), and #26 Codex supervision. - **MCP Apps folds into TODO**: `notes/mcp-apps/PROJECT.md` goes; its TODO item keeps the design, acceptance criteria and the probe's commit `a8ed55e68`. - **#23 workspace persistence is dropped** with `notes/workspace-followups.md`; #20's brief moves into its TODO item. - **Undo reach is decided**: keep `z`'s reach unlimited, name the gesture and its age, and spend the first press revealing a target that is out of view or already picked up. `notes/undo-reach/README.md` now briefs that build; its playground goes (kept in history at `29966712b`). - **The agent-driven UI-quality note goes** with its TODO item; `leaf-dev eval-ui-review` and `/ui-sweep` cover what it proposed. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…the words after it A worktree's summary draws its label and its branch on two rows of a grid, but the template ran `</strong>` straight into the branch's `<span>`, so both readings read "retain-draftscodex/retain-drafts" and searching "retain-drafts codex/retain-drafts" found 4 on main and none here (#25). Ten figure captions in docs/ui.html (7) and docs/threads.html (3) run a title the docs' CSS draws as a block straight into the caption's text, so "A large windowThe workspace…" read as one word and searching "window The workspace" found 1 on main and none here (#26). Each now has whitespace there, which the grid and the block title draw as nothing. A `<summary>` holds phrasing content only, so the worktree's two rows stay spans; the captions keep the one form every other caption in the docs has, a title and then its text after a space. The `serve` fixture now resolves an example's package selected by its path from the checkout (the docs' `./docs/package`) against the checkout rather than the page's scratch directory, so a test can serve a product doc as it ships. Tests, each failing on a930610 in Chromium and Firefox: - test_page_search_reads_a_worktrees_label_and_branch_apart (#25); - test_page_search_reads_a_docs_captions_title_apart_from_its_text, on ui and threads (#26).
Problem
Run 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(), actualvisible— with the log holding the reject the assertion is about. The cause is the test's own instrument:page.unroutedrops 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
postawaiting forever — the widget the gesture was made on stays insending,reconcileStateskips it for the rest of the tab's life, and the page sits ataria-busydisagreeing 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.
CutOffkeeps that handler installed and switches polling between refusal and continuation. On currentmain, eleven of the twelve polling-route lifts now use this pattern. The remainingarrive()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-commitwas clean.The reading that named it
Three tabs,
thirdbeing the one cut off.pollscounts entries topoll(),asked/heardareTraffic's counts of what the browser reported:Seven polls, six requests: the third one's
fetchwas never issued to the network the browser reports on, and never settled.posttherefore never reached itsreturn minted,sendAction'sfinallynever ran, andsendingkeptsug-thistleout of every later reconciliation — the timer polls beside it kept working the whole time, which is whytold(third)returned and only the widget was wrong.What this does not change
The runtime's own behaviour under a poll that never returns is untouched: a stalled connection would pin a widget the same way, since
postawaits the read it ends with andsendingis 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.Automated fix for failed run