From 7705c35ec728857ea47d059f64385171fde5d337 Mon Sep 17 00:00:00 2001 From: AO Bot Date: Sun, 21 Jun 2026 14:41:17 +0000 Subject: [PATCH 1/2] fix(frontend): inject orchestrator session into cache before navigating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #370 — new project creation navigated to the session route before useWorkspaceQuery's cache contained the spawned orchestrator session, leaving SessionView stuck on "Session not found" until the 15s refetchInterval caught up. Root cause: createProject's optimistic setQueryData (adding the workspace with sessions: []) reset dataUpdatedAt, and React Query v5's invalidateQueries swallows refetch errors (refetchQueries does promise.catch(noop)), so a failed refetch left stale sessions: [] in the cache. The global staleTime: 10_000 then suppressed a mount-triggered refetch in SessionView. Fix: after spawnOrchestrator returns the sessionId, optimistically inject the orchestrator session into the workspace's sessions array via updateWorkspaces, then use refetchQueries (forces fresh data ASAP). SessionView can now find the session immediately regardless of refetch timing. --- frontend/src/renderer/routes/_shell.tsx | 33 +++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/frontend/src/renderer/routes/_shell.tsx b/frontend/src/renderer/routes/_shell.tsx index 762bb939..ab3c90d2 100644 --- a/frontend/src/renderer/routes/_shell.tsx +++ b/frontend/src/renderer/routes/_shell.tsx @@ -13,7 +13,7 @@ import { addRendererExceptionStep, captureRendererEvent, captureRendererExceptio import { ShellProvider } from "../lib/shell-context"; import { spawnOrchestrator } from "../lib/spawn-orchestrator"; import { readStoredTheme, type Theme, useUiStore } from "../stores/ui-store"; -import type { WorkspaceSummary } from "../types/workspace"; +import { toAgentProvider, type WorkspaceSession, type WorkspaceSummary } from "../types/workspace"; export const Route = createFileRoute("/_shell")({ // Prefetch the workspace list for the whole shell (parent loaders run before @@ -94,7 +94,36 @@ function ShellLayout() { updateWorkspaces((current) => [workspace, ...current.filter((item) => item.id !== workspace.id)]); try { const sessionId = await spawnOrchestrator(workspace.id); - await queryClient.invalidateQueries({ queryKey: workspaceQueryKey }); + // Optimistically inject the orchestrator session into the workspace + // cache so SessionView can render immediately — even if the background + // refetch is slow or fails (the daemon is busy with the spawn workload: + // git worktree, provisioning, Zellij runtime). Without this, the cache + // retains the workspace with sessions: [] from the optimistic update + // above, and the staleTime: 10_000 window suppresses a mount-triggered + // refetch in SessionView, so the route shows "Session not found" until + // the 15s refetchInterval fires. See issue #370. + const ts = new Date().toISOString(); + const orchestratorSession: WorkspaceSession = { + id: sessionId, + workspaceId: workspace.id, + workspaceName: workspace.name, + title: "orchestrator", + provider: toAgentProvider(input.orchestratorAgent), + kind: "orchestrator", + branch: `session/${sessionId}`, + status: "working", + createdAt: ts, + updatedAt: ts, + prs: [], + }; + updateWorkspaces((current) => + current.map((w) => + w.id === workspace.id + ? { ...w, sessions: [orchestratorSession, ...w.sessions] } + : w, + ), + ); + await queryClient.refetchQueries({ queryKey: workspaceQueryKey }); void navigate({ to: "/projects/$projectId/sessions/$sessionId", params: { projectId: workspace.id, sessionId }, From 6b31d4857f0a2f7c91416bf25ff15afe318c517b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 21 Jun 2026 14:41:51 +0000 Subject: [PATCH 2/2] chore: format with prettier [skip ci] --- frontend/src/renderer/routes/_shell.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/src/renderer/routes/_shell.tsx b/frontend/src/renderer/routes/_shell.tsx index ab3c90d2..ac2b194f 100644 --- a/frontend/src/renderer/routes/_shell.tsx +++ b/frontend/src/renderer/routes/_shell.tsx @@ -117,11 +117,7 @@ function ShellLayout() { prs: [], }; updateWorkspaces((current) => - current.map((w) => - w.id === workspace.id - ? { ...w, sessions: [orchestratorSession, ...w.sessions] } - : w, - ), + current.map((w) => (w.id === workspace.id ? { ...w, sessions: [orchestratorSession, ...w.sessions] } : w)), ); await queryClient.refetchQueries({ queryKey: workspaceQueryKey }); void navigate({