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): stage after gates + source-aware model disclosure

Adam Eivya746b976f286
diff --git a/client/src/pages/MediaAnnotate.jsx b/client/src/pages/MediaAnnotate.jsx
index 39b55fd21d..1337d09aca 100644
--- a/client/src/pages/MediaAnnotate.jsx
+++ b/client/src/pages/MediaAnnotate.jsx
@@ -58,11 +58,13 @@ export default function MediaAnnotate() {
useEffect(() => {
if (!isImage) return;
let active = true;
- getRegenAvailability()
+ // Pass the source filename so the reported model is the exact one a regen of
+ // THIS image would run (multi-model installs), keeping the dialog honest.
+ getRegenAvailability(parsed?.ref)
.then((r) => { if (active) setRegenInfo(r || null); })
.catch(() => { if (active) setRegenInfo(null); });
return () => { active = false; };
- }, [isImage]);
+ }, [isImage, parsed?.ref]);
// Load any previously-saved strokes for this media key. React Router reuses
// this component instance across :mediaKey changes (no remount), so reset all
diff --git a/client/src/services/apiImageVideo.js b/client/src/services/apiImageVideo.js
index 38839c8fc4..48bc800d68 100644
--- a/client/src/services/apiImageVideo.js
+++ b/client/src/services/apiImageVideo.js
@@ -74,7 +74,11 @@ export const regenerateGalleryImage = (filename, { strength, steps, prompt, meth
});
// Whether the local FLUX regen backend is installed (hardware gate). Also carries
// the strength slider bounds: `{ available, modelId, reason, strengthMin, strengthMax, strengthDefault }`.
-export const getRegenAvailability = () => request('/image-gen/regen/availability', { silent: true });
+// Pass a source `filename` (issue #2036) to get the EXACT model a regen of that
+// image would run — the backend picks by the source's own model on multi-model
+// installs, so the annotate dialog can disclose the real model before rendering.
+export const getRegenAvailability = (filename) =>
+ request(`/image-gen/regen/availability${filename ? `?filename=${encodeURIComponent(filename)}` : ''}`, { silent: true });
// Annotation re-render (issue #2036 phase 2). Feeds the saved flattened sketch
// (source image + drawn strokes) back through the local-FLUX img2img regen as the
// init image; returns the queue ack ({ jobId, position, ... }). The annotation
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.js
index 0f7ba8a146..970a5272bd 100644
--- a/server/routes/imageGen.js
+++ b/server/routes/imageGen.js
@@ -303,8 +303,18 @@ router.get('/active', asyncHandler(async (_req, res) => {
// SynthID-defeat regen availability (issue #912). Drives whether the lightbox
// shows the "Regenerate" action — it's hardware-gated on a local FLUX runner.
-router.get('/regen/availability', asyncHandler(async (_req, res) => {
- res.json(await getRegenAvailability());
+// Optional `?filename=` (issue #2036): when the caller names a source image, its
+// model is resolved from the sidecar and threaded into the backend pick so the
+// reported `modelId` matches the exact model a regen of THAT image would run —
+// the annotate re-render dialog must disclose the real model before the render.
+router.get('/regen/availability', asyncHandler(async (req, res) => {
+ const rawFilename = req.query.filename;
+ let sourceModelId;
+ if (typeof rawFilename === 'string' && rawFilename && resolveGalleryImage(rawFilename)) {
+ const { metadata } = await local.readImageSidecar(rawFilename);
+ sourceModelId = metadata?.modelId;
+ }
+ res.json(await getRegenAvailability({ sourceModelId }));
}));
// Shape returned for any image-gen job that goes through the mediaJobQueue
@@ -704,8 +714,10 @@ router.post('/:filename/regenerate', asyncHandler(async (req, res) => {
// Annotation re-render (issue #2036 phase 2): use the saved flattened sketch
// (source + strokes) as the img2img init image. It's a whole-image denoise, so
- // the light spatial pass can't honor the marks — GPU only.
- let initImageAbsPath = null;
+ // the light spatial pass can't honor the marks — GPU only. Validate cheaply
+ // here (no disk writes) so a bad request 400s without leaving anything behind;
+ // the actual staging copy happens below, only once every gate has passed.
+ let annotatedSketchPath = null;
if (body.annotated) {
if (body.method === 'light') {
throw new ServerError('Annotation re-render needs the GPU img2img pass, not the light method.', { status: 400, code: 'VALIDATION_ERROR' });
@@ -714,22 +726,10 @@ router.post('/:filename/regenerate', asyncHandler(async (req, res) => {
if (!isValidSketchKey(key)) {
throw new ServerError('Image cannot be annotated', { status: 400, code: 'VALIDATION_ERROR' });
}
- const sketchPngPath = await getSketchPngPath(key);
- if (!sketchPngPath) {
+ annotatedSketchPath = await getSketchPngPath(key);
+ if (!annotatedSketchPath) {
throw new ServerError('No saved annotation to re-render — draw over the image and save first.', { status: 400, code: 'NO_ANNOTATION' });
}
- // The local runner re-validates initImagePath against its approved image
- // roots (gallery / image-refs / visual-templates) and silently drops
- // anything outside them — `data/media-sketches/` is NOT one, so passing the
- // sidecar path directly would make the re-render ignore the annotation.
- // Stage a snapshot of the flattened annotation into the image-refs root the
- // runner accepts; the copy also freezes the markup at enqueue time so a
- // later re-save can't change what this queued job renders from. Use the
- // `init-<uuid>` name (it IS this job's init image) so imageRefsGc.js sweeps
- // it once unreferenced — a canceled/failed re-render doesn't leak the file.
- await ensureDir(PATHS.imageRefs);
- initImageAbsPath = join(PATHS.imageRefs, `init-${randomUUID()}.png`);
- await copyFile(sketchPngPath, initImageAbsPath);
}
// Sidecar (for prompt/model) and the on-disk dimension probe have no data
@@ -751,6 +751,23 @@ router.post('/:filename/regenerate', asyncHandler(async (req, res) => {
throw new ServerError(backend.reason, { status: 400, code: 'REGEN_BACKEND_UNAVAILABLE' });
}
+ // Stage the flattened annotation ONLY now that every gate has passed and the
+ // job is about to enqueue — so a rejected request (unavailable backend, failed
+ // read) never leaves an orphaned snapshot behind. The local runner re-validates
+ // initImagePath against its approved image roots (gallery / image-refs /
+ // visual-templates) and silently drops anything outside them — `data/media-
+ // sketches/` is NOT one, so the sidecar is copied into the image-refs root the
+ // runner accepts. The copy also freezes the markup at enqueue time (a later
+ // re-save can't change what this queued job renders from), and the `init-<uuid>`
+ // name (it IS this job's init image) lets imageRefsGc.js sweep it once
+ // unreferenced.
+ let initImageAbsPath = null;
+ if (annotatedSketchPath) {
+ await ensureDir(PATHS.imageRefs);
+ initImageAbsPath = join(PATHS.imageRefs, `init-${randomUUID()}.png`);
+ await copyFile(annotatedSketchPath, initImageAbsPath);
+ }
+
// Provider-aware default (issue #912): SynthID-bearing sources keep the
// known-good 0.25; local FLUX sources use a lighter pass. An annotation
// re-render instead defaults higher so the drawn marks reshape the render
diff --git a/server/routes/imageGen.test.js b/server/routes/imageGen.test.js
index e11dbef4f9..89ece6a6a9 100644
--- a/server/routes/imageGen.test.js
+++ b/server/routes/imageGen.test.js
@@ -1109,6 +1109,27 @@ describe('Image Gen Routes', () => {
expect(response.body.strengthDefault).toBeGreaterThanOrEqual(response.body.strengthMin);
expect(response.body.strengthDefault).toBeLessThanOrEqual(response.body.strengthMax);
});
+
+ it('threads a named source image’s model into the availability pick so the reported model matches the regen (issue #2036)', async () => {
+ const resolveGallerySpy = vi.spyOn(fileUtils, 'resolveGalleryImage')
+ .mockReturnValueOnce('/fake/gallery/source.png');
+ imageGen.local.readImageSidecar.mockResolvedValueOnce({
+ path: '', metadata: { modelId: 'flux2-klein-9b' },
+ });
+ const availSpy = vi.spyOn(regen, 'getRegenAvailability')
+ .mockResolvedValueOnce({ available: true, modelId: 'flux2-klein-9b', strengthMin: 0.02, strengthMax: 0.6, strengthDefault: 0.25 });
+
+ const response = await request(app).get('/api/image-gen/regen/availability?filename=source.png');
+
+ expect(response.status).toBe(200);
+ expect(response.body.modelId).toBe('flux2-klein-9b');
+ // The source model must reach the availability resolver, or the dialog can
+ // name a different model than the POST enqueues on a multi-model install.
+ expect(availSpy).toHaveBeenCalledWith({ sourceModelId: 'flux2-klein-9b' });
+
+ resolveGallerySpy.mockRestore();
+ availSpy.mockRestore();
+ });
});
describe('POST /api/image-gen/:filename/regenerate', () => {
diff --git a/server/services/imageGen/regen.js b/server/services/imageGen/regen.js
index e343a12003..32a766f50b 100644
--- a/server/services/imageGen/regen.js
+++ b/server/services/imageGen/regen.js
@@ -224,8 +224,14 @@ export async function resolveRegenBackend({ sourceModelId } = {}) {
// Slim shape for the UI gate — drives whether the lightbox shows the
// Regenerate action, and carries the strength bounds so the in-lightbox slider
// stays in lock-step with server validation (one place to tune the floor).
-export async function getRegenAvailability() {
- const resolved = await resolveRegenBackend();
+export async function getRegenAvailability({ sourceModelId } = {}) {
+ // Thread the source image's model through so the reported `modelId` is the
+ // EXACT backend a regen of that source would run — `resolveRegenBackend`
+ // orders candidates by the source's own model, so a generic (source-less)
+ // call can name a different model than the POST later enqueues on a
+ // multi-model install (issue #2036: the annotate dialog must disclose the
+ // real model before the render).
+ const resolved = await resolveRegenBackend({ sourceModelId });
return {
available: resolved.available,
modelId: resolved.model?.id || null,