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

feat: report provider concurrency and per-kind queue occupancy over the federated media wire (#4348)

[._.]/ Adam Eivybe04323bb067
diff --git a/client/src/components/instances/PeerMediaProviderPanel.jsx b/client/src/components/instances/PeerMediaProviderPanel.jsx
index d427c66e05..570b117b58 100644
--- a/client/src/components/instances/PeerMediaProviderPanel.jsx
+++ b/client/src/components/instances/PeerMediaProviderPanel.jsx
@@ -6,6 +6,7 @@ import {
federatedMediaModelKey as keyOf,
peerMediaProviderConfig,
resolvePeerMediaReadiness,
+ summarizePeerMediaQueue,
} from '../../lib/federatedMediaReadiness.js';
import Pill from '../ui/Pill';
@@ -47,7 +48,7 @@ export default function PeerMediaProviderPanel({ peer, onRefresh }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
[config.raw, capabilities],
);
- const queue = readiness.queue;
+ const queueSummary = useMemo(() => summarizePeerMediaQueue(readiness.queue), [readiness.queue]);
// Carry every kind's list forward on each write. The server merges the
// mediaProvider object, but a patch that omitted a list this panel never
@@ -119,12 +120,12 @@ export default function PeerMediaProviderPanel({ peer, onRefresh }) {
{config.enabled && (
<>
- {queue && (
- <div className="flex items-center gap-1.5 text-[10px] text-gray-500">
- <Gauge size={11} />
- <span>
- {queue.running} running · {queue.queued} queued · {queue.totalActive}/{queue.maxQueuedJobs} shared slots active
- </span>
+ {queueSummary.slots && (
+ <div className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[10px] text-gray-500">
+ <Gauge size={11} className="shrink-0" />
+ <span>{queueSummary.slots} active</span>
+ {queueSummary.drain && <span>· runs {queueSummary.drain}</span>}
+ {queueSummary.kinds.length > 0 && <span>· {queueSummary.kinds.join(' · ')}</span>}
</div>
)}
diff --git a/client/src/components/instances/PeerMediaProviderPanel.test.jsx b/client/src/components/instances/PeerMediaProviderPanel.test.jsx
index a10b35922f..f7b65630da 100644
--- a/client/src/components/instances/PeerMediaProviderPanel.test.jsx
+++ b/client/src/components/instances/PeerMediaProviderPanel.test.jsx
@@ -43,6 +43,11 @@ const readyStatus = {
// by design — a patch that omitted a list would only read as "unchanged" by luck.
const emptyLists = { audioModels: [], imageModels: [], videoModels: [] };
+const withQueue = (queue) => ({
+ ...readyStatus,
+ snapshot: { ...readyStatus.snapshot, queue: { ...readyStatus.snapshot.queue, ...queue } },
+});
+
beforeEach(() => {
vi.clearAllMocks();
updatePeer.mockResolvedValue({ id: basePeer.id });
@@ -64,6 +69,24 @@ describe('PeerMediaProviderPanel', () => {
expect(onRefresh).toHaveBeenCalled();
});
+ it('reports how fast the peer drains its queue and which kinds are occupying it', () => {
+ const peer = {
+ ...basePeer,
+ mediaProvider: { enabled: true, audioModels: [] },
+ mediaProviderStatus: withQueue({
+ concurrency: 2,
+ byKind: { audio: { running: 1, queued: 2 }, image: { running: 0, queued: 0 }, video: { running: 0, queued: 0 } },
+ }),
+ };
+ render(<PeerMediaProviderPanel peer={peer} onRefresh={vi.fn()} />);
+
+ fireEvent.click(screen.getByRole('button', { name: /Remote media provider/i }));
+ expect(screen.getByText(/runs 2 at a time/i)).toBeInTheDocument();
+ expect(screen.getByText(/audio 1 running, 2 queued/i)).toBeInTheDocument();
+ // An idle kind is omitted, not rendered as a zero.
+ expect(screen.queryByText(/(image|video) \d/i)).not.toBeInTheDocument();
+ });
+
it('shows queue capacity and persists an allowlisted model without dropping future config fields', async () => {
const onRefresh = vi.fn();
const peer = {
@@ -74,7 +97,7 @@ describe('PeerMediaProviderPanel', () => {
render(<PeerMediaProviderPanel peer={peer} onRefresh={onRefresh} />);
fireEvent.click(screen.getByRole('button', { name: /Remote media provider/i }));
- expect(screen.getByText(/1 running · 2 queued · 3\/4 shared slots active/i)).toBeInTheDocument();
+ expect(screen.getByText(/1 running · 2 queued · 3\/4 slots active/i)).toBeInTheDocument();
fireEvent.click(screen.getByLabelText('Allow audio model MiniMax Music 3'));
await waitFor(() => expect(updatePeer).toHaveBeenCalledWith('peer-example', {
diff --git a/client/src/components/system-resources/MediaCapacityPanel.jsx b/client/src/components/system-resources/MediaCapacityPanel.jsx
index ce1a93479c..3ebfefba6e 100644
--- a/client/src/components/system-resources/MediaCapacityPanel.jsx
+++ b/client/src/components/system-resources/MediaCapacityPanel.jsx
@@ -8,6 +8,7 @@ import { timeAgo } from '../../utils/formatters';
import {
FEDERATED_MEDIA_KINDS,
resolvePeerMediaReadiness,
+ summarizePeerMediaQueue,
} from '../../lib/federatedMediaReadiness.js';
// Three-state, never a boolean. `unknown` means the nvidia-smi probe itself
@@ -44,7 +45,7 @@ function LaneRow({ label, help, lane }) {
function PeerRow({ peer }) {
const readiness = resolvePeerMediaReadiness(peer);
- const queue = readiness.queue;
+ const queue = summarizePeerMediaQueue(readiness.queue);
return (
<div className="rounded-lg border border-port-border bg-port-bg px-3 py-2">
<div className="flex items-center gap-2">
@@ -57,11 +58,9 @@ function PeerRow({ peer }) {
{readiness.kinds.length > 0
? <span>{readiness.kinds.join(' · ')}</span>
: <span>no models allowlisted</span>}
- {queue && (
- <span>
- {queue.running} running · {queue.queued} queued · {queue.totalActive}/{queue.maxQueuedJobs} slots
- </span>
- )}
+ {queue.slots && <span>{queue.slots}</span>}
+ {queue.drain && <span>{queue.drain}</span>}
+ {queue.kinds.length > 0 && <span>{queue.kinds.join(' · ')}</span>}
{readiness.checkedAt && <span>checked {timeAgo(readiness.checkedAt)}</span>}
</div>
{readiness.help && (
diff --git a/client/src/components/system-resources/MediaCapacityPanel.test.jsx b/client/src/components/system-resources/MediaCapacityPanel.test.jsx
index f16f535024..039547621e 100644
--- a/client/src/components/system-resources/MediaCapacityPanel.test.jsx
+++ b/client/src/components/system-resources/MediaCapacityPanel.test.jsx
@@ -94,6 +94,38 @@ describe('MediaCapacityPanel', () => {
expect(screen.getByText('1 running · 0 queued · 1/4 slots')).toBeInTheDocument();
});
+ // The local lanes above already show running/limit; a peer row that could only
+ // report depth left the two halves of this card answering different questions.
+ it('reports a peer’s drain rate and busy kinds beside its queue depth', async () => {
+ api.getInstances.mockResolvedValue({ peers: [providerPeer({
+ mediaProviderStatus: {
+ checkedAt: new Date().toISOString(),
+ state: 'ready',
+ freshUntil: new Date(Date.now() + 60_000).toISOString(),
+ snapshot: {
+ queue: {
+ running: 1, queued: 0, totalActive: 1, maxQueuedJobs: 4, accepting: true,
+ concurrency: 4,
+ byKind: { audio: { running: 1, queued: 0 }, image: { running: 0, queued: 0 }, video: { running: 0, queued: 0 } },
+ },
+ capabilities: [],
+ },
+ },
+ })] });
+ renderPanel();
+ expect(await screen.findByText('4 at a time')).toBeInTheDocument();
+ expect(screen.getByText('audio 1 running')).toBeInTheDocument();
+ });
+
+ // An older provider sends neither field. The row drops the segments rather
+ // than reporting lanes as idle that the peer never told us about.
+ it('omits the drain rate for a peer on a build that does not report one', async () => {
+ api.getInstances.mockResolvedValue({ peers: [providerPeer()] });
+ renderPanel();
+ expect(await screen.findByText('render-box')).toBeInTheDocument();
+ expect(screen.queryByText(/\d+ at a time/)).not.toBeInTheDocument();
+ });
+
it('shows an expired snapshot as stale with its remedy, not as ready', async () => {
api.getInstances.mockResolvedValue({
peers: [providerPeer({
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 84fc6c11bc..8f0d14d5bd 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -44,7 +44,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `creativeDirectorPlan.js` | Pure presentation helpers for the CD studio Plan board (CDO Phase 4) — annotate `plan.steps[]` with tool cost-class/timing/approval flags, cost/status summaries, owning-surface deep links, status/cost badge tone maps. |
| `creativeDirectorPreview.js` | `selectProjectPreview(project)` → `{ kind: 'video'\|'image'\|'audio'\|'none', jobId?, src?, poster?, label, durationSec? }` — picks a CD project's representative produced asset (finalVideoId → last rendered scene → last done plan video/image step → `musicBed` audio → startingImageFile) for the list cards + Overview tab (#2702, audio #2772). Pure, computed off the already-returned project payload (no fetch). Plus `previewAspectClass(aspectRatio)` (literal Tailwind classes — a computed `aspect-[w/h]` never lands in the build), `startingImageSrc()` (client mirror of `localImageFilename`), and the `videoSrcForJob`/`videoPosterForJob`/`imageSrcForJob`/`musicBedSrc` path builders — the one client-side definition of the `<jobId>`-named asset convention, shared with `ScenePreview.jsx`. |
| `editorialRoadmap.js` | `projectAnalyzedPoints` (aggregate roadmap → analyzed chart points with arc-position `frac`) + `dominant` (most-frequent string). Shared by EditorialRoadmapPanel and the Reader Map page. |
-| `federatedMediaReadiness.js` | One reading of a peer’s federated media-provider readiness (#4348), shared by the Instances peer card and the System Health capacity panel so the two cannot disagree. `resolvePeerMediaReadiness(peer, { now })` maps the stored probe onto a display state/label/tone plus its remedy text, queue snapshot, capabilities, and per-kind allowlists; it re-derives `stale` when the snapshot’s `freshUntil` has passed, so a snapshot probed as `ready` cannot keep reading `ready` after the server would refuse to submit against it. Also exports `FEDERATED_MEDIA_KINDS` (audio/image/video + their config fields and icons), the state/help tables, and `peerMediaProviderConfig`. Display only — the server re-probes and fail-closes before any job leaves. |
+| `federatedMediaReadiness.js` | One reading of a peer’s federated media-provider readiness (#4348), shared by the Instances peer card and the System Health capacity panel so the two cannot disagree. `resolvePeerMediaReadiness(peer, { now })` maps the stored probe onto a display state/label/tone plus its remedy text, queue snapshot, capabilities, and per-kind allowlists; it re-derives `stale` when the snapshot’s `freshUntil` has passed, so a snapshot probed as `ready` cannot keep reading `ready` after the server would refuse to submit against it. Also exports `FEDERATED_MEDIA_KINDS` (audio/image/video + their config fields and icons), the state/help tables, and `peerMediaProviderConfig`. `summarizePeerMediaQueue(queue)` renders the peer’s queue block — slot occupancy, how many jobs drain in parallel, and which kinds are busy — dropping any segment an older provider did not send rather than showing it as a zero. Display only — the server re-probes and fail-closes before any job leaves. |
| `glbFailure.js` | Turns a 3D asset failure into an actionable sentence. `glbFailureHint(error)` matches the message against a shared table (an HTML body reaching the glTF parser, a WebGL context failure, a 404) and returns `null` when nothing recognizes it — so a caller can tell "we know the cause" from "we don't" and fall back to the raw text. `glbErrorText(error)` reads a message off whatever shape was thrown. Shared because the CoS avatars load remote GLBs too: every caught error there used to be reported as "this display has no WebGL", sending the user to change an unrelated setting (#4688). Consumed by `media/GlbViewer.jsx` and `cos/CoSCanvasGuard.jsx`. |
| `grokVideoClip.js` | Mirror of `server/lib/grokVideoClip.js` — `GROK_VIDEO_DURATIONS` (`[6, 10]`) + `GROK_VIDEO_DEFAULT_DURATION`, the clip lengths grok's `image_to_video` actually delivers. |
| `imageCleaners.js` | Mirror of `resolveCleanersFromConfig` from `server/lib/imageClean.js`. Reads `{cleanC2PA, denoise}` off a per-mode settings record. `cleanC2PA` defaults are mode-aware (on for `codex` + `external` — the backends that emit C2PA chunks today — off otherwise, as an allow-list rather than a deny-list); `denoise` defaults off everywhere (lossy, opt-in only). |
diff --git a/client/src/lib/federatedMediaReadiness.js b/client/src/lib/federatedMediaReadiness.js
index f496b174fa..08dc7783b8 100644
--- a/client/src/lib/federatedMediaReadiness.js
+++ b/client/src/lib/federatedMediaReadiness.js
@@ -130,6 +130,56 @@ function verifiedState(status, now) {
return state;
}
+// Same rationale as NO_CAPABILITIES, for the queue summary's kind list.
+const NO_KIND_SUMMARY = Object.freeze([]);
+const isCount = (value) => Number.isInteger(value) && value >= 0;
+
+/**
+ * The peer's queue block as a display summary, shared by both surfaces.
+ *
+ * `concurrency` and `byKind` reached the wire after v1 shipped (#4348), so an
+ * older provider omits them and every segment here is independently optional —
+ * a missing field is dropped rather than rendered as a zero, which would claim
+ * an idle lane the peer never reported. `slots` stays first because it is the
+ * one segment every provider has always sent.
+ *
+ * @param {object|null} queue - `snapshot.queue` from a probed peer
+ * @returns {{slots: string|null, drain: string|null, kinds: string[]}}
+ */
+export function summarizePeerMediaQueue(queue) {
+ if (!isRecord(queue)) return { slots: null, drain: null, kinds: NO_KIND_SUMMARY };
+ const slots = isCount(queue.running) && isCount(queue.queued)
+ && isCount(queue.totalActive) && isCount(queue.maxQueuedJobs)
+ ? `${queue.running} running · ${queue.queued} queued · ${queue.totalActive}/${queue.maxQueuedJobs} slots`
+ : null;
+ // "How fast does that backlog drain?", which queue depth alone cannot answer:
+ // two jobs ahead on a 1-wide lane is a very different wait from two on a
+ // 10-wide one.
+ const drain = Number.isInteger(queue.concurrency) && queue.concurrency > 0
+ ? `${queue.concurrency} at a time`
+ : null;
+ // Only kinds actually occupying a lane. Listing three zeroes crowds out the
+ // one number that matters, and the `slots` segment above already reports
+ // whether anything is running at all.
+ const byKind = isRecord(queue.byKind) ? queue.byKind : null;
+ const kinds = byKind
+ ? FEDERATED_MEDIA_KINDS
+ .map(({ kind, label }) => {
+ const entry = byKind[kind];
+ if (!isRecord(entry)) return null;
+ const running = isCount(entry.running) ? entry.running : 0;
+ const queued = isCount(entry.queued) ? entry.queued : 0;
+ if (running + queued === 0) return null;
+ const parts = [];
+ if (running > 0) parts.push(`${running} running`);
+ if (queued > 0) parts.push(`${queued} queued`);
+ return `${label} ${parts.join(', ')}`;
+ })
+ .filter(Boolean)
+ : NO_KIND_SUMMARY;
+ return { slots, drain, kinds: kinds.length > 0 ? kinds : NO_KIND_SUMMARY };
+}
+
/**
* Resolve one peer's media-provider readiness for display.
*
diff --git a/client/src/lib/federatedMediaReadiness.test.js b/client/src/lib/federatedMediaReadiness.test.js
index 947f102201..9cef0aae24 100644
--- a/client/src/lib/federatedMediaReadiness.test.js
+++ b/client/src/lib/federatedMediaReadiness.test.js
@@ -5,6 +5,7 @@ import {
federatedMediaModelKey,
peerMediaProviderConfig,
resolvePeerMediaReadiness,
+ summarizePeerMediaQueue,
} from './federatedMediaReadiness.js';
const NOW = Date.parse('2026-08-20T12:00:00.000Z');
@@ -186,3 +187,51 @@ describe('federatedMediaModelKey', () => {
.not.toBe(federatedMediaModelKey({ engine: 'a-b', modelId: 'c' }));
});
});
+
+describe('summarizePeerMediaQueue', () => {
+ const queue = (overrides = {}) => ({
+ totalActive: 2, providerActive: 1, queued: 1, running: 1, maxQueuedJobs: 4, accepting: true, ...overrides,
+ });
+
+ it('renders slots, drain rate, and only the kinds actually occupying a lane', () => {
+ const summary = summarizePeerMediaQueue(queue({
+ concurrency: 2,
+ byKind: {
+ audio: { running: 1, queued: 1 },
+ image: { running: 0, queued: 1 },
+ video: { running: 0, queued: 0 },
+ },
+ }));
+ expect(summary.slots).toBe('1 running · 1 queued · 2/4 slots');
+ expect(summary.drain).toBe('2 at a time');
+ expect(summary.kinds).toEqual(['audio 1 running, 1 queued', 'image 1 queued']);
+ });
+
+ // An older provider sends neither field. Rendering the absence as a zero
+ // would claim idle lanes the peer never reported on.
+ it('drops the segments an older provider never sent instead of showing zeroes', () => {
+ const summary = summarizePeerMediaQueue(queue());
+ expect(summary.slots).toBe('1 running · 1 queued · 2/4 slots');
+ expect(summary.drain).toBeNull();
+ expect(summary.kinds).toEqual([]);
+ });
+
+ it('drops a concurrency that is absent, zero, or not a whole count', () => {
+ expect(summarizePeerMediaQueue(queue({ concurrency: 0 })).drain).toBeNull();
+ expect(summarizePeerMediaQueue(queue({ concurrency: 1.5 })).drain).toBeNull();
+ expect(summarizePeerMediaQueue(queue({ concurrency: '4' })).drain).toBeNull();
+ });
+
+ it('omits a kind reporting no work rather than listing it as idle', () => {
+ const summary = summarizePeerMediaQueue(queue({
+ byKind: { audio: { running: 0, queued: 0 }, image: { running: 2, queued: 0 } },
+ }));
+ expect(summary.kinds).toEqual(['image 2 running']);
+ });
+
+ it('reports no slot line at all when the queue block is missing or malformed', () => {
+ for (const bad of [null, undefined, 'busy', queue({ maxQueuedJobs: null })]) {
+ expect(summarizePeerMediaQueue(bad).slots).toBeNull();
+ }
+ });
+});
diff --git a/docs/FEDERATED_MEDIA_PROVIDERS.md b/docs/FEDERATED_MEDIA_PROVIDERS.md
index 7fbd3f9126..2404b692bc 100644
--- a/docs/FEDERATED_MEDIA_PROVIDERS.md
+++ b/docs/FEDERATED_MEDIA_PROVIDERS.md
@@ -263,7 +263,8 @@ An unreadable capacity report renders as unknown rather than as an idle machine.
The **peer** half lists every peer enabled as a media provider with its
readiness state, allowlisted kinds, the peer's own shared queue depth against its
-`maxQueuedJobs`, and how long ago it was probed — the same state vocabulary and
+`maxQueuedJobs`, how many of those jobs it runs in parallel, which kinds are
+occupying its lanes, and how long ago it was probed — the same state vocabulary and
remedy text the Instances peer card uses, from one shared resolver
(`client/src/lib/federatedMediaReadiness.js`), so the two screens cannot
disagree.
@@ -314,6 +315,27 @@ CUDA has three states: `available`, `absent`, and `unknown`. A CUDA model is rea
The configured `maxQueuedJobs` is conservative: all queued/running work that consumes this machine's media resources counts against it. Outgoing proxy jobs are excluded because they consume another peer's capacity; counting them could make two idle peers report busy while waiting on each other.
+The queue block also reports how fast that backlog drains, because a depth alone
+cannot say:
+
+| Field | Meaning |
+|-------|---------|
+| `totalActive` | every queued/running local media job, including kinds this contract does not federate |
+| `providerActive` / `queued` / `running` | the subset owned by federated callers |
+| `maxQueuedJobs` | the admission bound `accepting` is computed against |
+| `concurrency` | how many of those active jobs actually run at once here |
+| `byKind` | per-kind `{running, queued}` for `audio`/`image`/`video` |
+
+Two jobs ahead of a submission mean two renders' wait on a serialized lane and
+roughly none on a parallel one; `concurrency` is what tells those apart.
+`byKind` covers the federated kinds only, so it need not sum to `totalActive` —
+local work of an unfederated kind (LoRA training) occupies the same lanes.
+
+`concurrency` and `byKind` were added after wire v1 shipped, so both are
+optional: a provider on an older build omits them and a consumer must read the
+absence as **unknown**, never as zero. The UI drops the segment rather than
+rendering a lane as idle that the peer never reported on.
+
Status never includes prompts, lyrics, credentials, local paths, commission records, or private creative metadata.
### Submit a job
diff --git a/server/lib/federatedMediaWire.js b/server/lib/federatedMediaWire.js
index bb9676bc93..df65c292cf 100644
--- a/server/lib/federatedMediaWire.js
+++ b/server/lib/federatedMediaWire.js
@@ -179,6 +179,14 @@ export const federatedMediaCapabilitySchema = z.object({
})).max(100).nullable().optional(),
});
+// Per-kind occupancy of the provider's own generation lanes. Counts only —
+// never a job id, an owner, or anything derived from a prompt (ADR
+// docs/decisions/2026-08-20-federated-visual-prompts.md rule 3).
+const federatedMediaKindOccupancySchema = z.object({
+ running: z.number().int().nonnegative(),
+ queued: z.number().int().nonnegative(),
+});
+
const federatedMediaQueueStatusSchema = z.object({
totalActive: z.number().int().nonnegative(),
providerActive: z.number().int().nonnegative(),
@@ -186,6 +194,25 @@ const federatedMediaQueueStatusSchema = z.object({
running: z.number().int().nonnegative(),
maxQueuedJobs: z.number().int().positive(),
accepting: z.boolean(),
+ // Added after wire v1 shipped, so both are optional AND nullable: a provider
+ // on an older build omits them, and reading an absent value as a number
+ // would invent capacity that was never reported. `null`/absent means
+ // "unknown", never "zero" — the sentinel rule in CLAUDE.md.
+ //
+ // `concurrency` is how many of the reported active jobs actually run at
+ // once here, which is what turns a queue depth into an expected wait: two
+ // jobs ahead of you on a serialized lane is a very different answer from two
+ // on a parallel one, and `maxQueuedJobs` alone cannot tell them apart.
+ concurrency: z.number().int().positive().max(64).nullable().optional(),
+ // `byKind` covers the federated kinds only. `totalActive` legitimately
+ // exceeds their sum: it also counts local media work of kinds this contract
+ // does not federate (e.g. LoRA training), which occupies the same lanes.
+ //
+ // `partialRecord`, not `record`: a Zod 4 record over an enum key is
+ // exhaustive, so the day a fourth kind joins KNOWN_MEDIA_KINDS every older
+ // provider's three-kind payload would fail validation on a newer consumer.
+ // The provider only ever reports the kinds the consumer negotiated anyway.
+ byKind: z.partialRecord(mediaKindSchema, federatedMediaKindOccupancySchema).optional(),
});
// Strip unknown fields from peer responses before persisting or exposing them
diff --git a/server/lib/federatedMediaWire.test.js b/server/lib/federatedMediaWire.test.js
index 3614f7108f..91110adb78 100644
--- a/server/lib/federatedMediaWire.test.js
+++ b/server/lib/federatedMediaWire.test.js
@@ -171,6 +171,58 @@ describe('federated media status kind projection', () => {
expect(parsed.maxNumFrames).toBeUndefined();
expect(parsed.resolutionOptions).toBeUndefined();
});
+
+ it('validates a queue block reporting concurrency and per-kind occupancy', () => {
+ const parsed = federatedMediaProviderStatusSchema.parse(status({
+ kinds: ['audio', 'image', 'video'],
+ queue: {
+ totalActive: 3,
+ providerActive: 1,
+ queued: 0,
+ running: 1,
+ maxQueuedJobs: 4,
+ accepting: true,
+ concurrency: 2,
+ byKind: {
+ audio: { running: 1, queued: 0 },
+ image: { running: 0, queued: 1 },
+ video: { running: 0, queued: 0 },
+ },
+ },
+ }));
+ expect(parsed.queue.concurrency).toBe(2);
+ expect(parsed.queue.byKind.image).toEqual({ running: 0, queued: 1 });
+ });
+
+ it('validates an older provider queue block omitting concurrency and byKind', () => {
+ const parsed = federatedMediaProviderStatusSchema.parse(status());
+ expect(parsed.queue.concurrency).toBeUndefined();
+ expect(parsed.queue.byKind).toBeUndefined();
+ });
+
+ // The kind list is negotiated, so a provider legitimately reports fewer kinds
+ // than the consumer knows about. A record that demanded every key would make
+ // an audio-only projection unparseable the moment a fourth kind is added.
+ it('accepts a byKind covering only the negotiated kinds', () => {
+ expect(federatedMediaProviderStatusSchema.safeParse(status({
+ queue: { ...status().queue, byKind: { audio: { running: 1, queued: 0 } } },
+ })).success).toBe(true);
+ });
+
+ it('rejects a byKind entry that is not a non-negative count pair', () => {
+ const bad = (byKind) => federatedMediaProviderStatusSchema.safeParse(status({
+ queue: { ...status().queue, byKind },
+ })).success;
+ expect(bad({ audio: { running: -1, queued: 0 } })).toBe(false);
+ expect(bad({ audio: { running: 1 } })).toBe(false);
+ expect(bad({ holo: { running: 1, queued: 0 } })).toBe(false);
+ });
+
+ it('rejects a concurrency that claims no capacity at all', () => {
+ expect(federatedMediaProviderStatusSchema.safeParse(status({
+ queue: { ...status().queue, concurrency: 0 },
+ })).success).toBe(false);
+ });
});
describe('normalizeRequestedMediaKinds', () => {
diff --git a/server/services/federatedMediaProvider.js b/server/services/federatedMediaProvider.js
index 1459a010e7..bda2b799af 100644
--- a/server/services/federatedMediaProvider.js
+++ b/server/services/federatedMediaProvider.js
@@ -28,6 +28,7 @@ import {
cancelJob,
enqueueJob,
getJob,
+ getQueueCapacity,
isRemoteMediaJob,
listJobs,
} from './mediaJobQueue/index.js';
@@ -347,6 +348,22 @@ async function capabilitiesForKind(kind, config, { pythonPath = null } = {}) {
return [];
}
+/**
+ * How many of the locally-counted active jobs actually run at once here.
+ *
+ * `maxQueuedJobs` is an admission bound, not a rate: it says how much work this
+ * provider will hold, not how fast that work drains. Two jobs ahead of a
+ * submission mean two renders' wait on the serialized GPU lane and roughly none
+ * on the parallel cloud-CLI lane, and a consumer reading only the queue depth
+ * cannot tell those apart. Summing exactly the lanes `activeQueueSnapshot`
+ * counts — the local generation lanes, never the outgoing proxy lane — keeps
+ * the two numbers describing the same population.
+ */
+function localGenerationConcurrency() {
+ const { lanes } = getQueueCapacity();
+ return lanes.gpu.limit + lanes.cloud.limit;
+}
+
function activeQueueSnapshot(config) {
// Outgoing proxy jobs consume a remote peer's capacity, not this provider's
// local generation resources. Counting them here can create a federation
@@ -356,6 +373,21 @@ function activeQueueSnapshot(config) {
ACTIVE_STATUSES.has(job.status) && !isRemoteMediaJob(job),
);
const providerActive = active.filter((job) => job.owner?.startsWith(OWNER_PREFIX));
+ // Seed every federated kind so an idle lane reports 0 rather than being
+ // absent — an absent key and a zero read identically in a UI, and only one of
+ // them is true. Derived from the same filtered list as the slot count, not
+ // from getQueueCapacity().byKind, which also counts the outgoing proxy jobs
+ // this snapshot deliberately excludes.
+ const byKind = Object.fromEntries(
+ KNOWN_MEDIA_KINDS.map((kind) => [kind, { running: 0, queued: 0 }]),
+ );
+ for (const job of active) {
+ // A local job of a kind this contract does not federate (LoRA training)
+ // still occupies a lane, so it counts toward `totalActive` — it just has
+ // no bucket of its own, which is why the two need not sum.
+ const bucket = byKind[job.kind];
+ if (bucket) bucket[job.status === 'running' ? 'running' : 'queued'] += 1;
+ }
return {
totalActive: active.length,
providerActive: providerActive.length,
@@ -363,6 +395,8 @@ function activeQueueSnapshot(config) {
running: providerActive.filter((job) => job.status === 'running').length,
maxQueuedJobs: config.maxQueuedJobs,
accepting: active.length < config.maxQueuedJobs,
+ concurrency: localGenerationConcurrency(),
+ byKind,
};
}
diff --git a/server/services/federatedMediaProvider.test.js b/server/services/federatedMediaProvider.test.js
index d5f2fc869f..17a25739f7 100644
--- a/server/services/federatedMediaProvider.test.js
+++ b/server/services/federatedMediaProvider.test.js
@@ -13,6 +13,7 @@ const state = vi.hoisted(() => ({
imageModels: [],
videoModels: [],
cachedRepos: new Set(),
+ queueCapacity: null,
}));
vi.mock('./settings.js', () => ({
@@ -53,6 +54,7 @@ vi.mock('./musicEngineCapabilities.js', () => ({
vi.mock('./mediaJobQueue/index.js', () => ({
listJobs: vi.fn(() => state.jobs),
+ getQueueCapacity: vi.fn(() => state.queueCapacity),
isRemoteMediaJob: (job) => job?.kind === 'audio' && job.params?.remoteMedia !== undefined,
getJob: vi.fn((id) => state.jobs.find((job) => job.id === id) || null),
enqueueJob: vi.fn(({ kind, owner, params }) => {
@@ -151,6 +153,11 @@ beforeEach(() => {
state.imageModels = [];
state.videoModels = [];
state.cachedRepos = new Set();
+ // Mirrors getQueueCapacity()'s real shape: a serialized GPU lane, a parallel
+ // cloud-CLI lane, and the outgoing proxy lane the provider must ignore.
+ state.queueCapacity = {
+ lanes: { gpu: { running: 0, queued: 0, limit: 1 }, cloud: { running: 0, queued: 0, limit: 3 }, remote: { running: 0, queued: 0, limit: 20 } },
+ };
__resetFederatedMediaProviderForTests();
});
@@ -208,6 +215,42 @@ describe('federated media provider capacity and idempotency', () => {
});
});
+ it('reports the local generation concurrency behind the queue depth', async () => {
+ const status = await getFederatedMediaProviderStatus(config());
+ // GPU (1) + cloud CLI (3). The 20-wide outgoing proxy lane is excluded for
+ // the same reason its jobs are: it renders on someone else's hardware.
+ expect(status.queue.concurrency).toBe(4);
+ });
+
+ it('breaks the shared queue down by federated kind, excluding outgoing proxy jobs', async () => {
+ state.jobs = [
+ { id: 'a', kind: 'audio', status: 'running', owner: 'federated-media:peer-example' },
+ { id: 'b', kind: 'audio', status: 'queued', owner: null },
+ { id: 'c', kind: 'image', status: 'queued', owner: null },
+ // Outgoing proxy work: rendered on a peer, so it occupies no lane here.
+ { id: 'd', kind: 'audio', status: 'running', owner: null, params: { remoteMedia: {} } },
+ // A kind this contract does not federate still holds a local lane, so it
+ // counts toward totalActive while having no bucket of its own.
+ { id: 'e', kind: 'training', status: 'running', owner: null },
+ ];
+ const status = await getFederatedMediaProviderStatus(config(), { kinds: ['audio', 'image', 'video'] });
+ expect(status.queue.byKind).toEqual({
+ audio: { running: 1, queued: 1 },
+ image: { running: 0, queued: 1 },
+ video: { running: 0, queued: 0 },
+ });
+ expect(status.queue.totalActive).toBe(4);
+ });
+
+ it('seeds an idle kind with zeroes rather than omitting it', async () => {
+ const status = await getFederatedMediaProviderStatus(config());
+ expect(status.queue.byKind).toEqual({
+ audio: { running: 0, queued: 0 },
+ image: { running: 0, queued: 0 },
+ video: { running: 0, queued: 0 },
+ });
+ });
+
it('queues allowlisted audio without exposing the prompt in its response', async () => {
const result = await submitFederatedMediaJob({
callerId: 'peer-example', config: config(), input: input(), idempotencyKey: 'commission-1',