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
fix([med-ai-dispatch-server-lib-tuipromptrunner-js-198]): raise TUI output buffer cap 1MB→8MB and warn on overflow
[._.]/ Adam Eivy9cdd37432e38
diff --git a/server/lib/tuiHandshake.js b/server/lib/tuiHandshake.jsindex 34a497c28d..0475e6e885 100644--- a/server/lib/tuiHandshake.js+++ b/server/lib/tuiHandshake.js@@ -36,12 +36,23 @@ export const PASTE_TO_ENTER_FALLBACK_MS = 3500;export const DEFAULT_TUI_PROMPT_DELAY_MS = 2500;export const DEFAULT_TUI_IDLE_TIMEOUT_MS = 180000;-// ─── Buffer caps (defensive, not load-bearing) ────────────────────────────-+// ─── Buffer caps (defensive RAM bounds) ───────────────────────────────────+//+// RAW caps stay small — the raw PTY stream is only used for paste-marker+// detection and a short failure-tail in the exit error message, both of+// which need only the recent past.+//+// OUTPUT caps are larger because the ANSI-stripped buffer is the fallback+// response text when a TUI fails to write its response file. A 1MB cap was+// silently truncating the *head* of large model responses mid-token; bumped+// to 8MB so realistic full-context replies (~600KB UTF-8 from a 200K-token+// window, plus screen chrome) fit cleanly. Consumers should still treat+// overflow as a fault — see `outputBufferTruncated` tracking in+// `tuiPromptRunner.js`.export const RAW_BUFFER_CAP = 512 * 1024;export const RAW_BUFFER_HEADROOM = 640 * 1024;-export const OUTPUT_BUFFER_CAP = 1024 * 1024;-export const OUTPUT_BUFFER_HEADROOM = 1280 * 1024;+export const OUTPUT_BUFFER_CAP = 8 * 1024 * 1024;+export const OUTPUT_BUFFER_HEADROOM = 10 * 1024 * 1024;// ─── Command + args helpers ───────────────────────────────────────────────diff --git a/server/lib/tuiHandshake.test.js b/server/lib/tuiHandshake.test.jsindex bb40f93e55..7b6d401bc4 100644--- a/server/lib/tuiHandshake.test.js+++ b/server/lib/tuiHandshake.test.js@@ -69,8 +69,12 @@ describe('tuiHandshake — paste timing constants', () => {it('pins buffer caps with headroom > cap (defensive growth allowance)', () => {expect(RAW_BUFFER_CAP).toBe(512 * 1024);expect(RAW_BUFFER_HEADROOM).toBe(640 * 1024);- expect(OUTPUT_BUFFER_CAP).toBe(1024 * 1024);- expect(OUTPUT_BUFFER_HEADROOM).toBe(1280 * 1024);+ // OUTPUT cap was bumped 1MB → 8MB so realistic full-context LLM responses+ // (~600KB UTF-8 from a 200K-token window + screen chrome) fit cleanly+ // when the file-write path falls back to the buffer scrape. A regression+ // back to ~1MB would silently mid-token-truncate large fallback responses.+ expect(OUTPUT_BUFFER_CAP).toBe(8 * 1024 * 1024);+ expect(OUTPUT_BUFFER_HEADROOM).toBe(10 * 1024 * 1024);// Headroom must exceed cap so the slice-tail-after-overflow logic in// the callers actually keeps recent bytes instead of dropping them.expect(RAW_BUFFER_HEADROOM).toBeGreaterThan(RAW_BUFFER_CAP);diff --git a/server/lib/tuiPromptRunner.js b/server/lib/tuiPromptRunner.jsindex b9176b158d..f8630a599c 100644--- a/server/lib/tuiPromptRunner.js+++ b/server/lib/tuiPromptRunner.js@@ -177,6 +177,10 @@ ${prompt}`;let lastOutputAt = startTime;let firstResponseAt = null;let finalized = false;+ // True once outputBuffer overflowed OUTPUT_BUFFER_HEADROOM and the head was+ // dropped. We warn once and surface it in the run record so /runs can flag+ // responses where the fallback path may have lost the start.+ let outputBufferTruncated = false;const streamingStrip = createStreamingAnsiStripper();let readyTimer = null;@@ -217,7 +221,7 @@ ${prompt}`;// set post-write and never made it to disk → /runs replay missed it).const metadata = await finalizeRunRecord({runId, output: responseText, exitCode, success, error, startTime,- extras: { completionReason: reason, usedResponseFile },+ extras: { completionReason: reason, usedResponseFile, outputTruncated: outputBufferTruncated },}).catch((err) => {console.error(`❌ TUI run ${runId} finalize failed: ${err.message}`);return {@@ -225,7 +229,7 @@ ${prompt}`;duration: Date.now() - startTime, completionReason: reason,};});- onComplete?.({ ...metadata, text: responseText, usedResponseFile });+ onComplete?.({ ...metadata, text: responseText, usedResponseFile, outputTruncated: outputBufferTruncated });resolve();};@@ -239,6 +243,10 @@ ${prompt}`;outputBuffer += stripped;if (outputBuffer.length > OUTPUT_BUFFER_HEADROOM) {outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_CAP);+ if (!outputBufferTruncated) {+ outputBufferTruncated = true;+ console.warn(`⚠️ TUI run ${runId} output buffer exceeded ${OUTPUT_BUFFER_HEADROOM} bytes — head dropped (response file is the authoritative path; fallback may be incomplete)`);+ }}onData?.(stripped);}