Problem
pi/extensions/control.ts has an explicit TODO for stale socket/alias cleanup. Over long-lived runtimes, .pi/session-control can accumulate stale files from crashes or interrupted shutdowns.
Proposed solution
- Implement periodic GC in control extension startup (and/or heartbeat interval):
- delete orphaned
.alias symlinks
- delete stale
.sock entries not owned by a live process
- optionally age-gate cleanup (e.g., older than 7 days)
- Add safety checks to avoid deleting active sockets.
- Add tests for stale/orphaned file handling.
Helpful context
- TODO marker in code:
pi/extensions/control.ts around removeAliasesForSocket.
- Existing cleanup behavior is mainly in
start.sh (best-effort on startup), but extension-level GC would keep state healthy during long uptimes.