fix: session restoration now properly attaches to existing screens

- Pass existing screenSession to Session constructor for restored sessions
- Skip terminal buffer clearing when attaching to restored (existing) screens
- Frontend auto-calls /interactive endpoint when selecting a restored session
- Fixes issue where restored sessions appeared broken after server restart

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-19 19:56:28 +01:00
co-authored by Claude Opus 4.5
parent 611815628e
commit 3e26a6a18e
3 changed files with 60 additions and 26 deletions
+13
View File
@@ -633,6 +633,19 @@ class ClaudemanApp {
this.activeSessionId = sessionId;
this.renderSessionTabs();
// Check if this is a restored session that needs to be attached
const session = this.sessions.get(sessionId);
if (session && session.pid === null && session.status === 'idle') {
// This is a restored session - attach to the existing screen
try {
await fetch(`/api/sessions/${sessionId}/interactive`, { method: 'POST' });
// Update local session state
session.status = 'busy';
} catch (err) {
console.error('Failed to attach to restored session:', err);
}
}
// Load terminal buffer for this session
try {
const res = await fetch(`/api/sessions/${sessionId}/terminal`);
+3 -2
View File
@@ -1393,14 +1393,15 @@ export class WebServer extends EventEmitter {
const screens = this.screenManager.getScreens();
for (const screen of screens) {
if (!this.sessions.has(screen.sessionId)) {
// Create a session object for this screen
// Create a session object for this screen with the existing screenSession
const session = new Session({
id: screen.sessionId, // Preserve the original session ID
workingDir: screen.workingDir,
mode: screen.mode,
name: screen.name || screen.screenName,
screenManager: this.screenManager,
useScreen: true
useScreen: true,
screenSession: screen // Pass the existing screen so startInteractive() can attach to it
});
this.sessions.set(session.id, session);