Skip to content

Keep open pages working across Leaf updates, breaking only at a protocol bump - #2476

Merged
max-sixty merged 5 commits into
mainfrom
fix-delivery-cursor
Oct 12, 2026
Merged

max-sixty merged 5 commits into
mainfrom
fix-delivery-cursor

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Open pages stop breaking on every Leaf update. Until now each page server refused a page whose vendored runtime fingerprint (a hash of all of assets/runtime/) differed from the running Leaf's, and since #2416 the append door also refused every write when the hash of all Leaf's Python differed. Over the last 30 days those hashes changed in 751 and 494 of 1828 commits, so almost any plugin update left every open page unservable and unwritable by the new Leaf, its hooks included, until leaf page init. That is how a live session's hook came to deliver a batch, fail to record the pickup, and redeliver it every turn.

Compatibility is now a declared number. layer.PROTOCOL is recorded by page init as $layer.protocol; page servers (http.page_endpoint, the website's page_binding) and the append door (event_contracts.write_refusal) refuse only a page vendored at another number, through layer.incompatible_layer. The comment on PROTOCOL says when to bump it. A bump is when consumers have to re-vendor; between bumps, pages keep working.

Additive kernel changes stay compatible at one number because the running Leaf owns the kernel's event records: admission, the browser event door and sample histories validate against registry.kernel.kernel_event_kinds() rather than the page's captured $events, and registry/layer.validate_event_contracts is gone (merge_layer_declarations still stops a layer changing $events). This fixes the first half of #2415 — a newer CLI's reply refused by an older page's schema — without a re-vendor.

The hook also plans each page's write refusal once (PagePlan.unwritable): pick_up_acknowledged records no pickup on a page it cannot write, and the turn's attention names the refusal with its leaf page init remedy, instead of the prompt hook exiting 1 with nothing delivered.

Behavior changes:

  • A page another Leaf vendored at the same protocol is served, written and checked.
  • A page vendored at another protocol, which includes every page vendored before this change, is refused once with the leaf page init command.
  • The render gate (page check --render, page picture) still requires the exact runtime, now checked in render_gate/preview.py, because its probe modules import the page's runtime modules by name.

Part of #2415

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

max-sixty and others added 5 commits October 11, 2026 18:20
A hook records pickups in two places: receipt of a delivery, and the entry
of already-acknowledged, unanswered updates into a new turn
(`pick_up_acknowledged`). The previous change made a refused receipt hand
its delivery over as a pointer, but the second writer still raised on a
page another Leaf vendored: a prompt hook whose session owed an answer
there exited 1 before printing, so the turn got no delivery, no reminder
and no reason.

The hook plan now reads `event_contracts.write_refusal` once per page,
the same check the append door raises on. The hook records no pickup on a
page it cannot write and names the refusal (with its `leaf page init`
remedy) in the turn's attention, beside the pointer or debt reminder.

Behavior change: on such a page the prompt hook reminds the turn of its
debt instead of failing, and an undeliverable batch's pointer arrives
with the reason. Test: a prompt on a foreign page with acknowledged debt.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…col bump

Every page server refused a page whose vendored runtime fingerprint (a hash
of all of assets/runtime/) differed from the running Leaf's, and since #2416
the append door also refused any write when the hash of all Leaf's Python
differed. Over the last 30 days those hashes changed in 751 and 494 of 1828
commits, so nearly every plugin update made every open page unservable and
unwritable by the newly installed Leaf, hooks included, until `leaf page
init`. That is what stopped a live session's hooks from confirming receipt.

Compatibility is now a declared number. `layer.PROTOCOL` is recorded by
`page init` under `$layer.protocol`, and every page server and the append
door refuse only a page vendored at another number
(`layer.incompatible_layer`). The comment on PROTOCOL says when to bump it.
The render gate keeps the exact runtime check, now in `render_gate.preview`,
because its probe modules import the page's runtime modules by name.

Additive kernel changes stay compatible at one number because the running
Leaf owns the kernel's event records: admission, the browser door and sample
histories validate against `registry.kernel.kernel_event_kinds()` instead of
the page's captured `$events` copy, and reading a vendored layer no longer
requires that copy to equal the running kernel (`validate_event_contracts`
is gone; `merge_layer_declarations` still stops a layer changing `$events`).
This fixes #2415 part 1 (a newer CLI's reply refused by an older page's
schema) without a re-vendor.

