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 rejecting grok-pinned video, keep settings writes off stale snapshots

[._.]/ Adam Eivy141be766aa95
diff --git a/client/src/components/settings/SharingTab.jsx b/client/src/components/settings/SharingTab.jsx
index 14e296d2af..54f7fe6105 100644
--- a/client/src/components/settings/SharingTab.jsx
+++ b/client/src/components/settings/SharingTab.jsx
@@ -4,6 +4,7 @@ import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
import { getAuthStatus, getMediaShareCandidates, getSettings, listMusicEngines, updateSettings } from '../../services/api';
+const isRecord = (value) => value && typeof value === 'object' && !Array.isArray(value);
const modelKey = ({ engine, modelId }) => `${engine}\u0000${modelId}`;
// Image and video share one shape: a flat candidate list from the server, each
@@ -151,7 +152,10 @@ export function SharingTab() {
const handleStrictPullToggle = async (next) => {
setStrictPullSaving(true);
- const federation = { ...federationSettings, strictPullAuthorization: next };
+ // Same whole-slice replacement hazard as the provider save below.
+ const fresh = await getSettings({ silent: true }).catch(() => null);
+ const base = isRecord(fresh?.federation) ? fresh.federation : federationSettings;
+ const federation = { ...base, strictPullAuthorization: next };
const merged = await updateSettings({ federation }).catch(() => null);
setStrictPullSaving(false);
if (!merged) return;
@@ -201,8 +205,16 @@ export function SharingTab() {
audioModels: normalizeSelectedModels(providerModels),
...Object.fromEntries(VISUAL_KINDS.map(({ kind, field }) => [field, visualSelections[kind]])),
};
- const federation = { ...federationSettings, mediaProvider };
setProviderSaving(true);
+ // /api/settings replaces the top-level `federation` slice wholesale, so this
+ // write has to carry everything else in it. Re-read immediately before
+ // saving rather than trusting the mount-time snapshot: the Instances page
+ // owns `mediaRouting`, and a Settings tab left open across a routing change
+ // would otherwise write back the slice as it looked before, silently
+ // clearing the route and sending unattended renders back to local.
+ const fresh = await getSettings({ silent: true }).catch(() => null);
+ const base = isRecord(fresh?.federation) ? fresh.federation : federationSettings;
+ const federation = { ...base, mediaProvider };
const merged = await updateSettings({ federation }, { silent: true }).catch(() => null);
setProviderSaving(false);
if (!merged) {
diff --git a/client/src/components/settings/SharingTab.test.jsx b/client/src/components/settings/SharingTab.test.jsx
index bd33ac178f..3a136767c4 100644
--- a/client/src/components/settings/SharingTab.test.jsx
+++ b/client/src/components/settings/SharingTab.test.jsx
@@ -209,3 +209,47 @@ describe('SharingTab — visual provider models', () => {
expect(screen.getByText(/no longer installed/)).toBeInTheDocument();
});
});
+
+// /api/settings replaces the whole `federation` slice, and the Instances page
+// owns mediaRouting — a tab left open across a routing change must not write
+// back the slice as it looked before.
+describe('SharingTab — writes against the freshest federation slice', () => {
+ it('preserves a route added elsewhere after this tab loaded', async () => {
+ getMediaShareCandidates.mockResolvedValue({ image: [], video: [] });
+ getAuthStatus.mockResolvedValue({ enabled: true });
+ // Start enabled, then turn sharing OFF — disabling needs no model selection,
+ // so the save actually reaches updateSettings.
+ getSettings.mockResolvedValueOnce({
+ sharingDisplayName: '', sharingBio: '',
+ federation: {
+ mediaProvider: {
+ enabled: true, maxQueuedJobs: 2,
+ audioModels: [{ engine: 'minimax-music3', modelId: 'minimax-music3' }],
+ },
+ },
+ });
+
+ render(<SharingTab />);
+ const toggle = await screen.findByLabelText(/Accept audio generation jobs/i);
+
+ // The Instances page saves a route while this tab is sitting open.
+ const route = { peerId: 'peer-1', engine: 'comfy', modelId: 'sdxl-base' };
+ getSettings.mockResolvedValueOnce({
+ federation: {
+ mediaProvider: {
+ enabled: true, maxQueuedJobs: 2,
+ audioModels: [{ engine: 'minimax-music3', modelId: 'minimax-music3' }],
+ },
+ mediaRouting: { image: route },
+ },
+ });
+ fireEvent.click(toggle);
+ fireEvent.click(screen.getByRole('button', { name: 'Save provider' }));
+
+ // Writing the mount-time snapshot would have dropped mediaRouting entirely,
+ // silently sending every unattended render back to local.
+ await waitFor(() => expect(updateSettings).toHaveBeenCalledWith({
+ federation: expect.objectContaining({ mediaRouting: { image: route } }),
+ }, { silent: true }));
+ });
+});
diff --git a/server/services/federatedMedia/defaultRouting.js b/server/services/federatedMedia/defaultRouting.js
index 392c397ca9..dc34a4de97 100644
--- a/server/services/federatedMedia/defaultRouting.js
+++ b/server/services/federatedMedia/defaultRouting.js
@@ -28,6 +28,7 @@
import { ServerError } from '../../lib/errorHandler.js';
import { buildFederatedMediaRequest } from '../../lib/federatedMediaRequest.js';
import { getSettings } from '../settings.js';
+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']);
@@ -110,14 +111,27 @@ function assertRoutableConditioning(kind, params) {
// silently gets the opposite of what it asked for. Only a truthy value is a
// conflict — the common `false` is the provider's own default anyway.
if (kind === 'video' && params?.disableAudio === true) unsupported.push('a silent (audio-disabled) render');
- // For LOCAL video, `mode` is the pipeline semantic for the lane (t2v / i2v /
- // first-last-frame / audio-to-video), not a backend selector — and only
- // text-to-video crosses the wire. Because `routedJobParams` drops `mode`
- // outright, an unguarded 'fflf' or 'a2v' job would come back as a plain
- // text-to-video clip: a valid-looking render of the wrong pipeline. Mirrors
- // the interactive route's non-text-mode rejection.
- if (kind === 'video' && params?.mode !== undefined && params.mode !== 'text') {
- unsupported.push(`a non-text render mode ('${params.mode}')`);
+ // `params.mode` on a video job is OVERLOADED: it is either a backend token
+ // ('local' / 'grok', what enforceRenderBackendPin writes) or, for the local
+ // lane, the pipeline semantic (t2v / i2v / first-last-frame / audio-to-video).
+ // The two need opposite treatment, and conflating them either rejects every
+ // routable Grok-pinned job or silently renders the wrong pipeline.
+ if (kind === 'video' && params?.mode !== undefined) {
+ const mode = params.mode;
+ if (CLOUD_VIDEO_GEN_MODES.includes(mode)) {
+ // A cloud-CLI render spends that provider's quota with its own model and
+ // its own duration vocabulary, none of which the wire carries. Refuse
+ // rather than quietly substituting the peer's model — the interactive
+ // route rejects a federated Grok render for the same reason.
+ unsupported.push(`the ${mode} backend`);
+ } else if (!VIDEO_GEN_MODES.includes(mode) && mode !== 'text') {
+ // A genuine pipeline semantic other than text-to-video. `routedJobParams`
+ // drops `mode`, so an unguarded 'fflf' or 'a2v' job would come back as a
+ // plain text-to-video clip: a valid-looking render of a different thing.
+ unsupported.push(`a non-text render mode ('${mode}')`);
+ }
+ // A bare 'local' backend token falls through: it states where the job would
+ // have run, not what pipeline it is, and routedJobParams strips it.
}
if (!unsupported.length) return;
throw new ServerError(
diff --git a/server/services/federatedMedia/defaultRouting.test.js b/server/services/federatedMedia/defaultRouting.test.js
index b0ee230b1f..4db7008fd5 100644
--- a/server/services/federatedMedia/defaultRouting.test.js
+++ b/server/services/federatedMedia/defaultRouting.test.js
@@ -280,3 +280,28 @@ describe('non-text video pipelines', () => {
.resolves.toMatchObject({ peer: { id: 'peer-1' } });
});
});
+
+// `params.mode` on a video job is overloaded — a backend token OR a pipeline
+// semantic — and the two need opposite treatment.
+describe('overloaded video mode token', () => {
+ const route = { peerId: 'peer-1', engine: 'comfy', modelId: 'wan-remote' };
+
+ beforeEach(() => {
+ getSettings.mockResolvedValue({ federation: { mediaRouting: { video: route } } });
+ });
+
+ it('routes a job carrying the local backend token, which states where it would have run', async () => {
+ await expect(resolveDefaultMediaRoute({ kind: 'video', params: { prompt: 'p', mode: 'local' } }))
+ .resolves.toMatchObject({ peer: { id: 'peer-1' } });
+ });
+
+ it('refuses a grok-pinned job rather than substituting the peer model for the cloud render', async () => {
+ await expect(resolveDefaultMediaRoute({ kind: 'video', params: { prompt: 'p', mode: 'grok' } }))
+ .rejects.toThrow(/grok backend/);
+ });
+
+ it('still refuses a genuine non-text pipeline semantic', async () => {
+ await expect(resolveDefaultMediaRoute({ kind: 'video', params: { prompt: 'p', mode: 'fflf' } }))
+ .rejects.toThrow(/non-text render mode/);
+ });
+});