You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A cancelled or interrupted SaveStateAsync truncates the state file and destroys the previous save; HasSavedStateAsync then says true while LoadStateAsync returns false #71
File.WriteAllTextAsync truncates the file before it writes. If the write is interrupted, the previously good state is already gone. That happens when:
the CancellationToken the method accepts is cancelled,
the process dies mid-write, or
the disk fills up.
LoadStateAsync then hits a JsonException and returns null, so the saved history is lost without any error. Meanwhile HasSavedStateAsync keeps reporting true.
Repro (net10.0)
varprovider=newJsonFilePersistenceProvider<NavigationItem>(path);varnav=newNavigation<NavigationItem>(null,provider);for(inti=0;i<100_000;i++)nav.NavigateTo(newNavigationItem($"p{i}",$"Page {i}"));awaitnav.SaveStateAsync();// good savenav.NavigateTo(newNavigationItem("last","Last"));usingvarcts=newCancellationTokenSource();vart=nav.SaveStateAsync(cts.Token);cts.CancelAfter(1);try{awaitt;}catch(OperationCanceledException){}varfresh=newNavigation<NavigationItem>(null,provider);awaitfresh.LoadStateAsync();
Observed over three runs:
first save ok: 14166702 bytes
second save cancelled
file now: 2809856 bytes (696320 and 4956160 on the other runs)
LoadStateAsync -> False, Count=0, HasSavedState=True
Suggested fix / acceptance criteria
Write to a temporary file in the same directory and flush it, then atomically replace the target (File.Replace, or File.Move(tmp, path, overwrite: true)).
Delete the temporary file if the write is cancelled or fails.
Test: cancelling a save leaves the previously saved state loadable and unchanged, and leaves no temporary file behind.
A successful save still produces the same JSON as today.
Priority: High. A cancelled token, a crash, or a full disk during a save silently destroys the previous good state. Afterwards HasSavedStateAsync reports true while LoadStateAsync returns false, so callers can't detect the loss. The fix is the standard write-to-temp-then-replace pattern.
Area / suggested assignment:SaveStateAsync in Navigation/Services/JsonFilePersistenceProvider.cs.
Activity
matt-edmondson commentedon Sep 29, 2026
Triage
HasSavedStateAsyncreportstruewhileLoadStateAsyncreturnsfalse, so callers can't detect the loss. The fix is the standard write-to-temp-then-replace pattern.SaveStateAsyncinNavigation/Services/JsonFilePersistenceProvider.cs.Generated by Claude Code