Repository navigation
Make a preview slot its page directory, and watch before the URL goes out - #816
Merged
Merged
Conversation
… out A slot was a page directory plus three files beside it: the watcher's identity and stop flag in `<slot>.preview.json`, the lease `--stop` waits on, and a second lock serializing writes to that flag. The two locks sat next to what they guard, which is why a discard could not remove them — a `--reset` that unlinked the lease would hand a waiting `--stop` an inode excluding nobody, and that stop would then take down the server the reset had just started. `leaf.leases` already keeps a stable per-path lock in the state home for exactly this reason, and the page's own transition lease is one, so both of a slot's locks are page locks now. The stop flag is gone with them. `--stop` holds its request open for as long as it waits, so the watcher reads it between passes and wherever it would bring the server back up, an update in flight finishes, and its pending restart is suppressed — the guarantee the flag was for, minus the file, the lock that protected it, and the case where a watcher starting after the flag was written overwrote it and left the stop waiting forever. With one writer left, the watcher's own, the identity moves into the page's `preview.json` beside the fields the browser chrome shows: the slot's whole record in one file the discard already removes, and `.tmp/previews` is empty after one. `preview_metadata` projects the named safe fields, so the checkout and fixture paths in that record reach no browser, which is what `page-storage.md` already said the server does. `PreviewService` owns the one difference between a reader preview's durable claimed service and an automation preview's process-owned temporary server. The watch loop branched on it seven times and now states what it wants — stop, refresh, start — without knowing which kind it has. `lock_is_held` asks with a shared lock. An exclusive probe is refused by another probe as readily as by a lease, so two processes reading at once told each other a lease was held. One bug found while testing this, and older than it: `watchfiles` starts its rust watcher on the subscription's first read, and the read the preview's loop makes comes after it has announced its URL. The edit a developer makes the moment that URL appears landed in a window nothing was watching — measured on the parent commit, six of six such edits were lost, and none of six are now. That is also what made `test_a_detached_preview_restarts_under_its_original_codex_claim` and `test_stopping_a_preview_waits_for_its_active_recompose` fail under load: both edit an input the instant the preview reports ready. `watch_changes` reads once before it returns and hands that batch on as its caller's first. Three test assertions moved with the state they read: the lease and the stop request are read as locks, the fixture requires the directory it swept to be clean, and the released detached watcher is asked for the record that lets a later start resume rather than for a flag saying it stopped. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-home # Conflicts: # scripts/preview.py
leaf-agent
approved these changes
Sep 18, 2026
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 slot was a page directory plus three files beside it: the watcher's identity and stop flag in
<slot>.preview.json, the lease--stopwaits on, and a second lock serializing writes to that flag. The two locks sat next to what they guard, which is why a discard could not remove them — a--resetthat unlinked the lease would hand a waiting--stopan inode excluding nobody, and that stop would then take down the server the reset had just started.leaf.leasesalready keeps a stable per-path lock in the state home for exactly this reason, and the page's own transition lease is one, so both of a slot's locks are page locks now.The stop flag is gone with them.
--stopholds its request open for as long as it waits, so the watcher reads it between passes and wherever it would bring the server back up, an update in flight finishes, and its pending restart is suppressed — the guarantee the flag was for, minus the file, the lock that protected it, and the case where a watcher starting after the flag was written overwrote it and left the stop waiting forever. With one writer left, the watcher's own, the identity moves into the page'spreview.jsonbeside the fields the browser chrome shows: the slot's whole record in one file the discard already removes, and.tmp/previewsis empty after one.preview_metadataprojects the named safe fields, so the checkout and fixture paths in that record reach no browser, which is whatpage-storage.mdalready said the server does.PreviewServiceowns the one difference between a reader preview's durable claimed service and an automation preview's process-owned temporary server. The watch loop branched on it seven times and now states what it wants — stop, refresh, start — without knowing which kind it has.lock_is_heldasks with a shared lock. An exclusive probe is refused by another probe as readily as by a lease, so two processes reading at once told each other a lease was held.One bug found while testing this, and older than it:
watchfilesstarts its rust watcher on the subscription's first read, and the read the preview's loop makes comes after it has announced its URL. The edit a developer makes the moment that URL appears landed in a window nothing was watching — measured on the parent commit, six of six such edits were lost, and none of six are now. That is also what madetest_a_detached_preview_restarts_under_its_original_codex_claimandtest_stopping_a_preview_waits_for_its_active_recomposefail under load: both edit an input the instant the preview reports ready.watch_changesreads once before it returns and hands that batch on as its caller's first.Three test assertions moved with the state they read: the lease and the stop request are read as locks, the fixture requires the directory it swept to be clean, and the released detached watcher is asked for the record that lets a later start resume rather than for a flag saying it stopped.
Verified
uv run pytest tests --run-nightly— 2728 passed, 4 failed. All four —test_render_drafts.py::test_a_single_space_is_message_content_in_every_composer(reply, general, composer) andtest_render_options_addition.py::test_the_add_field_previews_the_option_it_will_make— fail identically on the merge base 9e5e0d3 with no branch in play: they assert a press face or preview disc differs from its transparent button, and Take the solid accent fill off every pressable #803 made both transparent.uv run pytest tests— 1145 passed.uv run pre-commit run --all-filesclean.test_a_watch_subscription_collects_before_its_first_readis the bug-back — red on the merge base, green here.--stop,--reset --background, discard — after which.tmp/previewsholds nothing.