From 5f3a75f16046e9ed947aebf4d80a21341245a982 Mon Sep 17 00:00:00 2001 From: codex Date: Fri, 31 Jul 2026 15:44:11 +0300 Subject: [PATCH] fix: release persisted pilot session before state transition --- Launcher.Next.Infrastructure/PilotExecutionService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher.Next.Infrastructure/PilotExecutionService.cs b/Launcher.Next.Infrastructure/PilotExecutionService.cs index 65f8adf..ca2cd3b 100644 --- a/Launcher.Next.Infrastructure/PilotExecutionService.cs +++ b/Launcher.Next.Infrastructure/PilotExecutionService.cs @@ -148,7 +148,7 @@ public sealed class PilotExecutionService( { if (!exists) { if (File.Exists(path)) File.Delete(path); return; } Directory.CreateDirectory(Path.GetDirectoryName(path)!); var temp = path + ".tmp"; await File.WriteAllTextAsync(temp, content, ct); File.Move(temp, path, true); } private static async Task WriteJsonAtomic(string path, T value, CancellationToken ct) => await WriteTextAtomic(path, JsonSerializer.Serialize(value), ct, true); private static async Task ReadSession(string root, CancellationToken ct) - { var path = Path.Combine(root, "state", "pilot-session.json"); return File.Exists(path) ? await JsonSerializer.DeserializeAsync(File.OpenRead(path), cancellationToken: ct) : null; } + { var path = Path.Combine(root, "state", "pilot-session.json"); if (!File.Exists(path)) return null; await using var stream = File.OpenRead(path); return await JsonSerializer.DeserializeAsync(stream, cancellationToken: ct); } private static Task WriteSession(string root, PersistedSession session, CancellationToken ct) => WriteJsonAtomic(Path.Combine(root, "state", "pilot-session.json"), session, ct); private static async Task MarkFailed(string root, string code, CancellationToken ct) { var s = await ReadSession(root, ct); if (s is not null) await WriteSession(root, s with { State = "Failed", UpdatedAtUtc = DateTimeOffset.UtcNow, LastErrorCode = code, LastErrorMessage = code }, ct); }