Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): release watched TUI run on leaving Shell page

[._.]/ Adam Eivy084341aa258f
diff --git a/client/src/pages/Shell.jsx b/client/src/pages/Shell.jsx
index 0fb9084ce9..ee2f86841b 100644
--- a/client/src/pages/Shell.jsx
+++ b/client/src/pages/Shell.jsx
@@ -719,6 +719,12 @@ export default function Shell() {
socket.off('shell:exit', handleShellExit);
socket.off('shell:detached', handleShellDetached);
socket.off('shell:error', handleShellError);
+ // Leaving the Shell page: tell the server we've stopped viewing so any
+ // watched TUI run resumes normal idle completion instead of staying
+ // paused for a page we've left (the singleton socket stays connected
+ // across navigations, so `disconnect` won't fire). This effect only
+ // re-binds on socket identity change, so this runs on real unmount.
+ if (socket.connected) socket.emit('shell:release-views');
// Don't kill session on unmount — it persists server-side
sessionIdRef.current = null;
};
diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.js
index 056bf82497..c49372ff62 100644
--- a/server/lib/tuiPromptRunner.js
+++ b/server/lib/tuiPromptRunner.js
@@ -13,8 +13,10 @@
* promptRunner needs when `provider.type === 'tui'`.
*
* Spawning bypasses `services/shell.js` deliberately:
- * - shellService caps total sessions at 5, which the central handler can
- * exceed easily (arc planner fans out parallel calls).
+ * - shellService caps interactive sessions, which the central handler can
+ * exceed easily (arc planner fans out parallel calls). We still *register*
+ * the spawned PTY as an external view afterward (see below) — that path is
+ * exempt from the cap, so surfacing the run doesn't re-introduce the limit.
* - shellService wraps a login shell around the TUI; pasting `${cmd}\n`
* into a zsh prompt is slower and noisier than spawning the TUI directly.
*
diff --git a/server/services/shell.js b/server/services/shell.js
index 7ef1d4009c..a3f43803f8 100644
--- a/server/services/shell.js
+++ b/server/services/shell.js
@@ -274,6 +274,21 @@ export function isExternalSessionAttached(sessionId) {
return !!(session && session.external && session.socket);
}
+/**
+ * Public "stopped viewing" signal — the client emits this when it leaves the
+ * Shell page (the SocketProvider socket persists across navigations, so a plain
+ * disconnect doesn't fire). Releases every external (TUI-run) view bound to this
+ * socket so those runs resume normal idle completion instead of staying paused
+ * for a page the user has navigated away from. Tab-switching already releases via
+ * attach/create; this covers navigating away from /shell entirely.
+ */
+export function releaseExternalViewsForSocket(socket) {
+ if (!socket) return;
+ const held = [...shellSessions.values()].some(s => s.external && s.socket === socket);
+ releaseExternalViews(socket);
+ if (held) broadcastSessionList();
+}
+
/**
* Attach an existing session to a new socket
*
diff --git a/server/services/shell.test.js b/server/services/shell.test.js
index 34294af192..f2dbb21250 100644
--- a/server/services/shell.test.js
+++ b/server/services/shell.test.js
@@ -448,6 +448,29 @@ describe('registerExternalSession / unregisterExternalSession', () => {
expect(shell.isExternalSessionAttached(runB)).toBe(true);
});
+ it('releaseExternalViewsForSocket releases watched runs and broadcasts when something changed', () => {
+ const observer = makeSocket('obs');
+ shell.subscribeSessionList(observer);
+ const viewer = makeSocket('viewer');
+ const runId = shell.registerExternalSession('run-leave', makeFakePty(), {});
+ shell.attachSession(runId, viewer);
+ expect(shell.isExternalSessionAttached(runId)).toBe(true);
+ observer.emit.mockClear();
+ // Viewer navigated away from /shell — release without disconnecting.
+ shell.releaseExternalViewsForSocket(viewer);
+ expect(shell.isExternalSessionAttached(runId)).toBe(false);
+ expect(shell.getSession(runId)).toBeTruthy(); // run still alive, just unwatched
+ expect(observer.emit).toHaveBeenCalledWith('shell:sessions', expect.anything());
+ });
+
+ it('releaseExternalViewsForSocket is a no-op (no broadcast) when the socket held no runs', () => {
+ const observer = makeSocket('obs');
+ shell.subscribeSessionList(observer);
+ observer.emit.mockClear();
+ shell.releaseExternalViewsForSocket(makeSocket('stranger'));
+ expect(observer.emit).not.toHaveBeenCalledWith('shell:sessions', expect.anything());
+ });
+
it('unregister removes the session, emits shell:exit to the viewer, broadcasts', () => {
const observer = makeSocket('obs');
shell.subscribeSessionList(observer);
diff --git a/server/services/socket.js b/server/services/socket.js
index 41d37d9f12..ecf338e00f 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -562,6 +562,13 @@ export function initSocket(io) {
shellService.killSession(validated.sessionId);
});
+ // Client left the Shell page — release any watched TUI-run views so those
+ // runs resume normal completion instead of staying paused (the persistent
+ // SocketProvider socket means a navigation doesn't fire `disconnect`).
+ socket.on('shell:release-views', () => {
+ shellService.releaseExternalViewsForSocket(socket);
+ });
+
// Cleanup on disconnect — detach sessions, don't kill them
socket.on('disconnect', () => {
console.log(`🔌 Client disconnected: ${socket.id}`);