Skip to content

Read the server's Ask reading in the browser instead of deriving it again - #808

Merged
max-sixty merged 3 commits into
mainfrom
agent-a6b528393561ab81e
Sep 18, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-a6b528393561ab81e

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

TODO.md #4. application.ts folded the whole Ask reading a second time — which Asks a document holds, which of them the reader still owes, every declared target's awaiting value, and each thread's awaits_reader — over DOM-captured descriptors, while leaf.asks folds all of it under the page transaction that answers every state read. The browser copy is gone and the wire is what it reads.

Deleted: deriveAsks (176 lines), deriveThreadReaderObligations (55), the ask predicates between them, admittedUnansweredAsks with the approval gate's projectionDeferred branch, and askDescriptor / conversationDescriptor / retirementAncestors in widget-descriptors.js, which existed only to feed them. In their place, normalizedAsks maps the wire's records to the public {id, tag, sourceId, sourceTag, thread} shape, page asks before thread asks.

served_state/document.py serializes the page reading it has been computing and dropping since #747, and served_state/conversation.py builds its own through one _AskReducer rather than two. Each listed Ask now names the source that answers it beside the surface the reader is sent to, which is what the browser's records carried and the wire did not; leaf state shows both as well.

The two copies of the when predicate disagreed: Python asks whether an attribute is present and TypeScript asked whether it was non-null, so an attribute a value record had set to null read differently on each side. Python's reading is now the only one, and the browser's action-availability gate and the server's POST door read the same unanswered_awaiting map.

What moves on screen

The Ask reading is no longer optimistic, and that is the one judgement call in this change. A reader still sees their own gesture in its widget at once — the pick, the cleared pick, the swiped card, the withdrawn classification, the controls rebuilt by an Undo — because the unresolved-attempt ledger, foldThreads' pending branch, the DOM-captured authored baseline and foldWidgetStates all stay. But the Asks tray, the banner count, the a/A walk, the approval gate and an action's requires gate now turn over when the state that gesture's own POST returns is adopted, where they used to turn over as the gesture was sent.

Keeping them optimistic is what the deleted code was for: doing it exactly needs the answer verbs, the until verb, the nonempty-facet rule, the completion containers, the rollup tree and the existence reading — which is the duplication itself. Against a local server the gap is one short round trip: answering and withdrawing an answer on review-a-plan in Chrome moved Asks 0/1 and the Approve control with no visible lag, console clean. Eight tests asserted the reading at the held-POST moment and now assert it on the log's answer, and CLAUDE.md's cross-runtime invariant now says which gestures the page can draw for itself and which wait for the log. Revert that paragraph and those eight tests together if the optimism should stay.

One case is not that delay and is fixed rather than accepted (leaf-agent found it): a thread carrying a frozen Ask the reader still owes used to lose its "awaits you" mark the moment they started sending a reply and take it back when the reply landed — true → false → true, reversing direction rather than lagging. A thread the server still names in the reader's Ask list now keeps awaits_reader over foldThreads' pending-reply branch, read off that same list rather than folded again.

A correction to the item

TODO.md #4 also said foldProjection re-folds the winner resolution although the wire carries actions / reports / desired. It does not: it has consumed those id lists since #525. Its only re-derivation is recompute(), which runs solely for coordinates a pending entry touches, to reveal the next durable winner when a local undo withdraws the server's — the pending ledger's own work. Removing that would take a wire addition (per-coordinate ordered eligible candidates), not a deletion, so it stayed.

Validation

  • uv run pytest tests — 1,145 passed on this head
  • uv run pytest tests --run-nightly on the first commit — 2,723 passed, 1 failure (test_render_export.py::test_a_detached_preview_restarts_under_its_original_codex_claim) traced to a leaf ack waiter left standing by my own earlier scripts/preview.py run; tests/test_render_export.py is 59/59 green with that state cleared, and 59/59 on the merge base as a control
  • npm run check:browser and npm run test:browser — 55 passed
  • uv run pre-commit run --all-files
  • Chrome, review-a-plan preview: answered the Ask, watched Asks 0/1 → 1/1 and Approve enable; deselected, watched both reverse
  • test_a_live_revision_reapplies_the_authored_conversation_seat_predicate read openAsks() straight after sending(...) and failed 1 in 3 alone, because the Ask list is the applied state's now and round_trip returns one beat before applyAcceptedState finishes; it reads through told(page) and is 4/4

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

max-sixty and others added 2 commits September 18, 2026 12:16
…gain

`application.ts` folded the whole Ask reading a second time — which Asks a
document holds, which of them the reader still owes, every declared target's
awaiting value, and each thread's `awaits_reader` — over DOM-captured
descriptors, while `leaf.asks` folds all of it under the page transaction that
answers every state read. The browser copy is gone and the wire is what it
reads: `deriveAsks`, `deriveThreadReaderObligations`, the ask predicates between
them, `admittedUnansweredAsks` with the approval gate's `projectionDeferred`
branch, and the descriptor captures that existed only to feed them.

