end a turn whose agent has gone

restarting officer-agent takes every persistent session with it and nothing
downstream notices: the browser's socket is healthy, officer's subscription is
a bus filter, and there is simply never another event. the spinner ran forever
and a refresh didn't help, because the transcript has no ending to read.

keyed off the agent *registering*, not disconnecting — a disconnect fires on
every `pm2 restart officer`, when the turn is fine. a registration socket dies
with its process, so an agent appearing on it is a new one. covers the sitting
tab; the reconnect path covers the rest, with the client now sending its belief
that a turn is in flight and officer checking it against the agent over a new
claude:is-generating. the check fails toward alive.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-07 01:43:01 +00:00
co-authored by Claude Opus 5
parent d8ee678ec4
commit 876b39b301
8 changed files with 173 additions and 3 deletions
@@ -93,6 +93,9 @@ export function useChat(initialSessionId?: string, initialModel?: string | null,
const onTurnCompleteRef = useRef(onTurnComplete);
onTurnCompleteRef.current = onTurnComplete;
const resumeSummaryRef = useRef<string | undefined>(initialResumeSummary);
// Mirror for the reconnect handshake, which runs from a stable callback and cannot read state.
const isGeneratingRef = useRef(false);
isGeneratingRef.current = isGenerating;
const client = useClient();
@@ -393,6 +396,10 @@ export function useChat(initialSessionId?: string, initialModel?: string | null,
cursor: cursorRef.current,
...(modelRef.current ? { model: modelRef.current } : {}),
...(cwdRef.current ? { cwd: cwdRef.current } : {}),
// Whether we still think a turn is running. If the agent restarted under us there is nothing left
// to produce output, and this is the only moment anyone can notice — the socket is healthy, the
// transcript just stops. The server checks the claim with the agent and answers if it's false.
generating: isGeneratingRef.current,
});
}, []);