Skip to content

Commit baea1ae

Browse files
PureWeenCopilot
andcommitted
Fix stale log tags and add ProcessingGeneration guard (INV-3)
- Diagnostic filter: [RESUME-ABORT -> [RESUME-ACTIVE] + [RESUME-CHECK] (without this, RESUME-ACTIVE entries wouldn't appear in event-diagnostics.log) - Utilities.cs: [RESUME-ABORT] -> [RESUME-CHECK] in HasInterruptedToolExecution - RESUME-ACTIVE InvokeOnUI: add ProcessingGeneration capture/check per INV-3/INV-12 to prevent stale callback from re-arming IsProcessing after a user-initiated turn has already completed (race window: send -> complete -> stale callback) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2fd49ed commit baea1ae

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

PolyPilot/Services/CopilotService.Persistence.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,12 @@ private async Task EnsureSessionConnectedAsync(string sessionName, SessionState
414414
{
415415
Debug($"[RESUME-ACTIVE] '{sessionName}' has unmatched tool starts — marking as processing and waiting for events");
416416
// INV-2: marshal to UI thread — EnsureSessionConnectedAsync runs from Task.Run.
417+
// INV-3/INV-12: capture generation to prevent stale callback from re-arming
418+
// IsProcessing after a user-initiated turn has already completed.
419+
var gen = Interlocked.Read(ref state.ProcessingGeneration);
417420
InvokeOnUI(() =>
418421
{
422+
if (Interlocked.Read(ref state.ProcessingGeneration) != gen) return;
419423
state.Info.IsProcessing = true;
420424
state.Info.IsResumed = true;
421425
state.HasUsedToolsThisTurn = true;

PolyPilot/Services/CopilotService.Utilities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ internal bool HasInterruptedToolExecution(string sessionId, string basePath)
271271
var result = unmatchedStarts > 0 && (sawShutdown || !sawOnlyControlEvents);
272272
if (result)
273273
{
274-
Debug($"[RESUME-ABORT] events.jsonl for '{sessionId}' has {unmatchedStarts} interrupted tool(s) " +
274+
Debug($"[RESUME-CHECK] events.jsonl for '{sessionId}' has {unmatchedStarts} interrupted tool(s) " +
275275
$"(shutdown={sawShutdown}, force-kill={!sawShutdown})");
276276
}
277277
return result;
278278
}
279279
catch (Exception ex)
280280
{
281-
Debug($"[RESUME-ABORT] Failed to check events.jsonl for '{sessionId}': {ex.Message}");
281+
Debug($"[RESUME-CHECK] Failed to check events.jsonl for '{sessionId}': {ex.Message}");
282282
return false;
283283
}
284284
}

PolyPilot/Services/CopilotService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ internal static bool ShouldPersistDiagnostic(string message)
694694
message.StartsWith("[RECONNECT") || message.StartsWith("[UI-ERR") ||
695695
message.StartsWith("[DISPATCH") || message.StartsWith("[WATCHDOG") ||
696696
message.StartsWith("[HEALTH") || message.StartsWith("[ZERO-IDLE") ||
697-
message.StartsWith("[PERMISSION") || message.StartsWith("[RESUME-ABORT") ||
697+
message.StartsWith("[PERMISSION") || message.StartsWith("[RESUME-ACTIVE") || message.StartsWith("[RESUME-CHECK") ||
698698
message.StartsWith("[KEEPALIVE") || message.StartsWith("[ERROR") ||
699699
message.StartsWith("[ABORT") || message.StartsWith("[BRIDGE") ||
700700
message.StartsWith("[SYNC") ||

0 commit comments

Comments
 (0)