`served_state/document.py` serializes the page reading it has been computing and
dropping since #747, and `served_state/conversation.py` builds its own through
one `_AskReducer` rather than two. Each listed Ask now names the `source` that
answers it beside the surface the reader is sent to, which is what the browser's
records carried and the wire did not; `leaf state` shows both as well.

The two copies of the `when` predicate disagreed. Python asks whether an
attribute is present and TypeScript asked whether it was non-null, so an
attribute a value record had set to `null` read differently on each side.
Python's reading is now the only one, and the browser's action-availability gate
and the server's POST door read the same `unanswered_awaiting` map.

What moved: the Ask reading is no longer optimistic. A reader still sees their
own gesture in its widget at once — the pick, the cleared pick, the swiped card,
the withdrawn classification, the rebuilt controls after an Undo — because the
unresolved-attempt ledger, `foldThreads`' pending branch, the DOM-captured
authored baseline and `foldWidgetStates` all stay. But the Asks tray, the banner
count, the `a`/`A` walk, the approval gate and an action's `requires` gate now
turn over when the state that gesture's own POST returns is adopted, where they
used to turn over as the gesture was sent. Against a local server that is one
short round trip: answering and withdrawing an answer on `review-a-plan` in
Chrome moved `Asks 0/1` and the Approve control with no visible lag. Eight tests
asserted the reading at the held-POST moment and now assert it on the log's
answer; `CLAUDE.md`'s cross-runtime invariant says which gestures the page can
draw for itself and which wait for the log.

The browser tests that pinned each folded rule are gone with the fold. What
replaces them is one test of the boundary the browser still owns: the wire's
records mapped to the public `{id, tag, sourceId, sourceTag, thread}` shape,
page asks before thread asks, and no list moving for a local gesture.

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

@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.

Deleting the second derivation is clearly right, and the page-ask serialization plus the single _AskReducer land it well. One thing the deletion drops that isn't part of the latency you argue for.

A thread with a standing frozen Ask loses its "awaits you" mark when the reader starts typing, then gets it back. deriveThreadReaderObligations restored awaits_reader for any thread still in asks.reader, which is what kept a pending prose reply from hiding an unanswered structural Ask. With it gone, the last writer is foldThreads' pending-reply branch in runtime/conversation/model.js — thread.awaits_agent = true; thread.awaits_reader = false; — and nothing puts the obligation back until the reply is admitted, at which point _thread_awaits_reader returns True again on its if thread_id in open_ask_threads line. So the mark goes true → false → true: it reverses direction rather than lagging, which is a different user-visible shape from the count and gate delays the PR takes on deliberately. It also leaves skills/leaf/assets/CLAUDE.md asserting both halves within one paragraph — "a later plain turn does not hide an earlier structural Ask" two lines above "The one local correction is the reader's own unsent reply, which foldThreads hands to the agent". The deleted browser case a pending prose reply preserves a frozen structural Ask is what pinned the first half.

The inline suggestion puts it back from the wire reading rather than by re-deriving anything — it reads asks.reader, which is now the server's own list. Applying it needs npm run build:browser to regenerate the committed bundle.

How I checked it

Driving createSemanticApplication directly on the merged tree: adopt a state whose conversation.asks.reader lists a frozen ask on thread question, with that thread's awaits_reader: true, then enqueue a pending reply to its root.

before reply:                   [awaits_agent=false, awaits_reader=true]
after pending reply:            [awaits_agent=true,  awaits_reader=false]
asks.reader still lists it:     ['frozen-choice']

With the suggested lines, the same probe reports [true, true], matching what the deleted case asserted. npm run test:browser is 53/54 with the change applied, the one failure being the build gate asking for the regenerated bundle.

Verified separately and not findings: the page/thread awaiting merge and the WireAsk shape match what _items and result emit; the browser's asks.unanswered concatenation is now literally the same list event_endpoint builds for the approval door; requirementMatches via projectedParent is equivalent to the inlined walk it replaces, including the !parent and cycle exits; and the active === undefined window is unreachable because identify only runs before the first adopt and adoptable requires the view.

Test selection run on the merged tree: tests/test_interact_document.py tests/test_interact_anchors.py tests/test_interact_server.py tests/test_website_server.py (387 passed), tests/test_render_application_boundary.py --run-nightly (10), tests/test_render_widgets.py -k "ask or approval or swipe or ideas or classified" (53), tests/test_render_projection.py -k "thread_question or command_hub or ask or undo" (23), tests/test_render_controls.py -k "undo or ask or choice" (6), plus npm run check:browser and npm run test:browser (54).

