Repository navigation
fix(studio-server): a file the drive never answers no longer holds a project's first history copy - #8187
Conversation
…project's first history copy
Edit accuracy: accurate 271 (base branch 271), smooth 57 of thoseThe gate passes. Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 29ee475f42ea4e6fd0c74f25c8f6e8223953c7cf.
The deadline correctly sits outside the first-copy limiter, so timing out does not release the underlying read's slot. Per-path serialization also avoids overlapping retries of that read.
Important — retain a successful initial copy that finishes after the deadline (packages/studio-server/src/history/projectHistory.ts:661–664,862–866). owedAfter discards the original promise's eventual result. Adoption waits behind it, then rereads the file and installs those newer bytes as the baseline. If an external editor changes the file after the project opens but before the original blob write finishes, a valid original copy is kept on disk but never referenced by history; the newer content becomes START instead of an undoable change.
Independent reproduction: delay the first incoming-* blob write after the original bytes were read; open with a 50 ms first-copy deadline; externally overwrite the source after open returns; release the original write and wait for adoption to finish. START is the newer digest (f1d822…), not the successfully captured original (f02580…). The added probe fails at this head. The base awaited and used that initial result rather than discarding it.
Carry the late successful result into deferred adoption as the initial baseline, then perform a fresh observation to record changes since it. Do not mark old bytes as the current file version without checking again. Only retry from scratch when the first attempt was missing/changing/failed. Add this delayed-write plus external-edit regression alongside the stalled-open case.
Validation: full build passed; gated firstCopy/projectHistory suites 152 passed, 2 skipped. The named stuck-read regression times out at 20 s with main's production file restored and passes in 134 ms after restoring the fix. The independent late-copy regression fails as described; no real stalled filesystem was used.
Follow-up limit: an actually unending read also keeps its adoption pending, and current close waits for adoption. This fix bounds initial open, not the entire history lifecycle; avoid claiming general stalled-drive recovery.
Need: yes · Size: ok · Reuse: existing first-copy limiter and adoption machinery · Simpler: hand the late copy outcome to adoption rather than losing it · Structure: fine (checked blobStore and recordAdopted; no second history implementation needed)
Risk: medium — changes when the initial undo baseline becomes available.
Verdict: REQUEST CHANGES
Reasoning: Opening now completes, but a successful late original copy can be discarded and an external edit absorbed into the baseline. Preserve that history boundary before approval.
— cutroom-review
… as the file's start
|
Fixed at e718969: a first copy that lands past its deadline is no longer thrown away.
On the limit: agreed, and the PR body now says it. This bounds the open only. A read that never answers keeps that file's adoption pending, and close waits for adoption. |
terencecho
left a comment
There was a problem hiding this comment.
P1 — A successful late copy can still be lost while adoption waits. At packages/studio-server/src/history/projectHistory.ts:693, each file’s adoption waits for the previous file’s first try. When two files miss the deadline, the first file can remain stalled after the second file has successfully copied. A claim for the second file then waits behind the unrelated read. Its completed blob is also absent from the prune keep-set at line 1159. In an isolated test, I edited the second file after open, triggered budget pruning with unrelated writes, then released the first read. The second file’s original blob had been pruned, and recordAdopted used the edited bytes as START.
Make completed late copies available for adoption independently of stalled paths and keep their blobs through the baseline commit. Please exercise a claim and pruning while an earlier file remains stalled, while preserving the first-copy slot limit.
Full build and studio-server typecheck passed. The history suite reported 317 passed and 2 skipped. Both named regressions passed at this head and failed against their respective earlier versions. The stalls were simulated with local fixtures. No failing-drive hardware was exercised. CI was still running at review time.
— tai (automated review)
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at e718969d9868acdc63432288e4170377b1d23e54, delta from 29ee475f42ea4e6fd0c74f25c8f6e8223953c7cf.
The original single-file late-copy case is repaired: the successful first result is handed to adoption, then a fresh sweep records the intervening edit.
Important — the same baseline loss remains when another file stalls first. +1 to the existing review. I independently traced the same case before reading that review: projectHistory.ts:693 (adoptMediaInBackground) serializes each first adoption behind the previous one, while projectHistory.ts:1159 (keepWithinBudget) does not retain a completed-but-unadopted first-copy hash. projectHistory.ts:776 (recordAdopted) then rereads the edited source if that blob was pruned, making the newer content START again.
Keep completed first-copy hashes referenced through their baseline commit, and allow their adoption without waiting on an unrelated stalled path; retain the existing copy-slot limit. Add the two-file scenario with both an unrelated budget-pruning commit and a claim for the completed file while the earlier read remains held. This is a remaining case of the previous baseline blocker, now also demonstrated by Tai, rather than a request to solve all stalled-drive behavior.
Validation: full bun run build passed. Gated firstCopy.test.ts and projectHistory.test.ts: 153 passed, 2 skipped, plus my independent two-file pruning probe failed. It held both original blob writes beyond the deadline, released B while A stayed held, edited B, and flushed an unrelated file with a zero history budget. The probe first confirmed B’s original blob had actually been pruned; after releasing A, START contained the edited digest (139249…) rather than the original (c3ca705…). The same probe with a larger budget retains the blob and passes (1 passed), isolating pruning as the cause. The submitted single-file delayed-write regression passed; restoring only projectHistory.ts from 29ee475f makes it fail, and restoring this head gives 1 passed. A fresh adversarial source pass independently checked the newly exposed prune window against the base.
The description correctly limits this to initial open: a permanently stalled read can still hold close. No real failing exFAT drive was exercised.
Need: yes · Size: ok · Reuse: existing first-copy limiter, adoption and blob keep-set · Simpler: retain and adopt completed outcomes directly · Structure: fine (checked blobStore, recordAdopted and keepWithinBudget; no parallel history implementation needed)
Risk: medium — successful initial bytes can still be lost from the undo baseline.
Verdict: REQUEST CHANGES
Reasoning: The single-file repair works, but a completed late copy can still be pruned while an unrelated adoption holds it back.
— hf-review
…er file's read is stalled
|
Fixed at 4892c12, for both reviews (the two-file case).
The limit in the body stands: a read that never answers still keeps that file's own adoption, and close, waiting. |
terencecho
left a comment
There was a problem hiding this comment.
The new two-file regression passes, and an independent claim test confirms that a completed late copy can be adopted while a different read remains stalled. Two regressions remain.
- P1 — A pending baseline copy can evict unrelated undo history. In
packages/studio-server/src/history/projectHistory.ts:1157,historyBytes()subtracts tracked hashes only. A late first copy is now protected from pruning but still counts toward the budget until adoption gets its turn on the history queue. In a gated test, a 768-byte pending file caused a small, otherwise in-budgetindex.htmledit to be folded into START. After the file was adopted, the edit was still missing from history. The same edit survives when that file finishes during open. Exclude protected baseline hashes from the budget while they await adoption, deduplicating them with the tracked hashes. - P2 — Changed or failed first copies can fan out into parallel retries. At
packages/studio-server/src/history/projectHistory.ts:699, having a first-copy promise bypasses the serial adoption chain even when that promise produces no usable copy. The fallback at line 765 then reads outside the first-copy slots. A fixture where 12 files each reported changing before the deadline reached 12 simultaneous fallback reads. The previous head stayed within four in the same fixture. Let successful copies reach the history queue independently and bound the fresh reads that follow an unsuccessful copy.
The history suite passed 318 tests with two skips. The new regression and the two review cases used controlled I/O. No physical drive was tested.
— tai (automated review)
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 4892c12fcf69ee3d99d2c742d10502f0bdea2c19.
The previous two-file late-copy/prune/claim scenario is fixed. I independently reproduced both new cases in tai's review:
- Important — protected baseline bytes consume the undo budget before adoption.
projectHistory.ts:1157subtracts tracked hashes only. A protected 768-byte late copy awaiting the history queue still consumes a 128-byte history budget, so committing a small index edit folds that otherwise retainable edit into START. The history list becomes empty. Exclude protected baseline hashes from historyBytes(), deduplicated with tracked hashes. This loses the undo step, not the current file contents. - Important — unsuccessful first copies bypass the read limit. At
:699and the fallback at:765, merely having a first-copy promise bypasses the serial chain even when it returns changing. Twelve such files start twelve simultaneous fresh fallback reads. Keep successful copies independently adoptable, but send fresh fallback reads through the existing shared first-copy limiter.
Validation: full build passed. Focused firstCopy/projectHistory suites passed 154 existing tests with two skipped, plus an independent successful-stall slot probe. Three additional probes pass one and fail two on this head; all three pass with prior e718969d source. A temporary deduplicated budget exclusion and bounded-fallback correction passes all nine firstCopy/probe cases. The submitted two-file regression fails with prior/no-pin controls and passes after restoration. Temporary changes restored.
The successful-stall slot test does not cover the unsuccessful-copy fallback; no physical failing-drive behavior was exercised.
Need: yes · Size: ok · Reuse: existing first-copy limiter and history budget accounting · Simpler: count pending baseline bytes as baseline and limit fresh reads · Structure: fine (checked adoption, pruning and copy lifetime; no new subsystem)
Risk: medium — undo steps can be folded early and fallback reads exceed their intended bound.
Verdict: REQUEST CHANGES
Reasoning: The earlier baseline-loss case is repaired, but the new pin and independent-adoption paths need consistent budget and concurrency accounting.
— Rames (hf-review)
…rereads a few at a time
|
Fixed at 68a04bb, for both reviews.
|
terencecho
left a comment
There was a problem hiding this comment.
The undo-budget regression and the first fallback read limit now pass. Two remaining cases reproduce with controlled I/O.
- P1 — Pruning a completed fallback can put a stalled read back on the history queue. In
packages/studio-server/src/history/projectHistory.ts:765, a fresh fallback result queues adoption without protecting its hash. The initial late-copy path protects its hash while waiting, but the fallback does not. I held a checkpoint while one fallback stored its bytes, edited that file, then let the checkpoint prune. The fallback blob was removed.recordAdoptedthen started a third read inside the history queue at line 784. While that read was stalled, a claim on a different, successfully copied path stayed pending. After release, the edited bytes became START. Keep successful fallback copies through queued adoption, and keep any necessary fresh read outside the history queue. - P2 — The second fallback bypasses the four-slot limit. At
packages/studio-server/src/history/projectHistory.ts:765, slot use depends onlate. The adoption loop clears it after its first try, then retries independently. In a 12-file test where both initial and first fallback copies reported changing, the next retry started all 12 reads together. Preserve whether the adoption came from first open across retries and apply the same slot bound to each fresh read.
The new concurrency test also matches a hard-coded /parts/ substring at packages/studio-server/src/history/firstCopy.test.ts:350, which misses native Windows paths. Match the platform-native fixture directory and release the read gate in a finally so a failed assertion can finish teardown.
The history suite passed 320 tests with two skips. Studio Server typecheck passed. The Windows path concern was checked with path semantics. No physical drive or Windows test run was used.
— tai (automated review)
…d is kept until adopted
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 68a04bbce32ef765946e2958e2f7f93212255624, delta from 4892c12f.
The two prior introduced regressions are fixed: protected pending-baseline hashes are deduplicated with tracked hashes before budget accounting, and the first fresh fallback uses the existing read-slot limiter. The earlier late-copy adoption and two-file pruning fixes remain covered.
Pre-existing follow-ups: I independently reproduced both cases in tai's latest review: pruning a completed fresh fallback can trigger a reread inside the history queue, block an unrelated claim and change START; a second fallback can reach twelve simultaneous reads. Crucially, the identical probes produce the same failures on this head, 4892c12f, e718969d, and pre-PR parent 959edbcd0737b7953ba2d9976b413a48312b4adf. Those returned-changing-copy cases predate this PR, so they do not block this improvement. Follow up by protecting every successful fallback hash until adoption, keeping necessary rereads outside the history queue, and preserving the limiter across every retry.
Nit: as tai noted, use the platform-native fixture path instead of /parts/ in the new test, and release held read gates in finally blocks.
Validation through the shared test gate: firstCopy/projectHistory suites at this head 159 passed, 2 skipped; the two previous-regression probes fail against 4892c12f, and the restored focused run passes 11 tests. The two additional follow-up probes fail identically at all four refs above. Temporary source substitutions were restored. No physical stalled-drive or Windows run was performed. This approves the initial-open improvement, not a claim that every history lifecycle operation is bounded.
Need: yes · Size: focused re-review · Reuse: existing baseline protection, budget accounting and first-copy limiter · Simpler: retain those mechanisms · Structure: fine (checked adoption, claim queue and blob pruning; no parallel subsystem)
Risk: medium — changes the timing of persistent undo baselines.
Verdict: APPROVE.
Reasoning: the regressions introduced by the prior revision are repaired; independently verified base behavior remains documented for follow-up.
— Rames (hf-review)
|
Fixed at 4b65fe7. Rather than closing one more path, this puts the three rules every adoption read follows in one place, in
|
terencecho
left a comment
There was a problem hiding this comment.
Changes requested at 4b65fe7cc5b876de7aacc75f7e9b603c3a04fb02
- P1 · Protect reread bytes when the blob is published. In
packages/studio-server/src/history/projectHistory.ts:768, adoption marks the hash after the copy promise resolves. The blob store can already list the new hash by then. A checkpoint can capture its keep set in that gap and prune the fallback copy. A controlled local I/O probe confirmed the original blob disappeared and a later edit became START. Hold the blob as part of publishing it, and keep that protection through the baseline commit. The new retry correctly runs outside the queue, so an unrelated checkpoint can still finish while the retry waits. - P2 · Carry the copy policy of the bytes actually read. In
packages/studio-server/src/history/projectHistory.ts:787, the missing-blob check uses the size captured at the initial scan. When an owed file starts below the threshold but grows past 64 MiB before its fallback read,storeNowreturns a valid reference-only hash. Adoption treats it as a lost blob and rehashes it on every retry without adding it to START. The same sparse-file test adopted it on68a04bbcand failed on this head. A local control carrying the reference-only result fromstoreNowpassed.
The later retries stayed within four slots, and the portability change uses the native path separator. All 322 focused history tests passed with two skips. Studio Server typecheck passed. The timing probes used local temporary files and controlled I/O.
— tai (automated review)
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 4b65fe7cc5b876de7aacc75f7e9b603c3a04fb02.
The previous completed-fallback and second-retry probes now pass: the copy is retained through queued adoption in those scenarios, and later retries use the four-slot limiter. The native-path/finally test changes are also present.
Important — carry the policy of the copy actually read. +1 to tai's second finding, independently reproduced. At packages/studio-server/src/history/projectHistory.ts:787, recordAdopted checks isUncopied using the size from the initial directory listing. An owed non-media file can grow beyond 64 MiB before its fallback read. storeNow correctly returns a reference-only hash using its current stat, but no blob exists for that policy. Adoption uses the old small size, treats the valid reference as missing, returns changing and repeats instead of entering START.
An independent sparse 65 MiB fixture remains unadopted through the bounded retry observation at this head; the identical growth case passes at 68a04bbc. The source predicate explains why further retries keep making the same decision. Carry the copy/reference-only decision alongside the hash in Copied, and consume that decision in recordAdopted rather than restatting or using old ListedFile metadata. A temporary implementation of that correction passes all three targeted probes.
Validation via the test gate: 160 focused tests passed, 2 skipped, with the additional growth probe failing. Against 68a04bb, the two previous fallback/retry probes fail while the growth case passes. Temporary correction: 3/3 passed; restored current-source rerun of the two previous cases: 2/2 passed. Source restored clean. This uses controlled local I/O and a sparse file, not a real failed drive or a performance benchmark.
Tai also reports a narrower publication/pruning window. I have not independently reproduced that exact timing window and make no additional verification claim about it here.
Need: yes · Size: focused re-review · Reuse: existing isUncopied policy, carried with its result · Simpler: avoid deciding copy policy twice from different metadata · Structure: fine (checked storeNow → recordAdopted; no new subsystem)
Risk: medium — an owed file can retry without becoming an initial history entry.
Verdict: REQUEST_CHANGES.
Reasoning: the new missing-blob retry must distinguish a deliberately reference-only result from a lost copied blob.
— Rames (hf-review)
…ference-only copy as such
|
Fixed at 065757f, for both reviews.
|
terencecho
left a comment
There was a problem hiding this comment.
Changes requested at 065757f6
- [P1] Serialize publication against pruning for the same hash. In
packages/studio-server/src/history/blobStore.ts:233, the write checks for an in-flight deletion before it stages the bytes. A prune can start against an earlier copy of the same hash during staging. In a history fixture, the fallback wrote and pinned the original bytes while the earlier deletion was in progress. The deletion removed the new copy, and adoption recorded the edited bytes as START. Keep deletion and publication for a hash mutually exclusive through the final rename and registration. - [P1] Release only pins a copy acquired. In
packages/studio-server/src/history/projectHistory.ts:675and:775, reference-only results callunpineven though they did not pin anything. With an MP4 and a JS file containing identical bytes, recording the MP4 reference released the pending JS pin. After the MP4 was removed, pruning dropped the pending copy and adoption used the edited bytes as START. Carry pin ownership with the copy result and release only the acquired pin. - [P2] Release the deduplication pin if staging cleanup fails. In
packages/studio-server/src/history/blobStore.ts:272, a simulatedEPERMwhile removing the duplicate staging file rejectedputand left the pin behind. A subsequent prune retained the blob for the store's lifetime. Release the pin on rejection.
The previous fallback-publication probe passed, and the 65 MiB growth probe verified that START holds the correct reference hash without storing a blob. 325 focused history tests passed with two skips, and the Studio Server typecheck passed. The new failures were reproduced with local files and controlled filesystem timing or errors. A real stalled drive and the full monorepo suite were outside this local run.
— tai (automated review)
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 065757f6b2520f192729544510337e5ceeef63ae.
The prior reference-only growth and retry cases now pass. I independently reproduced the three pin-ownership problems in tai's current review:
- Important — publication and deletion of the same hash still overlap. At
blobStore.ts:233,268, awaiting forgetting.get(hash) does not protect the later publication. My actual-store probe exercises the narrower check/await interleaving: no deletion is recorded at the check, pruning starts during the await, put returns the existing hash with a pin, then the held deletion removes that still-pinned blob. Coordinate publication/pin acquisition and deletion per hash through the final operation; a one-time pre-check is insufficient. This probe establishes that overlap, not every staging interleaving in tai's report. - Important — reference-only results release another copy's pin. At
projectHistory.ts:675,775, unpin runs for a reference-only result that acquired no pin. An actual history fixture with identical MP4/JS bytes releases the pending JS pin when the MP4 is recorded. Removing the MP4, pruning and editing the JS then installs edited bytes as START. Carry pin ownership with the result and release only the ownership that operation acquired. - Important — failed duplicate staging cleanup leaks its acquired pin. At
blobStore.ts:270-273, pinning precedes awaited temporary-file removal. A controlled EPERM makes put reject without returning ownership to its caller, leaving the blob protected from pruning for the store's lifetime unless another operation releases it. Release the acquired pin on rejection, or transfer ownership only after cleanup succeeds.
Validation through the shared gate: 178 checks passed, 2 skipped, with three new probes failing. Temporary diagnostic corrections pass all six targeted probes; the conditional-await diagnostic only counterchecks the observed overlap and is not proof of a complete publication/deletion design. Source restored; the three prior regressions pass again. Tests use local files and controlled filesystem timing/errors, not a real stalled drive.
Need: yes · Size: focused re-review · Reuse: existing blob-store copy policy and adoption handoff · Simpler: explicit owned-pin release and per-hash coordination · Structure: fine (checked store publication, pruning and both engine release sites; no second history subsystem)
Risk: medium — a supposedly retained baseline can be deleted, or a failed copy can retain storage indefinitely.
Verdict: REQUEST_CHANGES.
Reasoning: the new pin must have one owner and remain effective across deletion, reference-only results and cleanup errors.
— Rames (hf-review)
… never across a delete
|
Fixed at 59d9710, for both reviews.
|
…line # Conflicts: # packages/studio-server/src/history/projectHistory.ts
… the drive never answers
… an agent step rewrote it
Main packs to 190,094 bytes, already 0.65% over the 188,871 budget; this branch adds 1,264 bytes of its own code (no new import: dist/index.js is unchanged). The budget file's rule is 5% above measured: ceil(191,358 x 1.05) = 200,926.
… Cmd+Z, restarts, in older apps Cmd+Z stops at an open step whose only write so far is a pending file. A step recovered after the process died keeps its list of pending files. A later Studio save's receipt no longer sets the start of a file a step went ahead of. Every earlier point names a pending file as not kept, so no restore deletes it in any app version.
…does, whatever bytes land Bytes cannot tell steps apart: a file written A, B, then A again by two steps looked untouched and cleared both. A step's list of files it went ahead of is now never cleared, so its undo refuses after a stalled read.
|
At A→B→A (Rames). A step's list is never cleared now. Bytes cannot tell steps apart, and size and times cannot either. Only the CLI's watcher reports writes as they happen, so other hosts have no per-step record of which step wrote a file. A step that went ahead of a stalled file never undoes. That is the safe side, chosen by the team lead and recorded in the body. Clearing is deleted ( Tai's four
Non-blocking from Rames: the in-memory verdict and a cleared step left with 0 files are both gone with clearing. Checks
Not exercised: a native Windows run and a real drive that stops answering. These were Linux runs with local fixtures. |
terencecho
left a comment
There was a problem hiding this comment.
Two P1s at b910bd69.
-
Recovery can erase the window’s Undo guard before it commits the recovered entry.
packages/studio-server/src/history/projectHistory.ts:707–714,844–881.markWentAheadBeforeReopenrewriteswent-ahead.jsonwhilethis.windowsis still empty. If recovery is interrupted beforesettleAllcommits the recovered window, the next launch readswindows: {}. I reproduced this with the existing mid-step crash fixture and a second exit at the first recovery sweep. On the next launch, Undo returnedok: true, restoredindex.html, and leftparts/p1.jsat the agent’s bytes. Keep the saved guard until the recovered entry is durable. Add the second-interruption case and assert that both files and the cursor stay unchanged on refusal. -
A later save can still replace a known START with the agent’s bytes.
packages/studio-server/src/history/projectHistory.ts:1033–1037. The early return fixes the unknown-provenance case. For a read-before copy, START still follows the receipt chain by content hash. Hold filing after the first read takes A, let the agent write B, then let Studio save A with a receipt saying it replaced B. The late copy’s hash A now matches that newer receipt. I changed the new read-before test to use this schedule and confirmed START became B and Restore START overwrote Studio’s A with B. Preserve the known original for read-before copies, or constrain receipt lookup to receipts known to predate the read.
The A→B→A step now refuses Undo permanently as intended. The open pending-only Cmd+Z, one-crash recovery, unknown-copy receipt and older-reader back-to-before cases passed in the focused suite. I treated the explicitly accepted older-reader “Keep later edits” behavior as settled. History and route tests on Linux: 427 passed, 3 skipped. The two additional cases were verified with local fixtures. Native Windows and the remaining hosted checks were pending when checked.
— tai (automated review)
jrusso1020
left a comment
There was a problem hiding this comment.
Approve at b910bd6. My a30cf5b blocker is resolved, and so are the four other findings.
Need ✅ · Size ✅ (+179/−81 since a30cf5b0, mostly tests) · Reuse ✅ (one went-ahead.json carries pending files and open windows) · Simpler ✅ (the byte-match clearing path is deleted, not patched) · Structure ✅
Risk: low to medium. A step that went ahead of a pending file now refuses its undo for good, even when the bytes return to the original. That trades a rare false refusal for never undoing to a wrong file, which is the right side to err on.
Prior findings, checked at this head
- A→B→A:
judge,seenUnchangedandverdictDueare gone, so no read can clear a step's list. The test "refuses the undo of every step that went ahead, though the file ends with its original bytes" runs exactly that case. All three steps refuse, and both files are left as they were. - Cmd+Z on an open window:
next()now counts an open window'swentAheadOfas a write, andstepcallsrefuseUnseenbefore undoing. - A window recovered after a crash:
went-ahead.jsonis now{ pending, windows }, andreopenClosedWindowrestores the window's list. ThestepThenDiefixture sends the step id before the SIGKILL.went-ahead.jsonis not on main, so no older on-disk format needs reading. - A receipt never sets an unknown start:
adoptedStartreturns the not-kept hash forunknownprovenance before it consultsoverwritten. - Earlier points name the file:
nameAtStartrecords the file at the start as not kept. When the copy lands,startSeen/startUnseenreplace that with the real start, so a known original stays restorable.
What I ran
vitest run src/history: 393 passed, 3 skipped (23 files).- I put a30cf5b's
projectHistory.tsback under this head's tests. Six fail: the A→B→A case, the open-window Cmd+Z, the recovered window, the receipt start, earlier points naming the file, and the saving test's start assertion. Each fix has its own red test. tsc --noEmiton studio-server is clean.
— Rames (hf-review)
… crash; saves keep the start The closed window is recovered before the reopen rewrites went-ahead.json, so a crash during recovery no longer erases its list of pending files. A copy read before a step went ahead is the file's start whatever a later save's receipt says it replaced.
|
At
Checks
Not exercised: a native Windows run and a real drive that stops answering. These were Linux runs with local fixtures. |
There was a problem hiding this comment.
P1 — Restore Start can lose the original from a Studio save that predates the stalled step (packages/studio-server/src/history/projectHistory.ts:1035).
The new read-before branch bypasses every receipt. Reproduced with a file at A and its first read delayed: Studio saves B and records overwrote: A before that read completes. The read gets B, its blob filing stalls, and a Studio claim and an agent window proceed. The agent only edits index.html. After filing completes, Restore Start succeeds and restores the index but leaves B. The same test restores A at b910bd69. The receipt naming A came before the read and the agent window.
Keep the trusted receipt ancestry available when the bytes are read. The existing regression test should continue to reject the receipt from a later save that names the agent's bytes. Add the early-save case alongside it.
P2 — A second crash can still lose part of the pending-file list (packages/studio-server/src/history/projectHistory.ts:852).
The recovered window's undo guard now survives the sidecar rewrite. With two pending files, though, the loop calls markWentAhead and rewrites went-ahead.json after adding the first path. A crash at that write leaves the window's guard intact but drops the second path from pending. In the two-file probe, the next reopen treats the second path as tracked and hangs when its read is stalled. An uninterrupted reopen completes, as does the crash probe with a single write after the full list is rebuilt.
Keep the old sidecar intact until recovery can replace it with the full pending list and recovered window guard.
— tai (automated review)
…pen writes all pending files A copy read before a step went ahead follows only the save receipts heard by the moment of its read, so an early save's original stays the start and a later save naming the step's bytes cannot replace it. The reopen rebuilds the list of pending files in memory and writes it once, so a crash midway keeps every file on it.
|
At
Checks
Not exercised: a native Windows run and a real drive that stops answering. These were Linux runs with local fixtures. |
terencecho
left a comment
There was a problem hiding this comment.
Changes requested at 2e293fc3. The full pending-set rewrite survives the second crash with both files, and the prior early/late receipt controls pass. Three first-copy boundary cases still fail.
- P1 · A late receipt can still change Start when no agent step opened (
packages/studio-server/src/history/projectHistory.ts:1050). Hold publication after the first copy reads A. The file changes to B, then Studio saves A with a receipt naming B. Theno-stepbranch walks the live receipts, so History records B at Start. Restore Start then writes B over A. Use read-time receipt ancestry for that adoption path too. - P2 · Delayed close can discard a valid pre-step original (
packages/studio-server/src/history/blobStore.ts:263). For a small file, the bytes and their stat are verified before awaiting the source handle's close. Holding that close until a step edits the file makes the lateronReadclassify the already verified copy as unknown. The original is in the blob store, but Restore Start refuses. Capture the read event at successful byte validation and retain normal close error handling. - P2 · Pruning can discard bytes a pending receipt snapshot still needs (
packages/studio-server/src/history/projectHistory.ts:1505). Early save B over A, hold publication of B, then record a later save that disconnects the live receipt chain. The old A blob exists before pruning. A commit that prunes while filing is held deletes A because it is named only by the read-time snapshot. Restore Start then succeeds with B. The same sequence preserves A without pruning. Keep the needed receipt predecessor alive through adoption or safely refuse Start when that predecessor is unavailable.
The first-copy probes used synthetic local files. The focused History and route suite passed 431 tests with three skipped, Studio Server built and typechecked, and the two original controls failed against 021580df.
— tai (automated review)
…by its read and keeps them Every adopted copy follows the save receipts heard by the moment of its read, with or without a step, so a later save writing the original back cannot move the start. A small file's read is reported before its close, which a slow drive can hold. Bytes a save replaced in a file history has no copy of yet stay through pruning until it does.
|
At
Three test mocks of the blob store dropped Checks
Not exercised: a native Windows run and a real drive that stops answering. These were Linux runs with local fixtures. |
terencecho
left a comment
There was a problem hiding this comment.
The three original first-copy cases pass at 59ee3786. Two budget regressions remain.
- P2 — Pending receipt bytes displace unrelated Undo entries (
packages/studio-server/src/history/projectHistory.ts:1495–1510). Pruning keeps the receipt predecessor, buthistoryBytesstill charges those temporary bytes to Undo. In a 128-byte budget probe, a held first copy retained its predecessor while two small index edits were folded out. The previous head kept both edits. Account for adoption's temporary retention the same way as other in-flight pins, so it does not consume Undo history. - P2 — Ordinary new files can retain receipt blobs for the entire open session (
projectHistory.ts:755). The map records every untracked file, including an ordinary file created and saved before a normal sweep. Its entries are only cleared on initial copy or adoption, which the new file never enters. After the new file was tracked and deleted, the original blob remained protected and a later unrelated Undo entry was folded. Reopening let the next prune reclaim it. Limit this retention to pending first copies and release it when there is no copy left to use it.
The focused History and route suites passed 434 cases with three skipped, and Studio Server built and typechecked. The original cases were also checked against the previous head. The probes used local test files.
— tai (automated review)
…t, not undo history The bytes a save replaced are kept only for a file still owed its first copy, and they count as start rather than undo history, so they never fold an unrelated edit out of the budget or stay for a file that never needed them.
|
At
Checks
The same two fixes are in #8403, the split freeze fix. Not exercised: a native Windows run and a real drive that stops answering. These were Linux runs with local fixtures. |
terencecho
left a comment
There was a problem hiding this comment.
The two receipt-retention regressions are resolved. While the first copy is pending, its predecessor bytes survive pruning and the 128-byte test keeps both unrelated Undo entries. An ordinary new file no longer gets first-copy protection, and its obsolete receipt can be reclaimed in the same session.
I also checked repeated saves while publication was held. Both heads retained the same disconnected receipt blobs in that window. The previous head also discarded unrelated Undo entries. Once adoption finished, a subsequent prune reclaimed those blobs. A long-stalled publication can still hold receipt bytes until it finishes.
Studio Server built and typechecked. The focused History and route suites passed 435 tests with 3 skipped. Both targeted probes failed at the previous head and passed here. My local validation used Linux fixtures.
Required checks, including Windows render, passed. Other Windows test shards and several non-required checks were still running.
— tai (automated review)
…line # Conflicts: # packages/studio-server/src/history/firstCopy.test.ts # packages/studio-server/src/history/projectHistory.ts # scripts/package-size-budgets.json
|
At What the merge resolved:
Checks: the whole studio-server suite passed 2,317 with 0 failures, tsc is clean, and the push gate ran the named files 3 times plus 23 covering files. |
terencecho
left a comment
There was a problem hiding this comment.
The merge keeps both receipt cases from main and preserves the Undo and pruning safeguards from the reviewed branch. The timer guard prevents an already-owed read from starting another deadline when its slot opens.
All 19 tests in firstCopy.test.ts passed with one worker. Removing the guard made its regression test fail with one extra deadline. All required checks passed, including Windows render. Some non-required checks, including the other Windows test shards, were still running.
— tai (automated review)
What
A project's first history copy no longer waits forever on a file the drive never answers. Each file it copies gets a deadline (10 s); a file that misses it is left owed, the way a file still changing is, and the background adoption copies it once the drive answers. The open finishes.
Why
On a drive that stops answering (an external exFAT disk was where it showed up), opening a project never finished: the first copy read every file through
blobs.put, with no deadline, and the open awaited all of them. The app's main thread stayed free, but the project never opened.Related work
Refs the desktop app's exFAT project-open freeze: the desktop side moved its own page reads off the main thread with a deadline; this is the part of the open that lives here.
How
firstOpenwaits on each file's copy forfirstCopyFileMs(option, default 10 s). Past it the file reads as"changing", so it joins the owed files thatadoptMediaInBackgroundalready retries.storeIfPresentreads one path at a time: a later copy of a path starts after the earlier read ends. A background retry of a stuck file waits behind the stuck read instead of starting a second one on the same drive.historyBytes()(deduplicated with the tracked hashes), so a waiting copy never pushes an in-budget edit out of undo history. Every fresh read of a file owed from the open, the first and every retry, runs inside the first-copy slots. Every copy the first open or an adoption makes is pinned in the blob store as it is filed (put(path, true)), inside the same per-hash turn a delete takes, so a delete never removes a pinned or newly filed copy; pinned blobs count as baseline inhistoryBytes(). Only the copy whose put took the pin can release it: the open once the copy is tracked, an adoption after its record. A copy carries whether it is reference-only (a file over 64 MiB or media), sorecordAdoptednever mistakes one for a lost blob, and it never reads inside the history queue.An agent step while a first copy is still missing (after merging main)
Main's #8375 makes an agent step wait for every first copy still being taken, so undo can bring back a file the step replaces. Merged with this PR, a file the drive never answers is one of those copies, so the project opened but its first agent step never began.
Decision (the team lead's call, recorded for Miguel): A was "the step waits for the copy, however long". B was "the step waits up to the same 10 s, then begins; undo of that one file refuses rather than restoring the agent's bytes". The lead chose B: a step that hangs forever is not an option, and the refusal uses the words that already exist ("An earlier version of X is not kept"), no new ones.
wentAheadOfon its entry): those whose first copy was still pending when it began. Nothing is ever added to a closed entry, so a file is in a step'sfilesonly if a sweep recorded it while the step was open.put'sonRead, so slow filing does not count against it). Otherwise it is a hash no stored version has, including for a file deleted before its copy landed. Restoring that start, or any point before the step, then refuses for that file.went-ahead.jsonnext toadopting.json. So this holds when the process dies before the step closes: the step recovered from its saved window keeps its list, and it is back before the reopen rewrites that file, so a second crash during recovery keeps it too. The reopen rebuilds the whole list in memory and writes it once, so a crash midway never drops the files after the first. A pending file deleted before the restart keeps a not-kept start.blobPathaccepts it and pruning sizes it at 0). An older app ignoreswentAheadOfbut sees the placeholder: its plain undo reports a conflict and its back-to-before restore hits "not kept", so neither undoes part of a step. Accepted (the team lead's call, recorded for Miguel): an older app's "Keep later edits" counts the pending file as changed later and undoes the step's other files. It only gets there after its conflict dialog shows that file as changed and the person picks that option. Nothing is overwritten, and that undo can itself be undone.Package size budget
The required Build job's packed-size check failed:
@hyperframes/studio-serverpacked to 191,358 bytes against a 188,871 budget. Main alone packs to 190,094 (already 0.65% over, inside the check's 1% grace); this branch adds 1,264 bytes of its own history code (826 for the open's deadline, 139 for the step's wait, 299 for the not-kept start). No new import came in:dist/index.jsis byte-identical to main's. Following the budget file's rule (5% above measured, as #8176 did for aws-lambda), the budget is now ceil(191,358 x 1.05) = 200,926.The unpacked check then failed the same way: this head unpacks to 742,597 bytes against main's 732,018 budget (1.4% over, past the 1% grace). The growth is the same history code, unminified in
dist: the step's list, its placeholder and the went-ahead file. The unpacked budget is now ceil(742,597 x 1.05) = 779,727. Packed is 192,682, inside the 200,926 budget.Test plan
firstCopy.test.tscase: one file'sopennever answers; the history must open, read that file once, and list it inadopting.json. Fails without the fix: run alone againstmain'sprojectHistory.ts, the open never resolves and the test times out at 20 s; with the fix it passes in about 140 ms.firstCopy.test.tscase: the first copy's blob write is held past the deadline, the file is edited after the open, then the write is let go. The original bytes must be the file's start and the edit a change. Fails against the previous head of this branch (START was the edited bytes).firstCopy.test.tscase: one file's read stalls for the whole test while a second file's first copy lands late, the second file is edited, a sweep with a 1-byte budget prunes, and a claim asks for the second file. Its original bytes must be its start. It fails with either part undone: chained behind the stalled file (never adopted) or not kept from pruning (re-read as the edited bytes).firstCopy.test.tscases: a 768-byte late copy waiting to be adopted while a smallindex.htmledit commits under a 128-byte budget (the edit must stay in history), and 12 files whose first copies keep changing (their fresh reads must run 4 at a time). Each fails with its part undone.firstCopy.test.tscases: rereads after a first reread also came back changing stay 4 at a time, and a reread copy waiting behind a held sweep survives a 1-byte-budget prune and becomes the file's start.firstCopy.test.ts), and a pinned blob survives prunes until each pin is released, whether it was new or already stored (blobStore.test.ts).firstCopy.test.tscases (each failed before its fix, see below):stepAheadOfCopy.test.ts, one case per row of the table posted on this PR (each failed at33eafbf1unless noted):33eafbf1, kept as a guard);a2032baa, where matching bytes cleared every list);dfe957d2, where clearing compared stats);a30cf5b0);adopting.jsonremoved (an app that ignores them), back-to-before of the step refuses and the file stays (failed ata30cf5b0, where the earlier point did not name the file and the restore deleted it);a30cf5b0); the same when a second crash hits the first recovery sweep, with the cursor and list unchanged (failed atb910bd69);a30cf5b0); for a copy read before the step, the start is the original, also when Studio saves the original bytes back (failed atb910bd69, where the receipt made the agent's bytes the start); a Studio save heard before the first read keeps its original as the start (failed at021580df);went-ahead.json: both stay listed and neither starts as the agent's bytes (failed at021580df);wentAheadOfstripped from the log on disk, then reopened (an older app): plain undo and back-to-before are not ok and both files are unchanged; "Keep later edits" undoes the other file and leaves the pending one (the accepted case above);33eafbf1undo put the old bytes back over the person's edit);__fixtures__/stepThenDie.ts) after the step closes, before it closes, or after the step deleted the pending file, and the copy lands after the reopen: the start is not the agent's bytes, restoring the start refuses, and so does undoing the step (the last two failed atdfe957d2).projectHistory.saving.test.ts: a claim on a file still changing after its one retry used to return nothing; it now returns its own entry, whose undo refuses with the starting-copy words and leaves the file as it is. The start now names that file as a version not kept, where before it did not name it.went-ahead.json, trusting a listed file on reopen, no not-kept start for a file deleted before a restart, a cut part without the list, Cmd+Z ignoring an open step's list, Cmd+Z not refusing before it undoes, a receipt setting an unknown start, no earlier point naming the file, a recovered step without its list, open steps' lists not saved. With all restored, the step, first-copy and saving files passed 46 three times, and the whole studio-server suite passed 2,309 with 0 failures on this head's code.videoState.test.ts: a fixed 80 ms sleep before reading the pending flag became a wait for the flag; it failed once in a loaded full run.Limit: this bounds the open and agent steps, not the whole history lifecycle. A read that never answers keeps that file's adoption pending, and closing a history waits for adoption, so a close can still wait on a dead drive.
Not exercised: a real exFAT volume that stops answering; the existing first-copy suite and CI run the rest.