Skip to content

Commit c52948b

Browse files
PureWeenCopilot
andcommitted
Fix: recreate sessions when resume fails with 'Session not found'
Worker sessions that were created but never received messages have no events.jsonl, so the CLI server returns 'Session not found' on resume. This caused multi-agent workers to silently vanish from the sidebar after relaunch. Now falls back to CreateSessionAsync when resume fails with 'Session not found', preserving the session in _sessions so it remains visible and functional. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 101e36c commit c52948b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

PolyPilot/Services/CopilotService.Persistence.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ public async Task RestorePreviousSessionsAsync(CancellationToken cancellationTok
206206
{
207207
Debug($"Failed to restore '{entry.DisplayName}': {ex.GetType().Name}: {ex.Message}");
208208

209+
// "Session not found" means the CLI server doesn't know this session
210+
// (e.g., worker sessions that were created but never received a message).
211+
// Fall back to creating a fresh session so multi-agent workers don't vanish.
212+
if (ex.Message.Contains("Session not found", StringComparison.OrdinalIgnoreCase))
213+
{
214+
try
215+
{
216+
Debug($"Falling back to CreateSessionAsync for '{entry.DisplayName}'");
217+
await CreateSessionAsync(entry.DisplayName, entry.Model, entry.WorkingDirectory, cancellationToken);
218+
Debug($"Recreated session: {entry.DisplayName}");
219+
continue;
220+
}
221+
catch (Exception createEx)
222+
{
223+
Debug($"Fallback CreateSessionAsync also failed for '{entry.DisplayName}': {createEx.Message}");
224+
}
225+
}
226+
209227
// If the connection broke, recreate the client
210228
if (ex is System.IO.IOException or System.Net.Sockets.SocketException
211229
or ObjectDisposedException

0 commit comments

Comments
 (0)