Skip to content

Derive read state on the server from every reader move, and send read outside the gesture queue - #987

Merged
max-sixty merged 7 commits into
mainfrom
fix-read-state-model
Sep 23, 2026
Merged

max-sixty merged 7 commits into
mainfrom
fix-read-state-model

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Unread is now one server reading that every surface and the agent share, and read no longer rides the gesture queue.

The concept. read_state.unread_content derives, per thread, the agent content versions the reader has not read. A version is read once a read event names it, or once the reader moves in its thread after it: reply, reaction, answering a widget in it, resolve, or reopen. A move the reader later undoes does not count. An edit is a new version, so it reads as unread again. The browser gets this as each Thread's unread: [{message, version}]; leaf page state and leaf conversation read give each conversation's unread message ids. The Threads toggle, the panel's Unread jump and counts, the "New since you last looked" boundaries, margin entries (a new dot), Page Map rows and news all paint that one list. Before this, answering an Ask and then resolving left "1 unread thread" standing.

Bookkeeping, by declaration. $events.kinds.read declares bookkeeping: true. requires_agent_attention reads that declaration instead of checking the kind. In the browser, marking read has its own door (deliverBookkeeping) and its own publisher input (markingRead), both outside the ordered gesture ledger. The kind carve-outs in delivery.js, pending/model.js, application.js and application.ts are gone. A failing read no longer holds a Resolve back or mutes its "Connection lost" notice. A refused read is not resent; one whose answer never arrived is sent again on the next exposure pass.

One "last moved". moved(message) is the latest edit, else the message's arrival. It orders Recent (via threadSummary().latest), the first unread, and news, so an edited agent message now sorts under today's date group.

News uses the same unread reading. Unread agent content is news the first time a tab sees it, including when the page opens. A reply already read in another tab is not announced, and one read before its queued notice shows is dropped.

Exposure. The wide-code veto (hasHiddenInnerScroll) is removed. Geometry can say that a body's whole extent was shown. It cannot say which columns of a code line were read, and the veto kept such a message unread forever.

Docs. conversation-threads.md loses its reader-UI sections, and a short "What the reader has read" section for agents takes their place. conversation-loop.md no longer calls viewed the only reading of the reader's side. Reader-UI rules move to assets/CLAUDE.md. packages.md documents unread, message unread, edited and latest. In guidance, "acknowledge" now means only delivery (leaf wait --ack); leaf status --help says "unacknowledged input".

Tests that moved:

  • New Node tests cover the marking-read overlay, moved and threadSummary, Recent across midnight and DST, the unread boundary fold (extracted into summary-ranges.js), and narrowing transitions and facet counts.
  • The Python tests cover reader moves marking content read, edits reopening it, and page state.
  • The browser read-state tests drop geometry pins. They add a check that a Resolve goes out beside a held read and itself marks the content read, and a check that a wide code reply is marked read.
  • The chrome news contract now expects unread replies to be announced on open.

Known red that does not come from this branch: test_render_navigation.py::test_pressing_a_page_mark_stands_in_the_thread_it_opens[long] also fails on the merge base afb2133.

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

🤖 Generated with Claude Code

max-sixty and others added 5 commits September 23, 2026 00:02
… outside the gesture queue

Unread is now one server reading (`read_state.unread_content`) published as each
Thread's `unread`: a version is read once a `read` event names it or once the reader
replies, reacts, answers a widget in the thread, resolves or reopens it afterwards.
Panel, banner, margin entries, Page Map rows and news all paint that list, and
`leaf page state` / `leaf conversation read` expose it per conversation.

`$events` declares `read` bookkeeping. The server's agent-attention test reads that
declaration, and the browser marks versions read through its own door outside the
ordered gesture ledger, so a failing read no longer holds a gesture back or mutes
its outage notice. One `moved` primitive (latest edit, else arrival) orders Recent,
the first unread and news. News announces unread agent content the first time a tab
sees it, including on opening, and drops what was read before it showed.

