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

fix(shell): handle socket disconnect to prevent stuck session attach

Adam Eivyee350d9477f6
diff --git a/client/src/pages/Shell.jsx b/client/src/pages/Shell.jsx
index 7875c03703..697338a546 100644
--- a/client/src/pages/Shell.jsx
+++ b/client/src/pages/Shell.jsx
@@ -200,7 +200,7 @@ export default function Shell() {
}, []);
const startSession = useCallback(() => {
- if (!socket) return;
+ if (!socket?.connected) return;
if (termInstanceRef.current) {
termInstanceRef.current.clear();
termInstanceRef.current.writeln('\x1b[36mStarting shell session...\x1b[0m');
@@ -214,7 +214,7 @@ export default function Shell() {
}, [socket]);
const attachToSession = useCallback((sessionId) => {
- if (!socket) return;
+ if (!socket?.connected) return;
if (termInstanceRef.current) {
termInstanceRef.current.clear();
termInstanceRef.current.writeln('\x1b[36mAttaching to session...\x1b[0m');
@@ -267,6 +267,13 @@ export default function Shell() {
socket.emit('shell:list');
};
+ const handleDisconnect = () => {
+ // Clear session state so reconnect auto-reattaches
+ sessionIdRef.current = null;
+ setActiveSessionId(null);
+ setConnected(false);
+ };
+
const handleSessions = (sessionList) => {
setSessions(sessionList);
// On first load, auto-attach to existing session or create new
@@ -345,6 +352,7 @@ export default function Shell() {
};
socket.on('connect', handleConnect);
+ socket.on('disconnect', handleDisconnect);
socket.on('shell:sessions', handleSessions);
socket.on('shell:started', handleShellStarted);
socket.on('shell:attached', handleShellAttached);
@@ -358,6 +366,7 @@ export default function Shell() {
return () => {
socket.off('connect', handleConnect);
+ socket.off('disconnect', handleDisconnect);
socket.off('shell:sessions', handleSessions);
socket.off('shell:started', handleShellStarted);
socket.off('shell:attached', handleShellAttached);