fix(remote): stop button gives immediate feedback and prevents stuck thinking on remote server #8619
ClosedImBIOS(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/8619/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -0,0 +1,17 @@1+/**2+ * Strip terminal escape sequences from captured CLI stdout.3+ *4+ * OpenCode's CLI (and potentially other provider CLIs) can emit OSC title5+ * sequences (`ESC ]0;<title> BEL` / `ESC \`) and ANSI CSI color codes directly6+ * to stdout, even when stdout is a pipe. When T3 Code captures that output7+ * via `ChildProcessSpawner`, those bytes pollute structured parsing — e.g.8+ * `opencode agent list` becomes `\x1b]0;t3code: ready\x07build (primary)`9+ * instead of `build (primary)`, causing the agent inventory to store a10+ * polluted id that later fails with `Agent not found`.11+ *12+ * This is defensive for any provider CLI; the regexes are intentionally13+ * permissive and also handle Ghostty/Zsh title integrations that can leak14+ * through `shell: true` spawns.15+ */16+const OSC_RE = /\x1b\].*?(?:\x07|\x1b\\)/g;17+const CSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
- apps/web/src/components/ChatView.tsx lines 2528 to 2540Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2341,3 +2341,16 @@23412341 threadError,23422342 });23432343 const isWorking = phase === "running" || isSendBusy || isConnecting || isRevertingCheckpoint;2344+ // Optimistic stopping state for remote: mirrors isStoppingBackgroundWork so Stop2345+ // gives immediate feedback even though session stays "running" until provider settles.2346+ // See fix-remote-stop-no-feedback-stuck-thinking-7h3k9p2m (issue #8618).2347+ const [isStoppingTurn, setIsStoppingTurn] = useState(false);2348+ useEffect(() => {2349+ if (!isWorking) {2350+ setIsStoppingTurn(false);2351+ }2352+ }, [isWorking]);2353+ useEffect(() => {2354+ // Per-thread: switching threads must not leak Stopping... to B2355+ setIsStoppingTurn(false);2356+ }, [activeThreadId]);
- @@ -1245,0 +1363,21 @@1363+ // this repeat Stop escalates to a full session stop (#8618).1364+ if (1365+ previous !== undefined &&1366+ previous.turnId === activeTurnId &&1367+ Number.isFinite(requestedAtMs) &&1368+ requestedAtMs - previous.requestedAtMs >= INTERRUPT_ESCALATION_GRACE_MS1369+ ) {1370+ recentTurnInterrupts.delete(input.threadId);1371+ yield* releaseWedgedSession({1372+ threadId: input.threadId,1373+ turnId: activeTurnId,1374+ reason:1375+ `Stop did not settle the session within ` +1376+ `${INTERRUPT_ESCALATION_GRACE_MS / 1000}s; the session was stopped.`,1377+ createdAt: input.createdAt,1378+ });1379+ return true;1380+ }1381+ // Remember this request so a later repeat Stop can escalate.1382+ if (Number.isFinite(requestedAtMs)) {1383+ recentTurnInterrupts.set(input.threadId, { turnId: activeTurnId, requestedAtMs });@@ -1245,0 +1326,21 @@1326+ readonly threadId: ThreadId;1327+ readonly session: OrchestrationSession;1328+ readonly latestTurn: OrchestrationLatestTurn | null;1329+ readonly createdAt: string;1330+ }) {1331+ if (input.session.status !== "running") {1332+ return false;1333+ }1334+ const activeTurnId = input.session.activeTurnId;1335+ const latestTurn = input.latestTurn;1336+ // The pinned turn already reached a terminal state but the session still1337+ // claims running — release it now (#4713, #8802). The completedAt guard1338+ // matters: this very event's own projection also settles the turn with1339+ // completedAt === createdAt, and that healthy in-flight interrupt must1340+ // proceed to the provider instead of being mistaken for a zombie.1341+ if (1342+ latestTurn !== null &&1343+ (activeTurnId === null || latestTurn.turnId === activeTurnId) &&1344+ latestTurn.state !== "running" &&1345+ latestTurn.completedAt !== null &&1346+ latestTurn.completedAt < input.createdAt
- @@ -2525,3 +2525,16 @@25252525 threadError,25262526 });25272527 const isWorking = phase === "running" || isSendBusy || isConnecting || isRevertingCheckpoint;2528+ // Optimistic stopping state for remote: mirrors isStoppingBackgroundWork so Stop2529+ // gives immediate feedback even though session stays "running" until provider settles.2530+ // See fix-remote-stop-no-feedback-stuck-thinking-7h3k9p2m (issue #8618).2531+ const [isStoppingTurn, setIsStoppingTurn] = useState(false);2532+ useEffect(() => {2533+ if (!isWorking) {2534+ setIsStoppingTurn(false);2535+ }2536+ }, [isWorking]);2537+ useEffect(() => {2538+ // Per-thread: switching threads must not leak Stopping... to B2539+ setIsStoppingTurn(false);2540+ }, [activeThreadId]);@@ -214,3 +214,15 @@214214 const gitActions = useSelectedThreadGitActions();215215 const requests = useSelectedThreadRequests();216216 const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, "thread interrupt");217+ const [isStoppingThread, setIsStoppingThread] = useState(false);218+ const selectedThreadSessionStatus = selectedThread?.session?.status ?? null;219+ const selectedThreadIdentity = selectedThread220+ ? scopedThreadKey(selectedThread.environmentId, selectedThread.id)221+ : null;222+ useEffect(() => {223+ // "Stopping" holds until the session leaves running/starting; per-thread224+ // so a switch never leaks the state onto another thread.225+ if (selectedThreadSessionStatus !== "running" && selectedThreadSessionStatus !== "starting") {226+ setIsStoppingThread(false);227+ }228+ }, [selectedThreadIdentity, selectedThreadSessionStatus]);
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
4c863cd9-f882-4a7c-83ef-003675af4709You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.