Exposure no longer refuses a message holding its own scroller, such as a wide code
block. Behaviour that moved in tests: first-reading news in the chrome contract, the
bookkeeping delivery in the read-state tests, and geometry pins replaced by the
unread boundary fold's Node test.

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

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

Page state conversations now carry `unread`; the tests comparing them whole say so.
A resolve naming a thread whose opening message the log lost now marks it read.
The wide-code test waits for its read to reach the log.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/conversation/read.js

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unread_content reads the reader's moves straight off events, so a gesture they took back still counts as evidence they read the thread. Take back a resolve and build_threads reopens the thread while the same server reading keeps every agent message in it read; take back a reaction and the content it stood beside stays read too. Nothing later restores it — the messages are read for the rest of the page's life unless the agent edits them.

taken_back in events.py states the rule the other folds follow: "An undo names the gesture it withdraws and carries no counter-state, so every projection drops those ids." This is the one projection that doesn't, and the inconsistency is inside a single fold — the thread is open again, its content is read.

The inline suggestions add the filter. If the intent is the other way — that withdrawing an answer does not un-see what the reader answered — then the module docstring is the place to say so, since it currently reads as "a reader move in the version's thread logged after the version" with no exception.

Reproduction
from leaf.events import build_threads
from leaf.read_state import unread_content

events = [
    {"id": "c1", "seq": 1, "kind": "comment", "author": "agent", "text": "Question?"},
    {"id": "r1", "seq": 2, "kind": "reply", "author": "agent", "parent": "c1", "text": "More context."},
    {"id": "s1", "seq": 3, "kind": "resolve", "author": "user", "parent": "c1"},
    {"id": "u1", "seq": 4, "kind": "undo", "author": "user", "undoes": "s1"},
]
threads = build_threads(events, {})
threads["c1"]["resolved"]                      # None — the undo reopened it
unread_content(events, threads, {})            # {'c1': []} — but its content stays read

With the suggested filter both agent messages come back unread, and tests/test_read_state.py stays green.

Comment thread skills/leaf/scripts/leaf/read_state.py Resolved
Comment thread skills/leaf/scripts/leaf/read_state.py Resolved
max-sixty and others added 2 commits September 23, 2026 01:12
Every fold over the standing log drops what an undo took back; the unread reading
now does too, so reopening a thread by undoing its resolve reopens what it held.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	scripts/browser/generated/browser-runtime.js.map
#	scripts/browser/generated/browser-runtime.manifest.json
#	skills/leaf/assets/vendor/browser-runtime.js
@max-sixty
max-sixty merged commit 131443d into main Sep 23, 2026
5 checks passed
@max-sixty
max-sixty deleted the fix-read-state-model branch September 23, 2026 08:59
max-sixty added a commit that referenced this pull request Sep 23, 2026
`test_opening_threads_acknowledges_the_first_visible_answer` failed once
on #1010's first CI attempt with no `read` event in the log. The cause
is the harness wait, not the runtime.

`round_trip` treated a trip as over once the outbox held no attempt.
Some posts skip the outbox: a bookkeeping event such as `read` (#987,
`delivery.js`), the page's own `error` report, and a media upload
(`layer-client.js`). So `sending` around a gesture whose event is a read
returned as soon as the read's POST went out, and the log read behind it
raced the server's append. Holding the read's POST for 300ms reproduces
the CI failure every time (`IndexError` on `_read_events(...)[-1]`). 80
copies under `-n 12` did not reproduce it on a Mac.

