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, claude): raise vision token budget + tighten image-format gate

[._.]/ Adam Eivye060b04e1e27
diff --git a/client/src/components/digital-twin/tabs/AppearanceTab.jsx b/client/src/components/digital-twin/tabs/AppearanceTab.jsx
index 41ac8cb3a2..e8832311bc 100644
--- a/client/src/components/digital-twin/tabs/AppearanceTab.jsx
+++ b/client/src/components/digital-twin/tabs/AppearanceTab.jsx
@@ -17,6 +17,12 @@ import ProviderModelSelector from '../../ProviderModelSelector';
// JSON body limit and vision providers don't choke on huge payloads.
const MAX_IMAGE_BYTES = 10 * 1024 * 1024; // 10MB
+// Mirror the server's identityImageInputSchema regex so an unsupported format
+// (e.g. an iPhone HEIC) is rejected here with a clear message naming the real
+// cause, instead of passing the loose image/* gate and failing a generic 400.
+const ACCEPTED_MIME = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
+const ACCEPT_ATTR = ACCEPTED_MIME.join(',');
+
const DETAIL_FIELDS = [
{ key: 'appearance', label: 'Appearance' },
{ key: 'presentation', label: 'Presentation' },
@@ -40,8 +46,8 @@ export default function AppearanceTab({ onRefresh }) {
const handleFile = (file) => {
if (!file) return;
- if (!file.type.startsWith('image/')) {
- toast.error('Please choose an image file');
+ if (!ACCEPTED_MIME.includes(file.type)) {
+ toast.error('Unsupported format — use a PNG, JPEG, GIF, or WebP image');
return;
}
if (file.size > MAX_IMAGE_BYTES) {
@@ -157,7 +163,7 @@ export default function AppearanceTab({ onRefresh }) {
id="appearance-image"
ref={fileInputRef}
type="file"
- accept="image/*"
+ accept={ACCEPT_ATTR}
onChange={(e) => handleFile(e.target.files?.[0])}
disabled={analyzing}
className="hidden"
diff --git a/server/services/digital-twin-image-identity.js b/server/services/digital-twin-image-identity.js
index fcc3a63e1b..277775822c 100644
--- a/server/services/digital-twin-image-identity.js
+++ b/server/services/digital-twin-image-identity.js
@@ -28,6 +28,11 @@ const IDENTITY_DOC = {
category: 'core'
};
+// The vision helper defaults to a short-answer budget (500); the structured
+// JSON response here (four prose fields, descriptors, summary, and a woven
+// markdown document) needs considerably more headroom.
+const VISION_MAX_TOKENS = 1500;
+
/**
* Analyze a photo of the user and extract visible appearance / presentation
* descriptors.
@@ -59,18 +64,22 @@ export async function analyzeIdentityImage({ imageDataUrl, providerId, model })
}
// describeImageDataUrl throws on provider/transport errors; translate to the
- // { error } shape the rest of the digital-twin services use.
- const text = await describeImageDataUrl({ dataUrl: imageDataUrl, prompt, providerId, model })
- .catch((err) => ({ __error: err?.message || 'Vision request failed' }));
-
- if (text && typeof text === 'object' && text.__error) {
- return { error: text.__error };
+ // { error } shape the rest of the digital-twin services use. The structured
+ // JSON (profiles + woven documentMarkdown) needs more than the vision
+ // helper's short-answer default budget, so raise maxTokens or the reply
+ // truncates mid-JSON and fails to parse.
+ const vision = await describeImageDataUrl({ dataUrl: imageDataUrl, prompt, providerId, model, maxTokens: VISION_MAX_TOKENS })
+ .then((text) => ({ text }))
+ .catch((err) => ({ error: err?.message || 'Vision request failed' }));
+
+ if (vision.error) {
+ return { error: vision.error };
}
- if (!text) {
+ if (!vision.text) {
return { error: 'Vision model returned an empty response' };
}
- return parseIdentityImage(text);
+ return parseIdentityImage(vision.text);
}
/**
diff --git a/server/services/digital-twin-image-identity.test.js b/server/services/digital-twin-image-identity.test.js
index 3ef6d0cca1..5ac160979b 100644
--- a/server/services/digital-twin-image-identity.test.js
+++ b/server/services/digital-twin-image-identity.test.js
@@ -127,9 +127,12 @@ describe('analyzeIdentityImage', () => {
const r = await analyzeIdentityImage({ imageDataUrl: DATA_URL, providerId: 'p1', model: 'm' });
expect(r.error).toBeUndefined();
expect(r.suggestedDocument.filename).toBe('APPEARANCE.md');
+ // Must raise the vision token budget above the short-answer default, or the
+ // structured JSON reply truncates mid-output and fails to parse.
expect(describeImageDataUrl).toHaveBeenCalledWith(
expect.objectContaining({ dataUrl: DATA_URL, prompt: 'PROMPT', providerId: 'p1', model: 'm' })
);
+ expect(describeImageDataUrl.mock.calls[0][0].maxTokens).toBeGreaterThan(500);
});
});
diff --git a/server/services/visionTest.js b/server/services/visionTest.js
index 168e8c5350..52af14dbd0 100644
--- a/server/services/visionTest.js
+++ b/server/services/visionTest.js
@@ -60,9 +60,13 @@ async function loadImageAsBase64(imagePath) {
* @param {string} options.imageDataUrl - Base64 image data URL
* @param {string} options.prompt - Prompt to send with image
* @param {number} options.timeout - Request timeout in ms
+ * @param {number} [options.maxTokens=500] - Completion budget. The default suits
+ * short "describe this" calls; callers that ask the model for a larger
+ * structured response (e.g. a JSON object) must raise it or the reply
+ * truncates mid-output and fails to parse.
* @returns {Promise<Object>} - API response
*/
-async function callVisionAPI({ endpoint, apiKey, model, imageDataUrl, prompt, timeout = DEFAULT_VISION_TIMEOUT_MS }) {
+async function callVisionAPI({ endpoint, apiKey, model, imageDataUrl, prompt, timeout = DEFAULT_VISION_TIMEOUT_MS, maxTokens = 500 }) {
await ensureOllamaProviderReady({ endpoint }).then((ready) => {
if (!ready.success) throw new Error(`Ollama is not running and PortOS could not start it: ${ready.error || 'unknown error'}`);
});
@@ -92,7 +96,7 @@ async function callVisionAPI({ endpoint, apiKey, model, imageDataUrl, prompt, ti
]
}
],
- max_tokens: 500,
+ max_tokens: maxTokens,
temperature: 0.1
})
}, timeout);
@@ -215,9 +219,11 @@ export async function testVision({ imagePath, prompt, expectedContent, providerI
* @param {string} options.prompt - What to ask about the image
* @param {string} [options.providerId='lmstudio'] - Vision-capable API provider
* @param {string} [options.model] - Model override (defaults to provider default)
+ * @param {number} [options.maxTokens] - Completion budget; raise it above the
+ * default when asking the model for a long/structured reply (see callVisionAPI).
* @returns {Promise<string>} - The model's description text
*/
-export async function describeImageDataUrl({ dataUrl, prompt, providerId = 'lmstudio', model }) {
+export async function describeImageDataUrl({ dataUrl, prompt, providerId = 'lmstudio', model, maxTokens }) {
if (typeof dataUrl !== 'string' || !dataUrl.startsWith('data:image/')) {
throw new Error('dataUrl must be a base64 image data URL');
}
@@ -234,6 +240,7 @@ export async function describeImageDataUrl({ dataUrl, prompt, providerId = 'lmst
imageDataUrl: dataUrl,
prompt: prompt || 'Describe what you see in this image.',
timeout: provider.timeout || DEFAULT_VISION_TIMEOUT_MS,
+ ...(maxTokens != null ? { maxTokens } : {}),
});
return apiResponse.choices?.[0]?.message?.content || '';
}