Reset stuck send phase after turns settle
- Keep the send timer alive while a send is active - Fallback-reset sendPhase when a turn settles after a missed transition
This commit is contained in:
1 parent
a60daa1c76
commit
9a9be39751
1 file changed
+15
-2
@@ -2152,14 +2152,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
: "local";
|
||||
|
||||
useEffect(() => {
|
||||
if (phase !== "running") return;
|
||||
if (phase !== "running" && sendPhase === "idle") return;
|
||||
const timer = window.setInterval(() => {
|
||||
setNowTick(Date.now());
|
||||
}, 1000);
|
||||
return () => {
|
||||
window.clearInterval(timer);
|
||||
};
|
||||
}, [phase]);
|
||||
}, [phase, sendPhase]);
|
||||
|
||||
const beginSendPhase = useCallback((nextPhase: Exclude<SendPhase, "idle">) => {
|
||||
setSendStartedAt((current) => current ?? new Date().toISOString());
|
||||
@@ -2192,6 +2192,19 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
sendPhase,
|
||||
]);
|
||||
|
||||
// Fallback: if the "running" phase transition was missed (e.g. due to React
|
||||
// batching two snapshots, a WebSocket reconnect, or a very fast turn), the
|
||||
// primary auto-reset above never fires and sendPhase stays stuck. Detect
|
||||
// this by checking whether the turn has settled while sendPhase is still
|
||||
// non-idle — the turn completing is a definitive signal that "sending" is
|
||||
// over.
|
||||
useEffect(() => {
|
||||
if (sendPhase === "idle") return;
|
||||
if (phase !== "running" && phase !== "connecting" && latestTurnSettled) {
|
||||
resetSendPhase();
|
||||
}
|
||||
}, [latestTurnSettled, phase, resetSendPhase, sendPhase]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeThreadId) return;
|
||||
const previous = terminalOpenByThreadRef.current[activeThreadId] ?? false;
|
||||
|
||||
Reference in new issue
Block a user