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: report a CLI run killed by its own timeout as a timeout, not a quota failure

[._.]/ Adam Eivy6ea34b247eeb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 332d45ab36..751c2410e6 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,6 +6,8 @@
## Stability
+- **A story about money no longer gets your AI provider benched for a billing problem it doesn't have.** When a command-line AI run exceeded its time limit, PortOS killed it and then guessed at the cause by reading everything the run had printed. Codex echoes your entire prompt back as it works, so a single ordinary phrase inside a story — one character sending work on "without demanding credit" — was enough to match the billing/credit wording and file a plain five-minute timeout as *quota exceeded*: a perfectly healthy provider sidelined, a fallback sent to redo the work, and an investigation task queued about an account problem that never existed. A run stopped by its own time limit is now reported as a timeout on that basis alone, with no guessing from the text, and says so on the run record — the same rule the TUI runner already followed. Runs that fail for other reasons are still read for the provider's own error banner, which is usually the only clue there is.
+
- **[issue-3703] A worktree agent is no longer failed for commits it didn't write.** The primary-checkout guard used to fail any worktree agent whose run window overlapped commits landing on the shared primary checkout — but a concurrent coding-on-main agent, your own terminal, or `update.sh`'s pull can move it too, so read-only reasoners and correctly-behaved agents were being blamed and escalated to you. The guard now attributes the stranded commits by patch-id (`git cherry`, so a cherry-picked or rebased copy still counts) to the agent's own branch: only commits actually traceable to that agent fail the run. Everything else is warn-logged — the unreviewed commits on the primary are still surfaced — but a run that didn't cause them stays a success.
- **[issue-3704] The UI no longer goes blank when iCloud offloads a synced file** — macOS "Optimize Mac Storage" can evict MortalLoom and Obsidian files to the cloud. Reading one of those offloaded files used to stall indefinitely, and a handful of stalls was enough to freeze every page in PortOS while the server still looked healthy — pages simply never loaded and only a restart brought them back. PortOS now detects an offloaded file up front, skips the read, asks iCloud to download it in the background, and reports "temporarily unavailable" for just that record until it arrives.
diff --git a/server/services/runner.js b/server/services/runner.js
index 927d2864fb..3b896c06ec 100644
--- a/server/services/runner.js
+++ b/server/services/runner.js
@@ -241,6 +241,9 @@ export async function executeCliRun({ runId, provider, prompt, workspacePath, on
let output = '';
let immediateFallbackAnalysis = null;
let childProcess = null;
+ // Set by the wall-clock timeout below so the close handler can classify the
+ // kill as a timeout instead of scanning the model's output for a category.
+ let timeoutError = null;
const detectImmediateFallbackSignal = createImmediateFallbackSignalDetector();
const abortForImmediateFallbackSignal = (text) => {
@@ -314,6 +317,11 @@ export async function executeCliRun({ runId, provider, prompt, workspacePath, on
const timeoutHandle = effectiveTimeout > 0 ? setTimeout(() => {
if (childProcess && !childProcess.killed) {
console.log(`⏱️ Run ${runId} timed out after ${effectiveTimeout}ms`);
+ // Record the verdict BEFORE the kill: the close handler cannot otherwise
+ // tell this SIGKILL apart from a provider failure, and killProcessTree
+ // leaves `exitCode: null` — not the 124 the TUI runner synthesizes for
+ // the same condition.
+ timeoutError = `CLI run timed out after ${effectiveTimeout}ms`;
killProcessTree(childProcess);
}
}, effectiveTimeout) : null;
@@ -392,7 +400,23 @@ export async function executeCliRun({ runId, provider, prompt, workspacePath, on
} else if (!metadata.success && toolkit.services.errorDetection) {
// A mid-stream fallback signal (e.g. usage-limit hit) SIGTERM-kills the
// child; even an exit 0 must remain a failure so fallback can run.
- const errorAnalysis = immediateFallbackAnalysis || toolkit.services.errorDetection.analyzeError(output, exitCode);
+ //
+ // Our own wall-clock timeout is authoritative about WHY the child died,
+ // so analyze that message rather than the output — the same guard
+ // `finalizeRunRecord` applies to exit 124 for TUI runs. Codex echoes the
+ // whole prompt to stdout, so scanning `output` for a category let one
+ // word of story prose ("…without demanding credit.") match the
+ // billing/credit pattern and file a plain 5-minute timeout as
+ // `quota-exceeded`: a healthy provider benched and an investigation task
+ // spawned over a run that simply needed longer (#3726).
+ // A mid-stream signal outranks the clock in both places: it names a
+ // specific provider condition, where the timeout only says the run ran
+ // out of time — and the two can coexist if the deadline lands between
+ // the signal's kill and the child's close.
+ const timedOut = !!timeoutError && !immediateFallbackAnalysis;
+ if (timedOut) metadata.completionReason = 'timeout';
+ const errorAnalysis = immediateFallbackAnalysis
+ || toolkit.services.errorDetection.analyzeError(timedOut ? timeoutError : output, exitCode);
metadata.error = errorAnalysis.message || `Process exited with code ${exitCode}`;
metadata.errorCategory = errorAnalysis.category;
metadata.errorAnalysis = errorAnalysis;
diff --git a/server/services/runner.test.js b/server/services/runner.test.js
index d2d4742a39..b52907e233 100644
--- a/server/services/runner.test.js
+++ b/server/services/runner.test.js
@@ -164,6 +164,62 @@ describe('finalizeRunRecord — authoritative timeout classification', () => {
});
});
+describe('executeCliRun — wall-clock timeout classification', () => {
+ // The CLI runner kills its own child on timeout, so the close event carries
+ // `exitCode: null` rather than the 124 finalizeRunRecord keys on. Without the
+ // runner's own timeout verdict, the close handler scanned the output — and
+ // Codex echoes the entire prompt to stdout, so one word of story prose
+ // ("credit") filed a 5-minute timeout as `quota-exceeded`, benching a healthy
+ // provider and spawning an investigation task.
+ it('classifies its own timeout kill as a timeout instead of scanning story text', async () => {
+ const child = makeChild();
+ spawn.mockReturnValue(child);
+ const onRunFailed = vi.fn();
+ setAIToolkit(fakeToolkit({ analyzeError }), {
+ dataDir: '/tmp/test-runner',
+ hooks: { onRunFailed },
+ });
+ const onComplete = vi.fn();
+ const provider = {
+ id: 'codex',
+ name: 'Codex CLI',
+ command: 'codex',
+ args: [],
+ defaultModel: 'gpt-test',
+ timeout: 1,
+ };
+
+ await executeCliRun({
+ runId: 'run-cli-timeout',
+ provider,
+ prompt: 'A story about a designer who sends the work on without demanding credit.',
+ workspacePath: TEST_WORKSPACE,
+ onComplete,
+ });
+ // Codex echoes the prompt back on stdout, which is how the quota-shaped
+ // word reaches the classifier at all.
+ child.stdout.emit('data', Buffer.from('...sends the work on without demanding credit.'));
+ // Let the 1ms timer fire, then settle the kill the way the OS would.
+ await new Promise((resolve) => setTimeout(resolve, 10));
+ child.emit('close', null, 'SIGKILL');
+ await flushMicrotasks();
+
+ expect(onComplete).toHaveBeenCalledWith(expect.objectContaining({
+ success: false,
+ completionReason: 'timeout',
+ errorCategory: ERROR_CATEGORIES.TIMEOUT,
+ errorAnalysis: expect.objectContaining({
+ category: ERROR_CATEGORIES.TIMEOUT,
+ // A timeout is not evidence the provider is unhealthy: it must not
+ // route to the actionable/fallback handling quota-exceeded triggers.
+ requiresFallback: false,
+ actionable: false,
+ }),
+ }));
+ expect(onComplete.mock.calls.at(-1)[0].error).toMatch(/timed out/i);
+ });
+});
+
describe('executeCliRun — intentional cancellation', () => {
it('skips output classification and provider-failure hooks after stopRun', async () => {
const child = makeChild();