Repository navigation
Store repair after a late save from another window - #218
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 changed
A window now repairs localStorage when another window's older save lands after its own newer one.
template.html: on astorageevent for the model, a window that already built on that model and finds it in the store writes its newer model back. On astorageevent for the log, it writes the log back when the store is missing any of its entries.deck.htmlandlibrary.html: rebuilt from the template.test/autosave.test.mjs: a deterministic test that replays the late save in all four browser projects. The existing shape check on the storage listener moves to the new code. Its check thatreceive()writes nothing stays as it was.docs/editor.mdandCHANGELOG.md: the "never writes back" claim now names the exception.Why
The Firefox two-window failure on
main(runs 40194889668 and 40340413387, plus 36496159863 and 36493033117 per #197) is a real lost edit, not a slow test. #197 treated it as a read that came too early.Window B is typing when window A saves. A writes its model and tells B over BroadcastChannel. B commits its words on top and saves. B's save can still reach the store first, so A's older model lands last and stays there. Both windows show the right deck in memory, and a reload loses B's words.
Verification
A temporary CI workflow ran the two-window flow in Firefox, with three loops alongside the full suite and one loop alone. It read the store from A, from B and from a fresh page.
ponytail:
template.html,restoreModelandrestoreLog: localStorage tier only, since only that tier has astorageevent. The IndexedDB tier has no repair. Upgrade path: read the store back after a save made on top of a heard model.template.html,restoreModel: if A saves a third model in the moment B repairs, B's write can land after it and leave the store one model behind until the next save. Upgrade path: stamp each model with a sequence number and refuse older writes.🤖 Generated with Claude Code