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
address review (codex): resolve peer reachability into one usable reading, re-checked at click
[._.]/ Adam Eivy42dc1ca50b1b
diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsxindex a6db85b055..1110089002 100644--- a/client/src/components/music/MusicGenPanel.jsx+++ b/client/src/components/music/MusicGenPanel.jsx@@ -331,7 +331,7 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artistconst remoteReadiness = selectedRemotePeer ? resolvePeerMediaReadiness(selectedRemotePeer) : null;const remoteQueueSegments = remoteReadiness ? summarizePeerMediaQueue(remoteReadiness.queue) : [];const remoteReady = isRemote- && remoteReadiness?.state === 'ready'+ && remoteReadiness?.usable === true&& remoteReadiness.queue?.accepting === true&& selectedRemoteModel?.ready === true;const canGenerate = (isRemote ? remoteReady : !!engine?.ready && selectedModelReady)@@ -397,6 +397,18 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artistconst handleGenerate = async () => {if (!generationEngine) return;if (!prompt?.trim()) { toast.error('Add a generation prompt first'); return; }+ // The button's own reading is as old as the last render, and a capacity+ // window expires on the clock rather than on a state change — so between+ // polls an enabled button can already be pointing at a stale peer. Re-derive+ // now, and say so here instead of letting the server reject a submission the+ // user just committed to.+ if (isRemote) {+ const fresh = resolvePeerMediaReadiness(selectedRemotePeer);+ if (!fresh.usable) {+ toast.error(fresh.help || 'The selected peer is no longer reporting available capacity');+ return;+ }+ }setGenerating(true);const body = {prompt: prompt.trim(),diff --git a/client/src/components/music/MusicGenPanel.test.jsx b/client/src/components/music/MusicGenPanel.test.jsxindex 91196e2a28..74ed8fd30d 100644--- a/client/src/components/music/MusicGenPanel.test.jsx+++ b/client/src/components/music/MusicGenPanel.test.jsx@@ -3,6 +3,7 @@ import { StrictMode } from 'react';import { fireEvent, render, screen, waitFor } from '@testing-library/react';import MusicGenPanel from './MusicGenPanel';import * as api from '../../services/api';+import toast from '../ui/Toast';vi.mock('../../services/api', () => ({listMusicEngines: vi.fn(),@@ -16,6 +17,10 @@ vi.mock('../../services/api', () => ({removeAudioModel: vi.fn(),}));+vi.mock('../ui/Toast', () => ({+ default: { error: vi.fn(), success: vi.fn(), info: vi.fn() },+}));+vi.mock('../install/RuntimeInstallModal', () => ({default: ({ open, label, onClose }) => (open ? (<div>@@ -300,6 +305,46 @@ describe('MusicGenPanel', () => {expect(requestBody).not.toHaveProperty('lyrics');});+ // A capacity window expires on the clock, not on a state change, so between+ // polls the button can still be enabled against a peer that has gone stale.+ it('refuses at click time when the window expired since the last render', async () => {+ api.listMusicEngines.mockResolvedValue({ defaultEngine: 'musicgen', engines: [engine({ ready: true })] });+ const freshUntil = new Date(Date.now() + 300).toISOString();+ api.getInstances.mockResolvedValue({+ peers: [{+ id: 'peer-example',+ name: 'Example GPU',+ status: 'online',+ mediaProvider: { enabled: true, audioModels: [{ engine: 'minimax-music3', modelId: 'minimax-music3' }] },+ mediaProviderStatus: {+ state: 'ready',+ checkedAt: new Date().toISOString(),+ freshUntil,+ snapshot: {+ queue: { accepting: true, running: 0, queued: 0 },+ capabilities: [{+ kind: 'audio', engine: 'minimax-music3', engineName: 'MiniMax Music 3', modelId: 'minimax-music3',+ modelName: 'MiniMax Music 3', ready: true, autoDuration: false, lyrics: true,+ minDurationSec: 10, maxDurationSec: 300, defaultDurationSec: 60,+ }],+ },+ },+ }],+ });++ render(<MusicGenPanel track={{ id: 'track-1' }} prompt="private prompt" />);+ fireEvent.change(await screen.findByRole('combobox', { name: /generation target/i }), { target: { value: 'peer-example' } });+ const generate = screen.getByRole('button', { name: /^generate$/i });+ expect(generate).toBeEnabled();++ // The window lapses without anything re-rendering the panel.+ await new Promise((resolve) => setTimeout(resolve, 350));+ fireEvent.click(generate);++ await waitFor(() => expect(toast.error).toHaveBeenCalledWith(expect.stringMatching(/capacity snapshot expired/i)));+ expect(api.generateMusic).not.toHaveBeenCalled();+ });+// The stored probe keeps saying `ready` long after the server would refuse// the submission. Leaving Generate enabled beside a caption reading "stale"// just moves the rejection to the server, after the user committed to it.diff --git a/client/src/lib/federatedMediaReadiness.js b/client/src/lib/federatedMediaReadiness.jsindex 8e809e169f..fd976ee5a9 100644--- a/client/src/lib/federatedMediaReadiness.js+++ b/client/src/lib/federatedMediaReadiness.js@@ -7,10 +7,11 @@* worse than either alone. The state machine, its labels, and the remedy text* therefore live here rather than inside one component.*- * The server stays authoritative. `assertFederatedMediaProviderSelection`+ * The server stays authoritative: `assertFederatedMediaProviderSelection`* (server/services/federatedMediaConsumer.js) re-probes and fail-closes before- * any job leaves this instance, so nothing here gates work — it only decides- * what the user is shown.+ * any job leaves this instance. What `usable` gates is the client's own+ * submit affordance, so a peer the server would refuse is refused before the+ * user commits to it rather than after.*/import { Film, Image, Music2 } from 'lucide-react';@@ -190,9 +191,10 @@ export function summarizePeerMediaQueue(queue) {** @param {object} peer - a sanitized peer record from `GET /api/instances`* @param {{now?: number}} [options]- * @returns {{configured: boolean, state: string|null, label: string, tone: string,- * help: string|null, queue: object|null, capabilities: object[], checkedAt: string|null,- * models: Record<string, object[]>, modelCount: number, kinds: string[]}}+ * @returns {{configured: boolean, state: string|null, usable: boolean, label: string,+ * tone: string, help: string|null, queue: object|null, capabilities: object[],+ * checkedAt: string|null, models: Record<string, object[]>, modelCount: number,+ * kinds: string[]}}*/export function resolvePeerMediaReadiness(peer, { now = Date.now() } = {}) {const config = peerMediaProviderConfig(peer);@@ -201,16 +203,24 @@ export function resolvePeerMediaReadiness(peer, { now = Date.now() } = {}) {// An unverifiable status does not get to keep whatever the probe concluded —// including the `ready` it concluded at probe time.const state = status ? verifiedState(status, now) : null;- const meta = peer?.enabled === false+ // `state` is the provider's own verdict on its provider surface — it says+ // nothing about whether this peer is switched on or reachable. Composing the+ // two happens once, here, rather than at each caller: a surface that gated a+ // button on the bare `state` would enable it for a disabled or offline peer+ // still holding a fresh snapshot from before it went away.+ const blocked = peer?.enabled === false? PEER_DISABLED: !config.enabled? OFF: peer?.status !== 'online'? PEER_OFFLINE- : (FEDERATED_MEDIA_STATE_META[state] || CHECKING);+ : null;+ const meta = blocked ?? (FEDERATED_MEDIA_STATE_META[state] || CHECKING);return {configured: config.enabled,state,+ // The one reading a caller should gate work on.+ usable: !blocked && state === 'ready',label: meta.label,tone: meta.tone,// A peer-level reading carries its own remedy; otherwise the remedy belongsdiff --git a/client/src/lib/federatedMediaReadiness.test.js b/client/src/lib/federatedMediaReadiness.test.jsindex 538ce8d133..cdb372da4c 100644--- a/client/src/lib/federatedMediaReadiness.test.js+++ b/client/src/lib/federatedMediaReadiness.test.js@@ -188,6 +188,47 @@ describe('federatedMediaModelKey', () => {});});+describe('resolvePeerMediaReadiness usable', () => {+ const freshReady = (overrides = {}) => ({+ id: 'peer-1',+ enabled: true,+ status: 'online',+ mediaProvider: { enabled: true, audioModels: [{ engine: 'e', modelId: 'm' }] },+ mediaProviderStatus: {+ state: 'ready',+ checkedAt: iso(-1_000),+ freshUntil: iso(60_000),+ snapshot: { queue: { running: 0, queued: 0, totalActive: 0, maxQueuedJobs: 4, accepting: true }, capabilities: [] },+ },+ ...overrides,+ });++ it('is true only for an enabled, online, opted-in peer with a fresh ready snapshot', () => {+ expect(resolvePeerMediaReadiness(freshReady(), { now: NOW }).usable).toBe(true);+ });++ // `state` is the provider's verdict on its own surface and says nothing about+ // reachability, so a caller gating on it alone would enable work against a+ // peer that is switched off or gone.+ it('is false for a peer that is switched off, offline, or not opted in, however fresh its snapshot', () => {+ for (const overrides of [+ { enabled: false },+ { status: 'offline' },+ { mediaProvider: { enabled: false, audioModels: [] } },+ ]) {+ const readiness = resolvePeerMediaReadiness(freshReady(overrides), { now: NOW });+ expect(readiness.state).toBe('ready');+ expect(readiness.usable).toBe(false);+ }+ });++ it('is false once the capacity window has expired', () => {+ const stale = freshReady();+ stale.mediaProviderStatus.freshUntil = iso(-1_000);+ expect(resolvePeerMediaReadiness(stale, { now: NOW }).usable).toBe(false);+ });+});+describe('summarizePeerMediaQueue', () => {const queue = (overrides = {}) => ({totalActive: 2, providerActive: 1, queued: 1, running: 1, maxQueuedJobs: 4, accepting: true, ...overrides,