fix: Ralph Loop wizard screen creation and session idle detection

- Fix screen creation failing when using cpulimit/nice (env vars were passed
  as command args instead of shell variables)
- Fix session status never becoming 'idle' after startInteractive()
- Add automatic state file cleanup on startup (removes orphaned sessions)
- Add /api/cleanup-state endpoint for manual cleanup
- Make frontend session readiness check more robust (20 attempts, multiple checks)
- Add fallback to direct PTY write if writeViaScreen fails

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-27 11:02:02 +01:00
co-authored by Claude Opus 4.5
parent 2d8597a66f
commit f92d009034
9 changed files with 649 additions and 104 deletions
+26
View File
@@ -177,6 +177,32 @@ export class StateStore {
this.save();
}
/**
* Cleans up stale sessions from state that don't have corresponding active sessions.
* @param activeSessionIds - Set of currently active session IDs
* @returns Number of sessions cleaned up
*/
cleanupStaleSessions(activeSessionIds: Set<string>): number {
const allSessionIds = Object.keys(this.state.sessions);
let cleanedCount = 0;
for (const sessionId of allSessionIds) {
if (!activeSessionIds.has(sessionId)) {
delete this.state.sessions[sessionId];
// Also clean up Ralph state for this session
this.ralphStates.delete(sessionId);
cleanedCount++;
}
}
if (cleanedCount > 0) {
console.log(`[StateStore] Cleaned up ${cleanedCount} stale session(s) from state`);
this.save();
}
return cleanedCount;
}
/** Returns all task states keyed by task ID. */
getTasks() {
return this.state.tasks;