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(tui): let agent raw PTY buffer grow instead of dropping the head at 1MB
Adam Eivy734cd4205ed8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex debe646edb..beb2f8cf55 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -17,3 +17,4 @@- Federated peer-sync category toggles for **Universe** and **Pipeline** silently no-op'd. The Zod `syncCategoriesSchema` in `server/routes/instances.js` was missing both keys; Zod's default object parsing strips unknown keys, so the PATCH validated as an empty `syncCategories` object, the service-side merge became a no-op, and the checkbox stayed unchecked with no server-side error. Added `universe` and `pipeline` to the schema to restore parity with `DEFAULT_SYNC_CATEGORIES` and the UI's `SYNC_CATEGORY_META`.- Auto-run the world → universe data rename on server boot. The conversion previously shipped as a manual CLI script (`server/scripts/migrateWorldToUniverse.js`) that nobody knew to invoke, so installs upgrading from the World Builder era kept stale `data/world-builder.json` files and never saw their worlds appear as universes. The new migration `031-world-to-universe-data-rename.js` does the file rename, top-level key rename (`worlds`→`universes`), `worldId`→`universeId` rewrite in `pipeline-series.json`, `worldRun`→`universeRun` rewrite in `media-jobs.json`, and also relinks any `"World: <name>"` render collections in `media-collections.json` to their universe by canonical-name match.- Universe Builder picker dropdown rendered beneath the tab subnav and downstream section cards in Lumen Glass / Blueprint Ops themes. Those themes ship a non-`none` `--port-backdrop-filter`, and the global rule in `index.css` applies it to every `.bg-port-card.border.rounded*` — which turns each such card into its own stacking context. The picker's `absolute z-30` dropdown was trapped inside the header card's context and couldn't paint over later sibling cards. Adding `relative z-30` to the picker's `<header>` lets that stacking context win against subsequent siblings so the dropdown overlays them as intended.+- TUI agent raw-PTY buffer no longer truncates the head at ~640KB ("⚠️ raw PTY buffer exceeded 1MB — head dropped"). The buffer feeds `analyzeAgentFailure` at finalize, so silently slicing the head was the exact behavior the warning admitted to ("failure analysis may miss earlier symptoms"). `server/services/agentTuiSpawning.js` now lets `rawBuffer` grow for the duration of the run; `outputBuffer` keeps its 10MB cap (it has an authoritative on-disk source via the line-batched `output.txt` append). The `rawBufferTruncated` agent-metadata flag is gone with the truncation logic.diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 24147c7779..ab8852ced0 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -29,8 +29,6 @@ import {PASTE_TO_ENTER_MIN_DELAY_MS,PASTE_TO_ENTER_FALLBACK_MS,PASTE_DEADLINE_MS,- RAW_BUFFER_CAP,- RAW_BUFFER_HEADROOM,OUTPUT_BUFFER_CAP,OUTPUT_BUFFER_HEADROOM,inferTuiCommand,@@ -138,14 +136,13 @@ export async function spawnTuiAgent({let lastOutputAt = Date.now();let lastLine = '';let sessionId = null;- // True once the respective buffer crossed its HEADROOM and the head was- // dropped. Mirrors `outputBufferTruncated` in `tuiPromptRunner.js`: warn- // once per buffer and surface via agent metadata so the agent record- // distinguishes a long-run-with-overflow from a clean short run. The raw- // buffer feeds analyzeAgentFailure on failure, so a silent slice there can- // hide the actual failure tail behind chatty progress redraws.+ // True once outputBuffer crossed its HEADROOM and the head was dropped.+ // Mirrors `outputBufferTruncated` in `tuiPromptRunner.js`: warn once per+ // buffer and surface via agent metadata so the agent record distinguishes+ // a long-run-with-overflow from a clean short run. rawBuffer is intentionally+ // uncapped — it feeds analyzeAgentFailure at finalize and silently slicing+ // the head can hide the actual failure tail behind chatty progress redraws.let outputBufferTruncated = false;- let rawBufferTruncated = false;let pendingLines = [];let flushTimer = null;@@ -285,15 +282,6 @@ export async function spawnTuiAgent({const handleData = async (data) => {const text = data.toString();rawBuffer += text;- if (rawBuffer.length > RAW_BUFFER_HEADROOM) {- rawBuffer = rawBuffer.slice(-RAW_BUFFER_CAP);- if (!rawBufferTruncated) {- rawBufferTruncated = true;- console.warn(`⚠️ TUI agent ${agentId} raw PTY buffer exceeded ${Math.round(RAW_BUFFER_HEADROOM / 1024 / 1024)}MB — head dropped (failure analysis may miss earlier symptoms)`);- updateAgent(agentId, { metadata: { rawBufferTruncated: true } })- .catch(err => console.error(`❌ TUI agent ${agentId} rawBufferTruncated metadata write failed: ${err.message}`));- }- }lastOutputAt = Date.now();if (firstOutputAt === null) firstOutputAt = lastOutputAt;diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex 3f42d83ce0..f28dc87a7d 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -86,8 +86,8 @@ vi.mock('../lib/providerModels.js', () => ({}));// Shrink buffer thresholds so the truncation tests can trip them with tiny-// inputs. Real values (640 KB raw, 10 MB output) would force tests to push-// millions of bytes through the spawner; the wiring under test is identical.+// inputs. Real values (10 MB output) would force tests to push millions of+// bytes through the spawner; the wiring under test is identical.// OUTPUT_BUFFER_HEADROOM is intentionally 1 byte so ANY appendLine call// trips it — otherwise the output-buffer overflow test would assert on the// byte count of the two spawn-startup string literals (which would silently@@ -98,8 +98,6 @@ vi.mock('../lib/tuiHandshake.js', async (importOriginal) => {...actual,OUTPUT_BUFFER_HEADROOM: 1,OUTPUT_BUFFER_CAP: 1,- RAW_BUFFER_HEADROOM: 200,- RAW_BUFFER_CAP: 100,};});@@ -429,43 +427,19 @@ describe('spawnTuiAgent runtime', () => {);});- // ── 6. Raw-buffer truncation warning + metadata flag ────────────────────────- // Mirrors `outputBufferTruncated` in tuiPromptRunner.js — long-running TUI- // agents whose raw PTY stream overflows RAW_BUFFER_HEADROOM silently dropped- // the head before this change; analyzeAgentFailure then operated on a slice- // missing the failure tail with no signal that anything was clipped.- it('rawBuffer overflow: warns once and writes rawBufferTruncated:true to agent metadata', async () => {+ // ── 6. Raw-buffer growth (no cap) ───────────────────────────────────────────+ // rawBuffer feeds analyzeAgentFailure at finalize. Capping/slicing it would+ // silently drop the head of long agent runs and hide earlier failure+ // symptoms behind chatty progress redraws, so the buffer is allowed to grow+ // for the duration of the run. No warn, no metadata flag.+ it('rawBuffer grows without truncation warn or metadata flag', async () => {runSpawn();await flushMicrotasks();- // Feed a chunk larger than the mocked 200-byte HEADROOM in one go so the- // raw buffer trips on the first handleData call.- await capturedOnData(Buffer.from('x'.repeat(300)));+ // Push well past the previous 640KB cap to prove growth is uncapped.+ await capturedOnData(Buffer.from('x'.repeat(2 * 1024 * 1024)));await flushMicrotasks();-- // Second chunk: should NOT emit a second warn or metadata write — the- // flag is a once-per-run signal, not a per-overflow counter.- await capturedOnData(Buffer.from('x'.repeat(300)));- await flushMicrotasks();-- const truncWarns = warnSpy.mock.calls.filter(args =>- typeof args[0] === 'string' && args[0].includes('raw PTY buffer exceeded')- );- expect(truncWarns).toHaveLength(1);-- const truncMetaCalls = vi.mocked(cosAgents.updateAgent).mock.calls.filter(- ([_id, payload]) => payload?.metadata?.rawBufferTruncated === true- );- expect(truncMetaCalls).toHaveLength(1);- expect(truncMetaCalls[0][0]).toBe('agent-1');- });-- it('rawBuffer below threshold: no truncation warn or metadata flag', async () => {- runSpawn();- await flushMicrotasks();-- // 150 bytes is under the mocked 200-byte HEADROOM.- await capturedOnData(Buffer.from('x'.repeat(150)));+ await capturedOnData(Buffer.from('y'.repeat(2 * 1024 * 1024)));await flushMicrotasks();const truncWarns = warnSpy.mock.calls.filter(args =>