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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review round 2 (codex P2s): bullet-suffixed counter + drop runner gate
[._.]/ Adam Eivyadc7c22e987a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex d90d5e1535..8b97cfc8c6 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -80,6 +80,6 @@- **TUI agents no longer leave the prompt sitting unsent in the input box** — CoS agents that run inside a terminal-UI provider (Claude Code, Codex) bracketed-paste their task prompt and then send a single Enter to submit it. On a large multi-line prompt that one `\r` could arrive while the TUI was still reflowing the paste and get swallowed — so the prompt sat typed-but-unsubmitted, the agent did no work, idled out after 3 minutes, and was (wrongly) recorded as a successful run. You'd see it only by opening the Shell tab and hitting Enter yourself. The submit Enter now fires a few times spaced ~700ms apart so one lands after the paste settles; re-sending is safe because once the prompt submits the input box is empty and a bare Enter is a no-op. Applies to both the long-running agent path and the one-shot TUI runner. (`server/lib/tuiHandshake.js`, `server/services/agentTuiSpawning.js`, `server/lib/tuiPromptRunner.js`)-- **A TUI agent that never started working is no longer recorded as a success** — Two follow-ups to the unsent-prompt fix above. First, the paste-commit fast path that submits the prompt the moment Claude Code finishes ingesting it was effectively dead: it scanned the raw terminal stream for the `[Pasted text #N]` marker, but Claude Code draws that marker with cursor-positioning codes between every word, so the literal text never matched and *every* run fell back to a blind 3.5-second timer. The matcher now runs against the cleaned text, so the fast path fires again on large pastes (short prompts still use the timer, and the multi-Enter safety net covers both). Second, a run that idled out without ever submitting its prompt was still marked **successful** — the idle check only confirmed the terminal had repainted *something*, and the status bar repaints constantly even with an unsent prompt. A run now must show a real sign of work — the terminal's elapsed-time working counter actually advancing — before an idle-out counts as done; an idle-out with no such activity is recorded as a **failure** instead, so a no-op run can't masquerade as completed. Both fixes apply to the long-running agent path and the one-shot TUI runner. (`server/lib/tuiHandshake.js`, `server/services/agentTuiSpawning.js`, `server/lib/tuiPromptRunner.js`)+- **A TUI agent that never started working is no longer recorded as a success** — Two follow-ups to the unsent-prompt fix above. First, the paste-commit fast path that submits the prompt the moment Claude Code finishes ingesting it was effectively dead: it scanned the raw terminal stream for the `[Pasted text #N]` marker, but Claude Code draws that marker with cursor-positioning codes between every word, so the literal text never matched and *every* run fell back to a blind 3.5-second timer. The matcher now runs against the cleaned text, so the fast path fires again on large pastes (short prompts still use the timer, and the multi-Enter safety net covers both). Second, a long-running agent that idled out without ever submitting its prompt was still marked **successful** — the idle check only confirmed the terminal had repainted *something*, and the status bar repaints constantly even with an unsent prompt. An agent now must show a real sign of work — the terminal's elapsed-time working counter actually advancing — before an idle-out counts as done; an idle-out with no such activity is recorded as a **failure** instead, so a no-op run can't masquerade as completed. (The paste-marker fix applies to both the agent path and the one-shot prompt runner; the work-activity gate is agent-only — the one-shot runner's idle fallback legitimately captures inline answers that carry no working counter, and its authoritative signal is the response file.) (`server/lib/tuiHandshake.js`, `server/services/agentTuiSpawning.js`, `server/lib/tuiPromptRunner.js`)- **`calendarSync` test no longer depends on the developer's machine state** — the "throws 401 when Google OAuth is not configured" test read the REAL Google credentials/tokens off disk, so on a machine with OAuth configured it failed with a `GaxiosError` (400 invalid_grant) instead of the pinned 401. The auth client is now mocked to the not-configured state. (`server/services/calendarSync.test.js`)diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex 2d1f67864e..8c36f6b475 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -67,23 +67,34 @@ export function detectPasteMarker(strippedText) {// We key on the TUI's elapsed-time WORKING COUNTER — `(1s · …` (Claude Code) /// `(57s • …` (Codex) — which renders only while a request is in flight and// INCREMENTS as the model works. This is the most model-agnostic signal (present-// in both providers, absent on the stuck screen) AND it is echo-proof: the prompt-// is echoed into the input box BEFORE submission, so word-matching `thinking` or-// `esc to interrupt` could be tripped by a task description that merely contains-// those words (flagged in review of #1229). A literal `(5s` in a prompt is a-// single fixed value; the live counter passes through MANY distinct values, so we-// require ≥ MIN_WORK_COUNTER_SAMPLES distinct second-counts before trusting it.-// Verified against real transcripts: the working run cycled through ~29 counter+// in both providers, absent on the stuck screen) AND the only one that's+// echo-proof. The prompt is echoed into the input box BEFORE submission (and+// `promptSentAt` is set when the paste starts, before Enter), so word-matching+// `thinking`/`esc to interrupt` — or even a bare `(5s)` — could be tripped by a+// task description that merely contains those tokens (both flagged in review of+// #1229). Two defenses make the counter immune to the echo:+// 1. We require the counter's trailing bullet separator (`· ` / `• `, U+00B7 /+// U+2022) — `(\d+s` alone matches log lines and durations in prose, but+// `(\d+s ·` is the TUI's specific status-line format and effectively never+// appears in a pasted prompt. (The bullet survives ANSI stripping intact —+// verified in real transcripts: `(1s · thinking…`.)+// 2. We require ≥ MIN_WORK_COUNTER_SAMPLES DISTINCT second-counts — the live+// counter passes through many values; a static echoed literal is just one.+// Verified against real transcripts: the working run cycled through many counter// values; the two confirmed stuck runs (`agent-92ed2c56`, `agent-30a3ab56`) had-// none. Heuristic by nature, so it gates only the FALLBACK idle-complete path —-// the authoritative success signal remains the `.agent-done` sentinel.-export const WORK_COUNTER_PATTERN = /\(\s*(\d+)\s*s\b/g;+// none. Heuristic by nature, so it gates only the FALLBACK idle-complete path on+// the long-running agent path — the authoritative success signal remains the+// `.agent-done` sentinel. (The one-shot runner is deliberately NOT gated: its+// idle-complete legitimately captures inline output that may carry no counter,+// and its authoritative path is the response file.)+export const WORK_COUNTER_PATTERN = /\(\s*(\d+)\s*s\s*[·•]/g;export const MIN_WORK_COUNTER_SAMPLES = 2;/*** Extract every elapsed-second value from the TUI working counter in- * `strippedText` (e.g. `(1s · …` → 1, `(57s • …` → 57). Callers MUST pass- * ANSI-stripped output. Returns an array (possibly empty); non-string input+ * `strippedText` (e.g. `(1s · …` → 1, `(57s • …` → 57). Matches only the TUI's+ * bullet-suffixed status-line counter, not a bare `(5s)` in prose. Callers MUST+ * pass ANSI-stripped output. Returns an array (possibly empty); non-string input* yields `[]`.** @param {string} strippedText — ANSI-stripped output (a chunk or accumulator).diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex 53cc8c7639..141cd82620 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -99,14 +99,21 @@ describe('tuiHandshake — paste timing constants', () => {expect(detectPasteMarker('[Pasted text #1 +3 lines]')).toBe(true);});- it('extractWorkCounterSeconds parses the TUI elapsed working counter', () => {+ it('extractWorkCounterSeconds parses the TUI bullet-suffixed working counter', () => {// Claude Code: `(1s · …`; Codex: `(57s • …`.expect(extractWorkCounterSeconds('(1s · thinking with high effort)')).toEqual([1]);expect(extractWorkCounterSeconds('(57s • esc to interrupt)')).toEqual([57]);expect(extractWorkCounterSeconds('(0s · Churning…)')).toEqual([0]);- // Multiple counters in one buffer (e.g. an accumulated screen).- expect(extractWorkCounterSeconds('(1s) … (2s) … (3s)')).toEqual([1, 2, 3]);- // No counter → empty; non-string → empty (guard).+ // Multiple bulleted counters in one buffer (e.g. an accumulated screen).+ expect(extractWorkCounterSeconds('(1s · a (2s • b (3s · c')).toEqual([1, 2, 3]);+ });++ it('extractWorkCounterSeconds ignores bare (Ns) durations in prose/logs (echo-proof)', () => {+ // The #1229 review fix: a bare `(5s)` in a pasted prompt / log line must NOT+ // count — only the TUI's bullet-suffixed status-line counter does. Without+ // this, an echoed prompt containing duration literals could fake "work".+ expect(extractWorkCounterSeconds('please respond within (5s) of receiving this')).toEqual([]);+ expect(extractWorkCounterSeconds('[12:00:01] (3s) elapsed (4s) total')).toEqual([]);expect(extractWorkCounterSeconds('● high · /effort')).toEqual([]);expect(extractWorkCounterSeconds('')).toEqual([]);expect(extractWorkCounterSeconds(null)).toEqual([]);@@ -114,20 +121,22 @@ describe('tuiHandshake — paste timing constants', () => {it('extractWorkCounterSeconds is stateless across calls (no lastIndex carryover)', () => {// A module-level /g regex would skip matches on the 2nd call; assert it doesn't.- expect(extractWorkCounterSeconds('(4s)')).toEqual([4]);- expect(extractWorkCounterSeconds('(4s)')).toEqual([4]);+ expect(extractWorkCounterSeconds('(4s · x')).toEqual([4]);+ expect(extractWorkCounterSeconds('(4s · x')).toEqual([4]);});it('createWorkActivityTracker activates only after the counter ADVANCES (echo-proof)', () => {const tracker = createWorkActivityTracker();expect(tracker.active).toBe(false);- // A single counter value — e.g. a literal `(5s` echoed from the prompt text —- // must NOT activate. This is the #1229 review fix: word/single-value matching- // could be tripped by the echoed prompt before submission.- expect(tracker.observe('please respond within (5s) of receiving this')).toBe(false);- expect(tracker.observe('still (5s) (5s) repainted chrome')).toBe(false);+ // Bare duration literals echoed from the prompt — even two distinct ones —+ // must NOT activate (no bullet separator → not the TUI counter).+ expect(tracker.observe('finish within (1s) and definitely under (2s)')).toBe(false);+ expect(tracker.active).toBe(false);+ // A single bulleted counter value also must NOT activate (one sample).+ expect(tracker.observe('(5s · thinking)')).toBe(false);+ expect(tracker.observe('(5s · thinking)')).toBe(false);expect(tracker.active).toBe(false);- // A second DISTINCT value — the live counter actually advanced — activates.+ // A second DISTINCT bulleted value — the live counter actually advanced.expect(tracker.observe('(6s · thinking)')).toBe(true);expect(tracker.active).toBe(true);// Stays active once tripped.diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.jsindex c5414f9baf..bdf8d06af9 100644--- a/server/lib/tuiPromptRunner.js+++ b/server/lib/tuiPromptRunner.js@@ -44,7 +44,6 @@ import {DEFAULT_TUI_PROMPT_DELAY_MS,PASTE_MARKER_POLL_MS,detectPasteMarker,- createWorkActivityTracker,PASTE_TO_ENTER_MIN_DELAY_MS,PASTE_TO_ENTER_FALLBACK_MS,scheduleSubmitEnters,@@ -209,11 +208,6 @@ ${prompt}`;// path dead (issue #1229). Lives only during the paste→Enter window; nulled// when detection resolves or the run finalizes.let postPasteStripped = null;- // Echo-proof "model is actively working" tracker (working counter advancing).- // Gates the inline-output idle-complete fallback so a never-submitted one-shot- // prompt can't be scraped as a successful response (issue #1229) — the same- // guard the agent path uses; the authoritative path here is the response file.- const workActivity = createWorkActivityTracker();let firstOutputAt = null;let lastOutputAt = startTime;let firstResponseAt = null;@@ -314,7 +308,6 @@ ${prompt}`;const stripped = streamingStrip(text);if (stripped) {if (postPasteStripped !== null) postPasteStripped += stripped;- if (promptSentAt && !workActivity.active) workActivity.observe(stripped);outputBuffer += stripped;if (outputBuffer.length > OUTPUT_BUFFER_HEADROOM) {outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_CAP);@@ -358,21 +351,16 @@ ${prompt}`;if (isExternalSessionAttached(runId)) return;const idle = Date.now() - lastOutputAt;if (idle >= idleThresholdMs) {- // Mirror the agent path's #1229 guard: idle-complete is the inline-- // output fallback (the response file is authoritative), so only trust- // it as success when the model actually worked (working counter- // advanced). Pure chrome churn from a never-submitted prompt would- // otherwise let the screen-scrape fallback masquerade as a response.- if (workActivity.active) {- finish({ success: true, exitCode: 0, reason: 'idle-complete' });- } else {- finish({- success: false,- exitCode: 1,- error: 'TUI run idled out with no sign of work — the prompt likely never submitted (no working indicator after paste) and no response file was written.',- reason: 'idle-no-activity',- });- }+ // 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.+ finish({ success: true, exitCode: 0, reason: 'idle-complete' });}}, 1000);}