Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Hold TUI idle completion while the screen still shows the model thinking (#11169)

[._.]/508144d2835d
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index 54972bd092..1b6626002a 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -764,6 +764,53 @@ export const WORK_COUNTER_PATTERN = /\(\s*(\d+)\s*s\s*[·•]/g;
export const GENERATION_ACTIVITY_PATTERN =
new RegExp(`Generating\\s*[.·•…]|${WORK_COUNTER_PATTERN.source}`, 'i');
+// Chrome a TUI's status line shows while a request is still in flight, for the
+// one-shot runner's idle-completion guard (`screenShowsInFlightChrome`). Broader
+// than GENERATION_ACTIVITY_PATTERN on purpose — that one latches "recovered" and
+// must never false-positive, while a false positive here only means waiting for
+// the response file or the hard timeout instead of scraping the screen early.
+// The `\s*` gaps tolerate cursor-forward escapes that strip to nothing; the
+// counter also takes Claude Code's `(1m 5s ·` form past the first minute.
+const IN_FLIGHT_CHROME_PATTERN = new RegExp([
+ `Generating\\s*[.·•…]`,
+ `\\(\\s*(?:\\d+\\s*[hm]\\s*)*\\d+\\s*s\\s*[·•]`,
+ `thinking\\s*with\\s*\\w+\\s*effort`,
+ `esc\\s*to\\s*interrupt`,
+].join('|'), 'gi');
+// How much visible text may follow the last in-flight chrome before the screen
+// counts as having moved on. Below the spinner Claude Code paints its composer
+// box and footer (`? for shortcuts`, mode hints), so the allowance has to clear
+// that chrome; an inline answer — the case idle completion exists for — is a
+// structured response that runs far longer.
+const IN_FLIGHT_CHROME_TRAILING_CHARS = 300;
+// Box-drawing (U+2500–U+257F) and block elements (U+2580–U+259F) are composer
+// frame, not content, so they never count toward the trailing allowance.
+const NON_CONTENT_CHARS = /[\s\u2500-\u259F]+/g;
+
+/**
+ * Whether the END of an ANSI-stripped screen transcript is still showing a
+ * request in flight — a working counter, `thinking with <level> effort`,
+ * `esc to interrupt` — rather than an answer printed after it.
+ *
+ * A model can sit in a long thinking stretch without repainting its spinner
+ * (Claude Code on Fable did, 2026-10-11), so silence alone is not completion:
+ * the one-shot runner consults this before idle-completing, and while it holds
+ * the run waits for its response file, process exit, or the hard timeout.
+ *
+ * @param {string} strippedTail recent ANSI-stripped output (a few KB is plenty)
+ * @returns {boolean}
+ */
+export function screenShowsInFlightChrome(strippedTail) {
+ if (typeof strippedTail !== 'string' || !strippedTail) return false;
+ let lastEnd = -1;
+ for (const match of strippedTail.matchAll(IN_FLIGHT_CHROME_PATTERN)) {
+ lastEnd = match.index + match[0].length;
+ }
+ if (lastEnd < 0) return false;
+ const trailing = strippedTail.slice(lastEnd).replace(NON_CONTENT_CHARS, '');
+ return trailing.length <= IN_FLIGHT_CHROME_TRAILING_CHARS;
+}
+
// Carry-over kept across chunks so in-flight chrome split by a PTY chunk boundary
// (`Generat` + `ing…`) still matches.
//
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index bad5f60d55..7983763bbe 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -65,6 +65,7 @@ import {
TOOL_PERMISSION_DECLINE_MAX,
TOOL_PERMISSION_NUDGE_TEXT,
CODEX_COMPOSER_READY_PATTERN,
+ screenShowsInFlightChrome,
} from './tuiHandshake.js';
import { detectImmediateFallbackSignal } from './aiToolkit/errorDetection.js';
import { CODEX_CONFIGURED_DEFAULT } from './providerModels.js';
@@ -2218,3 +2219,22 @@ describe('createAgyResumeGate', () => {
expect(gate.attempts).toBe(2);
});
});
+
+describe('screenShowsInFlightChrome', () => {
+ const footer = '╭──────────────╮\n│ > │\n╰──────────────╯\n ? for shortcuts\n';
+ it.each([
+ ['effort status under the composer', `✻ Pondering… (55s · ↓ 1.2k tokens · still thinking with medium effort)\n${footer}`],
+ ['a past-a-minute counter', '✶ Thinking… (1m 5s · ↓ 3.4k tokens)\n'],
+ ['cursor-forward gaps stripped to nothing', '(12s·esctointerrupt)'],
+ ])('reads %s as in flight', (_label, screen) => {
+ expect(screenShowsInFlightChrome(screen)).toBe(true);
+ });
+
+ it.each([
+ ['an inline answer printed after the spinner', `(40s · thinking with high effort)\n${'{"logline":"A long answer"} '.repeat(20)}\n${footer}`],
+ ['a finished turn summary', '✻ Worked for 55s\n{"ok":true}\n'],
+ ['no output', ''],
+ ])('does not read %s as in flight', (_label, screen) => {
+ expect(screenShowsInFlightChrome(screen)).toBe(false);
+ });
+});
diff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.js
index 4879fb5fc4..edb15691a8 100644
--- a/server/services/tuiPromptRunner.js
+++ b/server/services/tuiPromptRunner.js
@@ -74,6 +74,7 @@ import {
createInputReadyTracker,
detectMissingTuiBinary,
createSelfClearingSignalGate,
+ screenShowsInFlightChrome,
SUBMIT_KEY,
} from '../lib/tuiHandshake.js';
import { buildCliChildEnv } from '../lib/cliChildEnv.js';
@@ -89,6 +90,9 @@ import { killProcessTree } from '../lib/bufferedSpawn.js';
// to stop talking)
const DEFAULT_TIMEOUT_MS = 300000;
const DEFAULT_ONE_SHOT_IDLE_MS = 8000;
+// Enough stripped screen to hold a status line plus the composer and footer
+// painted beneath it; see screenShowsInFlightChrome.
+const IN_FLIGHT_SCREEN_TAIL_CHARS = 4096;
// A one-shot prompt must return one machine-consumed answer. Codex's general
// interactive TUI inherits the user's multi-agent feature flag, which can turn
@@ -793,13 +797,19 @@ ${prompt}`;
const idle = Date.now() - lastOutputAt;
if (idle >= idleThresholdMs) {
if (requiresResponseFileForIdleCompletion) return;
- // NOTE: unlike the long-running agent path, the one-shot runner does
- // NOT gate non-Codex providers on a work-activity signal.
- // Idle-complete is their inline-output fallback when a model prints
- // its answer instead of writing the response file; that output may
- // legitimately carry no `(Ns ·` working counter. Codex is held to
- // the response-file contract above because its quiet reasoning
- // stretches are otherwise indistinguishable from completion.
+ // A quiet screen whose last paint is still in-flight chrome (a
+ // working counter, `thinking with medium effort`) is a model
+ // thinking without repainting, not an answer — Fable sat silent
+ // on that spinner past the idle threshold and the run scraped it
+ // as the response. Hold for the response file, process exit, or
+ // the hard timeout instead.
+ if (screenShowsInFlightChrome(outputBuffer.slice(-IN_FLIGHT_SCREEN_TAIL_CHARS))) return;
+ // NOTE: non-Codex providers are NOT required to show a work-activity
+ // signal. Idle-complete is their inline-output fallback when a model
+ // prints its answer instead of writing the response file; that
+ // output may legitimately carry no `(Ns ·` working counter. Codex is
+ // held to the response-file contract above because its quiet
+ // reasoning stretches are otherwise indistinguishable from completion.
finish({ success: true, exitCode: 0, reason: 'idle-complete' });
}
}, 1000);
diff --git a/server/services/tuiPromptRunner.test.js b/server/services/tuiPromptRunner.test.js
index efcaccfc11..dd90169ef9 100644
--- a/server/services/tuiPromptRunner.test.js
+++ b/server/services/tuiPromptRunner.test.js
@@ -951,6 +951,39 @@ describe('executeTuiRun', () => {
expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({ runId: 'run-unbounded-quiet', success: true }));
});
+ it('does not idle-complete a run whose screen still shows it thinking', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'] });
+ const provider = { id: 'claude-tui', type: 'tui', command: 'echo', tuiPromptDelayMs: 50, tuiOneShotIdleMs: 500 };
+ const runId = 'run-claude-silent-thinking';
+ const promise = executeTuiRun({ runId, provider,
+ prompt: 'write the creative direction to the response file', workspacePath: TEST_WORKSPACE, timeout: 60000 });
+ await flushAsync();
+ const pty = ptyInstances[0];
+ pty.emitData('claude code ready> ');
+ await vi.advanceTimersByTimeAsync(2000); // paste
+ await vi.advanceTimersByTimeAsync(4000); // enter
+ // The last paint before a long silent thinking stretch: spinner status
+ // line, then the composer box and footer Claude Code draws beneath it.
+ pty.emitData('✻ Pondering… (55s · ↓ 1.2k tokens · still thinking with medium effort)\n'
+ + '╭────────────────────────╮\n│ > │\n╰────────────────────────╯\n ? for shortcuts\n');
+
+ await vi.advanceTimersByTimeAsync(10000);
+ await flushAsync();
+ expect(runnerMocks.finalizeRunRecord).not.toHaveBeenCalled();
+
+ seedResponseFile(runId, '{"logline":"x"}');
+ await vi.advanceTimersByTimeAsync(1100);
+ await vi.advanceTimersByTimeAsync(1100);
+ await flushAsync();
+ await promise;
+ expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({
+ runId,
+ success: true,
+ output: '{"logline":"x"}',
+ extras: expect.objectContaining({ completionReason: 'response-file' }),
+ }));
+ });
+
it('does not reap a quiet Codex reasoning pass before its response file exists', async () => {
vi.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],