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

Press Enter again when a pasted prompt sits unsubmitted (#12788)

[._.]/638312ad5fb1
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index 65e7de8abb..f824e095e6 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -1884,6 +1884,9 @@ const SELECTOR_AFTER_PASTE_PATTERN = /enter\s*to\s*(?:select|confirm)|↑\s*\/\s
* - `worked` — whether the run ever painted in-flight chrome or produced output
* that was not the echo of a PortOS keystroke. A run whose stall-nudge budget runs out with this still
* false never started, and the caller fails it rather than parking it.
+ * - `awaitingSubmit` — the chip still looks unsubmitted and an Enter remains in
+ * the budget, so a quiet screen is not an answer yet (the one-shot runner's
+ * idle-completion must not scrape the composer as the response).
*
* @param {{ promptMarkerCount?: number, settleMs?: number, maxAttempts?: number, workEvidenceMs?: number }} [options]
*/
@@ -1927,6 +1930,9 @@ export function createPromptSubmissionGate({
return enters;
},
get worked() { return worked; },
+ get awaitingSubmit() {
+ return !worked && inputAt !== null && enters < maxAttempts && holdsUnsubmittedPaste();
+ },
};
}
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index ef598f17eb..9519614d0c 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -2138,6 +2138,15 @@ describe('createPromptSubmissionGate', () => {
expect(settled(gate, 31_000)).toBe(0);
});
+ it('reports awaitingSubmit only while a chip looks unsubmitted and Enters remain', () => {
+ const gate = createPromptSubmissionGate({ settleMs: 20_000, maxAttempts: 1 });
+ expect(gate.awaitingSubmit).toBe(false);
+ gate.noteInput(0, CHIP);
+ expect(gate.awaitingSubmit).toBe(true);
+ expect(settled(gate)).toBe(1);
+ expect(gate.awaitingSubmit, 'an exhausted budget hands the screen back to idle completion').toBe(false);
+ });
+
it('treats in-flight chrome as a started turn, however soon it went quiet', () => {
const gate = createPromptSubmissionGate({ settleMs: 20_000, workEvidenceMs: 30_000 });
gate.noteInput(0, CHIP);
diff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.js
index fcffffa197..f58c5b4508 100644
--- a/server/services/tuiPromptRunner.js
+++ b/server/services/tuiPromptRunner.js
@@ -76,8 +76,10 @@ import {
OPENCODE_INPUT_READY_PATTERN,
detectMissingTuiBinary,
createSelfClearingSignalGate,
+ createPromptSubmissionGate,
screenShowsInFlightChrome,
SUBMIT_KEY,
+ UNSUBMITTED_PROMPT_ENTER_MAX_ATTEMPTS,
} from '../lib/tuiHandshake.js';
import { buildCliChildEnv } from '../lib/cliChildEnv.js';
import { isCodexCommand } from '../lib/codex.js';
@@ -92,6 +94,12 @@ import { killProcessTree } from '../lib/bufferedSpawn.js';
// to stop talking)
const DEFAULT_TIMEOUT_MS = 300000;
const DEFAULT_ONE_SHOT_IDLE_MS = 8000;
+const UNSUBMITTED_PROMPT_POLL_MS = 1000;
+// A one-shot answer can be short, quick and free of in-flight chrome (OpenCode).
+// The agent path's 30s echo window would read it as an ignored submit and hold
+// idle completion for the whole Enter budget. An ignored Enter repaints nothing,
+// so output this long after PortOS's last keystroke means the turn ran.
+const ONE_SHOT_PROMPT_WORK_EVIDENCE_MS = 2500;
// 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;
@@ -281,6 +289,9 @@ ${prompt}`;
// STRIP first so a pasted RAW transcript's cursor-positioned marker (counts as 0
// unstripped) is counted the same way the stripped post-paste buffer is.
const promptMarkerCount = countPasteMarkers(stripAnsi(wrappedPrompt));
+ // The paste chip can render and every submit Enter still be ignored, leaving
+ // the prompt sitting in the composer (#12769). Shared with the agent path.
+ const promptGate = createPromptSubmissionGate({ promptMarkerCount, workEvidenceMs: ONE_SHOT_PROMPT_WORK_EVIDENCE_MS });
// Shared composition (provider.envVars + OpenCode models map + PWD pin +
// CLAUDECODE strip) — see buildCliChildEnv. The PWD pin matters here because
@@ -482,6 +493,7 @@ ${prompt}`;
let readyTimer = null;
let pasteEnterTimer = null;
let submitEnterTimer = null;
+ let unsubmittedPromptTimer = null;
let idleWatchTimer = null;
let responseFileWatchTimer = null;
let hardTimeoutTimer = null;
@@ -509,6 +521,7 @@ ${prompt}`;
if (readyTimer) { clearInterval(readyTimer); readyTimer = null; }
if (pasteEnterTimer) { clearInterval(pasteEnterTimer); pasteEnterTimer = null; }
if (submitEnterTimer) { clearInterval(submitEnterTimer); submitEnterTimer = null; }
+ if (unsubmittedPromptTimer) { clearInterval(unsubmittedPromptTimer); unsubmittedPromptTimer = null; }
if (idleWatchTimer) { clearInterval(idleWatchTimer); idleWatchTimer = null; }
if (responseFileWatchTimer) { clearInterval(responseFileWatchTimer); responseFileWatchTimer = null; }
if (hardTimeoutTimer) { clearTimeout(hardTimeoutTimer); hardTimeoutTimer = null; }
@@ -670,6 +683,7 @@ ${prompt}`;
// survive only in raw output, while startup dialog text is ANSI-stripped.
inputReady.observe(text, stripped);
if (stripped) {
+ promptGate.observe(stripped, now);
if (postPasteStripped !== null) postPasteStripped += stripped;
outputBuffer += stripped;
if (outputBuffer.length > OUTPUT_BUFFER_HEADROOM) {
@@ -811,6 +825,9 @@ ${prompt}`;
// either while the mode command is being processed or after the task
// has been re-submitted.
if (lowPriorityCommandAttempted) return;
+ // Quiet with the paste chip still in the composer is a prompt that was
+ // never submitted, not an answer; unsubmittedPromptTimer owes it an Enter.
+ if (promptGate.awaitingSubmit) return;
const idle = Date.now() - lastOutputAt;
if (idle >= idleThresholdMs) {
if (requiresResponseFileForIdleCompletion) return;
@@ -949,16 +966,36 @@ ${prompt}`;
|| elapsed >= PASTE_TO_ENTER_FALLBACK_MS) {
clearInterval(pasteEnterTimer);
pasteEnterTimer = null;
+ // The commit buffer holds the chip: a TUI that ignores the Enter may
+ // never repaint it.
+ promptGate.noteInput(Date.now(), postPasteStripped || '');
postPasteStripped = null;
// Submit with repeated Enters — a single `\r` can be swallowed while
// the TUI is still reflowing a large paste, stranding the prompt
// unsent. Tracked in submitEnterTimer so finish()'s cleanupTimers()
// cancels pending retries if the run ends first.
submitEnterTimer = scheduleSubmitEnters(
- () => { try { ptyProcess.write(SUBMIT_KEY); } catch { /* PTY may have already exited */ } },
+ () => {
+ promptGate.noteInput(Date.now());
+ try { ptyProcess.write(SUBMIT_KEY); } catch { /* PTY may have already exited */ }
+ },
() => finalized
);
promptSubmittedAt = Date.now();
+ unsubmittedPromptTimer = setInterval(() => {
+ if (finalized || promptGate.worked) {
+ clearInterval(unsubmittedPromptTimer);
+ unsubmittedPromptTimer = null;
+ return;
+ }
+ const now = Date.now();
+ const enter = promptGate.takeEnter(now, lastOutputAt);
+ if (!enter) return;
+ try {
+ ptyProcess.write(SUBMIT_KEY);
+ console.log(`🔁 TUI run ${runId} prompt still unsubmitted in the composer — pressed Enter (attempt ${enter}/${UNSUBMITTED_PROMPT_ENTER_MAX_ATTEMPTS})`);
+ } catch { /* PTY may have already exited */ }
+ }, UNSUBMITTED_PROMPT_POLL_MS);
}
}, PASTE_MARKER_POLL_MS);
};
diff --git a/server/services/tuiPromptRunner.test.js b/server/services/tuiPromptRunner.test.js
index 6959431be9..2acd0ecdff 100644
--- a/server/services/tuiPromptRunner.test.js
+++ b/server/services/tuiPromptRunner.test.js
@@ -1396,6 +1396,63 @@ describe('executeTuiRun', () => {
}));
});
+ it('presses Enter again when the paste chip sits unsubmitted, instead of idle-completing on it', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'] });
+ const provider = { id: 'claude', type: 'tui', command: 'claude', tuiPromptDelayMs: 50 };
+ const promise = executeTuiRun({
+ runId: 'run-unsubmitted', provider, prompt: 'complete this task', workspacePath: TEST_WORKSPACE, timeout: 600000,
+ });
+ await flushAsync();
+
+ const pty = ptyInstances[0];
+ pty.emitData('\x1b[?2004h');
+ await vi.advanceTimersByTimeAsync(300);
+ pty.emitData('❯ [Pasted text #1 +113 lines]');
+ await vi.advanceTimersByTimeAsync(3000);
+ const enters = () => pty.write.mock.calls.filter(([keys]) => keys === '\r').length;
+ const submitted = enters();
+ expect(submitted).toBeGreaterThan(0);
+
+ // Every submit Enter was ignored: nothing repaints past the chip.
+ await vi.advanceTimersByTimeAsync(10_000);
+ expect(runnerMocks.finalizeRunRecord, 'a quiet composer holding the chip is not an answer').not.toHaveBeenCalled();
+ await vi.advanceTimersByTimeAsync(12_000);
+ expect(enters()).toBe(submitted + 1);
+
+ pty.emitData('\n✻ Thinking… (2s · esc to interrupt)');
+ await vi.advanceTimersByTimeAsync(60_000);
+ expect(enters(), 'a started turn gets no further Enters').toBe(submitted + 1);
+ pty.emitExit({ exitCode: 0 });
+ await flushAsync();
+ await promise;
+ expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({ runId: 'run-unsubmitted' }));
+ });
+
+ it('idle-completes a quick reply with no in-flight chrome without extra Enters', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'] });
+ const provider = { id: 'claude', type: 'tui', command: 'claude', tuiPromptDelayMs: 50 };
+ const promise = executeTuiRun({
+ runId: 'run-quick-reply', provider, prompt: 'complete this task', workspacePath: TEST_WORKSPACE, timeout: 600000,
+ });
+ await flushAsync();
+
+ const pty = ptyInstances[0];
+ pty.emitData('\x1b[?2004h');
+ await vi.advanceTimersByTimeAsync(300);
+ pty.emitData('❯ [Pasted text #1 +113 lines]');
+ await vi.advanceTimersByTimeAsync(5000);
+ const enters = () => pty.write.mock.calls.filter(([keys]) => keys === '\r').length;
+ const submitted = enters();
+
+ pty.emitData('\nA child rebuilds wonder in a green ruin.');
+ await vi.advanceTimersByTimeAsync(10_000);
+ await promise;
+ expect(enters()).toBe(submitted);
+ expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({
+ runId: 'run-quick-reply', success: true, extras: expect.objectContaining({ completionReason: 'idle-complete' }),
+ }));
+ });
+
it('falls back on Claude session-limit chrome when low-priority is not enabled', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'] });
const provider = { id: 'claude', type: 'tui', command: 'claude', tuiPromptDelayMs: 50 };