Repository navigation
fix(widget-dev): remove leftover and orphaned snapshots at boot before any folder is watched - #668
Merged
Merged
Conversation
…e any folder is watched Superseded snapshots were pruned only after an install, so a session that never installed again kept its leftovers, and digests that fell off a session's list or left with a forgotten session stayed in the package cache for good. Resume now prunes every stored session, and sweeps a bounded number of orphaned snapshots recorded in a ledger beside the session store, while no session watches a folder: a start waits for it.
…n guards, and tighten the orphan list A snapshot no session lists but a generation still names (installed, or the one a rollback returns to) is kept by the boot sweep, and a resume made while a session is watched removes nothing; both guards now have tests that fail without them. The orphan list accepts only snapshot digests and says why its bound keeps any leak bounded.
Contributor
Author
|
Review attestation: ready to merge at A push to this PR makes this attestation stale; the new head needs its own review. |
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.
Fixes #657
What leaked
Widget dev sessions removed superseded snapshots only after an install. A session that never installs again kept its leftovers, including snapshots whose removal was held (
EBUSYon Windows) or skipped byclose(). PastWIDGET_DEV_SNAPSHOTS_MAX(64), the oldest digests dropped off a session's list, and a session the store forgot to make room took its list with it. Nothing ever removed those folders.What changes
resumeprunes every stored session, live or stopped, with the sameprunean install runs. It keeps what the session runs, what it waits on and the snapshot a rollback returns to.local/folder also holds the snapshots an ordinary install of a local package takes. No session may remove those, and nothing on disk tells them apart from a session's. So a digest that leaves every session's list is written towidget-dev/orphaned-snapshots.jsonbefore the session store drops it. That covers the oldest past the list bound, and the snapshots, running and pending digests of a session forgotten bymakeRoom. The ledger is a separate file, so the session store's format does not change, and it holds at most 1024 digests.resumeremoves at mostWIDGET_DEV_SWEEP_MAX(64) orphaned snapshots per boot. It skips any that a session lists again, runs or waits on, and any that a generation row still names. A failed removal stays in the ledger for the next boot.rmwithSNAPSHOT_REMOVAL. NormSync.Ordering invariant
The boot's tidying removes a snapshot only while no session watches a folder. Only a watched session's engine builds. A build can reuse a folder already at its content-addressed name before the session remembers it, so a removal running beside that build could pull the folder from under an install. The ordering prevents that:
resumewatches no folder until the tidying ends.startawaits the tidying before it watches a folder, and nothing is awaited between that point andwatch.live.size === 0. This ends the tidying early if a session is watched anyway, for example whenresumeis called again while sessions are live.close(), no removal starts.close()returns early fromresume, and the tidying's own chain is inchains, soclose()waits for the removal in flight within its bound.Tests (
apps/runtime/test/widget-dev-sessions.spec.ts, "what widget dev sessions leave in the package cache")EBUSY) are removed on resume; the running and rollback snapshots stay;makeRoomare swept at the next boot;startmade while a sweep removal is held waits for it, and its build of the same bytes keeps its snapshot;The first five fail with
main'swidget-dev-sessions.ts. The fifth also fails when only theawait tidyinginstartis removed.Docs
EN and VI
docs/widget-development(.vi).md: cleanup at the next start, and the cache note on what is collected.docs/manifest.jsonwas refreshed.Not covered
Folders leaked before this change were never written to the ledger. They cannot be told apart from an ordinary install's snapshots, so they stay.