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

fix: preserve quiet Codex one-shot work

[._.]/ Adam Eivyb1d1f241f8c9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1dbacfbdd2..4c3f953b8d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -57,6 +57,8 @@
## Fixed
- **A note that iCloud wrongly reports as "not downloaded" can now be saved anyway.** The write guard screens for an offloaded note by looking for a real byte length with no local blocks — a shape an ordinary sparse or compressed file also has. When that misfired the lockout was permanent: asking iCloud to download an already-local file succeeds instantly and changes nothing, so every save was refused forever while the message told the user to try again shortly. The server now checks whether the download both succeeded and actually moved the file, so it can tell a download still in flight (or one that failed) from a refusal that will never clear — and only the second of those, twice in a row on the same note, offers the Brain Notes and Wiki editors a deliberate "Save anyway" row that writes it regardless. While a download really is in flight you still just wait, and the ordinary Save button, ⌘S, and background mirrors always refuse, so nothing bypasses the guard without an explicit click. The message no longer says to try again shortly when trying again cannot help.
+- **Quiet Codex reasoning is no longer mistaken for a finished one-shot response.** The TUI runner's eight-second screen-idle fallback could kill an active long-form Luna or Sol stage between status repaints, then hand terminal chrome such as `[Pasted Content …]` to a JSON parser as if it were the model's answer. Codex one-shot calls now wait for their required response file, a natural exit, explicit cancellation, or the configured hard cap; inline idle completion remains available for other TUIs that do not honor file output.
+
- **Post-arc character repair no longer invents plot events that the episode plan never stages.** Character reconciliation could improve a supporting cast member by adding new early `atIssue` transitions, then the next foundation verdict correctly penalized structure because those characters were absent from the corresponding synopses. Existing transition beats are now read-only after the macro arc exists: character repair may deepen motivation, arc type, and start/end states, while the structure editor exclusively owns adding or moving dramatized events. Pre-arc character-first planning still authors provisional transitions normally.
- **Complete LLM answers no longer fail on recoverable JSON serialization mistakes.** Long foundation calls could begin as normal JSON, then emit the complete remaining objects as escaped `\\n` / `\\"` text, leave quotation marks inside prose unescaped, or omit a prose field's closing quote immediately before its structural `}` line. The shared parser now decodes an escaped tail only from the JSON parser's exact failure position, repairs quotes only at structurally unambiguous boundaries, and accepts repairs only when the entire reconstructed response parses—preserving expensive completed work without making partial or arbitrary text look valid.
diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.js
index 7ba297f1b3..ee2d8222a0 100644
--- a/server/lib/tuiPromptRunner.js
+++ b/server/lib/tuiPromptRunner.js
@@ -24,12 +24,15 @@
* is the authoritative "done" signal (the wrapped prompt directs it to write
* its full answer to `tui-response.txt` and then finish) — checked
* unconditionally, even while a human watches. Output-idle is the fallback for
- * runs that print inline instead of writing the file (paused while watched, so
- * a viewer isn't snapped shut mid-read). The hard timeout is the backstop, and
- * salvages an already-written file before failing. Per-binary input-prompt
+ * TUIs that print inline instead of writing the file (paused while watched, so
+ * a viewer isn't snapped shut mid-read). Codex is excluded from that fallback:
+ * its status chrome can go silent for long stretches during real reasoning,
+ * and the required response file is the only safe completion signal. The hard
+ * timeout is the backstop, and salvages an already-written file before failing.
+ * Per-binary input-prompt
* regexes were considered for idle but are fragile across versions and screen
- * sizes; the idle threshold (~8s) works universally and matches how a human
- * knows the TUI finished — output stopped scrolling.
+ * sizes; for non-Codex TUIs, the idle threshold (~8s) remains the pragmatic
+ * inline-output fallback.
*/
import { spawn as ptySpawn } from 'node-pty';
@@ -146,6 +149,13 @@ export async function executeTuiRun({ runId, provider, prompt, workspacePath, on
const promptDelayMs = provider.tuiPromptDelayMs ?? DEFAULT_TUI_PROMPT_DELAY_MS;
const idleThresholdMs = idleMs ?? provider.tuiOneShotIdleMs ?? DEFAULT_ONE_SHOT_IDLE_MS;
const totalTimeoutMs = timeout ?? provider.timeout ?? DEFAULT_TIMEOUT_MS;
+ // Codex is explicitly instructed to write the machine-consumed answer to a
+ // response file. Its PTY may stop repainting for many seconds or minutes
+ // while the model is still reasoning; treating that quiet screen as a final
+ // inline answer kills the live request and returns terminal chrome such as
+ // "[Pasted Content …]" to JSON parsers. Wait for the authoritative file,
+ // natural process exit, explicit cancellation, or the configured hard cap.
+ const requiresResponseFileForIdleCompletion = isCodexCommand(command);
// Mirror runner.js#executeCliRun's runs-path resolution so TUI runs land
// under the runner-config dataDir (not always PATHS.runs) — otherwise a
// non-default dataDir would split metadata + output across two trees.
@@ -503,15 +513,14 @@ ${prompt}`;
if (isExternalSessionAttached(runId)) return;
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 this on a work-activity signal. Idle-complete here is the
- // inline-output fallback for a model that prints its answer instead of
- // writing the response file — that output legitimately may carry no
- // `(Ns ·` working counter (fast reply, or a non-Claude/Codex TUI), so
- // requiring one would falsely fail a completed run whose answer is
- // already in outputBuffer. The authoritative done-signal is the
- // response file (handled by responseFileWatchTimer); this stays the
- // permissive fallback it has always been.
+ // 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.
finish({ success: true, exitCode: 0, reason: 'idle-complete' });
}
}, 1000);
diff --git a/server/lib/tuiPromptRunner.test.js b/server/lib/tuiPromptRunner.test.js
index 93da195516..32dcccd73c 100644
--- a/server/lib/tuiPromptRunner.test.js
+++ b/server/lib/tuiPromptRunner.test.js
@@ -488,6 +488,56 @@ describe('executeTuiRun', () => {
}));
});
+ it('does not reap a quiet Codex reasoning pass before its response file exists', async () => {
+ vi.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],
+ });
+ const provider = {
+ id: 'codex-tui', type: 'tui', command: 'codex',
+ tuiPromptDelayMs: 50, tuiOneShotIdleMs: 500,
+ };
+ const runId = 'run-codex-quiet-reasoning';
+ const promise = executeTuiRun({
+ runId,
+ provider,
+ prompt: 'reason carefully and write the complete structured response',
+ workspacePath: TEST_WORKSPACE,
+ timeout: 60000,
+ });
+ await flushAsync();
+
+ const pty = ptyInstances[0];
+ pty.emitData('OpenAI Codex ready> ');
+ await vi.advanceTimersByTimeAsync(2000); // paste
+ await vi.advanceTimersByTimeAsync(4000); // enter
+ pty.emitData('Working (0s • esc to interrupt)');
+
+ // This is well beyond the configured 500ms idle fallback. A generic TUI
+ // would have completed from its screen scrape, but Codex is still doing
+ // real work and has not written the authoritative response yet.
+ await vi.advanceTimersByTimeAsync(5000);
+ await flushAsync();
+ expect(runnerMocks.finalizeRunRecord).not.toHaveBeenCalled();
+
+ const runDir = join(runsTmpDirRef.current, runId);
+ await mkdir(runDir, { recursive: true });
+ await writeFile(join(runDir, 'tui-response.txt'), '{"repaired":true}');
+ await vi.advanceTimersByTimeAsync(1100);
+ await vi.advanceTimersByTimeAsync(1100);
+ await flushAsync();
+ await promise;
+
+ expect(runnerMocks.finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({
+ runId,
+ success: true,
+ output: '{"repaired":true}',
+ extras: expect.objectContaining({
+ completionReason: 'response-file',
+ usedResponseFile: true,
+ }),
+ }));
+ });
+
it('does NOT idle-complete while a Shell viewer is attached, then completes once they detach', async () => {
vi.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],