Behavior changes: a page another Leaf vendored at the same protocol is
served, written and checked; one vendored at another protocol, including
every page vendored before this change, is refused once with the
`leaf page init` command. Tests: the reply and page-check case on an older
vocabulary, and the protocol refusals (server start, wait revival, website,
reply, hooks). Three tests that relied on a mismatched kernel copy being
refused now expect it to be read: an old plugin missing `attempt`, a page an
earlier Leaf left behind, and the Stop-guard test, which now breaks a
required declaration instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/scripts/leaf/event_contracts.py
# Conflicts:
#	worker/leaf_website/__init__.py
@max-sixty
max-sixty merged commit e22b91e into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the fix-delivery-cursor branch October 12, 2026 03:49
max-sixty added a commit that referenced this pull request Oct 12, 2026
…bers (#2486)

Follow-up to #2476. The page protocol number was a Python constant,
`layer.PROTOCOL`, that `page init` stamped under `$layer.protocol`,
apart from every schema it versions. It now lives in the kernel registry
as `$events.protocol`, beside the kinds and ownership it numbers, where
Leaf's other format versions already sit (`leaf-drawing/3` is a `const`
in the same object). A page carries the number in the `$events` it was
vendored with, so the `$layer` stamp, its storage check and its place in
the re-vendor comparison are gone; the layer fingerprint covers it.

