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

address review (codex): strip codex transcript from CLI vision text, honor provider timeout, parse bare-array crop proposals

Adam Eivy2a867bf3f987
diff --git a/server/services/loraDatasetGenerate.js b/server/services/loraDatasetGenerate.js
index 9676cb5ae4..da903fef00 100644
--- a/server/services/loraDatasetGenerate.js
+++ b/server/services/loraDatasetGenerate.js
@@ -519,9 +519,19 @@ export async function proposeCropRegions(sheetPath, dims, {
});
if (!result?.text) return [];
- const { value } = extractJson(result.text, {
- shapePredicate: (v) => Array.isArray(v?.boxes) || Array.isArray(v),
- });
+ // The model may answer with the documented `{"boxes":[…]}` OR a bare top-level
+ // array `[{…}]`. extractJson defaults to walking `{…}` blocks — for a bare
+ // array it would return the first inner box OBJECT (its no-predicate-match
+ // fallback), which normalizeCropProposals can't use. So accept the object
+ // form only when it actually carries a `boxes` array; otherwise walk for a
+ // top-level array block. This keeps a valid bare-array reply from silently
+ // falling back to the grid.
+ const objValue = extractJson(result.text, {
+ shapePredicate: (v) => Array.isArray(v?.boxes),
+ }).value;
+ const value = Array.isArray(objValue?.boxes)
+ ? objValue
+ : extractJson(result.text, { blockType: 'array' }).value;
const rects = normalizeCropProposals(value, dims);
if (rects.length) {
console.log(`🔎 Vision proposed ${rects.length} crop region(s) via ${resolved.model}`);
diff --git a/server/services/loraDatasetGenerate.test.js b/server/services/loraDatasetGenerate.test.js
index fa4711d571..1eb354def6 100644
--- a/server/services/loraDatasetGenerate.test.js
+++ b/server/services/loraDatasetGenerate.test.js
@@ -251,6 +251,15 @@ describe('proposeCropRegions', () => {
expect(rects).toEqual([{ left: 450, top: 0, width: 450, height: 600 }]);
});
+ it('parses the bare top-level array form (not just {boxes:[…]})', async () => {
+ const describeImage = vi.fn().mockResolvedValue({
+ text: '[{"x":0,"y":0,"w":0.5,"h":1.0}]',
+ });
+ const resolveModel = vi.fn().mockResolvedValue({ providerId: 'lmstudio', model: 'qwen2.5-vl' });
+ const rects = await proposeCropRegions('/sheet.png', dims, { describeImage, resolveModel, readImage });
+ expect(rects).toEqual([{ left: 0, top: 0, width: 450, height: 600 }]);
+ });
+
it('returns [] (→ grid fallback) when no vision model resolves', async () => {
const describeImage = vi.fn();
const resolveModel = vi.fn().mockRejectedValue(new Error('no vision model'));
diff --git a/server/services/visionCli.js b/server/services/visionCli.js
index 70218312a1..03afdf7901 100644
--- a/server/services/visionCli.js
+++ b/server/services/visionCli.js
@@ -29,6 +29,7 @@ import { tmpdir } from 'os';
import { join } from 'path';
import { buildCliArgs } from '../lib/cliProviderArgs.js';
import { resolveCliModel } from '../lib/providerModels.js';
+import { extractCodexAssistant } from '../lib/codexAssistantExtract.js';
const CLI_VISION_TIMEOUT_MS = 120000;
const IMAGE_BASENAME = 'vision-input.png';
@@ -141,7 +142,12 @@ export async function describeImageViaCli({
child.stderr?.on('data', (d) => { err += d.toString(); });
child.on('close', (code) => {
clearTimers();
- if (code === 0) return resolve(out.trim());
+ // `codex exec` prints the whole session transcript (banner, echoed
+ // prompt, tool sections, `tokens used` footer) to stdout — carve out
+ // the assistant reply so captioning doesn't persist the transcript as
+ // the caption. A no-op for non-codex output (extractCodexAssistant
+ // returns its input unless it starts with the Codex banner).
+ if (code === 0) return resolve(extractCodexAssistant(out).trim());
const tail = err.trim().split('\n').slice(-4).join('\n');
reject(new Error(`${command} vision call exited ${code}${tail ? `: ${tail}` : ''}`));
});
diff --git a/server/services/visionCli.test.js b/server/services/visionCli.test.js
index 37cca180ef..91a3135234 100644
--- a/server/services/visionCli.test.js
+++ b/server/services/visionCli.test.js
@@ -94,6 +94,33 @@ describe('describeImageViaCli', () => {
expect(spawnImpl).toHaveBeenCalledOnce();
});
+ it('strips the codex session transcript down to the assistant reply', async () => {
+ const child = makeFakeChild();
+ const spawnImpl = vi.fn(() => child);
+ const promise = describeImageViaCli({
+ provider: { id: 'codex', command: 'codex', args: [] },
+ dataUrl: PNG_DATA_URL,
+ prompt: 'caption',
+ model: 'gpt-5',
+ spawnImpl,
+ });
+ await new Promise((r) => setTimeout(r, 10));
+ // A realistic codex exec transcript: banner … \ncodex\n<reply>\ntokens used …
+ const transcript = [
+ 'OpenAI Codex v0.141.0',
+ '--------',
+ 'user',
+ 'caption',
+ 'codex',
+ 'a woman in a red cloak, bust shot',
+ 'tokens used: 1234',
+ ].join('\n');
+ child.stdout.emit('data', Buffer.from(transcript));
+ child.emit('close', 0);
+ const result = await promise;
+ expect(result.text).toBe('a woman in a red cloak, bust shot');
+ });
+
it('rejects with a tail of stderr on a non-zero exit', async () => {
const child = makeFakeChild();
const spawnImpl = vi.fn(() => child);
diff --git a/server/services/visionTest.js b/server/services/visionTest.js
index 4601503617..02393634e7 100644
--- a/server/services/visionTest.js
+++ b/server/services/visionTest.js
@@ -264,6 +264,10 @@ export async function describeImageDataUrlDetailed({ dataUrl, prompt, providerId
if (provider.type === 'cli') {
return describeImageViaCli({
provider, dataUrl, prompt: prompt || 'Describe what you see in this image.', model,
+ // Honor the provider's configured timeout (seeded codex/claude CLI
+ // providers allow 300s/900s) — a vision caption/crop run can outlast the
+ // CLI path's 120s default. Falls back to that default when unset.
+ ...(provider.timeout ? { timeout: provider.timeout } : {}),
});
}
if (provider.type !== 'api') throw new Error(`Provider '${providerId}' is not an API provider (type: ${provider.type})`);
diff --git a/server/services/visionTest.test.js b/server/services/visionTest.test.js
index 1ccd0229f9..aa2d02a481 100644
--- a/server/services/visionTest.test.js
+++ b/server/services/visionTest.test.js
@@ -323,6 +323,13 @@ describe('Vision Test Service', () => {
await expect(describeImageDataUrlDetailed({ dataUrl: DATA_URL, prompt: 'x', providerId: 'codex-tui' }))
.rejects.toThrow(/not an API provider/);
});
+
+ it('forwards the CLI provider timeout to the CLI vision path', async () => {
+ getProviderById.mockResolvedValue({ id: 'codex', type: 'cli', command: 'codex', timeout: 300000 });
+ describeImageViaCli.mockResolvedValue({ text: 'ok', finishReason: null, usage: null, reasoning: '' });
+ await describeImageDataUrlDetailed({ dataUrl: DATA_URL, prompt: 'caption', providerId: 'codex' });
+ expect(describeImageViaCli).toHaveBeenCalledWith(expect.objectContaining({ timeout: 300000 }));
+ });
});
describe('checkVisionHealth', () => {