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
unlink a staged reference upload when the prompt gate rejects the render
[._.]/ Adam Eivy4679fc6f00dd
diff --git a/PLAN.md b/PLAN.mdindex 40348ab92c..5f87c603c7 100644--- a/PLAN.md+++ b/PLAN.md@@ -327,10 +327,6 @@ is not reliably announced.- [ ] `client/src/components/imageGen/GalleryImagePicker.jsx` gained an `allowUpload` prop (#2953) that encapsulates the file → `readFileAsBase64` → `uploadGalleryImage` → normalize → select flow inside the shared picker. Three existing callers still roll their own upload path with a separate file `<input>` + `toast` alongside the picker: `client/src/components/music/AlbumsManager.jsx:177`, `client/src/components/music/ArtistsManager.jsx:147`, and `client/src/pages/Authors.jsx:167`. Migrate each to `<GalleryImagePicker allowUpload>` and delete the bespoke upload handlers so the duplication the prop was designed to end actually collapses. Deferred from #2953 (adjacent files outside that issue's scope). Surfaced by the /simplify altitude review.-### Let Agy renders take reference images (it is not text-to-image-only)--- [ ] PortOS treats the Agy backend as text-to-image-only: `server/services/imageGen/prepareParams.js` and `agy.js#generateImage` both hard-400 with `AGY_IMAGE_EDIT_UNSUPPORTED` when an `initImagePath`/`referenceImagePaths` is present, and `I2I_CAPABLE_MODES` (`client/src/lib/imageGenModes.js`) omits agy. That is wrong — dumping `generate_image`'s schema from a live agy 1.1.8 session shows an `ImagePaths` parameter: *"Optional absolute paths to the images to use in generation. You can pass in images here if you would like to edit, combine, or use as references… you cannot pass in more than 3 images."* So agy supports i2i, reference conditioning, and multi-image combination, and PortOS is declining all three. Wire it the way `AspectRatio` was: direct the absolute staging paths in `buildAgyPrompt` (they must be absolute — agy ignores relative paths with no active workspace), cap at 3, drop the 400s, and add agy to `I2I_CAPABLE_MODES` + `pickI2iMode`'s ladder. Note grok's `describeFidelity` phrasing is the precedent for mapping the local runner's numeric `strength` onto words for a CLI with no denoise knob. Verify against pixels, not agy's self-report — it will confidently claim it honored requests it ignored (see `AGY_IMAGEGEN_IMAGE_MODEL` in `services/imageGen/modes.js`). Surfaced while re-probing agy's model-selection channels on 2026-07-30.-### Let the Image Gen "Test Render" panel pick its provider- [ ] `client/src/components/settings/ImageGenTab.jsx` — Test Connection now probes the provider whose sub-tab is open, but the Test tab's `handleRenderTest` still renders with `saved.mode` (the saved default backend). So a user who wants to smoke-test an Agy or Grok render must first make it their default, which is the same friction the Test Connection fix just removed. Add a provider `<select>` to the Test Render panel (default: the saved backend, options limited to enabled backends via `isModeUsable`/`pickUsableMode`'s client mirror), thread the chosen mode into `generateImage({ mode })`, and update the panel copy from "the active backend" to name the selected one. Out of scope for the Test Connection fix (needs new UI, not a re-target of an existing call). Surfaced by the /simplify altitude review.diff --git a/server/routes/imageGen.multipart.test.js b/server/routes/imageGen.multipart.test.jsindex 9f4ed2c0fe..60d9ca9863 100644--- a/server/routes/imageGen.multipart.test.js+++ b/server/routes/imageGen.multipart.test.js@@ -333,6 +333,57 @@ describe('POST /api/image-gen/generate — multipart reference-image packing', (for (const p of params.referenceImagePaths) expect(p.startsWith(refsSandbox)).toBe(true);});+ it('unlinks an already-staged ref when the prompt gate rejects a prompt-less agy render', async () => {+ // The one throw that can fire with an upload ALREADY copied into+ // PATHS.imageRefs: agy's tool lists `Prompt` as required, so a prompt-less+ // agy render carrying a reference gets past the pre-stage gates, stages the+ // file, and only then is rejected. Nothing downstream knows that file+ // exists — the route's res.on('close') sweep is wired from the return value+ // this throw prevents — so the throw itself has to unlink it.+ mockedSettings = { imageGen: { mode: 'agy', agy: { enabled: true } } };+ const tmpRoot = tmpdir();+ const beforeTmp = new Set((await readdir(tmpRoot).catch(() => []))+ .filter((f) => f.startsWith('upload-')));++ const res = await postMultipart(app, '/api/image-gen/generate', [+ { name: 'referenceImage1', filename: 'a.png', contentType: 'image/png', value: PNG_FIXTURE },+ ]);++ expect(res.status).toBe(400);+ expect(res.body.error || res.body).toMatch(/prompt is required/i);+ expect(enqueueJob).not.toHaveBeenCalled();+ await new Promise((r) => setTimeout(r, 50));+ const refDirContents = await readdir(refsSandbox).catch(() => []);+ expect(refDirContents.filter((f) => f.startsWith('ref-'))).toHaveLength(0);+ const afterTmp = new Set((await readdir(tmpRoot).catch(() => []))+ .filter((f) => f.startsWith('upload-')));+ expect([...afterTmp].filter((f) => !beforeTmp.has(f))).toEqual([]);+ });++ it('deletes the multer temp when the gallery init image is missing', async () => {+ // Same family, smaller blast radius: `initImageFile` naming a nonexistent+ // gallery image throws BEFORE the reference loop stages anything, so only+ // the multer temps are at risk. Reachable on every cloud backend now that+ // they accept reference uploads.+ mockedSettings = { imageGen: { mode: 'codex', codex: { enabled: true } } };+ const tmpRoot = tmpdir();+ const before = new Set((await readdir(tmpRoot).catch(() => []))+ .filter((f) => f.startsWith('upload-')));++ const res = await postMultipart(app, '/api/image-gen/generate', [+ { name: 'prompt', value: 'a fox' },+ { name: 'initImageFile', value: 'does-not-exist.png' },+ { name: 'referenceImage1', filename: 'a.png', contentType: 'image/png', value: PNG_FIXTURE },+ ]);++ expect(res.status).toBe(400);+ expect(res.body.error || res.body).toMatch(/init image not found/i);+ await new Promise((r) => setTimeout(r, 50));+ const after = new Set((await readdir(tmpRoot).catch(() => []))+ .filter((f) => f.startsWith('upload-')));+ expect([...after].filter((f) => !before.has(f))).toEqual([]);+ });+it('rejecting a non-FLUX.2 ref upload deletes the multer-staged tmp file (no os.tmpdir leak)', async () => {// Snapshot the tmpdir's `upload-*` entries before and after the request.// The multipart parser writes uploads as `upload-<uuid><ext>`, so thediff --git a/server/services/imageGen/prepareParams.js b/server/services/imageGen/prepareParams.jsindex 7744017f02..df37b41558 100644--- a/server/services/imageGen/prepareParams.js+++ b/server/services/imageGen/prepareParams.js@@ -74,6 +74,19 @@ export async function prepareGenerateParams({ data, files, referenceImageFields}};+ // Every file THIS request copied into PATHS.imageRefs. A throw AFTER staging+ // has to unlink these or they are orphaned forever: nothing downstream knows+ // they exist, and the route's `res.on('close')` sweep only covers multer+ // temps — it is wired from `uploadedTempPaths`, which a throw prevents+ // prepareGenerateParams from ever returning. Only staged COPIES go in here,+ // never a gallery path resolved by `resolveGalleryImage` (that's a real+ // gallery image the user still owns).+ const stagedRefPaths = [];+ const cleanupStagedAndTemp = () => {+ cleanupReqFilesTemp();+ for (const p of stagedRefPaths) unlink(p).catch(() => {});+ };+// Resolve the effective backend BEFORE staging reference uploads — an// `external` request that uploaded refs would otherwise stage files under// `PATHS.imageRefs` and write sidecar metadata claiming references were used,@@ -158,10 +171,12 @@ export async function prepareGenerateParams({ data, files, referenceImageFields// resolveImageInputPath, which accepts the refs dir.initImagePath = join(PATHS.imageRefs, initFilename);await copyFile(initUpload.path, initImagePath);+ stagedRefPaths.push(initImagePath);uploadedTempPaths.push(initUpload.path);} else if (data.initImageFile) {const resolved = resolveGalleryImage(data.initImageFile);if (!resolved) {+ cleanupStagedAndTemp();throw new ServerError('Init image not found in gallery', { status: 400, code: 'INIT_IMAGE_NOT_FOUND' });}initImagePath = resolved;@@ -176,6 +191,7 @@ export async function prepareGenerateParams({ data, files, referenceImageFieldsconst refFilename = `ref-${randomUUID()}${ext}`;const refPath = join(PATHS.imageRefs, refFilename);await copyFile(upload.path, refPath);+ stagedRefPaths.push(refPath);uploadedTempPaths.push(upload.path);referenceImagePaths.push(refPath);// Default to 1.0 when the client didn't send a parallel strength entry,@@ -198,8 +214,13 @@ export async function prepareGenerateParams({ data, files, referenceImageFields// tool schema). Reject synchronously here so direct API callers get a 400// instead of a 200-then-async-job-failure. Mirrors the guards in// codex.js/grok.js/agy.js and the client's needs-prompt gate.+ // This is the one throw that can fire with an input image already staged:+ // agy requires a prompt even then, so a prompt-less agy render with a+ // reference upload reaches here having already copied it into+ // PATHS.imageRefs. Unlink before throwing or it is orphaned on disk.const hasInputImage = Boolean(initImagePath) || referenceImagePaths.length > 0;if (cloudPromptRequired(mode, hasInputImage) && !data.prompt?.trim()) {+ cleanupStagedAndTemp();// Naming "text-to-image" would be wrong for the agy-with-input-images case,// which is precisely the one that isn't.const what = hasInputImage ? 'an image render' : 'text-to-image';