Skip to content

Startup sweep for orphaned temp session directories #217

@PureWeen

Description

@PureWeen

Problem

When \CreateSessionAsync\ is called with \workingDirectory: null, it creates a temp directory under \polypilot-sessions/\ in the system temp folder. Cleanup only happens in \CloseSessionAsync. If the app crashes, is force-quit, or the process is killed (e.g. during
elaunch.ps1), these directories accumulate indefinitely.

Proposed Fix

On app startup (during \CopilotService.InitAsync\ or similar), scan for \polypilot-sessions/\ directories that don't correspond to any active or persisted session, and delete them.

Something like:
\\csharp
var tempBase = Path.Combine(Path.GetTempPath(), "polypilot-sessions");
if (Directory.Exists(tempBase))
{
foreach (var dir in Directory.GetDirectories(tempBase))
{
var dirName = Path.GetFileName(dir);
if (!_sessions.ContainsKey(dirName) && !persistedSessionIds.Contains(dirName))
try { Directory.Delete(dir, true); } catch { }
}
}
\\

Impact

Low risk — temp dirs are small (empty or near-empty). But over time with frequent relaunches during development, they accumulate.

Found during multi-model review of PR #205.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions