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

address review (codex): poll for the response file independently of streamed output

[._.]/ Adam Eivy13422172e293
diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.js
index 6c57c06c2c..321053055d 100644
--- a/server/lib/tuiPromptRunner.js
+++ b/server/lib/tuiPromptRunner.js
@@ -234,12 +234,14 @@ ${prompt}`;
let readyTimer = null;
let pasteEnterTimer = null;
let idleWatchTimer = null;
+ let responseFileWatchTimer = null;
let hardTimeoutTimer = null;
const cleanupTimers = () => {
if (readyTimer) { clearInterval(readyTimer); readyTimer = null; }
if (pasteEnterTimer) { clearInterval(pasteEnterTimer); pasteEnterTimer = null; }
if (idleWatchTimer) { clearInterval(idleWatchTimer); idleWatchTimer = null; }
+ if (responseFileWatchTimer) { clearInterval(responseFileWatchTimer); responseFileWatchTimer = null; }
if (hardTimeoutTimer) { clearTimeout(hardTimeoutTimer); hardTimeoutTimer = null; }
};
@@ -323,25 +325,16 @@ ${prompt}`;
// Defer the idle-watch timer until the first response chunk so we
// don't run a 1Hz no-op throughout the 5-30s spawn + paste window.
// Significant on parallel fan-out paths (arc planner).
- idleWatchTimer = setInterval(async () => {
+ idleWatchTimer = setInterval(() => {
if (finalized) return;
- // The model writing its response file is the authoritative completion
- // signal (it's what the wrapped prompt asks for) — check it FIRST and
- // unconditionally. Claude Code's TUI never exits after a one-shot task
- // (it returns to its interactive prompt), so without this a watched run
- // has no terminus but the hard timeout. This is intentionally NOT gated
- // on attach: once the file exists the task is done, so completing it is
- // correct even while a human is watching.
- if (await responseFileSettled()) {
- finish({ success: true, exitCode: 0, reason: 'response-file' });
- return;
- }
- // Idle-completion fallback (no response file yet — e.g. the model
- // printed inline instead of writing the file). Don't auto-complete a
- // run a human is actively watching in the Shell page — they may be
- // reading the output or about to type a correction or an answer the
- // model is waiting on. Unattended pipeline runs keep the snappy idle
- // threshold for throughput.
+ // Idle-completion is the FALLBACK for runs that print their answer
+ // inline instead of writing the response file (the authoritative
+ // done-signal, handled by responseFileWatchTimer from paste onward).
+ // Don't auto-complete a run a human is actively watching in the Shell
+ // page — they may be reading the output or about to type a correction
+ // or an answer the model is waiting on. The run then ends only on
+ // natural process exit or an explicit Stop. Unattended pipeline runs
+ // keep the snappy idle threshold for throughput.
if (isExternalSessionAttached(runId)) return;
const idle = Date.now() - lastOutputAt;
if (idle >= idleThresholdMs) {
@@ -402,6 +395,21 @@ ${prompt}`;
}
console.log(`📟 Pasted prompt into TUI ${command} (${reason})`);
+ // Watch for the response file from paste onward — it's the model's
+ // authoritative "done" signal and must complete the run INDEPENDENTLY of
+ // whether any post-paste PTY output ever arrives. A model that writes the
+ // file silently (no streamed output to arm idleWatchTimer) would otherwise
+ // hang until the hard-timeout salvage. Runs unconditionally, even while a
+ // human watches: once the file exists the task is finished, so there's
+ // nothing left to intervene in. (Idle/attach gating lives only on
+ // idleWatchTimer, the inline-output fallback.)
+ responseFileWatchTimer = setInterval(async () => {
+ if (finalized) return;
+ if (await responseFileSettled()) {
+ finish({ success: true, exitCode: 0, reason: 'response-file' });
+ }
+ }, 1000);
+
const pasteSentAt = Date.now();
pasteEnterTimer = setInterval(() => {
if (finalized) { clearInterval(pasteEnterTimer); pasteEnterTimer = null; return; }
diff --git a/server/lib/tuiPromptRunner.test.js b/server/lib/tuiPromptRunner.test.js
index 1566df71b9..2b341edd8b 100644
--- a/server/lib/tuiPromptRunner.test.js
+++ b/server/lib/tuiPromptRunner.test.js
@@ -522,6 +522,45 @@ describe('executeTuiRun', () => {
}));
});
+ it('completes via the response file even when the TUI emits NO post-paste output (watcher is not gated on streamed output)', async () => {
+ vi.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],
+ });
+ // Regression guard: the response-file watcher must run independently of
+ // idleWatchTimer (which only arms after the first POST-PASTE output chunk).
+ // A model that writes its file silently would otherwise hang until the
+ // hard-timeout salvage despite the result already being on disk.
+ const provider = { id: 'claude', type: 'tui', command: 'claude', tuiPromptDelayMs: 50 };
+ const runId = 'run-silent-respfile';
+ const promise = executeTuiRun({ runId, provider, prompt: 'do the task quietly then write the file', workspacePath: '/cwd', timeout: 60000 });
+ await flushAsync();
+
+ const pty = ptyInstances[0];
+ // Pre-paste banner lets the ready-watch paste — but NOTHING is emitted
+ // after the paste, so idleWatchTimer never arms.
+ pty.emitData('claude code ready> ');
+ await vi.advanceTimersByTimeAsync(2000); // ready-watch pastes → response-file watcher starts
+ await vi.advanceTimersByTimeAsync(4000); // enter submitted; still zero post-paste output
+
+ const runDir = join(runsTmpDirRef.current, runId);
+ await mkdir(runDir, { recursive: true });
+ await writeFile(join(runDir, 'tui-response.txt'), 'silent result body');
+
+ await vi.advanceTimersByTimeAsync(1100); // poll 1: seed baseline
+ await vi.advanceTimersByTimeAsync(1100); // poll 2: stable → complete
+ await flushAsync();
+ await promise;
+
+ // Completed long before the 60s hard timeout, with no idle output to lean on.
+ expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({
+ runId,
+ success: true,
+ exitCode: 0,
+ output: 'silent result body',
+ extras: expect.objectContaining({ completionReason: 'response-file', usedResponseFile: true }),
+ }));
+ });
+
it('salvages the response file on hard timeout → success with reason "timeout-response-file" instead of a false failure + fallback', async () => {
vi.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],