Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ClaudeNest.Agent/Services/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ public async Task HealthCheckAsync()
}
catch
{
// Process no longer exists — dispose handle immediately to free native resources
// Process no longer exists — mark session as crashed and clear process reference.
// Don't dispose Process here as SpawnProcessAsync/MonitorAdoptedProcessAsync may
// still be awaiting WaitForExitAsync() on the same instance. Let the owning code
// path handle disposal; the 1-hour cleanup will catch any stragglers.
Comment on lines +203 to +206
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new comment says HealthCheckAsync will "clear process reference", but the code no longer clears session.Process (and likely must not, since SpawnProcessAsync/MonitorAdoptedProcessAsync may still use that instance). Please update the comment to accurately describe the behavior (e.g., that we intentionally keep the Process reference and avoid disposing it here, letting the owning path/cleanup handle disposal).

Suggested change
// Process no longer exists — mark session as crashed and clear process reference.
// Don't dispose Process here as SpawnProcessAsync/MonitorAdoptedProcessAsync may
// still be awaiting WaitForExitAsync() on the same instance. Let the owning code
// path handle disposal; the 1-hour cleanup will catch any stragglers.
// Process no longer exists — mark session as crashed.
// Intentionally keep the existing Process reference and avoid disposing it here,
// as SpawnProcessAsync/MonitorAdoptedProcessAsync may still be awaiting
// WaitForExitAsync() on the same instance. Let the owning code path handle
// disposal; the 1-hour cleanup below will remove the session and dispose Process.

Copilot uses AI. Check for mistakes.
session.State = SessionState.Crashed;
session.EndedAt = DateTime.UtcNow;
session.Process?.Dispose();
session.Process = null;
await NotifyStatusChangedAsync(session);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ClaudeNest.Agent/Services/SignalRConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public async Task ConnectAsync(CancellationToken stoppingToken)
await OnReconnected(_connection.ConnectionId);
break;
}
catch (OperationCanceledException) when (_stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Reconnection cancelled — agent is shutting down");
break;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Manual reconnection failed, retrying in {Delay}s...", delay.TotalSeconds);
Expand Down
Loading