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): stop collapsing failed reads into empty configuration

[._.]/ Adam Eivy5b2c9c877266
diff --git a/client/src/components/instances/UnattendedRenderRouting.jsx b/client/src/components/instances/UnattendedRenderRouting.jsx
index d1797819c3..39b22fdbb6 100644
--- a/client/src/components/instances/UnattendedRenderRouting.jsx
+++ b/client/src/components/instances/UnattendedRenderRouting.jsx
@@ -92,10 +92,19 @@ export default function UnattendedRenderRouting({ peers }) {
// it immediately before writing rather than trusting the snapshot taken at
// mount: the Sharing tab owns mediaProvider and strict-pull, and a page left
// open across an edit there would otherwise write back the stale values it
- // captured. Fall back to the mount snapshot only if the re-read fails, which
- // is still strictly better than sending {}.
+ // captured.
+ //
+ // A FAILED re-read aborts the save. Falling back to the mount snapshot was
+ // the wrong instinct: it is not "better than sending {}", it is a write of
+ // known-stale state over whatever is actually on the server, which is how a
+ // newer mediaProvider or strictPullAuthorization gets silently reverted.
const fresh = await getSettings({ silent: true }).catch(() => null);
- const base = isRecord(fresh?.federation) ? fresh.federation : federation;
+ if (!isRecord(fresh?.federation)) {
+ setSaving(false);
+ toast.error('Could not read current settings — routing not saved');
+ return;
+ }
+ const base = fresh.federation;
// Merge onto the freshest routing too, so a kind another surface set in the
// meantime isn't reverted by this one's stale copy.
const baseRouting = isRecord(base.mediaRouting) ? base.mediaRouting : routing;
@@ -121,14 +130,18 @@ export default function UnattendedRenderRouting({ peers }) {
// and there is no way left to clear it.
const hasSavedRoute = KINDS.some(({ kind }) => savedRoute(kind));
const anyOptions = KINDS.some(({ kind }) => optionsByKind[kind].length > 0);
+ // Shown regardless of whether any peer currently advertises a model: a failed
+ // settings read is not the same as "nothing is configured", and hiding it
+ // would leave a persisted route silently failing every enqueue with no
+ // on-screen explanation and no way to clear it.
if (loadFailed) {
- return anyOptions ? (
+ return (
<div className="mb-3 rounded-lg border border-port-border bg-port-bg/40 p-3">
<p className="text-[11px] text-port-warning">
Unattended render routing could not load this instance&rsquo;s settings, so it is read-only. Reload to try again.
</p>
</div>
- ) : null;
+ );
}
if (routing === null || (!anyOptions && !hasSavedRoute)) return null;
diff --git a/client/src/components/instances/UnattendedRenderRouting.test.jsx b/client/src/components/instances/UnattendedRenderRouting.test.jsx
index 2370928560..dc3f0aeaf2 100644
--- a/client/src/components/instances/UnattendedRenderRouting.test.jsx
+++ b/client/src/components/instances/UnattendedRenderRouting.test.jsx
@@ -181,7 +181,10 @@ describe('UnattendedRenderRouting — writes against the freshest settings', ()
}, { silent: true }));
});
- it('falls back to the mount snapshot when the re-read fails, never to an empty slice', async () => {
+});
+
+describe('UnattendedRenderRouting — a failed read is not an empty configuration', () => {
+ it('aborts the save rather than writing a known-stale slice over the server', async () => {
getSettings.mockResolvedValueOnce({ federation: { mediaProvider: { enabled: true } } });
render(<UnattendedRenderRouting peers={[peerWith()]} />);
const select = await screen.findByLabelText('Image');
@@ -189,11 +192,14 @@ describe('UnattendedRenderRouting — writes against the freshest settings', ()
getSettings.mockRejectedValueOnce(new Error('offline'));
fireEvent.change(select, { target: { value: JSON.stringify(['peer-1', 'comfy', 'sdxl-base']) } });
- await waitFor(() => expect(updateSettings).toHaveBeenCalledWith({
- federation: {
- mediaProvider: { enabled: true },
- mediaRouting: { image: { peerId: 'peer-1', engine: 'comfy', modelId: 'sdxl-base' } },
- },
- }, { silent: true }));
+ await waitFor(() => expect(toast.error)
+ .toHaveBeenCalledWith('Could not read current settings — routing not saved'));
+ expect(updateSettings).not.toHaveBeenCalled();
+ });
+
+ it('shows the read-only notice even when no peer advertises anything', async () => {
+ getSettings.mockRejectedValue(new Error('offline'));
+ render(<UnattendedRenderRouting peers={[]} />);
+ expect(await screen.findByText(/could not load this instance/i)).toBeInTheDocument();
});
});
diff --git a/client/src/components/settings/SharingTab.jsx b/client/src/components/settings/SharingTab.jsx
index 54f7fe6105..3b7c2db644 100644
--- a/client/src/components/settings/SharingTab.jsx
+++ b/client/src/components/settings/SharingTab.jsx
@@ -67,7 +67,11 @@ export function SharingTab() {
const [providerEnabled, setProviderEnabled] = useState(false);
const [providerMaxQueuedJobs, setProviderMaxQueuedJobs] = useState(2);
const [providerModels, setProviderModels] = useState([]);
- const [visualCandidates, setVisualCandidates] = useState({ image: [], video: [] });
+ // `null` per kind = the candidate list could not be fetched, which is NOT the
+ // same as a genuinely empty local catalog — reporting "no models installed"
+ // for a transient API failure would send the user hunting for a model they
+ // already have.
+ const [visualCandidates, setVisualCandidates] = useState({ image: null, video: null });
const [providerVisualModels, setProviderVisualModels] = useState({ image: [], video: [] });
const [savedProviderVisualModels, setSavedProviderVisualModels] = useState({ image: [], video: [] });
const [savedProviderEnabled, setSavedProviderEnabled] = useState(false);
@@ -86,10 +90,10 @@ export function SharingTab() {
// the model cache, so keep it off the critical path for the other controls.
getMediaShareCandidates({ silent: true })
.then((candidates) => setVisualCandidates({
- image: Array.isArray(candidates?.image) ? candidates.image : [],
- video: Array.isArray(candidates?.video) ? candidates.video : [],
+ image: Array.isArray(candidates?.image) ? candidates.image : null,
+ video: Array.isArray(candidates?.video) ? candidates.video : null,
}))
- .catch(() => setVisualCandidates({ image: [], video: [] }));
+ .catch(() => setVisualCandidates({ image: null, video: null }));
Promise.all([
getSettings({ silent: true }),
getAuthStatus({ silent: true }).catch(() => ({ enabled: false })),
@@ -397,12 +401,17 @@ export function SharingTab() {
</fieldset>
{VISUAL_KINDS.map(({ kind, label, field }) => {
- const rows = candidateRows(visualCandidates[kind], providerVisualModels[kind]);
+ const unavailable = visualCandidates[kind] === null;
+ const rows = candidateRows(visualCandidates[kind] || [], providerVisualModels[kind]);
return (
<fieldset key={field}>
<legend className="block text-xs uppercase tracking-wider text-gray-500 mb-2">Allowed {label} models</legend>
{rows.length === 0 ? (
- <p className="text-sm text-gray-500">No local {label} models are installed to share.</p>
+ <p className="text-sm text-gray-500">
+ {unavailable
+ ? `Could not load the local ${label} model list. Reload to try again.`
+ : `No local ${label} models are installed to share.`}
+ </p>
) : (
<div className="grid grid-cols-1 lg:grid-cols-2 gap-2">
{rows.map((candidate, index) => {
diff --git a/client/src/components/settings/SharingTab.test.jsx b/client/src/components/settings/SharingTab.test.jsx
index 3a136767c4..e78676f4ab 100644
--- a/client/src/components/settings/SharingTab.test.jsx
+++ b/client/src/components/settings/SharingTab.test.jsx
@@ -253,3 +253,30 @@ describe('SharingTab — writes against the freshest federation slice', () => {
}, { silent: true }));
});
});
+
+describe('SharingTab — a failed candidate fetch is not an empty catalog', () => {
+ it('says the list could not load rather than "no models installed"', async () => {
+ getMediaShareCandidates.mockRejectedValue(new Error('offline'));
+ getAuthStatus.mockResolvedValue({ enabled: true });
+ getSettings.mockResolvedValue({
+ sharingDisplayName: '', sharingBio: '',
+ federation: { mediaProvider: { enabled: true, audioModels: [] } },
+ });
+
+ render(<SharingTab />);
+ expect(await screen.findByText(/Could not load the local image model list/i)).toBeInTheDocument();
+ expect(screen.queryByText(/No local image models are installed/i)).not.toBeInTheDocument();
+ });
+
+ it('still reports a genuinely empty catalog as empty', async () => {
+ getMediaShareCandidates.mockResolvedValue({ image: [], video: [] });
+ getAuthStatus.mockResolvedValue({ enabled: true });
+ getSettings.mockResolvedValue({
+ sharingDisplayName: '', sharingBio: '',
+ federation: { mediaProvider: { enabled: true, audioModels: [] } },
+ });
+
+ render(<SharingTab />);
+ expect(await screen.findByText(/No local image models are installed/i)).toBeInTheDocument();
+ });
+});
diff --git a/docs/FEDERATED_MEDIA_PROVIDERS.md b/docs/FEDERATED_MEDIA_PROVIDERS.md
index 6acd2d07be..32eef6489e 100644
--- a/docs/FEDERATED_MEDIA_PROVIDERS.md
+++ b/docs/FEDERATED_MEDIA_PROVIDERS.md
@@ -200,9 +200,16 @@ Three properties are worth stating explicitly:
Destination tags on the job (`creativeDirectorSceneImage`, `musicVideo`,
`catalogAttach`, …) survive routing untouched, so the same completion hooks file
-a federated render exactly where a local one would land. An unreadable settings
-file is treated as "no route configured" — logged, then rendered locally —
-because a transient read error must not hard-fail every autonomous render.
+a federated render exactly where a local one would land.
+
+An **unreadable** settings file fails the enqueue with `MEDIA_ROUTING_UNREADABLE`
+rather than falling back to a local render. It is not the same as a settings file
+that parses and simply configures no route (that renders locally, as it should):
+a failed read cannot tell us whether a route exists, and guessing "no route"
+would silently spend local GPU on work the operator deliberately sent to another
+machine. A provider rejection inside a batch is contained rather than fatal —
+one refused portrait or scene frame is recorded in that run's `skipped` list and
+the rest of the batch still queues.
## Authentication and identity
diff --git a/server/services/creative/tools/media.test.js b/server/services/creative/tools/media.test.js
index c08720ca60..91de4c40c3 100644
--- a/server/services/creative/tools/media.test.js
+++ b/server/services/creative/tools/media.test.js
@@ -224,11 +224,19 @@ describe('render-backend pin — image (#3135)', () => {
expect(enqueued().params.modelId).toBe('planner-model');
});
- it('falls through untouched when settings are unreadable', async () => {
+ // The backend PIN still falls through untouched on an unreadable read — but
+ // since #4348 the enqueue itself now fails instead of completing. An
+ // unreadable settings file cannot tell us whether a federated route is
+ // configured, and treating that as "no route" would silently render on local
+ // GPU work the user deliberately sent to another machine. Failing loudly is
+ // the project's sentinel rule (never collapse failed-to-fetch into
+ // legitimately-empty) applied to a spend-bearing decision.
+ it('fails the enqueue rather than guessing at routing when settings are unreadable', async () => {
getSettings.mockRejectedValue(new Error('settings unavailable'));
getProject.mockResolvedValue(projectWithPin({ image: { mode: 'grok' } }));
- await run('media_enqueueImageJob', { prompt: 'p' }, { projectId: 'cd-1' });
- expect(enqueued().params).toEqual({ prompt: 'p' });
+ await expect(run('media_enqueueImageJob', { prompt: 'p' }, { projectId: 'cd-1' }))
+ .rejects.toMatchObject({ code: 'MEDIA_ROUTING_UNREADABLE' });
+ expect(enqueueJob).not.toHaveBeenCalled();
});
});
diff --git a/server/services/creativeDirector/firstPassGen.js b/server/services/creativeDirector/firstPassGen.js
index 14c9b9c9fa..1467e8e605 100644
--- a/server/services/creativeDirector/firstPassGen.js
+++ b/server/services/creativeDirector/firstPassGen.js
@@ -178,18 +178,29 @@ export async function enqueueFirstPassPortraits(members = [], project = null) {
skipped.push({ ingredientId, reason: skip });
continue;
}
- const queued = await enqueueUnattendedMediaJob({
- kind: 'image',
- params: {
- ...resolved.jobParams,
- prompt,
- // Tag the job so the durable catalogImageAttachHook (#1359) files the
- // finished render as this ingredient's portrait — no mounted client
- // required. Explicit `kind: 'portrait'` since this is a deliberate
- // first-pass portrait, not an ad-hoc reference render.
- catalogAttach: { ingredientId, kind: 'portrait' },
- },
- });
+ // A routed enqueue can reject on provider preflight (busy, stale,
+ // unauthorized, unsupported conditioning) where a local one could not. An
+ // uncaught rejection here would abandon every REMAINING portrait in the
+ // batch over one bad member — record the reason and keep going.
+ let queued;
+ try {
+ queued = await enqueueUnattendedMediaJob({
+ kind: 'image',
+ params: {
+ ...resolved.jobParams,
+ prompt,
+ // Tag the job so the durable catalogImageAttachHook (#1359) files the
+ // finished render as this ingredient's portrait — no mounted client
+ // required. Explicit `kind: 'portrait'` since this is a deliberate
+ // first-pass portrait, not an ad-hoc reference render.
+ catalogAttach: { ingredientId, kind: 'portrait' },
+ },
+ });
+ } catch (error) {
+ console.error(`❌ CD first-pass portrait ${ingredientId}: could not queue: ${error.message}`);
+ skipped.push({ ingredientId, reason: error.code || 'enqueue-failed' });
+ continue;
+ }
enqueued.push({ ingredientId, jobId: queued.jobId });
}
console.log(`🎨 CD first-pass portraits: ${enqueued.length} queued, ${skipped.length} skipped (${resolved.mode})`);
@@ -282,20 +293,29 @@ export async function enqueueFirstPassSceneFrames(project) {
skipped.push({ sceneId: scene.sceneId, reason: 'no-prompt' });
continue;
}
- const queued = await enqueueUnattendedMediaJob({
- kind: 'image',
- params: {
- ...resolved.jobParams,
- prompt,
- width,
- height,
- // Tag the job so the durable creativeDirectorSceneImageHook files the
- // finished render onto this scene's sourceImageFile — no mounted
- // client required. Mirrors the catalogAttach tag the portrait path
- // uses for the catalog hook.
- creativeDirector: { projectId: project.id, sceneId: scene.sceneId },
- },
- });
+ // Same reason as the portrait loop: a routed enqueue can reject on provider
+ // preflight, and one bad scene must not abandon the rest of the batch.
+ let queued;
+ try {
+ queued = await enqueueUnattendedMediaJob({
+ kind: 'image',
+ params: {
+ ...resolved.jobParams,
+ prompt,
+ width,
+ height,
+ // Tag the job so the durable creativeDirectorSceneImageHook files the
+ // finished render onto this scene's sourceImageFile — no mounted
+ // client required. Mirrors the catalogAttach tag the portrait path
+ // uses for the catalog hook.
+ creativeDirector: { projectId: project.id, sceneId: scene.sceneId },
+ },
+ });
+ } catch (error) {
+ console.error(`❌ CD first-pass scene ${scene.sceneId}: could not queue: ${error.message}`);
+ skipped.push({ sceneId: scene.sceneId, reason: error.code || 'enqueue-failed' });
+ continue;
+ }
enqueued.push({ sceneId: scene.sceneId, jobId: queued.jobId });
}
console.log(`🎬 CD first-pass scene frames: ${enqueued.length} queued, ${skipped.length} skipped (${resolved.mode})`);
diff --git a/server/services/federatedMedia/defaultRouting.js b/server/services/federatedMedia/defaultRouting.js
index dc34a4de97..0009e46c9e 100644
--- a/server/services/federatedMedia/defaultRouting.js
+++ b/server/services/federatedMedia/defaultRouting.js
@@ -33,6 +33,10 @@ import { CLOUD_VIDEO_GEN_MODES, VIDEO_GEN_MODES } from '../videoGen/modes.js';
// Only the visual kinds. See the audio note in the module docblock.
export const ROUTABLE_MEDIA_KINDS = Object.freeze(['image', 'video']);
+// Distinct from both `null` and `{}` so a failed settings read can never be
+// mistaken for "settings say nothing is routed".
+const UNREADABLE_SETTINGS = Symbol('unreadable-settings');
+
const isRecord = (value) => value && typeof value === 'object' && !Array.isArray(value);
const trimmed = (value) => (typeof value === 'string' ? value.trim() : '');
@@ -155,8 +159,13 @@ function assertRoutableConditioning(kind, params) {
*/
export async function hasConfiguredMediaRoute(kind) {
if (!ROUTABLE_MEDIA_KINDS.includes(kind)) return false;
- const settings = await getSettings().catch(() => null);
- return !!(settings && normalizeMediaRoutingConfig(settings)[kind]);
+ // On an unreadable read, answer TRUE: every caller uses this to decide whether
+ // a local-readiness verdict may skip the render, and skipping is the one
+ // outcome that silently discards work. Saying "routed" defers the decision to
+ // resolveDefaultMediaRoute, which fails loudly with MEDIA_ROUTING_UNREADABLE.
+ const settings = await getSettings().catch(() => UNREADABLE_SETTINGS);
+ if (settings === UNREADABLE_SETTINGS) return true;
+ return !!normalizeMediaRoutingConfig(settings)[kind];
}
/**
@@ -171,19 +180,23 @@ export async function hasConfiguredMediaRoute(kind) {
*/
export async function resolveDefaultMediaRoute({ kind, params }) {
if (!ROUTABLE_MEDIA_KINDS.includes(kind)) return null;
- // An unreadable settings file is an install-level fault, not a provider
- // fault: no configuration is knowable at all, which is the same state as a
- // fresh install. Rendering locally matches what the rest of this enqueue
- // path already does with an unreadable settings read (the render-backend
- // pin ladder falls through untouched) — hard-failing every autonomous
- // render on a transient read error would be a far worse outcome than one
- // local render. It is logged rather than swallowed so it can never look
- // like "no route configured".
+ // UNREADABLE is not the same as NO ROUTE. A settings object that parses and
+ // simply has no `mediaRouting` is a fresh install and must render locally; a
+ // settings read that FAILS tells us nothing, and treating it as "no route"
+ // would silently bypass a route the user configured — burning local GPU (or
+ // another backend's quota) on work they deliberately sent elsewhere. That is
+ // exactly the collapse the project's sentinel rule forbids, so a failed read
+ // gets its own typed error rather than a null.
const settings = await getSettings().catch((error) => {
console.error(`❌ Federated media routing could not read settings: ${error.message}`);
- return null;
+ return UNREADABLE_SETTINGS;
});
- if (!settings) return null;
+ if (settings === UNREADABLE_SETTINGS) {
+ throw new ServerError(
+ 'Could not read this instance\'s media routing configuration',
+ { status: 503, code: 'MEDIA_ROUTING_UNREADABLE' },
+ );
+ }
const route = normalizeMediaRoutingConfig(settings)[kind];
if (!route) return null;
diff --git a/server/services/federatedMedia/defaultRouting.test.js b/server/services/federatedMedia/defaultRouting.test.js
index 4db7008fd5..2b26a98aa5 100644
--- a/server/services/federatedMedia/defaultRouting.test.js
+++ b/server/services/federatedMedia/defaultRouting.test.js
@@ -242,11 +242,9 @@ describe('hasConfiguredMediaRoute', () => {
expect(prepareRemoteMediaJob).not.toHaveBeenCalled();
});
- it('reports false for an unroutable kind and for an unreadable settings file', async () => {
+ it('reports false for an unroutable kind', async () => {
getSettings.mockResolvedValue({ federation: { mediaRouting: { audio: { peerId: 'p', engine: 'e', modelId: 'm' } } } });
await expect(hasConfiguredMediaRoute('audio')).resolves.toBe(false);
- getSettings.mockRejectedValue(new Error('unreadable'));
- await expect(hasConfiguredMediaRoute('image')).resolves.toBe(false);
});
});
@@ -305,3 +303,34 @@ describe('overloaded video mode token', () => {
.rejects.toThrow(/non-text render mode/);
});
});
+
+// The project's sentinel rule: absent / failed-to-fetch / invalid must never
+// collapse into the same value as fetched-and-legitimately-empty.
+describe('unreadable settings are not "no route"', () => {
+ it('fails the routed enqueue instead of quietly rendering locally', async () => {
+ getSettings.mockRejectedValue(new Error('EACCES'));
+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))
+ .rejects.toMatchObject({ code: 'MEDIA_ROUTING_UNREADABLE' });
+ });
+
+ it('still treats a parsed settings object with no routing as local', async () => {
+ getSettings.mockResolvedValue({});
+ await expect(resolveDefaultMediaRoute({ kind: 'image', params: { prompt: 'p' } }))
+ .resolves.toBeNull();
+ });
+
+ // Callers use this to decide whether a local-readiness verdict may SKIP the
+ // render. Skipping is the outcome that silently discards work, so an
+ // unreadable read must defer to resolveDefaultMediaRoute's loud failure.
+ it('reports routed on an unreadable read, so no caller skips the render', async () => {
+ getSettings.mockRejectedValue(new Error('EACCES'));
+ await expect(hasConfiguredMediaRoute('image')).resolves.toBe(true);
+ });
+
+ it('propagates the unreadable failure through the shared enqueue helper', async () => {
+ getSettings.mockRejectedValue(new Error('EACCES'));
+ await expect(enqueueUnattendedMediaJob({ kind: 'image', params: { prompt: 'p' } }))
+ .rejects.toMatchObject({ code: 'MEDIA_ROUTING_UNREADABLE' });
+ expect(enqueueJob).not.toHaveBeenCalled();
+ });
+});