fix(terminal): reconcile tabs with server sessions and keep shown terminals alive

The tab list lived only in per-tab sessionStorage, so a new browser
tab, another device, or cleared storage showed an empty terminal
sidebar while PTYs kept running server-side, and orphans leaked until
the idle sweep. Add GET /api/terminal/sessions and adopt unknown
server sessions into the local tab projection (additive only; a failed
listing changes nothing).

The idle sweep also reaped terminals in background tabs because only
the active tab holds a WebSocket attachment. Add POST
/api/terminal/touch and have open clients periodically refresh
activity for every session their tabs reference.
This commit is contained in:
Bohdan Triapitsyn
2026-08-24 14:30:00 +03:00
parent 0918bee566
commit 2f27f0ec4b
9 changed files with 249 additions and 2 deletions
+10
View File
@@ -8,6 +8,8 @@ import {
restartTerminalSession,
forceKillTerminal,
listTerminalShells,
listTerminalSessions,
touchTerminalSessions,
} from '@openchamber/ui/lib/terminalApi';
import type {
TerminalAPI,
@@ -23,6 +25,14 @@ export const createWebTerminalAPI = (): TerminalAPI => ({
return listTerminalShells();
},
async listSessions(cwd: string) {
return listTerminalSessions(cwd);
},
async touchSessions(sessionIds: string[]) {
await touchTerminalSessions(sessionIds);
},
async createSession(options: CreateTerminalOptions): Promise<TerminalSession> {
return createTerminalSession(options);
},