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: extend TUI idle-reap grace for do:release/do:pr/do:rpr review loops

Adam Eivye2198dbe7d5a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
new file mode 100644
index 0000000000..fcf0abe557
--- /dev/null
+++ b/.changelog/NEXT.md
@@ -0,0 +1,5 @@
+# Unreleased Changes
+
+## Fixed
+
+- **CoS TUI agents running `/do:release`/`/do:pr`/`/do:rpr` no longer get prematurely reaped as "done" while a reviewer is still working** — the idle-timeout reaper only special-cased the `/do:next --swarm` merge-queue wait (#2074); a slow multi-reviewer pass (e.g. codex reading a large diff) could go silent past the default 3-minute idle window and get finalized as a false `idle-complete` success before the release ever reached the merge gate, leaving the PR open with the task dashboard showing "completed" (observed on agent-61508f36, PR #2084, which sat open+unmerged for hours). Added a `createReviewLoopTracker` (`server/lib/tuiHandshake.js`) that latches on multi-reviewer-loop chrome ("Review plan:", "Review pass", "Multi-Reviewer", "review loop") and extends the idle reaper's grace to 15 minutes while active — mirroring the merge-queue fix exactly, including surfacing a timeout as a needs-manual-finish failure (`reason: 'review-loop-idle-timeout'`) instead of a silent success.
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.js
index dd3007f4c2..2d316b07c4 100644
--- a/server/lib/tuiHandshake.js
+++ b/server/lib/tuiHandshake.js
@@ -378,6 +378,70 @@ export function createMergeQueueTracker() {
};
}
+// Extended idle threshold applied while a `/do:release`, `/do:pr`, or `/do:rpr`
+// multi-reviewer loop is waiting on a slow external reviewer (a Copilot cloud
+// review, a headless codex/agy/claude review pass, an Ollama pass, or an
+// arbitrary @<login> human reviewer). Observed 2026-07-02 (agent-61508f36): the
+// review loop correctly backgrounds the reviewer and polls for it rather than
+// blocking — but the reviewer itself can go silent in the wrapped TUI for well
+// over the 3-minute default while it works (e.g. codex reading a large diff),
+// and the runner reaped the still-waiting release agent as `idle-complete` (a
+// false SUCCESS) before it ever reached the merge gate, leaving the release PR
+// open and unmerged. Mirrors the merge-queue grace (#2074) exactly: 15 minutes
+// comfortably covers one reviewer's silent working stretch while still
+// bounding a genuinely-dead agent's reap.
+export const REVIEW_LOOP_IDLE_TIMEOUT_MS = 900000;
+
+// Distinctive markers the multi-reviewer loop (do:release/do:pr/do:rpr) prints
+// once it starts waiting on a reviewer pass. Detection is deliberately
+// conservative, same rationale as MERGE_QUEUE_MARKERS above: a false POSITIVE
+// only extends the (bounded) idle window, and a false NEGATIVE just preserves
+// prior behavior. Matched against ANSI-stripped output, lower-cased.
+const REVIEW_LOOP_MARKERS = [
+ 'review plan:',
+ 'review pass',
+ 'multi-reviewer',
+ 'review loop',
+];
+
+/**
+ * True when a chunk of ANSI-stripped TUI output shows the multi-reviewer loop
+ * (do:release/do:pr/do:rpr) has started a reviewer pass. Callers MUST pass
+ * stripped output. Non-string / empty input yields false.
+ *
+ * @param {string} strippedText — ANSI-stripped output (a chunk or accumulator).
+ * @returns {boolean}
+ */
+export function isReviewLoopSignal(strippedText) {
+ if (typeof strippedText !== 'string' || !strippedText) return false;
+ const lower = strippedText.toLowerCase();
+ return REVIEW_LOOP_MARKERS.some((marker) => lower.includes(marker));
+}
+
+/**
+ * Latching tracker for "this agent is waiting inside a multi-reviewer loop"
+ * (do:release/do:pr/do:rpr). Feed it each ANSI-stripped post-submit chunk via
+ * `observe(text)`; it becomes `active` the first time a review-loop marker
+ * appears and STAYS active thereafter (same latching rationale as
+ * createMergeQueueTracker — the failure mode is a silent external-reviewer
+ * wait, so a recency window would age the flag out exactly when the extended
+ * grace is needed). Once latched, the idle reaper uses
+ * REVIEW_LOOP_IDLE_TIMEOUT_MS instead of the 3-minute default.
+ *
+ * @returns {{ observe: (strippedText: string) => boolean, readonly active: boolean }}
+ */
+export function createReviewLoopTracker() {
+ let active = false;
+ return {
+ observe(strippedText) {
+ if (active) return true;
+ if (isReviewLoopSignal(strippedText)) active = true;
+ return active;
+ },
+ get active() { return active; },
+ };
+}
+
// ─── Buffer caps (defensive RAM bounds) ───────────────────────────────────
//
// RAW caps stay small — the raw PTY stream is only used for paste-marker
diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.js
index 93ec80ea7a..301109489c 100644
--- a/server/lib/tuiHandshake.test.js
+++ b/server/lib/tuiHandshake.test.js
@@ -15,6 +15,9 @@ import {
MERGE_QUEUE_IDLE_TIMEOUT_MS,
isMergeQueueSignal,
createMergeQueueTracker,
+ REVIEW_LOOP_IDLE_TIMEOUT_MS,
+ isReviewLoopSignal,
+ createReviewLoopTracker,
rendersWorkCounter,
PASTE_TO_ENTER_MIN_DELAY_MS,
PASTE_TO_ENTER_FALLBACK_MS,
@@ -290,6 +293,49 @@ describe('tuiHandshake — merge-queue idle suppression (#2074)', () => {
});
});
+// Observed 2026-07-02 (agent-61508f36) — a do:release run's multi-reviewer
+// loop correctly backgrounded a slow codex review and polled for it rather
+// than blocking, but the reviewer's silent working stretch exceeded the
+// 3-minute default and the runner reaped the still-waiting release as a false
+// `idle-complete` success before it reached the merge gate, leaving PR #2084
+// open. Mirrors the merge-queue suppression above.
+describe('tuiHandshake — review-loop idle suppression', () => {
+ it('extends the idle timeout well past the default 3-minute window', () => {
+ expect(REVIEW_LOOP_IDLE_TIMEOUT_MS).toBe(900000);
+ expect(REVIEW_LOOP_IDLE_TIMEOUT_MS).toBeGreaterThan(DEFAULT_TUI_IDLE_TIMEOUT_MS);
+ });
+
+ it('isReviewLoopSignal matches multi-reviewer-loop chrome (case-insensitive)', () => {
+ expect(isReviewLoopSignal('Review plan: [claude, codex] (mode: series, stop-mode: all)')).toBe(true);
+ expect(isReviewLoopSignal('--- Review pass 1/2: codex ---')).toBe(true);
+ expect(isReviewLoopSignal('## Multi-Reviewer Summary')).toBe(true);
+ expect(isReviewLoopSignal('You are a COPILOT REVIEW LOOP agent.')).toBe(true);
+ });
+
+ it('isReviewLoopSignal ignores ordinary implementation/output chrome', () => {
+ expect(isReviewLoopSignal('Editing server/services/agentTuiSpawning.js')).toBe(false);
+ expect(isReviewLoopSignal('● high · (12s · running tests)')).toBe(false);
+ expect(isReviewLoopSignal('')).toBe(false);
+ expect(isReviewLoopSignal(null)).toBe(false);
+ expect(isReviewLoopSignal(undefined)).toBe(false);
+ });
+
+ it('createReviewLoopTracker latches on first signal and stays active through silence', () => {
+ const tracker = createReviewLoopTracker();
+ expect(tracker.active).toBe(false);
+ tracker.observe('implementing the fix, running the suite');
+ expect(tracker.active).toBe(false);
+ // Enters the multi-reviewer loop — latches.
+ expect(tracker.observe('Review plan: [claude, codex] (mode: series, stop-mode: all)')).toBe(true);
+ expect(tracker.active).toBe(true);
+ // Subsequent quiet reviewer-wait chunks (no marker) must NOT un-latch it —
+ // the whole point is that the silent gap is when the grace is needed.
+ tracker.observe('waiting for codex...');
+ tracker.observe('');
+ expect(tracker.active).toBe(true);
+ });
+});
+
describe('tuiHandshake.inferTuiCommand', () => {
// Catch-all default also returns claude; the claude rows just confirm
// an explicit match isn't accidentally tagged codex/antigravity/gemini.
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index 8adef08168..17736d3ede 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -26,12 +26,14 @@ import {
DEFAULT_TUI_PROMPT_DELAY_MS,
DEFAULT_TUI_IDLE_TIMEOUT_MS,
MERGE_QUEUE_IDLE_TIMEOUT_MS,
+ REVIEW_LOOP_IDLE_TIMEOUT_MS,
READY_POLL_INTERVAL_MS,
READY_IDLE_THRESHOLD_MS,
PASTE_MARKER_POLL_MS,
countPasteMarkers,
createWorkActivityTracker,
createMergeQueueTracker,
+ createReviewLoopTracker,
createInputReadyTracker,
rendersWorkCounter,
PASTE_TO_ENTER_MIN_DELAY_MS,
@@ -283,6 +285,14 @@ export async function spawnTuiAgent({
// latched, the idle reaper uses the extended MERGE_QUEUE_IDLE_TIMEOUT_MS so a
// still-working orchestrator isn't reaped mid-merge (issue #2074).
const mergeQueue = createMergeQueueTracker();
+ // Latches once the agent enters a do:release/do:pr/do:rpr multi-reviewer
+ // loop, whose external reviewer passes (codex reading a large diff, a
+ // Copilot cloud review, a human @<login> review) can go silent in the TUI
+ // for well over the default idle window. While latched, the idle reaper
+ // uses the extended REVIEW_LOOP_IDLE_TIMEOUT_MS so a still-waiting release
+ // isn't reaped as a false `idle-complete` success before it reaches the
+ // merge gate (issue observed on agent-61508f36, PR #2084).
+ const reviewLoop = createReviewLoopTracker();
// Tracks claude's interactive input-readiness (footer chrome) and its first-run
// folder-trust gate. Gates the prompt paste for the claude TUI so we never
// paste into a startup banner, a trust menu, or a returned shell prompt.
@@ -639,6 +649,13 @@ export async function spawnTuiAgent({
emitLog('info', `TUI agent ${agentId} entered merge queue — idle reaper extended to ${Math.round(MERGE_QUEUE_IDLE_TIMEOUT_MS / 60000)}min`, { agentId, phase: 'merge-queue' });
await updateAgent(agentId, { metadata: { phase: 'merge-queue' } });
}
+ // Detect entry into a do:release/do:pr/do:rpr multi-reviewer loop so the
+ // idle reaper can extend its grace across a slow reviewer's silent
+ // working stretch (see reviewLoop declaration above for the incident).
+ if (promptSubmittedAt && stripped && !reviewLoop.active && reviewLoop.observe(stripped)) {
+ emitLog('info', `TUI agent ${agentId} entered review loop — idle reaper extended to ${Math.round(REVIEW_LOOP_IDLE_TIMEOUT_MS / 60000)}min`, { agentId, phase: 'review-loop' });
+ await updateAgent(agentId, { metadata: { phase: 'review-loop' } });
+ }
lastOutputAt = now;
if (firstOutputAt === null) firstOutputAt = lastOutputAt;
@@ -901,7 +918,9 @@ export async function spawnTuiAgent({
// extended window still bounds a genuinely-dead orchestrator's reap.
const effectiveIdleTimeoutMs = mergeQueue.active
? Math.max(tuiConfig.idleTimeoutMs, MERGE_QUEUE_IDLE_TIMEOUT_MS)
- : tuiConfig.idleTimeoutMs;
+ : reviewLoop.active
+ ? Math.max(tuiConfig.idleTimeoutMs, REVIEW_LOOP_IDLE_TIMEOUT_MS)
+ : tuiConfig.idleTimeoutMs;
if (idle >= effectiveIdleTimeoutMs) {
// Reaped AFTER the extended merge-queue grace elapsed: the orchestrator
// almost certainly died mid-merge with PRs opened/merged-but-uncleaned.
@@ -918,6 +937,22 @@ export async function spawnTuiAgent({
});
return;
}
+ // Reaped AFTER the extended review-loop grace elapsed: a reviewer
+ // (copilot/codex/agy/claude/ollama/@<login>) likely hung, or the wait
+ // simply exceeded budget. Surface it as a needs-manual-finish FAILURE
+ // rather than the silent `status: completed` that let PR #2084 sit
+ // open+unmerged for hours while agent-61508f36 looked "done".
+ if (reviewLoop.active) {
+ finish({
+ success: false,
+ exitCode: 1,
+ error: `TUI agent idled out after ${Math.round(effectiveIdleTimeoutMs / 60000)}min waiting inside the multi-reviewer loop — a reviewer may have hung or the wait exceeded budget; check the PR's review/merge state and finish manually.`,
+ reason: 'review-loop-idle-timeout',
+ }).catch(err => {
+ emitLog('error', `Failed to finalize TUI agent ${agentId}: ${err.message}`, { agentId });
+ });
+ return;
+ }
// Distinguish a real (sentinel-less) completion from a never-submitted
// prompt that just idled out. `lastOutputAt > promptSentAt` only proves
// the TUI repainted SOMETHING — banner/status chrome churns even with the
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index 0e022144d4..9ce854cf79 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -1010,16 +1010,22 @@ describe('spawnTuiAgent runtime', () => {
// tested without standing up the full fake-timer PTY harness.
describe('agentTuiSpawning — idle reap decision (#2074)', () => {
const MERGE_QUEUE_IDLE_TIMEOUT_MS = 900000;
+ const REVIEW_LOOP_IDLE_TIMEOUT_MS = 900000;
// Faithful copy of the idleTimer body's finalize-selection logic.
- function decideIdleReap({ idle, baseIdleTimeoutMs, mergeQueueActive, workActive, rendersCounter }) {
+ function decideIdleReap({ idle, baseIdleTimeoutMs, mergeQueueActive, reviewLoopActive, workActive, rendersCounter }) {
const effectiveIdleTimeoutMs = mergeQueueActive
? Math.max(baseIdleTimeoutMs, MERGE_QUEUE_IDLE_TIMEOUT_MS)
- : baseIdleTimeoutMs;
+ : reviewLoopActive
+ ? Math.max(baseIdleTimeoutMs, REVIEW_LOOP_IDLE_TIMEOUT_MS)
+ : baseIdleTimeoutMs;
if (idle < effectiveIdleTimeoutMs) return { action: 'wait', effectiveIdleTimeoutMs };
if (mergeQueueActive) {
return { action: 'reap', success: false, reason: 'merge-queue-idle-timeout', effectiveIdleTimeoutMs };
}
+ if (reviewLoopActive) {
+ return { action: 'reap', success: false, reason: 'review-loop-idle-timeout', effectiveIdleTimeoutMs };
+ }
const noWorkButCounterExpected = !workActive && rendersCounter;
if (noWorkButCounterExpected) {
return { action: 'reap', success: false, reason: 'idle-no-activity', effectiveIdleTimeoutMs };
@@ -1063,3 +1069,63 @@ describe('agentTuiSpawning — idle reap decision (#2074)', () => {
expect(r.reason).toBe('merge-queue-idle-timeout');
});
});
+
+// Generalizes #2074's fix to do:release/do:pr/do:rpr's multi-reviewer loop —
+// observed 2026-07-02 on agent-61508f36 (PR #2084): a slow codex review pass
+// went silent past the 3-minute default and the still-waiting release agent
+// was reaped as a false `idle-complete` success before it ever merged.
+describe('agentTuiSpawning — idle reap decision (review loop)', () => {
+ const REVIEW_LOOP_IDLE_TIMEOUT_MS = 900000;
+
+ function decideIdleReap({ idle, baseIdleTimeoutMs, mergeQueueActive, reviewLoopActive, workActive, rendersCounter }) {
+ const effectiveIdleTimeoutMs = mergeQueueActive
+ ? Math.max(baseIdleTimeoutMs, 900000)
+ : reviewLoopActive
+ ? Math.max(baseIdleTimeoutMs, REVIEW_LOOP_IDLE_TIMEOUT_MS)
+ : baseIdleTimeoutMs;
+ if (idle < effectiveIdleTimeoutMs) return { action: 'wait', effectiveIdleTimeoutMs };
+ if (mergeQueueActive) {
+ return { action: 'reap', success: false, reason: 'merge-queue-idle-timeout', effectiveIdleTimeoutMs };
+ }
+ if (reviewLoopActive) {
+ return { action: 'reap', success: false, reason: 'review-loop-idle-timeout', effectiveIdleTimeoutMs };
+ }
+ const noWorkButCounterExpected = !workActive && rendersCounter;
+ if (noWorkButCounterExpected) {
+ return { action: 'reap', success: false, reason: 'idle-no-activity', effectiveIdleTimeoutMs };
+ }
+ return { action: 'reap', success: true, reason: 'idle-complete', effectiveIdleTimeoutMs };
+ }
+
+ const BASE = 180000;
+
+ it('does NOT reap at the 3-min default while in a review loop — grace extends to 15min', () => {
+ const r = decideIdleReap({ idle: BASE + 5000, baseIdleTimeoutMs: BASE, reviewLoopActive: true, workActive: true, rendersCounter: true });
+ expect(r.action).toBe('wait');
+ expect(r.effectiveIdleTimeoutMs).toBe(REVIEW_LOOP_IDLE_TIMEOUT_MS);
+ });
+
+ it('reaps a review-loop agent as needs-manual-finish once the EXTENDED window blows', () => {
+ const r = decideIdleReap({ idle: REVIEW_LOOP_IDLE_TIMEOUT_MS + 1, baseIdleTimeoutMs: BASE, reviewLoopActive: true, workActive: true, rendersCounter: true });
+ expect(r.action).toBe('reap');
+ expect(r.success).toBe(false);
+ expect(r.reason).toBe('review-loop-idle-timeout');
+ });
+
+ it('leaves the pre-existing idle-complete path untouched when NOT in a review loop', () => {
+ const r = decideIdleReap({ idle: BASE + 1, baseIdleTimeoutMs: BASE, reviewLoopActive: false, workActive: true, rendersCounter: true });
+ expect(r.action).toBe('reap');
+ expect(r.success).toBe(true);
+ expect(r.reason).toBe('idle-complete');
+ });
+
+ it('a review-loop reap takes precedence over the no-activity downgrade', () => {
+ const r = decideIdleReap({ idle: REVIEW_LOOP_IDLE_TIMEOUT_MS + 1, baseIdleTimeoutMs: BASE, reviewLoopActive: true, workActive: false, rendersCounter: true });
+ expect(r.reason).toBe('review-loop-idle-timeout');
+ });
+
+ it('a merge-queue reap takes precedence over a review-loop reap when both are (implausibly) active', () => {
+ const r = decideIdleReap({ idle: 900001, baseIdleTimeoutMs: BASE, mergeQueueActive: true, reviewLoopActive: true, workActive: true, rendersCounter: true });
+ expect(r.reason).toBe('merge-queue-idle-timeout');
+ });
+});