Repository navigation
Leave a stamp's activation for the next read in the same process - #3942
Merged
Merged
Conversation
leaf-agent
approved these changes
Oct 25, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 27, 2026
Main's #3942 holds a stamp's publication as the next activation's answer, keyed on the source reading taken before the check, and #3850 renamed --from-directory/--if-source to --replace. The stamp in place already takes those readings before its unlocked check, so _stamp_locked now receives them and holds the publication; the replace path takes them before its locked check. The note names --replace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
pushed a commit
that referenced
this pull request
Oct 27, 2026
`leaf page stamp` checked the source while it held the page transaction, so a tab's state read that arrived after the stamp locked the page waited for the whole check (about 450 ms on the corpus at low load) before checking the same source again itself. A stamp in place now checks before taking the transaction and holds it only to confirm and publish. Under the transaction it compares the page's source and history readings (`source_readings`, the stamps activation already keys on) with those it took before checking; a write that lands during the check moves one, and the stamp checks again. In the common case the tab's read activates the save during the stamp's first check, so the second check also runs outside the transaction and the stamp names the revision the read wrote. After `UNLOCKED_CHECKS` (2) moved checks, the last runs under the transaction, so a page written faster than the stamp checks still gets its stamp. `--replace` keeps its path: it writes the source under the transaction, so it checks there too. Either way the stamp holds its publication as the next activation's answer (`hold_published`, from #3942) keyed on the source reading it took before the check that published. Behavior change in tests: `test_stamp_keeps_its_checked_log_snapshot_until_the_note` asserted that a browser write waits behind the stamp's check. It now asserts the reverse: a user's action and the tab's activation both land during the check, and the stamp then names the revision the tab activated (it fails on the old code with "the tab waited on the stamp's check", and with the re-check removed with "revision r2 already exists"). A second test covers the transaction-held last check. Both move to `tests/model/`, since neither runs a server. Evidence, on an HTTP stand-in for the tab (save, start `leaf page stamp`, poll `/api/state` every 250 ms until it names the new revision, fetch that revision's document), base `f00911ed1` against this change, eight alternating runs at load 17–33 on 18 cores: - First poll fixed 500 ms after the save, where the base's stamp holds the lock: state answer median 2.25 s -> 1.19 s, document's last byte 2.98 s -> 1.93 s. - First poll at a random phase (10 runs): both arms took the save route, 0.75 s and 0.77 s to the state answer. `uv run leaf-dev bench-latency --page corpus --transition revision` at load 20–46 could not tell the arms apart: medians 2742 vs 2855 and 2857 vs 3054 ms (base vs head, five runs each) with spreads over 2 s, dominated by load. An earlier version that re-checked under the transaction read 3291 vs 5480 ms; in its runs the tab's later state reads waited on that re-check, so the second check now runs outside the transaction too (attributing the whole gap to it is a guess at that load). The note's 1.11–1.22 s stamp-route reading was taken at load 4–7, which this change has not been measured at. A stamp that follows the tab's activation still repeats that check outside the lock, about 450 ms of CPU beside the tab's document fetch and patch; on a loaded machine that work competes with the paint. `notes/user-feedback-responsiveness.md` records the result and keeps the record of a passed check as the remaining proposal. Ran: `tests/model/test_interact_document.py`, `test_interact_product.py`, `test_interact_anchors.py`, `test_todos.py`, `test_revision_delivery.py`, `interact_contract/test_revendoring.py` and `test_data_contracts.py` in full, and `tests/process/test_interact_server.py -k "stamp or revision or activat or publish or sample"`. Not verified: the browser benchmark at load 4–7, where the note's readings were taken; the journeys and browser tiers. Call Max may reverse: the record that a source passed its check (the note's other proposal) is left unbuilt. It would need an identity for Leaf's Python checker, which doesn't exist yet, and a new page-directory record; an earlier Leaf would read that record as one more source file and check as before, so it needs no protocol bump, but it is a new mechanism whose remaining benefit (`--replace` stamps, and the second check a stamp repeats after the tab's activation) should be measured first. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A page server's first
/api/stateread activates the page's source (activate_source): it runscheck_sourceonindex.htmland keeps the answer in the process's page memory, keyed on the source reading taken before the check. A stamp (page stamp,cmd_stamp) runs the same check on the same source and publishes it as the active revision, but kept nothing. A server in the same process as the stamp therefore checked the just-published source again on its first read.The suite pays this on every browser test that serves markup.
servestamps a markup page in the test process (publish) and then serves it from an in-processTemporaryPageServer, so each opening's first state read repeated the check before the page could present. That read is on the opening's path, since the page presents only once it has applied the answer. An example page is stamped once into its pooled template at another path, so its openings gain nothing here.The stamp now leaves its answer the way
activate_sourceleaves its own (hold_publishedinrevisioning.py). It takes the source reading before its check, and after publishing it holds that reading with the published revision as active and unchanged. A write to the source since that reading moves the page past the held answer, so the next read checks again, exactly as after an activation. The log and revisions the stamp writes are history, which a held answer without an error doesn't compare. A stamp from a separate process, such as an agent'sleaf page stampbeside a running server, keeps nothing in the server's memory, so its server checks once as before.Measurements
On an M-series Mac, the first
/api/stateof a servedSETTLED_PAGE, ten openings (server handler thread CPU, under cProfile): 22.9–24.1 ms before, 3.4–5.2 ms after.Per opening,
serveand the opening together (serve, new page,goto,wait_until_ready,one_frame), 20 openings per round, five interleaved rounds, load averages 8.7–10.4, medians:tests/browser/test_render_options.py,test_render_reactions.py,widgets/test_tabs.pyandnavigation/test_panes.py(182 tests,-n 3), three interleaved rounds: CPU 201.3, 190.9, 183.2 s on base and 197.0, 184.1, 185.0 s with this change; wall 57.1, 54.8, 51.6 s and 56.5, 52.2, 52.3 s (load averages 9–18). The saving per opening, about 18 ms of CPU, is about 2% of these files, below their run-to-run spread at this load, so the per-opening reading above is the measure.Coverage
No test's waits or assertions change. Activation still runs on every read after a source change, which is what the tests that edit
index.htmlbehind a live page exercise; process-tier servers run in their own process and check as before. Passing:tests/model/test_interact_document.py,tests/model/interact_contract/,tests/model/test_revision_delivery.py,tests/model/test_live_shell_artifact.py,tests/model/test_interact_layer.py,tests/model/test_interact_anchors.pyandtests/process/test_interact_server.py(988 passed, 1 skipped), andtests/browser/startup/test_versions.py,projection/test_live_versions.py,projection/test_revision_patches.py,drafts/test_revisions.py,startup/test_freshness.py,test_render_options.py,test_render_reactions.pyandtests/smoke/test_smoke.py(196 passed).