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 the capacity panel from advertising peers it cannot reach

[._.]/ Adam Eivyfbf1375d7b41
diff --git a/client/src/components/system-resources/MediaCapacityPanel.jsx b/client/src/components/system-resources/MediaCapacityPanel.jsx
index ca2c6cbb54..d5eed602cd 100644
--- a/client/src/components/system-resources/MediaCapacityPanel.jsx
+++ b/client/src/components/system-resources/MediaCapacityPanel.jsx
@@ -1,6 +1,7 @@
-import { useCallback, useEffect, useState } from 'react';
+import { useCallback, useState } from 'react';
import { Gauge } from 'lucide-react';
import { Link } from 'react-router';
+import { useAutoRefetch } from '../../hooks/useAutoRefetch.js';
import * as api from '../../services/api.js';
import Pill from '../ui/Pill';
import { timeAgo } from '../../utils/formatters';
@@ -97,7 +98,13 @@ export default function MediaCapacityPanel({ media }) {
setPeers(Array.isArray(data.peers) ? data.peers : []);
}, []);
- useEffect(() => { loadPeers(); }, [loadPeers]);
+ // Poll on the same cadence as the health report this panel sits in. Loading
+ // once on mount left a peer that came back (or was just enabled, or just went
+ // stale) frozen at its mount-time reading for as long as the user stayed on
+ // the page — and this panel's whole job is to say what is usable *now*.
+ // pollOnly: loadPeers owns its own state so it can keep "the read failed"
+ // separate from "there are no providers", which a single `data` slot cannot.
+ useAutoRefetch(loadPeers, 15_000, { pollOnly: true });
const providers = (peers || []).filter((peer) => peer?.mediaProvider?.enabled === true);
const cuda = CUDA_META[media?.gpu?.cudaStatus] || CUDA_META.unknown;
@@ -141,12 +148,21 @@ export default function MediaCapacityPanel({ media }) {
</Link>
</div>
- {peersFailed ? (
+ {/* A refresh that fails once we already have a list keeps showing it,
+ flagged as last-known — the same call QueuesPanel makes. Only a
+ failure with nothing to fall back on reports unknown, because that
+ is the one case where rendering an empty list would assert
+ "no providers configured" without having read anything. */}
+ {peersFailed && (
<p className="mt-2 text-xs text-port-warning">
- Peer list unavailable — provider readiness is unknown.
+ Peer list refresh failed. {peers === null
+ ? 'Provider readiness is unknown.'
+ : 'Showing the last known snapshot.'}
</p>
- ) : peers === null ? (
- <p className="mt-2 text-xs text-gray-500">Loading peer providers…</p>
+ )}
+
+ {peers === null ? (
+ !peersFailed && <p className="mt-2 text-xs text-gray-500">Loading peer providers…</p>
) : providers.length === 0 ? (
<p className="mt-2 text-xs text-gray-500">
No peer is enabled as a media provider. Enable one from Instances to render on another machine.
diff --git a/client/src/components/system-resources/MediaCapacityPanel.test.jsx b/client/src/components/system-resources/MediaCapacityPanel.test.jsx
index f64cedbadc..78444ab808 100644
--- a/client/src/components/system-resources/MediaCapacityPanel.test.jsx
+++ b/client/src/components/system-resources/MediaCapacityPanel.test.jsx
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { render, screen } from '@testing-library/react';
+import { act, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
const api = vi.hoisted(() => ({ getInstances: vi.fn() }));
@@ -121,10 +121,56 @@ describe('MediaCapacityPanel', () => {
});
// A failed read and a genuinely peerless install must not render identically.
- it('distinguishes a failed peer read from having no providers', async () => {
+ it('distinguishes a failed first peer read from having no providers', async () => {
api.getInstances.mockRejectedValue(new Error('offline'));
renderPanel();
expect(await screen.findByText(/provider readiness is unknown/i)).toBeInTheDocument();
expect(screen.queryByText(/No peer is enabled as a media provider/)).not.toBeInTheDocument();
});
+
+ it('shows a disabled peer connection as disabled, not as ready', async () => {
+ api.getInstances.mockResolvedValue({ peers: [providerPeer({ enabled: false })] });
+ renderPanel();
+ expect(await screen.findByText('peer disabled')).toBeInTheDocument();
+ expect(screen.queryByText('ready')).not.toBeInTheDocument();
+ });
+
+ // The panel's whole job is to say what is usable *now* — a mount-only read
+ // froze every peer at its mount-time reading for as long as the page stayed
+ // open.
+ it('re-reads the peer list on the poll interval', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ try {
+ api.getInstances.mockResolvedValue({ peers: [] });
+ renderPanel();
+ await act(async () => {});
+ await screen.findByText(/No peer is enabled as a media provider/);
+
+ api.getInstances.mockResolvedValue({ peers: [providerPeer()] });
+ await act(async () => { await vi.advanceTimersByTimeAsync(15_000); });
+
+ expect(await screen.findByText('render-box')).toBeInTheDocument();
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it('keeps the last known peers when a later refresh fails', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ try {
+ api.getInstances.mockResolvedValue({ peers: [providerPeer()] });
+ renderPanel();
+ await act(async () => {});
+ await screen.findByText('render-box');
+
+ api.getInstances.mockRejectedValue(new Error('offline'));
+ await act(async () => { await vi.advanceTimersByTimeAsync(15_000); });
+
+ expect(await screen.findByText(/Showing the last known snapshot/i)).toBeInTheDocument();
+ // The peer we already know about stays on screen rather than vanishing.
+ expect(screen.getByText('render-box')).toBeInTheDocument();
+ } finally {
+ vi.useRealTimers();
+ }
+ });
});
diff --git a/client/src/lib/federatedMediaReadiness.js b/client/src/lib/federatedMediaReadiness.js
index 6748e1904d..893fbbaede 100644
--- a/client/src/lib/federatedMediaReadiness.js
+++ b/client/src/lib/federatedMediaReadiness.js
@@ -47,6 +47,21 @@ export const FEDERATED_MEDIA_STATE_HELP = Object.freeze({
invalid: 'The peer returned a response that did not match the versioned media-provider contract.',
});
+// Peer-level readings that outrank whatever the last probe concluded. None of
+// them is a provider state from the wire; each carries its own remedy because
+// the wire's `state` may legitimately be absent (or stale-but-`ready`) while
+// one of these holds.
+//
+// PEER_DISABLED comes first for the same reason the server checks it first:
+// `assertFederatedMediaProviderSelection` rejects a submission to a disabled
+// peer with MEDIA_PROVIDER_PEER_DISABLED before it looks at anything else, so a
+// peer whose connection is switched off must never read as `ready` here no
+// matter how healthy its cached snapshot looks.
+const PEER_DISABLED = Object.freeze({
+ label: 'peer disabled',
+ tone: 'warning',
+ help: 'This peer connection is switched off. Re-enable it under Instances before routing work to it.',
+});
// Not a real provider state — the peer is opted in but no probe has landed yet.
// Kept distinct from `unavailable` so a first-run instance doesn't accuse a
// perfectly healthy peer of having nothing to offer.
@@ -108,19 +123,23 @@ export function resolvePeerMediaReadiness(peer, { now = Date.now() } = {}) {
const state = !status
? null
: (snapshotExpired(status, now) ? 'stale' : status.state);
- const meta = !config.enabled
- ? OFF
- : peer?.status !== 'online'
- ? PEER_OFFLINE
- : (FEDERATED_MEDIA_STATE_META[state] || CHECKING);
+ const meta = peer?.enabled === false
+ ? PEER_DISABLED
+ : !config.enabled
+ ? OFF
+ : peer?.status !== 'online'
+ ? PEER_OFFLINE
+ : (FEDERATED_MEDIA_STATE_META[state] || CHECKING);
return {
configured: config.enabled,
state,
label: meta.label,
tone: meta.tone,
- // Remedy text belongs to the provider state, not to the peer being offline
- // — an offline peer's own row already says so.
- help: (config.enabled && state && state !== 'ready' && FEDERATED_MEDIA_STATE_HELP[state]) || null,
+ // A peer-level reading carries its own remedy; otherwise the remedy belongs
+ // to the provider state. An offline peer gets none — its own row says so.
+ help: meta.help !== undefined
+ ? meta.help
+ : ((config.enabled && state && state !== 'ready' && FEDERATED_MEDIA_STATE_HELP[state]) || null),
queue: isRecord(snapshot?.queue) ? snapshot.queue : null,
capabilities: Array.isArray(snapshot?.capabilities) ? snapshot.capabilities : NO_CAPABILITIES,
checkedAt: typeof status?.checkedAt === 'string' ? status.checkedAt : null,
diff --git a/client/src/lib/federatedMediaReadiness.test.js b/client/src/lib/federatedMediaReadiness.test.js
index 50f55a43e5..d78d2c50c4 100644
--- a/client/src/lib/federatedMediaReadiness.test.js
+++ b/client/src/lib/federatedMediaReadiness.test.js
@@ -78,6 +78,20 @@ describe('resolvePeerMediaReadiness', () => {
expect(readiness.state).toBeNull();
});
+ // The server rejects a submission to a disabled peer with
+ // MEDIA_PROVIDER_PEER_DISABLED before it looks at capacity at all, so a
+ // healthy cached snapshot must not keep advertising it as ready.
+ it('reports a disabled peer connection as disabled despite a ready snapshot', () => {
+ const readiness = resolvePeerMediaReadiness(peer({ enabled: false }), { now: NOW });
+ expect(readiness.label).toBe('peer disabled');
+ expect(readiness.tone).toBe('warning');
+ expect(readiness.help).toMatch(/switched off/i);
+ });
+
+ it('treats a peer with no explicit enabled flag as enabled', () => {
+ expect(resolvePeerMediaReadiness(peer(), { now: NOW }).label).toBe('ready');
+ });
+
it('reports an offline peer as offline rather than as a provider fault', () => {
const readiness = resolvePeerMediaReadiness(peer({ status: 'offline' }), { now: NOW });
expect(readiness.label).toBe('peer offline');