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: buffer image-to-3D generator output by line so a chunk-split stage banner still matches (#3578)

[._.]/ Adam Eivycb731a00dab9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index bdab35d0d0..dff0449bb4 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -188,3 +188,5 @@
- **YouTube videos can be ingested into the Brain — transcript to your Obsidian vault, with an agent queued to act on it.** Paste a single-video YouTube link into Quick Capture on the dashboard and a sliders button appears next to the input; it expands into the ingest options. Three independent checkboxes decide what is pulled in: the **transcript** (on by default), the full **video** into the media library, and the **audio** as an mp3 kept next to the transcript — at least one is required. Below them, a free-text box asks what an agent should do with the content, and a tags field. Whatever the switches say, the ingest always records that you consumed and kept the video: a Brain link record, which federates to your other machines, and a `media.watch` event so the video shows on the Timeline next to the watch history that syncs passively. Transcripts land as a note in your Obsidian vault with frontmatter carrying the title, source, channel, duration, publish date and tags. YouTube's auto-generated captions are a rolling two-line display where each cue repeats most of the one before it, so a naive strip-the-timings pass yields a transcript with every sentence in it two or three times; the captions are de-duplicated and their inline markup removed before they are written, which took a 14-minute talk from 128KB of caption file down to 14KB of readable prose. Whether the captions were human-written or machine-generated is read from the video's metadata rather than guessed from the file yt-dlp produced — it writes both kinds under the same name — and recorded alongside the transcript, because auto-captions get proper nouns wrong often enough to be worth knowing about later. A video with no captions at all is not treated as a failure: the ingest finishes, says so, and still stores everything else you asked for. Filling in the agent prompt queues a Chief of Staff task pointed at the freshly-stored transcript with your prompt as its brief; leaving it blank queues nothing, so an ingest never starts AI work you did not ask for. Which vault and folder transcripts go to, and what the checkboxes default to, are configurable under Brain → Config; an unset vault inherits the Daily Log's, so anyone who has already pointed the journal at Obsidian needs no setup at all. Playlists and channel URLs are deliberately not accepted — they fall through to ordinary link capture rather than quietly starting a 300-video download. `yt-dlp` is required for any ingest and `ffmpeg` additionally for the video/audio options, so a transcript-only ingest still works on a machine that has only the first.
- **The Daily Log's first note into a new Obsidian folder no longer silently fails to write.** Mirroring a record into a vault tried to update the note first and only created it if the update reported the note missing — but a note whose *folder* does not exist yet cannot be containment-checked at all: the path can't be resolved, so it falls back to the raw path, which fails the check against the realpath'd vault root whenever the vault is reached through a symlink. On macOS that is any vault under a `/var`-rooted path, and more generally any vault behind a symlinked home or mount. The update therefore reported "invalid path" rather than "not found", the create fallback never ran, and the day was never mirrored. Creating first and updating only on "already exists" sidesteps it entirely — the folder is ensured before the path is resolved. The two vault mirrors (Daily Log and the new YouTube transcript) now share one `upsertNote` in the Obsidian adapter instead of each carrying its own copy of that ordering rule, and it is tested against a real vault on disk rather than against stubbed calls, which is how the failure surfaced in the first place.
+
+- **[issue-3578] Image-to-3D renders no longer stall the progress bar on a stage banner that lands across two chunks.** The shared generate driver split each `data` chunk from the generator on its own, with nothing carried between them — but a child process hands out its output on arbitrary byte boundaries, so a banner like "Baking textures at 2048px" could arrive as two halves, neither of which matched any stage signature. The percent then sat where the previous banner left it until the next one happened to land whole, which on the long sampling phase reads as a hung render. Both lanes now feed their output through the same buffered line reader the rest of the app's subprocess streams use, which stitches the partial line back together and flushes whatever is left when the child exits — so a generator that writes its final "Saved:" line without a trailing newline still has its asset path read. stdout and stderr keep separate buffers, since a shared one would splice a partial line from one stream onto a chunk from the other. Tqdm's carriage-return redraws still surface as individual frames, and the raw output kept for classifying a non-zero exit is unchanged, so an out-of-memory or gated-model failure is still named the same way.
diff --git a/server/services/imageTo3d/laneRunner.js b/server/services/imageTo3d/laneRunner.js
index fe7a1dc529..ba53cb5d22 100644
--- a/server/services/imageTo3d/laneRunner.js
+++ b/server/services/imageTo3d/laneRunner.js
@@ -21,6 +21,7 @@
import { spawn } from 'node:child_process';
import { sleep as defaultSleep } from '../../lib/fileUtils.js';
import { killWithEscalation } from '../../lib/killWithEscalation.js';
+import { createLineReader } from '../../lib/streamLines.js';
/**
* Build a case-insensitive predicate testing text against an alternation of signature
@@ -189,10 +190,17 @@ export function runInstallSteps({
* the produced asset path, and resolves `{ assetPath }` once the child exits 0 and the
* asset has been post-processed.
*
- * Output is split on `\r` AND `\n`: tqdm redraws its progress bar in place with
- * carriage returns, so a single chunk can carry several frames separated only by `\r`.
- * Splitting on `\n` alone would treat them as one line and parse just the first
- * (lowest) percent — under-reporting progress during the long sampling phase.
+ * Output is split on `\r` AND `\n` via `createLineReader`: tqdm redraws its progress
+ * bar in place with carriage returns, so a single chunk can carry several frames
+ * separated only by `\r`. Splitting on `\n` alone would treat them as one line and
+ * parse just the first (lowest) percent — under-reporting progress during the long
+ * sampling phase. The reader's carry buffer is what makes that safe: chunks arrive on
+ * arbitrary byte boundaries, so a stage banner straddling two `data` events would
+ * otherwise be seen as two partial lines, match no signature, and stall the bar at the
+ * previous percent until the next banner landed (#3578). Each stream gets its OWN
+ * reader (a shared carry would splice a partial stdout line onto a stderr chunk), and
+ * both are flushed on `close` so a final unterminated line — including the `Saved:`
+ * line carrying the asset path — is still parsed.
*
* `classifiers` turn a non-zero exit into an actionable error instead of a bare
* "exited N" — each is `{ test, code, help }` and the first match wins, so a lane can
@@ -222,20 +230,27 @@ export function runGenerateSubprocess({
const child = spawnImpl(command, args, { ...(cwd ? { cwd } : {}), ...(env ? { env } : {}) });
let assetPath = initialAssetPath;
let outputTail = '';
+ const onLine = (line) => {
+ const frame = parseProgress(line);
+ if (!frame) return;
+ if (frame.assetPath) assetPath = frame.assetPath;
+ if (onProgress) onProgress(frame);
+ };
+ const stdoutReader = createLineReader(onLine, { splitRe: /[\r\n]+/ });
+ const stderrReader = createLineReader(onLine, { splitRe: /[\r\n]+/ });
+ // The tail is appended from the RAW chunk, not the parsed lines, so an exit
+ // classifier still sees text the progress parser ignored.
+ const ingest = (reader) => (buf) => {
+ outputTail = appendTail(outputTail, buf);
+ reader.push(buf);
+ };
const promise = new Promise((resolve, reject) => {
- const ingest = (buf) => {
- outputTail = appendTail(outputTail, buf);
- for (const line of String(buf).split(/[\r\n]+/)) {
- const frame = parseProgress(line);
- if (!frame) continue;
- if (frame.assetPath) assetPath = frame.assetPath;
- if (onProgress) onProgress(frame);
- }
- };
- child.stdout?.on('data', ingest);
- child.stderr?.on('data', ingest);
+ child.stdout?.on('data', ingest(stdoutReader));
+ child.stderr?.on('data', ingest(stderrReader));
child.on('error', reject);
child.on('close', (code) => {
+ stdoutReader.flush();
+ stderrReader.flush();
if (code === 0 && assetPath) {
Promise.resolve()
.then(() => (postprocessGlb ? postprocessGlb(assetPath) : undefined))
diff --git a/server/services/imageTo3d/laneRunner.test.js b/server/services/imageTo3d/laneRunner.test.js
new file mode 100644
index 0000000000..368a567dff
--- /dev/null
+++ b/server/services/imageTo3d/laneRunner.test.js
@@ -0,0 +1,115 @@
+import { EventEmitter } from 'node:events';
+import { describe, expect, it, vi } from 'vitest';
+import { runGenerateSubprocess } from './laneRunner.js';
+
+const makeChild = () => {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ child.kill = vi.fn();
+ return child;
+};
+
+// A deliberately target-agnostic stand-in for a lane's progress vocabulary: one
+// whole-line banner plus a terminal asset line. laneRunner injects the parser, so
+// its tests must not import a lane's real signatures.
+const parseProgress = (line) => {
+ const text = String(line ?? '').trim();
+ if (!text) return null;
+ const glb = text.match(/(\S+\.glb)\b/i);
+ if (glb) return { stage: 'export', percent: 92, assetPath: glb[1], message: text };
+ if (/baking .*textures?/i.test(text)) return { stage: 'texturing', percent: 65, message: text };
+ return null;
+};
+
+const run = (child, overrides = {}) => runGenerateSubprocess({
+ command: 'python',
+ args: ['gen.py'],
+ label: 'Test lane',
+ codePrefix: 'TEST',
+ parseProgress,
+ spawnImpl: () => child,
+ ...overrides,
+});
+
+describe('runGenerateSubprocess line buffering', () => {
+ it('matches a banner that straddles two data chunks', async () => {
+ // Node delivers 'data' on arbitrary byte boundaries. Without a carry buffer the
+ // banner arrives as two partial lines, neither matches, and the progress bar
+ // stalls at the previous percent until the next banner lands (#3578).
+ const child = makeChild();
+ const frames = [];
+ const { promise } = run(child, { onProgress: (f) => frames.push(f) });
+ child.stdout.emit('data', 'Baking te');
+ child.stdout.emit('data', 'xtures at 2048px...\nSaved: /out/a.glb\n');
+ child.emit('close', 0);
+ await expect(promise).resolves.toEqual({ assetPath: '/out/a.glb' });
+ expect(frames.map((f) => f.stage)).toEqual(['texturing', 'export']);
+ });
+
+ it('stitches a multibyte codepoint split across chunks instead of mangling the line', async () => {
+ const child = makeChild();
+ const frames = [];
+ const { promise } = run(child, { onProgress: (f) => frames.push(f) });
+ const banner = Buffer.from('Baking ✨ textures at 2048px...\n', 'utf8');
+ child.stdout.emit('data', banner.subarray(0, 9)); // splits the ✨
+ child.stdout.emit('data', banner.subarray(9));
+ child.stdout.emit('data', 'Saved: /out/a.glb\n');
+ child.emit('close', 0);
+ await promise;
+ expect(frames[0].message).toBe('Baking ✨ textures at 2048px...');
+ });
+
+ it('flushes a final unterminated line on close so the asset path is not lost', async () => {
+ // The generator can exit without a trailing newline on its last write; the old
+ // per-chunk split parsed that tail immediately, so flushing keeps parity.
+ const child = makeChild();
+ const { promise } = run(child);
+ child.stdout.emit('data', 'Saved: /out/a.glb');
+ child.emit('close', 0);
+ await expect(promise).resolves.toEqual({ assetPath: '/out/a.glb' });
+ });
+
+ it('keeps stdout and stderr carries separate so partial lines are never spliced', async () => {
+ // A shared carry would join stdout's 'Baking te' to stderr's chunk and
+ // fabricate a line neither stream wrote.
+ const child = makeChild();
+ const frames = [];
+ const { promise } = run(child, { onProgress: (f) => frames.push(f) });
+ child.stdout.emit('data', 'Baking te');
+ child.stderr.emit('data', 'warning: unrelated\n');
+ child.stdout.emit('data', 'xtures at 2048px...\n');
+ child.stdout.emit('data', 'Saved: /out/a.glb\n');
+ child.emit('close', 0);
+ await promise;
+ expect(frames.map((f) => f.stage)).toEqual(['texturing', 'export']);
+ });
+
+ it('still parses every \\r-separated redraw inside one chunk', async () => {
+ const child = makeChild();
+ const frames = [];
+ const { promise } = run(child, { onProgress: (f) => frames.push(f) });
+ child.stdout.emit('data', 'Baking textures at 512px\rBaking textures at 2048px\r');
+ child.stdout.emit('data', 'Saved: /out/a.glb\n');
+ child.emit('close', 0);
+ await promise;
+ expect(frames.map((f) => f.message)).toEqual([
+ 'Baking textures at 512px',
+ 'Baking textures at 2048px',
+ 'Saved: /out/a.glb',
+ ]);
+ });
+
+ it('classifies a non-zero exit from the raw output tail, not the parsed lines', async () => {
+ // The tail is appended from the raw chunk, so a classifier still matches text
+ // the parser ignored — including a signature split across chunks.
+ const child = makeChild();
+ const { promise } = run(child, {
+ classifiers: [{ test: (t) => /out of memory/i.test(t), code: 'TEST_OOM', help: 'Free some VRAM.' }],
+ });
+ child.stderr.emit('data', 'torch.OutOfMemoryError: CUDA out of ');
+ child.stderr.emit('data', 'memory. Tried to allocate 2.00 GiB');
+ child.emit('close', 1);
+ await expect(promise).rejects.toMatchObject({ code: 'TEST_OOM' });
+ });
+});
diff --git a/server/services/imageTo3d/trellis2.test.js b/server/services/imageTo3d/trellis2.test.js
index 277a2bc307..7b9b4d61cf 100644
--- a/server/services/imageTo3d/trellis2.test.js
+++ b/server/services/imageTo3d/trellis2.test.js
@@ -448,6 +448,28 @@ describe('runTrellis2Generate', () => {
expect(frames.map((f) => f.percent)).toEqual([10, 30, 50, 92]);
});
+ it('matches a stage banner that arrives split across two stdout chunks', async () => {
+ // Real-vocabulary cover for the shared carry buffer (#3578): 'Baking textures'
+ // straddling a chunk boundary used to match no GENERATE_STAGE_SIGNATURES entry,
+ // stalling the bar at the previous percent until the next banner landed.
+ const child = makeChild();
+ const frames = [];
+ const { promise } = runTrellis2Generate({
+ imagePath: 'a.png',
+ outputPath: '/out/a.glb',
+ base: BASE,
+ exists: installed,
+ spawnImpl: () => child,
+ postprocessGlb: vi.fn(async () => {}),
+ onProgress: (f) => frames.push(f),
+ });
+ child.stdout.emit('data', 'Baking te');
+ child.stdout.emit('data', 'xtures at 2048px...\n Saved: /out/a.glb\n');
+ child.emit('close', 0);
+ await expect(promise).resolves.toEqual({ assetPath: '/out/a.glb' });
+ expect(frames.map((f) => f.stage)).toEqual(['texturing', 'export']);
+ });
+
it('selects the high-quality pipeline and 4K atlas on a high-memory host', async () => {
const child = makeChild();
const spawnImpl = vi.fn(() => child);