fix: release persisted pilot session before state transition
This commit is contained in:
@@ -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<T>(string path, T value, CancellationToken ct) => await WriteTextAtomic(path, JsonSerializer.Serialize(value), ct, true);
|
||||
private static async Task<PersistedSession?> ReadSession(string root, CancellationToken ct)
|
||||
{ var path = Path.Combine(root, "state", "pilot-session.json"); return File.Exists(path) ? await JsonSerializer.DeserializeAsync<PersistedSession>(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<PersistedSession>(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); }
|
||||
|
||||
Reference in New Issue
Block a user