From cd1454f851a2d627a1c0109833cd37fa4210cc45 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Tue, 9 Jun 2026 18:03:15 -0700 Subject: [PATCH] [eric] frontend: app reopen renders the cached chat instantly, stale-session verification moved to the background --- frontend/src/app/pages/Views/ViewEditor.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/pages/Views/ViewEditor.tsx b/frontend/src/app/pages/Views/ViewEditor.tsx index 565327f5..6bd79789 100644 --- a/frontend/src/app/pages/Views/ViewEditor.tsx +++ b/frontend/src/app/pages/Views/ViewEditor.tsx @@ -29,7 +29,7 @@ import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; import Collapse from '@mui/material/Collapse'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import { useAppDispatch, useAppSelector } from '@/shared/hooks'; -import { createDraftSession, removeDraftSession, fetchSession } from '@/shared/state/agentsSlice'; +import { createDraftSession, removeDraftSession } from '@/shared/state/agentsSlice'; import { createOutput, updateOutput, fetchOutputs, Output, SERVE_BASE } from '@/shared/state/outputsSlice'; import { useClaudeTokens } from '@/shared/styles/ThemeContext'; import AgentChat from '../AgentChat/AgentChat'; @@ -410,6 +410,13 @@ const ViewEditor: React.FC = ({ output }) => { (async () => { // Reattach: Output has an existing session + workspace; skip seeding/draft so we don't clobber agent state. if (output?.session_id && output?.workspace_id) { + // Mount the chat NOW so the cached conversation renders instantly + // (AgentChat's own hydrate + WS catch up on what we missed); holding it + // behind the verification round-trips blanked the chat for seconds on + // every reopen. The stale-id guard below still runs, just in the + // background, and swaps in a fresh draft on the rare 404. + setInitialDraftId(output.session_id); + let resolvedWorkspacePath: string | null = null; try { const res = await fetch(`${WORKSPACE_API}/${output.workspace_id}`); @@ -429,14 +436,9 @@ const ViewEditor: React.FC = ({ output }) => { sessionStillExists = sr.ok; } catch { /* network blip, treat as missing */ } - if (sessionStillExists) { - // Catch up on anything the agent did while we were on another tab. - dispatch(fetchSession(output.session_id)); - setInitialDraftId(output.session_id); - return; - } + if (sessionStillExists) return; - // Stale link: clear it so future opens skip the 404 round-trip, then fall through. + // Stale link: clear it so future opens skip the 404 round-trip, then swap to a fresh draft. if (output.id) { try { await dispatch(updateOutput({ id: output.id, session_id: null })).unwrap();