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([issue-2952]): match TRELLIS.2 runner to the real generate.py CLI

[._.]/ Adam Eivy3a90622539a3
diff --git a/server/services/imageTo3d/trellis2.js b/server/services/imageTo3d/trellis2.js
index a894b1d368..95e16edee0 100644
--- a/server/services/imageTo3d/trellis2.js
+++ b/server/services/imageTo3d/trellis2.js
@@ -84,43 +84,85 @@ export function buildInstallSteps(base, { exists = existsSync } = {}) {
}
/**
- * The generate invocation: `<venv-python> generate.py <image> [--output <glb>]`.
+ * The port's `--output` is a filename **stem**, NOT a full path — `generate.py`
+ * appends the extension itself (`glb_path = f"{args.output}.glb"`, plus sibling
+ * `.obj` / `_basecolor.png`). Callers hand us the real disk path they want the GLB
+ * at (`…/model.glb`), so strip a single trailing `.glb` before it reaches the CLI —
+ * otherwise the port writes `…/model.glb.glb` and PortOS serves a 404 at `…/model.glb`.
+ * Confirmed against the real `generate.py` during #2952 hands-on validation.
+ * @param {string} outputPath
+ * @returns {string}
+ */
+export function trellis2OutputStem(outputPath) {
+ return String(outputPath).replace(/\.glb$/i, '');
+}
+
+/**
+ * The generate invocation: `<venv-python> generate.py <image> [--output <stem>]`.
* Pure. Throws when no source image is given (a render with no input is a bug, not
- * an empty run).
+ * an empty run). `outputPath` is the desired `.glb` disk path; it is reduced to the
+ * stem the port expects (see `trellis2OutputStem`).
* @param {{imagePath: string, outputPath?: string, base?: string}} opts
* @returns {{command: string, args: string[]}}
*/
export function buildGenerateArgs({ imagePath, outputPath, base } = {}) {
if (!imagePath) throw new Error('buildGenerateArgs: imagePath is required');
const args = [trellis2GenerateScript(base), imagePath];
- if (outputPath) args.push('--output', outputPath);
+ if (outputPath) args.push('--output', trellis2OutputStem(outputPath));
return { command: trellis2VenvPython(base), args };
}
+/**
+ * The port's real progress vocabulary, confirmed against `generate.py` during #2952
+ * hands-on validation. `generate.py` prints **no overall percentage** — it emits an
+ * ordered sequence of stage banners (plus per-phase `tqdm` sampling bars). Each
+ * banner maps to a fixed, monotonically-increasing whole-render percent so the UI
+ * advances through a multi-minute render instead of sitting at 0 until the final
+ * `Saved:` line. Order is roughly: load model → sample (the long phase) → decode
+ * mesh → bake textures → export. Ordered most-specific first.
+ */
+const GENERATE_STAGE_SIGNATURES = [
+ { re: /loading pipeline/i, stage: 'loading', percent: 3 },
+ { re: /^device:/i, stage: 'loading', percent: 5 },
+ { re: /generating 3d model/i, stage: 'generating', percent: 10 },
+ { re: /^mesh:\s/i, stage: 'meshing', percent: 55 },
+ { re: /generation time/i, stage: 'meshing', percent: 58 },
+ { re: /baking .*textures?/i, stage: 'texturing', percent: 65 },
+ { re: /(uv unwrap|simplifying mesh)/i, stage: 'texturing', percent: 72 },
+];
+
/**
* Parse one line of `generate.py` output into a progress frame, or null when the
- * line carries no signal. Format-agnostic on purpose (the port's exact wording is
- * confirmed during hands-on validation): it extracts a percentage and/or a written
- * `.glb` path rather than matching guessed internal stage names.
+ * line carries no signal. The port has no single overall percentage, so this maps
+ * its real stage banners to monotonic percents (see `GENERATE_STAGE_SIGNATURES`),
+ * treats a written `.glb` path as the terminal export signal (carrying the asset
+ * path), and scales a bare `tqdm` percentage into the sampling band `[10,50]` — a
+ * per-phase bar hits 100% three times, so a raw pass-through would prematurely fill
+ * the whole render's bar during the first phase; scaling keeps it inside the sampler
+ * stage while the later banners carry it home.
* @param {string} line
* @returns {{stage: string, percent?: number, assetPath?: string, message: string}|null}
*/
export function parseGenerateProgress(line) {
const text = String(line ?? '').trim();
if (!text) return null;
- const pct = text.match(/(\d{1,3})\s*%/);
+
+ // A written .glb is the terminal export signal — it carries the produced asset path.
const glb = text.match(/(\S+\.glb)\b/i);
- const frame = { message: text };
- if (pct) frame.percent = Math.min(100, Number(pct[1]));
- if (glb) {
- frame.stage = 'export';
- frame.assetPath = glb[1];
- } else if (pct) {
- frame.stage = 'generating';
- } else {
- return null;
+ if (glb) return { stage: 'export', percent: 92, assetPath: glb[1], message: text };
+
+ // Named stage banners drive the whole-render percent.
+ for (const sig of GENERATE_STAGE_SIGNATURES) {
+ if (sig.re.test(text)) return { stage: sig.stage, percent: sig.percent, message: text };
+ }
+
+ // A bare percentage is a per-phase tqdm sampling bar — scale into the sampling band.
+ const pct = text.match(/(\d{1,3})\s*%/);
+ if (pct) {
+ const raw = Math.min(100, Number(pct[1]));
+ return { stage: 'generating', percent: 10 + Math.round(raw * 0.4), message: text };
}
- return frame;
+ return null;
}
/**
diff --git a/server/services/imageTo3d/trellis2.test.js b/server/services/imageTo3d/trellis2.test.js
index 8e67a88ccb..f934682737 100644
--- a/server/services/imageTo3d/trellis2.test.js
+++ b/server/services/imageTo3d/trellis2.test.js
@@ -7,6 +7,7 @@ import {
trellis2GenerateScript,
isTrellis2Installed,
buildInstallSteps,
+ trellis2OutputStem,
buildGenerateArgs,
parseGenerateProgress,
runTrellis2Generate,
@@ -68,6 +69,21 @@ describe('buildInstallSteps', () => {
});
});
+describe('trellis2OutputStem', () => {
+ it('strips a single trailing .glb (the port appends the extension itself)', () => {
+ expect(trellis2OutputStem('/data/image-to-3d/abc/model.glb')).toBe('/data/image-to-3d/abc/model');
+ });
+
+ it('is case-insensitive on the extension', () => {
+ expect(trellis2OutputStem('/out/Model.GLB')).toBe('/out/Model');
+ });
+
+ it('leaves a stem with no .glb extension untouched (and does not eat a mid-path .glb)', () => {
+ expect(trellis2OutputStem('/out/model')).toBe('/out/model');
+ expect(trellis2OutputStem('/out/model.glb.tmp')).toBe('/out/model.glb.tmp');
+ });
+});
+
describe('buildGenerateArgs', () => {
it('invokes the venv python with generate.py and the image', () => {
const { command, args } = buildGenerateArgs({ imagePath: '/data/images/x.png', base: BASE });
@@ -75,9 +91,9 @@ describe('buildGenerateArgs', () => {
expect(args).toEqual([trellis2GenerateScript(BASE), '/data/images/x.png']);
});
- it('appends --output when an output path is given', () => {
- const { args } = buildGenerateArgs({ imagePath: 'in.png', outputPath: 'out.glb', base: BASE });
- expect(args).toEqual([trellis2GenerateScript(BASE), 'in.png', '--output', 'out.glb']);
+ it('passes --output as a STEM — the port appends .glb, so a full path would double it', () => {
+ const { args } = buildGenerateArgs({ imagePath: 'in.png', outputPath: '/out/model.glb', base: BASE });
+ expect(args).toEqual([trellis2GenerateScript(BASE), 'in.png', '--output', '/out/model']);
});
it('throws when no source image is given', () => {
@@ -86,23 +102,52 @@ describe('buildGenerateArgs', () => {
});
describe('parseGenerateProgress', () => {
- it('extracts a percentage as a generating frame', () => {
- expect(parseGenerateProgress('sampling 42%')).toMatchObject({ stage: 'generating', percent: 42 });
+ // The real generate.py banners (see the module's GENERATE_STAGE_SIGNATURES),
+ // in the order the port prints them, and the monotonic percent each maps to.
+ it.each([
+ ['Loading pipeline...', 'loading', 3],
+ ['Device: MPS', 'loading', 5],
+ ['Generating 3D model (pipeline=512, seed=42)...', 'generating', 10],
+ ['Mesh: 812,043 vertices, 1,604,201 triangles', 'meshing', 55],
+ ['Generation time: 214.7s', 'meshing', 58],
+ ['Baking PBR textures via KDTree (1024x1024)...', 'texturing', 65],
+ [' UV unwrapping with xatlas...', 'texturing', 72],
+ [' Simplifying mesh: 1,604,201 -> ~200,000 faces', 'texturing', 72],
+ ])('maps the %o banner to a %s frame at %i%%', (line, stage, percent) => {
+ expect(parseGenerateProgress(line)).toMatchObject({ stage, percent, message: line.trim() });
});
- it('clamps an over-100 percentage', () => {
- expect(parseGenerateProgress('999%').percent).toBe(100);
+ it('the banner percents increase monotonically in emission order', () => {
+ const order = [
+ 'Loading pipeline...', 'Device: MPS', 'Generating 3D model (pipeline=512)...',
+ 'Mesh: 8 vertices, 8 triangles', 'Generation time: 1s',
+ 'Baking PBR textures via Metal (1024x1024)...',
+ ];
+ const percents = order.map((l) => parseGenerateProgress(l).percent);
+ for (let i = 1; i < percents.length; i += 1) expect(percents[i]).toBeGreaterThan(percents[i - 1]);
});
- it('recognizes a written .glb as an export frame carrying the asset path', () => {
- expect(parseGenerateProgress('saved /out/model.glb')).toMatchObject({
+ it('recognizes a written .glb as the terminal export frame carrying the asset path', () => {
+ expect(parseGenerateProgress(' Saved: /out/model.glb')).toMatchObject({
stage: 'export',
+ percent: 92,
assetPath: '/out/model.glb',
});
});
+ it('scales a bare per-phase tqdm bar into the sampling band [10,50] (never fills early)', () => {
+ // tqdm hits 100% once per sampling phase (three phases); a raw pass-through would
+ // fill the whole-render bar during phase 1. Scaled, even 100% stays inside sampling.
+ expect(parseGenerateProgress('Sampling: 100%|██████████| 12/12').percent).toBe(50);
+ expect(parseGenerateProgress('Sampling: 0%| | 0/12').percent).toBe(10);
+ expect(parseGenerateProgress('Sampling: 50%|█████ | 6/12')).toMatchObject({
+ stage: 'generating', percent: 30,
+ });
+ });
+
it('returns null for lines with no signal, and for blank lines', () => {
- expect(parseGenerateProgress('loading pipeline weights')).toBeNull();
+ expect(parseGenerateProgress('Input: /tmp/shoe.png (1024x1024)')).toBeNull();
+ expect(parseGenerateProgress('Saved: /out/model.obj')).toBeNull(); // .obj sidecar, not the GLB
expect(parseGenerateProgress(' ')).toBeNull();
expect(parseGenerateProgress(undefined)).toBeNull();
});
@@ -142,13 +187,15 @@ describe('runTrellis2Generate', () => {
[trellis2GenerateScript(BASE), 'a.png'],
{ cwd: trellis2Root(BASE) },
);
- child.stdout.emit('data', 'sampling 50%\n');
- child.stdout.emit('data', 'saved /out/a.glb\n');
+ child.stdout.emit('data', 'Generating 3D model (pipeline=512, seed=42)...\n');
+ child.stdout.emit('data', 'Sampling: 50%|█████ | 6/12\n');
+ child.stdout.emit('data', ' Saved: /out/a.glb\n');
child.emit('close', 0);
await expect(promise).resolves.toEqual({ assetPath: '/out/a.glb' });
expect(frames).toEqual([
- { stage: 'generating', percent: 50, message: 'sampling 50%' },
- { stage: 'export', assetPath: '/out/a.glb', message: 'saved /out/a.glb' },
+ { stage: 'generating', percent: 10, message: 'Generating 3D model (pipeline=512, seed=42)...' },
+ { stage: 'generating', percent: 30, message: 'Sampling: 50%|█████ | 6/12' },
+ { stage: 'export', percent: 92, assetPath: '/out/a.glb', message: 'Saved: /out/a.glb' },
]);
});