Skip to content

Commit d2f5166

Browse files
committed
Listen for connectivity changes and handle session state
1 parent 37cac03 commit d2f5166

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

apps/array/src/renderer/features/sessions/stores/sessionStore.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,11 @@ const useStore = create<SessionStore>()(
459459
});
460460

461461
if (result) {
462-
updateSession(taskRunId, { status: "connected" });
462+
// Set isPromptPending true - the resumed agent may still be generating
463+
updateSession(taskRunId, {
464+
status: "connected",
465+
isPromptPending: true,
466+
});
463467
} else {
464468
unsubscribeFromChannel(taskRunId);
465469
removeSession(taskRunId);
@@ -873,3 +877,24 @@ useAuthStore.subscribe(
873877
}
874878
},
875879
);
880+
881+
// Listen for connectivity changes and handle session state
882+
trpcVanilla.connectivity.onStatusChange.subscribe(undefined, {
883+
onData: (status) => {
884+
if (!status.isOnline) {
885+
log.info("Connectivity lost - marking sessions as disconnected");
886+
887+
useStore.setState((state) => {
888+
for (const session of Object.values(state.sessions)) {
889+
if (
890+
session.status === "connected" ||
891+
session.status === "connecting"
892+
) {
893+
session.status = "disconnected";
894+
session.isPromptPending = false;
895+
}
896+
}
897+
});
898+
}
899+
},
900+
});

apps/array/src/renderer/features/task-detail/components/TaskLogsPanel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useWorkspaceStore,
1313
} from "@features/workspace/stores/workspaceStore";
1414
import { Box } from "@radix-ui/themes";
15+
import { useConnectivity } from "@renderer/hooks/useConnectivity";
1516
import { logger } from "@renderer/lib/logger";
1617
import { useNavigationStore } from "@renderer/stores/navigationStore";
1718
import { trpcVanilla } from "@renderer/trpc/client";
@@ -34,6 +35,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
3435
const { connectToTask, sendPrompt, cancelPrompt } = useSessionActions();
3536
const markActivity = useTaskViewedStore((state) => state.markActivity);
3637
const markAsViewed = useTaskViewedStore((state) => state.markAsViewed);
38+
const { isOnline } = useConnectivity();
3739

3840
const isRunning =
3941
session?.status === "connected" || session?.status === "connecting";
@@ -46,6 +48,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
4648
useEffect(() => {
4749
if (!repoPath) return;
4850
if (isConnecting.current) return;
51+
if (!isOnline) return;
4952

5053
if (session?.status === "connected" || session?.status === "connecting") {
5154
return;
@@ -75,7 +78,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
7578
}).finally(() => {
7679
isConnecting.current = false;
7780
});
78-
}, [task, repoPath, session, connectToTask, markActivity]);
81+
}, [task, repoPath, session, connectToTask, markActivity, isOnline]);
7982

8083
const handleSendPrompt = useCallback(
8184
async (text: string) => {

0 commit comments

Comments
 (0)