Skip to content

Cut a corpus revision's server work, and the view check's forced pass after it - #3313

Merged
max-sixty merged 8 commits into
mainfrom
agent-a302ae0ff7b24d8f3
Oct 20, 2026
Merged

max-sixty merged 8 commits into
mainfrom
agent-a302ae0ff7b24d8f3

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

On the corpus example, a saved revision took 0.89–2.09 s to paint against the 1 s target that #3302 measured. Most of that time was server work, and much of it was either repeated or done for a caller that never reads the result. This change cuts it, and it removes a browser long task that made the slow case more frequent.

bench-latency --page corpus --transition revision ran fifteen paired runs over three invocations at load 4–7 on 18 cores. The revision reaches the tab by one of two routes:

Route Base Head
Save (the tab's freshness read finds the save first) 0.89–1.11 s 0.64–0.79 s
Stamp (leaf page stamp takes the page lock first) 1.77–2.09 s 1.11–1.22 s

The triage board's revision paints in a median 153 ms against the base's 139 (range 128–253 and 128–252), within noise. Of the 190 stills states, 188 are unchanged; the other two differ only in the layer fingerprint and the share token on the "About this page" view.

Server. check_source walked the page's containment once per live sample; passages.enclosing_ids now walks each document once. Anchor relocation walked both revisions in full on every activation and twice per stamp; SourceReading.decided_passages now also takes rewritten bodies and created children, so relocation reads the passages each reading already holds, and only when an open thread needs them. Every check judged the page's recorded data to produce advice that only page check prints, which cost a cold stamp about 200 ms; validation.source.source_advice now produces that advice for page check alone. Document delivery spliced each of thousands of marks into a fresh copy of the page; revision_delivery._spliced now joins the pieces in one pass, cutting it from 127 ms to 58 ms on the corpus with byte-identical output on 129 local pages.

Browser. The user-view report's arrangement and label readings asked about boxes in hidden tabs. Each question forced the browser to style and lay out that tab, about 280 ms of work landing 300 ms after each presentation. The view reading now leaves out skipped content (arrangedBoxes(open, { shown: true })), and a label is checked for visibility before its box is read. The render gate's own sweep is unchanged. The user-view checks test now includes a closed disclosure, and it fails on the base.

bench-latency now writes each request's start and end to results.json, so a run's time splits into server and page.

The stamp route stays over 1 s. notes/user-feedback-responsiveness.md ("A corpus revision's paint") proposes two fixes for a decision. One records with each revision the Leaf that checked it, so another process can skip checking an unchanged source again. The other has a stamp check before it takes the lock. A shortcut that compared only the revision's input digest was tried and removed: it covers neither the Leaf that did the checking nor the data contracts a sample reads.

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

max-sixty and others added 7 commits October 20, 2026 03:52
… after it

A saved revision of the corpus reached the tab in 0.9 s at best and 1.9 s when
`leaf page stamp` took the page lock first. Most of the time was the server's,
and much of it was work done twice or done for nobody:

- Checking a page walked the whole document once per live sample to find where
  each id sits. `passages.enclosing_ids` now walks a document once.
- Relocating anchors walked the predecessor and the candidate in full on every
  activation, and twice per stamp. `SourceReading.decided_passages` now also takes
  rewritten bodies and created children, so `revision_reanchors` reads the
  passages each reading holds, and only when an open thread asks.
- Every check judged the page's recorded data against its contracts for advice
  only `page check` reports; a stamp, a cold process, paid about 200 ms for it.
  `source_advice` now reads that drift for `page check` alone.
- After a stamp activated the source, the server checked it again from scratch,
  since its held answer is per process. Activation now takes a source that is the
  active revision's captured input as that revision (`active_input`), as the held
  answer already did within a process. A server restart benefits too.
- Delivering a document spliced each of thousands of marks into a fresh copy of
  the whole page. `revision_delivery` now joins the pieces in one pass, 127 ms to
  58 ms on the corpus, with output byte-identical on 129 local pages.

In the browser, the user-view report's arrangement reading asked for the style
of every box in the corpus's hidden tabs, which forced the browser to style and
lay out each hidden panel. After every revision that was a 280 ms task 300 ms
later. The view reading now leaves skipped content out
(`arrangedBoxes(open, { shown: true })`), and the user-view checks test covers a
closed disclosure. The render gate's sweep reads arrangement as before.

`bench-latency` now records when each request started and ended, so
`results.json` splits the server's time from the page's.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A label in a hidden tab has no box worth reading, and asking for one made the
browser lay out the whole tab first. On the corpus that was the user-view
report's remaining 100 ms of forced style after a revision.

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

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

The digest of the active revision's inputs covers neither the Leaf that checked
it nor the data contracts its samples read, so after a plugin update the
shortcut passed a source the current check refuses. The server checks a source
another process activated again, as it did. Rewrites and created children keep
their ids whole in the held passage reading, since they can stand on an element
another created child brought.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… the stamp route under 1 s

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	notes/user-feedback-responsiveness.md
#	skills/leaf/kernel/kernel.json
leaf-agent
leaf-agent previously approved these changes Oct 20, 2026
@max-sixty
max-sixty merged commit e1ed34c into main Oct 20, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a302ae0ff7b24d8f3 branch October 20, 2026 12:01
leaf-agent added a commit that referenced this pull request Nov 15, 2026
…amps from files.py (#6039)

This is the weekly duplicate sweep of `src/leaf/` and `hooks/` (ISO week
46). It moves four capabilities that were implemented more than once to
one home each, and moves every caller. Behavior does not change. Every
replaced copy computed the same result as the home it now calls.

- **Applying non-overlapping `(start, end, text)` edits to a source.**
The new home is `structure.splice`, which is
`revision_delivery._spliced` moved and generalised to str or bytes. It
replaces five copies:
  - `revision_delivery._spliced`, from #3313, removed.
- The reverse-slice loop in `revision_artifact.bind_imports`, from
#1280.
  - The loop in `structure.rewrite_attribute_references`, from #1658.
  - The loop in `leaf_dev.docs.compose`, from #2660.
  - The loop in `leaf_dev.arrangement_eval`, from #4629.

The four reverse-slice loops copied the whole source once per edit. Each
of them applies edits that don't overlap and don't start at the same
offset, so splicing them in one pass gives the same output.
- **The file name of a stamped version.** `live_shell` wrote
`f"v{version}.html"` inline, from #666. It now calls
`files.version_name`.
- **Whether a note stamps a revision.** `validation/source_history.py`
scanned for the note inline, from fe4e8ea. It now calls
`files.stamped_version`, which was added in the same commit.
- **The `sha256:` digest of a revision's HTML.**
`revision_artifact._capture_artifact` hashed `document.data` again, from
#666. It now reads `SourceDocument.digest`, from #606, which holds the
same value.

I left `compose_document`'s two-insertion loop in `revision_delivery.py`
alone. `splice` orders edits at the same offset by their text, but that
loop relies on list order when `<html>` and `<head>` are both implicit.

**Verification.** `ruff` and `ty` pass on the touched files. These model
tests pass: `test_module_url_delivery`, `test_revision_delivery`,
`test_live_shell_artifact`, `test_product_page`,
`test_interact_document`, `test_interact_anchors` and
`test_interact_layer`, 626 tests in all. In
`dev/tests/model/test_product_page.py`, the second case of
`test_a_composed_part_refuses_an_authored_copy` fails at `assert slot in
authored`, before `compose` runs. Its fixture string expects `<img`
followed by `alt="Sandbox` at 16 spaces of indentation, and
`docs/index.html` on `main` now indents that line by 18. The failure is
in the test's fixture, not in this change.

<details><summary>Sets found but not consolidated here</summary>

Another open pull request already changes each of these:

- **Claude Code and Codex config homes, and the inline-delivery opening,
repeated in `leaf_dev`.** #6014 moves them onto
`harness.claude_code_config`, `harness.codex_home` and
`hook_transport.INLINE_OPENING`.
- **`hooks._awaits_agent` repeats `holding.running_turns`.** #6032
rewrites `running_turns`.
- **The "N user updates with no answer" sentence**, written in both
`activity.unanswered` and the `page-open-owes` finding. `activity.py`,
`findings.py` and `session.py` are all being changed in #5979, #6018 and
#6032.
- **Raster magic bytes**, read in both `media._UPLOAD_TYPES` and
`revision_delivery.media_size`. `media.py` is being changed in #6014.

These are not worth a shared helper, because they are one-line stdlib
idioms or the copies differ in meaning:

- `json.dumps(..., sort_keys=True)` used as a cache key.
- Compact `json.dumps` with `separators=(",", ":")`.
- The `script_kind(...) in {"module", "classic"}` membership test.
- `lock_is_held(page_dir / SERVER_LOCK)`.
- Inline closed-object JSON schemas.

**Not consolidated, needs a separate look.**
`sample_content._non_json_number` repeats `http.reject_json_constant`.
The real question is where Leaf refuses non-finite numbers. The HTTP
path refuses NaN and numbers past a double's range. Sample fixtures
refuse only NaN and infinity. No other reader of event JSON in
`src/leaf/` passes `parse_constant`. Sharing the helper would change the
`sample-json` message without settling that question, so it is left out
of this PR.

</details>

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