Repository navigation
fix(studio-server): a file the drive never answers no longer holds a project's first copy - #8403
Merged
Merged
Conversation
…project's first history copy Each file the first copy reads gets a deadline from when its read starts. A file that misses it is left owed and adopted once the drive answers, keeping the bytes it read as the file's start, so the open finishes.
…ts read, kept through pruning A late first copy follows only the save receipts heard by the moment of its read, so a later save writing the original back cannot move the start. The bytes a save replaced in a file still owed its first copy stay through pruning, counted as start rather than undo history, until that copy is recorded.
Contributor
Edit accuracy: accurate 271 (base branch 271), smooth 62 of thoseThe gate passes. Quarantined, measured but not gated (0) |
2 of 3 tasks
vanceingalls
approved these changes
Nov 21, 2026
vanceingalls
left a comment
Collaborator
There was a problem hiding this comment.
Approved at cc29e5f. A file the drive never answers no longer holds the open.
- Deadline (
firstCopyOrOwed). Only queued reads have their deadline restarted. A read leavesfirstCopyProgresswhen it gets its slot and is armed once, so a stalled read is owed 10 s after its own start and is never stretched. Queue order is FIFO, and when every slot is stuck nothing finishes, so a queued read still expires 10 s after the last finish. Timers clear in.finally. - Pins. A late copy's pin is taken inside the per-hash
inTurn, the same turnforgetuses and re-checkspins.hasin, so a prune can't drop it first. It's released on adoption success, failure, gone and changing, and at open for in-deadline copies.historyBytescounts baseline, pinned and owed starts in one deduplicated set. - Receipts.
heardAtReadis snapshotted when the bytes are verified, and a later save records as an ordinary change through the extrasweepIn(0). - Retries.
storeIfPresentwaits are bounded by the stuck read. Owed retries back offmin(SETTLE_MS·2^n, 30 s), one at a time per file, on unref'd timers. - The five #8187 points are all addressed: the
heardAtReadsnapshot,onReadat byte validation,heardBeforeCopyin the prune keep-set,owedStartsinhistoryBytes, and receipt blobs held only whileadopting.has(path). - The fails-without-fix line is at
firstCopy.test.ts:186, and the tests use short real deadlines with no 10 s waits.
Nits:
- In
firstCopyOrOwed, a read that was owed while queued re-arms a ref'd 10 s timer when it later gets a slot, afterresulthas settled. It does nothing, but it can hold process exit for up to 10 s. Guard it with asettledflag orunrefit. - The queued-deadline test (400 ms deadline against 150 ms reads) could flake on a loaded runner.
- Unpacked size is only about 0.7% under the 1% tolerance, so the next history PR will trip the budget.
- A dead drive holds up to 4 global read slots, which delays other projects' first copies. They still open, with their files owed. That's the known limit, with #8187 to follow.
Merged
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.
What
A project's first history copy no longer waits forever on a file the drive never answers. Each file it reads gets a deadline (10 s) that starts when its read starts. A file that misses it is left owed, the way a file that is still changing is, and adoption copies it once the drive answers. The open finishes.
Why
On a drive that stops answering (it showed up on an external exFAT disk), opening a project never finished. The first copy read every file through
blobs.putwith no deadline, and the open waited for all of them. The app's main thread stayed free, but the project never opened.Related work
This is the open-deadline half of #8187, split out so the freeze fix can ship on its own. #8187 keeps the part about agent steps that go ahead of a pending first copy.
What this does not fix yet: since #8375 an agent step waits for every first copy still being taken. With only this PR, a dead drive no longer blocks the open, but the first agent step still waits on that one file until #8187 lands. That is still better than main today, where the open itself never finishes.
How
firstOpengives each file's copyfirstCopyFileMs(option, default 10 s) from when its read starts. While a copy waits for one of the four read slots, its deadline restarts each time another first copy finishes. So healthy progress never cuts off a queued read, and a stalled read is owed 10 s after its own start. Past the deadline the file reads as"changing"and joins the owed files thatadoptMediaInBackgroundalready retries.storeIfPresentreads one path at a time, so a retry of a stuck file waits behind the stuck read instead of starting a second read on the same drive.historyBytes(). Only the owner of a pin releases it.put's arguments; they now pass the read callback through.Package size budget
The packed
@hyperframes/studio-servertarball measures 191,581 bytes against a budget of 188,871. The extra bytes are this PR's history code; no new import comes in. Following the budget file's rule (5% above measured), the packed budget is now ceil(191,581 × 1.05) = 201,161. Unpacked, 737,155 bytes, fits its budget.Test plan
firstCopy.test.ts:mainthe open never resolves and the test times out at 20 s; with this PR it passes in about 140 ms.blobStore.test.ts: a pinned blob survives prunes until each pin is released.firstCopy.test.tspassed 3 times in a row, and the whole studio-server suite passed with 0 failures.Not exercised: a real drive that stops answering, and native Windows. These were Linux runs with local fixtures.