- `layer.incompatible_layer` reads the registry a server would serve the
page under: a snapshot's captured one, or else the vendored layer.
Snapshot previews copied the raw `$layer` and lost the number, so they
refused freshly initialized pages.
- A layer may restate only `$events.handling` and `answering`; every
other member is the kernel's, compared as JSON so `true` or `1.0` is not
taken for 1, and the kernel's copy is kept
(`registry/layer.merge_layer_declarations`).
- The bump rule moves from the constant's comment to
`layer-registry.md`, "Page protocol". The stale `$events` description
claim that `page init` checks the existing log (removed in #2020) gives
way to the protocol sentence.

Behaviour change: a page vendored under #2476 records the number only
under `$layer`, so it is refused once until `leaf page init`.

The other version marks stay separate: `Leaf-Layer` checks a tab against
the page's current layer, and `leaf-delivery-v5`,
`leaf-codex-delivery-v4` and `leaf-user-views-v1` version state-home
records that change independently of the page contract.

> _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
…ture (#2495)

A refused send could lose the user's words, or leave gestures stuck
behind it. This makes a refusal give every word back somewhere the user
can reach, say where, and take down exactly the gestures that depended
on what was refused.

**What a refusal now does with the words**

- **An anchored comment refused while the user has done nothing since
Send** reopens its composer on its passage, with the words and focus, as
the page comment card already did. Before, the thread the send drew was
withdrawn, focus was handed to the banner, and the comment read as lost
(seen on a real page whose comment was refused).
- **Words returned to a box out of view** (the composer after the user
moved on, the page comment card that closed with the send) make the
notice read "Couldn't send — <reason>. Draft kept — g i resumes
writing", and become the Resume writing destination so `g i` reaches
them. Words back in a box on screen get no extra sentence.
- **A reply written under a refused comment's pending thread**, sent
behind it or still unsent, is kept as part of the comment's own draft
record (`held` in `drafts.js`). The notice adds "Reply kept — it returns
when its comment sends". Every edit of the comment keeps it,
`transferDraft` carries it when the draft moves (Alt-click to another
passage), and the comment's next send, edited or not, puts it in the
reply box of the thread it opens. Before, it stayed keyed to the refused
attempt and was unreachable.
- The notice is composed by delivery after every refused gesture's own
answer handlers have run. It is a reaction on the same answer promises,
registered after the senders' handlers, rather than a microtask that
happened to run later.

**Which gestures a refusal takes down**

`pending/model.js` now declares once the fields through which a command
names another event (`NAMING_FIELDS`: `parent`, `message`, `base`,
`undoes`). Two consumers read it:

- **`applicationState.refuse`** drops every pending gesture that names a
refused one in any of those fields, transitively. Before, it listed
`undoTarget` and `parent` by hand and missed an edit's `base`. A second
rewrite saved over a first one still sending was never refused and never
sent when the first was refused: it stayed on the message as unsent
words, and the delivery queue stalled behind it.
- **`nameEvents`** replaces `nameParent` and `nameUndo`, renaming every
naming field from a pending id to the admitted id before a send. It
keeps `namedParent` for a reply's thread, and still drops an undo whose
target the log never took.

**Not changed:** #2476 had already fixed the original "served page
refuses events after an on-disk runtime change" report, so this branch
does not touch admission.

**Known edges left:**
- One reply box holds one draft generation. A reply sent and then a
second typed in the same pending thread keeps only the second if the
comment is refused.
- The link from a first message's attempt to its draft (`openedFrom`) is
in memory only, so a reload while the comment is in flight loses it.
- Discarding a refused comment's draft discards the reply it holds.

Tests: new and tightened cases in `tests/test_render_drafts.py` and
`tests/test_render_threads.py`, each shown failing on the commit before
its fix. Focused runs over the refusal, undo, rewrite, reply, resume and
carry selections pass on the merged tree (99), as does `pnpm run
test:browser`.

> _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
…elivery (#2505)

Follows #2476 and #2486, which let any Leaf at the same page protocol
serve and write a page another Leaf vendored. Three places still broke
on an ordinary plugin update, or would break silently when a contract
change slipped past the bump.

**The render gate refused nearly every existing page after an update.**
`layer.foreign_runtime` refused any page whose vendored runtime bytes
differed from the running Leaf's, which most commits change, so the
pre-handover `page check --render` failed until `leaf page init`
restarted the page's server and reloaded the user's tab. `page picture`,
which loads no probe module, was refused forever on revisions saved
before an update. Now every page snapshot serves this Leaf's probe
modules (`page_snapshot.py`), whichever Leaf captured the revision, so
the gate's Python readers and the probes they call always agree, and the
probes link against the page's runtime by name. A probe load that fails
with a `SyntaxError` answers `{unlinked}` from the driver, and the gate
refuses with the browser's reason and the re-vendor
(`render_gate/preview.py`). `foreign_runtime`,
`payload_runtime_fingerprint` and `$layer.runtime` are deleted.

**Input on a page this Leaf cannot write looped.** On a page vendored at
another protocol no receipt can be recorded, yet the watch delivered its
input on every pass, and Codex's receipt paths, which catch only
`ReceiptRefused`, failed every retry with `EventRefused`.
`receive_batch` now refuses such a receipt as `ReceiptRefused`, and
`delivery.deliverable` gives a watch, its nudge, both Codex capture
sites and the Claude Code and Pi hooks no input from such a page. The
input waits for a Leaf that can write it; the prompt hook still names
the page and the re-vendor.

**Nothing caught a breaking event-contract change shipped without a
bump.** The browser build now keeps
`build/browser/protocol-contract.d.ts`, the generated event contract as
it last stood at the current `$events.protocol`, and `protocol.test.ts`
fails a change that drops a kind or a field at any depth, requires a new
one, or narrows a type or constant. A passing build moves the baseline
forward; a bump starts it again. Patterns, bounds and conditional
clauses are not in the generated types, so they stay unchecked, as
`layer-registry.md` says.

Tests: `test_the_browser_gate_reads_a_page_another_leaf_vendored` and
`test_the_browser_gate_names_the_re_vendor_when_its_probes_cannot_link`
replace the refusal test, and fail on the old gate;
`test_codex_retires_a_receipt_on_a_page_its_leaf_cannot_write` and
`test_a_watch_delivers_nothing_from_a_page_its_leaf_cannot_write` and
`test_a_prompt_offers_no_new_input_from_a_page_its_leaf_cannot_write`
reproduce the loop. The protocol check was exercised by dropping a
nested drawing field, a field inside a list, a kind, adding a required
field and changing the drawing format (each fails), and adding an
optional field (passes).

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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