- `round_trip` also requires every issued post to have ended (`acked ==
sends`), through a `heard_back` predicate on one ledger reading. The
outbox condition still covers a failed post that the page will retry.
- The read-state test holds the read before the server appends it, so
every run hits this timing. While the read is held, it asserts that the
ledger does not yet count as heard back. With the old predicate, that
assertion fails on every run.
- Three paint-failure tests (`test_a_failed_ask_banner_paint…`,
`test_a_failed_ask_list_paint…`,
`test_a_failed_thread_list_update_retries…`) held `/api/event` and
released only the first request. The page's own `error` report of the
injected failure was also held and never ended. The stricter
`round_trip` exposed this. Those tests now wait with `holding` for both
requests, then release both.

`traffic.js`'s header, the `round_trip` comment, and `tests/AGENTS.md`
now describe the wait as both conditions and list the posts that skip
the outbox.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty pushed a commit that referenced this pull request Sep 23, 2026
…being true (#989)

This removes runtime code that nothing reaches any more and corrects
comments that justify code with reasons that stopped being true. The one
reader-visible change: the first-unread button's accessible name used to
announce "1 unread messages" and now says "1 unread message".

**Stale reasons.** Both `lf-chart.js` and `keyboard/scopes.js` justified
their shape with "every x-upgrade module loads on every page". Since
`importWidgets` became import-on-demand, that is false:
`widget-loader.js` imports only the declared tags that stand in the
markup. The code in both places is still right, for a different reason:

- **Plot import:** Plot still loads on the first draw, so a chart in a
shut panel keeps the 384KB bundle waiting until `measure` releases the
draw.
- **Scopes:** keyboard scopes still register at upgrade, because a
module outlives the elements it upgraded.

Both comments now say that. In the same vein, `widget-elements.js`
pointed at `keyboard/page.js` for `unaccountedGesture`, which lives in
`composing/engagement.js`. `lf-tabs.js` compared its tab memory to the
scroll position, which `storage.js`'s own header already names beside it
— "the reading position, which panel of a widget stands open, whether
design mode is on" — so the analogy was a second copy of what the store
settles, not a fact the widget owns.

**Dead code:**

- **`capture.js` / `selectionAnchor`:** computed `section` from
`datum?.dataset.lfProjection` before returning `anchorForDatum(datum)`,
which sets `section` itself. `section` is now computed only on the path
that reads it.
- **`state-application.js`:** `threads ?? []` and `receipts ?? []` guard
fields the served state always carries. The same function already reads
`threads.flatMap` unguarded a few lines later.
- **`engagement.js`:** `replyBoxHasDraft(...) ?? null` repeated a `null`
the callee already returns.
- **`read.js`:** no caller outside the module uses `scan` or
`scheduleScan`, so they are no longer in `createReadAcknowledgement`'s
returned object.

**`widget-api.js`: who imports the facade.** The first push removed the
`pageScroller` re-export after reading the runtime tree for importers
and finding none. The importer is `leaf/render-checks/layout.js`, which
loads the facade over HTTP from the served page, so no runtime-tree
search reaches it; every render gate then failed to parse its probe
module (`does not provide an export named 'pageScroller'`) and `test`
went red. The export is back, and the facade's header now states the
rule once rather than annotating the one export that broke: seven
modules under `leaf/render-checks/` import seventeen names this way, and
each is as invisible to a `runtime/` search as `pageScroller` was.

**Reference.** None. This branch had added the Thread's `unreadCount`
and the message's `unread` flag to `packages.md`; #987 landed first,
dropped `unreadCount` from the Thread model in favour of an `unread`
list of `{message, version}`, and documented both fields itself. Merging
`main` took its text for those two sentences, so the reference is
unchanged by this PR.

**Checks.** `lint` and `test` were green on `9a4d0815`, before `main`
was merged in.
`tests/test_smoke.py::test_a_shipped_page_passes_the_real_browser_gate`
fails on `c4f5edf8` with the SyntaxError above and passes on `9a4d0815`.
`npm run test:runtime` passes at the current head (77 tests). The plural
fix has no regression test: pinning one aria-label string would need a
browser case whose only assertion is that string, which
`tests/CLAUDE.md` would not keep.

---------

Co-authored-by: leaf-agent <[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