Skip to content

Commit 795242f

Browse files
committed
fix: add JsonStringEnumConverter and flush-to-disk before atomic rename to prevent checkpoint corruption and replay errors
1 parent a01b130 commit 795242f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/GsdOrchestrator/Checkpointing/FileCheckpointStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public sealed class FileCheckpointStore : ICheckpointStore
2626
private static readonly JsonSerializerOptions JsonOpts = new()
2727
{
2828
WriteIndented = true,
29-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
29+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
30+
Converters = { new System.Text.Json.Serialization.JsonStringEnumConverter() }
3031
};
3132

3233
/// <summary>
@@ -53,7 +54,10 @@ public async Task SaveAsync(GsdWorkflowContext ctx, CancellationToken ct = defau
5354
var tmp = path + ".tmp";
5455

5556
await using (var fs = new FileStream(tmp, FileMode.Create, FileAccess.Write, FileShare.None))
57+
{
5658
await JsonSerializer.SerializeAsync(fs, ctx, JsonOpts, ct);
59+
fs.Flush(flushToDisk: true);
60+
}
5761

5862
// Atomic rename — prevents partial writes leaving corrupt checkpoints
5963
File.Move(tmp, path, overwrite: true);

0 commit comments

Comments
 (0)