Test new session workflow
- User
Test new session workflow
Assistant
Let me check the server for terminal WebSocket support and the Shell.tsx to understand the full picture.
Assistant
The code looks structurally sound. Let me now run the app to test the new session workflow live.
Assistant
Build succeeds. Let me also do a quick type-check to surface any TS errors in the new session workflow code:
Assistant
No type errors. Here's a summary of the new session workflow:
Flow overview:
-
"New session" button (
ActiveSessions.tsx:188) opens a modal with a prompt textarea and optional working directory selector (populated fromrepoStatuses). -
handleSpawn(ActiveSessions.tsx:91-98) — on submit:- Escapes single quotes in the prompt
- Calls
openSpawnTab(cwd, "claude '<prompt>'", title)
-
openSpawnTab(TabsContext.tsx:90-95) — creates aspawntab with aspawnedAttimestamp and makes it active. -
SpawnSessionScreen(SpawnSessionScreen.tsx) renders:- Top: loading spinner until a matching session is found in the DB (polls every 2s + WebSocket updates, matching by )
-
- User
I am seeing delays with events from the xterm session not appearing in the SessionDetail conversation UI right above it
Assistant
Now let me see how
SessionDetailsubscribes and re-fetches:Assistant
Now I understand the delay chain. Let me check where
isLiveis used in SessionDetail and the server poll interval:Assistant
The delay chain is:
- Hook handler writes to DB
- Server polls DB every 2000ms, detects change, broadcasts
sessions_updatedWS SessionDetail'ssubscribeToUpdatesfires →fetchLogEventsHTTP call
For a live session the max lag is ~2s. The fix: add a fast polling interval in
SessionDetailwhen the sessionisLive, independent of the WS broadcast.Assistant
Now I have what I need. I'll add a live-poll
useEffectright after thesubscribeToUpdatesone (line 784), and also reduce the server broadcast poll from 2000ms to 500ms:Assistant
Now also reduce the server broadcast poll so non-spawn session tabs also update faster:
Assistant
Now build to verify:
Assistant
Two changes made:
-
SessionDetail.tsx— added a 500ms polling interval that activates whensession.isLiveis true. This runs independently of the WS broadcast, so new events appear within ~500ms while a session is active. It stops automatically once the session is no longer live. -
server.ts— reduced the broadcast poller from 2000ms → 500ms. This benefits all sessions (not just spawn tabs), cutting the max WS notification lag from ~2s to ~0.5s.
Together these cap the end-to-end delay at roughly 500ms + one
fetchLogEventsround trip.-
- User
Shouldn't the websocket already be handling this tho? Why am i not getting events from the web socket?
Assistant
Good question. The WS itself works fine —
subscribeToUpdatesclients do receivesessions_updated. But look at what triggers that broadcast inserver.ts:js// server.ts:1133 const poller = setInterval(async () => { // queries the DB for max event ID across all repos if (changed) broadcast(); }, 500); // was 2000The WS message is only sent after this poller detects a DB change. So the chain is:
codehook fires → writes to SQLite → server poller wakes up (up to 2s) → broadcasts WS → SessionDetail fetchesThe WS subscription is not the bottleneck — it's the 2-second polling gap on the server side before the broadcast even goes out. The WS is just a delivery mechanism for a signal that itself has up to 2s latency.
That's why I reduced the server poller from 2000ms → 500ms, which fixes the WS delay for all clients.
The 500ms client-side poll I added in
SessionDetailforisLivesessions is a belt-and-suspenders fallback — if for some reason the WS broadcast is missed (reconnecting, etc.), the session detail will still refresh within 500ms. But the server-side change is the primary fix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.