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: lazy-join raw chunks + fix stale comment + fix changelog cap value
Adam Eivyf5cec4e3b279
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex beb2f8cf55..9523515ca1 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -17,4 +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.+- 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 stores raw PTY output as an array of chunks (joined lazily, only on failure, to avoid O(n²) string-concat under chatty TUIs); `outputBuffer` keeps its existing 8MB cap / 10MB headroom (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 ce8e8b9fa6..12d550b3f6 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -131,8 +131,10 @@ export async function spawnTuiAgent({// rawBuffer is stored as an array of chunks (not `let rawBuffer = ''` with// `+=`) because a chatty TUI emits hundreds of chunks/sec and `string += x`// is O(n²) — every append reallocates and copies the full prior string.- // Joined only at finalize (single linear pass) and during the brief paste-- // marker polling window. See `getRawBuffer()` / `joinPostPaste()` helpers.+ // The array is joined lazily: only on failure (analyzeAgentFailure needs+ // a single string) and during the brief paste-marker polling window+ // (`rawChunks.slice(pasteChunkStart).join('')`), so successful runs never+ // pay the linear-time join.const rawChunks = [];let finalized = false;let hasStartedWorking = false;@@ -239,9 +241,21 @@ export async function spawnTuiAgent({// do NOT writeFile() it from outputBuffer at finalize — outputBuffer is// capped at OUTPUT_BUFFER_CAP and would silently truncate the on-disk// record for long runs. The append-only stream is the authoritative copy.- const rawBuffer = rawChunks.length ? rawChunks.join('') : '';- const analysisBuffer = rawBuffer || outputBuffer;- const errorAnalysis = finalSuccess ? null : analyzeAgentFailure(analysisBuffer, task, model);+ //+ // The raw chunks are only joined when analyzeAgentFailure will actually+ // run — successful runs skip the join entirely (large PTY streams can+ // be tens of MB; joining + the analyzer's linear scan would double peak+ // memory on every clean completion).+ const errorAnalysis = finalSuccess+ ? null+ : analyzeAgentFailure(+ rawChunks.length ? rawChunks.join('') : outputBuffer,+ task,+ model+ );+ // Drop chunk refs once the analyzer is done so GC can reclaim them+ // before the heavier finalizeAgent / cleanupWorktreeFn chain runs.+ rawChunks.length = 0;// try/finally so a throw from finalizeAgent (e.g. processAgentCompletion// hook crash) still runs the local cleanup — sentinel removal, worktree