Comment thread scripts/browser/application.ts Resolved
A thread carrying a frozen Ask the reader still owes lost its obligation the moment they started sending a reply, and took it back when the reply landed: `foldThreads` hands the thread to the agent, and with `deriveThreadReaderObligations` gone nothing put the standing Ask back on top. That reverses direction rather than lagging, which is not the delay the rest of this change takes on.

The correction reads the same reader list the tray and the walk read, so it adds no second fold: a thread the server still names there keeps `awaits_reader` whatever the pending reply did. `test_a_live_revision_reapplies_the_authored_conversation_seat_predicate` now reads the Ask list through `told`, because a trip is over when the outbox empties, one beat before the answer it carried has been applied.

Found by leaf-agent on #808.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit bdf581c into main Sep 18, 2026
7 checks passed
@max-sixty
max-sixty deleted the agent-a6b528393561ab81e branch September 18, 2026 21:33
max-sixty added a commit that referenced this pull request Sep 19, 2026
Three changes from a survey session: one code fix found by hitting it,
and the list and note edits that follow from the survey's own results.
Item numbers below are `TODO.md` ids, written without a hash so they do
not read as issue references.

## A claim this version cannot read is dropped, not raised on

The claims directory is one per machine and every worktree, host and
session on it writes there, each running the leaf it was built from — so
a record older than the code reading it is ordinary rather than
exceptional. #813 removed the last shim on the premise that "every claim
is written by the running version", which a shared state home makes
false.

Found by hitting it an hour ago: a session held six preview pages
claimed before #811 named a harness, merged a main that had landed it,
and every `leaf wait` afterwards died in `owned_by` on
`claim["harness"]` — taking the watcher off the unrelated page the
reader was on. The page's own loop guard then fired on every turn, and
nothing in the message said why.

This is the third refusal in the family #822 named an hour earlier, from
the same cause: an update swaps the running Leaf under standing state.
#822 fixed the registry read and the re-vendor; the claim read was still
crashing.

Stage still owes nothing to what an older version wrote, so nothing here
migrates a record or reads its old shape. `readable_claim` is one
predicate on the two file readers every other reader goes through: a
record the readings above can take their answers from is a claim, and
any other record is not one this version can read, so its page reads as
unclaimed until something claims it again. That is what deleting the
stale state would have done, without the deletion, and no session is
taken down by state it does not own.

The harness *name* is decided at that same door, which review caught:
`host.claim_harness` does `HARNESSES[claim["harness"]]`, so carrying the
field was not enough — a record naming a harness outside this version's
table passed the predicate and raised two calls further in, in the Stop
hook and in the nudge the append door takes under its lock. Renaming a
harness is reachable by exactly the mechanism that made the field rename
reachable. `turn_closed` joins the field set for the same reason:
`event_endpoint` brackets it, and it was covered only by the accident
that it predates `turn` in the schema.

`CLAUDE.md`'s Stage section gains the missing half of its own rule — it
said stale state is thrown away without saying who throws it.

### Verification


`test_a_claim_an_older_leaf_wrote_is_dropped_rather_than_read_or_raised_on`
runs the reported journey: two pages held by one session, the first
claimed in the shape written before #811, and `leaf wait` on the second.
Bug-back with `readable_claim` removed reproduces the exact production
error, `KeyError('harness')` out of `leaf wait`, rather than a weaker
assertion failure — which needed the stale page to sort ahead of the
reader's page in the watcher's walk, as it did in the wild.

The two review cases go through the Stop hook, which is where their
consequence is. Bug-back on the harness-name guard raises
`KeyError('some-host-a-later-leaf-named')` out of the hook; bug-back on
`turn_closed` has the hook name a page nothing owns, which is the flood
this PR is fixing rather than a raise.

Everyday suite green on the merged head: 1,172 passed.

## `TODO.md`: item 25 retired, items 5 and 7 re-measured

Item 25 asked for one App Server client instead of two. #811, #813 and
#834 dissolved what it named: `codex.py` exports `app_server_connect`,
`app_server_handshake` and `app_server_request`, both callers use them,
`AppServerClient` moved out to `codex_adapter.py`, and
`worker/server.py` imports 17 public names and no private one. The
reconnect backoff, written four ways when the item was raised, is
written once.

What survived it is two turn supervisors over that one protocol —
`HostedTurn` and `WebsiteCodexHost` in `worker/server.py` at about 900
lines, against `TaskObserver` and `DeliveryTurn` in `codex_adapter.py`
at about 1,000. They supervise different things, a local Codex process
with a queue and a lease against a hosted per-reader container turn, so
merging them is a restructure with no deletion. That is item 6's
question, under the product condition item 6 already carries, so item 25
retires and item 6 states what is left of it.

Items 5 and 7 carried figures from before #808, #815 and #797 landed;
both are re-measured against `main` at `76252900` and dated.

## `notes/dependency-survey.md`

One line pointed at a `TODO.md` item `b7e1efd0` had already removed. It
now points at the work that landed.

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