Repository navigation
fix(studio): recover a draft only for the project and file it was saved for - #7891
michaelwang11394 wants to merge 6 commits into
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 97 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 3ae73e59dd040f65ede5c52ca59eaf10e7fead52.
The exact project/file comparison closes the cross-key restoration case, but the new cleanup can erase a legitimate replacement draft.
Important: packages/studio/src/utils/externalConflictStorage.ts:165–171 reads in one transaction and deletes in another. Tab A reads an expired record; tab B saves a fresh draft under that key; A then unconditionally deletes B's draft. A fake-indexeddb regression that queues B's write during A's read reproduced the loss: expected the fresh draft, received undefined. Read, validate and conditionally delete within one readwrite transaction. A local diagnostic implementation of that change passes the same regression; source was restored after testing.
Validation: focused storage run using a minimal Vitest config: 20 passed and the new race regression failed; diagnostic fix: 1 passed. The normal Studio config could not load an unbuilt studio-server package, so this is not a full Studio suite result.
Pre-existing follow-up: there is still no record-shape validator, and timestamp arithmetic accepts numeric strings. The identity fix is real, but the Slack description's shape-validation claim is not implemented. Validate kind, content/version fields and a finite numeric timestamp separately.
Need: yes · Size: ok · Reuse: existing IndexedDB transaction helper · Simpler: keep validation and deletion in one transaction · Structure: fine (checked storage writer and recovery coordinator; no split)
Risk: medium — the new two-transaction cleanup can delete unsaved user work.
Verdict: REQUEST CHANGES
Reasoning: Make expired/mismatched-record cleanup atomic with its read so another tab's valid draft survives.
— Review by Rames
|
Thanks, Rames, good catch. In 559a654 the loader reads, checks and deletes inside one readwrite transaction, so another tab's fresh draft can't be removed between the read and the delete. Your race is now a regression test: "keeps a fresh draft another tab saves while an expired one is being cleared". It fails on the previous commit. The age check also requires a numeric On shape validation: you're right that my Slack note overstated it. I dropped the shape checks to keep this change small. This PR closes the cross-key case only. A record written under the right key by other code on the same origin is closed by running the preview sealed (#7846). I'll do kind and field validation as a separate follow-up. |
|
Closing this as superseded. #7904 (merged) fixed the same problem on main a different way: recovery drafts now live on each project's own Studio server, in the project's |
Summary
Studio keeps unsaved recovery drafts (a save that conflicted with an outside edit, or failed) in an IndexedDB store. That store is shared by every project served from the same origin. The loader returned whatever record sat under a key, and the caller then used the record's own
filePath. So a record written under one project's key could name a different project or file, and Studio would offer to restore its content over that file.loadExternalConflictSnapshotnow returns a record only when all of these hold:projectIdandfilePathequal the key it was read under,createdAtis a number less than 30 days old.A record that fails these checks is treated as absent. It is deleted in the same IndexedDB transaction that read it, so a fresh draft another tab saves at the same moment is never removed. A draft Studio saved for this project and file is recovered exactly as before.
Testing
fails without the fix:
packages/studio/src/utils/externalConflictStorage.test.ts"keeps a fresh draft another tab saves while an expired one is being cleared".fails without the fix:
packages/studio/src/utils/externalConflictStorage.test.ts"refuses and deletes a stored record with another project's id".packages/studio:env -u AWS_PROFILE npx vitest run src/utils/externalConflictStorage.test.ts src/hooks/useExternalFileChangeCoordinator.test.tsx(63 passed).No visible change
No screen changes. A genuine draft is recovered exactly as before; only records that name another project or file, or are over 30 days old, are no longer offered.