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 (claude): make the concurrency guard test able to fail, and finish the usable composition

[._.]/ Adam Eivy7e6062617121
diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsx
index 1110089002..23fdf18a3e 100644
--- a/client/src/components/music/MusicGenPanel.jsx
+++ b/client/src/components/music/MusicGenPanel.jsx
@@ -544,7 +544,7 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist
</select>
</label>
<p className="text-[11px] text-gray-400">
- {remoteReadiness?.state === 'ready' && remoteQueueSegments.length > 0
+ {remoteReadiness?.usable && remoteQueueSegments.length > 0
? remoteQueueSegments.join(' · ')
: remoteReadiness?.help
|| 'Remote generation requires a ready, authenticated peer with fresh capacity.'}
diff --git a/client/src/components/music/MusicGenPanel.test.jsx b/client/src/components/music/MusicGenPanel.test.jsx
index 74ed8fd30d..73a8bbdce0 100644
--- a/client/src/components/music/MusicGenPanel.test.jsx
+++ b/client/src/components/music/MusicGenPanel.test.jsx
@@ -305,6 +305,42 @@ describe('MusicGenPanel', () => {
expect(requestBody).not.toHaveProperty('lyrics');
});
+ // `state` is the provider's verdict on its own surface, so a peer switched off
+ // inside its freshness window still reads `ready`. Showing its queue there
+ // suppressed the one line explaining why Generate was disabled.
+ it('explains a switched-off peer instead of showing its last queue reading', async () => {
+ api.listMusicEngines.mockResolvedValue({ defaultEngine: 'musicgen', engines: [engine({ ready: true })] });
+ api.getInstances.mockResolvedValue({
+ peers: [{
+ id: 'peer-example',
+ name: 'Example GPU',
+ status: 'online',
+ enabled: false,
+ mediaProvider: { enabled: true, audioModels: [{ engine: 'minimax-music3', modelId: 'minimax-music3' }] },
+ mediaProviderStatus: {
+ state: 'ready',
+ checkedAt: new Date().toISOString(),
+ freshUntil: new Date(Date.now() + 60_000).toISOString(),
+ snapshot: {
+ queue: { accepting: true, running: 0, queued: 0, totalActive: 0, maxQueuedJobs: 4 },
+ 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' } });
+
+ expect(screen.getByRole('button', { name: /^generate$/i })).toBeDisabled();
+ expect(screen.getByText(/peer connection is switched off/i)).toBeInTheDocument();
+ expect(screen.queryByText(/shared slots active/i)).not.toBeInTheDocument();
+ });
+
// 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 () => {
diff --git a/server/services/federatedMediaProvider.js b/server/services/federatedMediaProvider.js
index 2c6e7725ac..2af10c2d3a 100644
--- a/server/services/federatedMediaProvider.js
+++ b/server/services/federatedMediaProvider.js
@@ -353,9 +353,11 @@ async function capabilitiesForKind(kind, config, { pythonPath = null } = {}) {
// so the lane a submission lands on is decided by its kind alone. The queue
// answers how wide that lane is; the minimum across the negotiated kinds is the
// fail-closed reading if two kinds ever route differently.
-const federatedLaneConcurrency = (kinds) => Math.min(
+// Serialized is the fail-closed answer for an empty kind list: Math.min() over
+// nothing is Infinity, which serializes to null and reads as "unknown".
+const federatedLaneConcurrency = (kinds) => (kinds.length === 0 ? 1 : Math.min(
...kinds.map((kind) => laneConcurrencyFor({ kind, params: {} })),
-);
+));
/**
* Jobs occupying this machine's own generation lanes, and whether another fits.
diff --git a/server/services/federatedMediaProvider.test.js b/server/services/federatedMediaProvider.test.js
index c68100ea77..221ab896d2 100644
--- a/server/services/federatedMediaProvider.test.js
+++ b/server/services/federatedMediaProvider.test.js
@@ -13,7 +13,7 @@ const state = vi.hoisted(() => ({
imageModels: [],
videoModels: [],
cachedRepos: new Set(),
- cloudLaneLimit: 3,
+ laneWidthByKind: {},
}));
vi.mock('./settings.js', () => ({
@@ -54,9 +54,10 @@ vi.mock('./musicEngineCapabilities.js', () => ({
vi.mock('./mediaJobQueue/index.js', () => ({
listJobs: vi.fn(() => state.jobs),
- // Mirrors the real lane routing: a federated job never sets a cloud `mode`,
- // so every kind this contract carries lands on the serialized GPU lane.
- laneConcurrencyFor: vi.fn((job) => (job?.params?.mode ? state.cloudLaneLimit : 1)),
+ // Widths deliberately differ per kind so a test can tell a minimum from a sum
+ // or a max; the real queue routes every federated kind to the same lane, but
+ // that is the thing under test, not a premise of it.
+ laneConcurrencyFor: vi.fn((job) => state.laneWidthByKind[job?.kind] ?? 1),
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 }) => {
@@ -87,7 +88,7 @@ import {
submitFederatedMediaJob,
__resetFederatedMediaProviderForTests,
} from './federatedMediaProvider.js';
-import { enqueueJob } from './mediaJobQueue/index.js';
+import { enqueueJob, laneConcurrencyFor } from './mediaJobQueue/index.js';
import { PATHS, sha256Text } from '../lib/fileUtils.js';
import { canonicalStringify } from '../lib/objects.js';
@@ -155,7 +156,7 @@ beforeEach(() => {
state.imageModels = [];
state.videoModels = [];
state.cachedRepos = new Set();
- state.cloudLaneLimit = 3;
+ state.laneWidthByKind = { audio: 1, image: 1, video: 1 };
__resetFederatedMediaProviderForTests();
});
@@ -215,11 +216,21 @@ describe('federated media provider capacity and idempotency', () => {
// The bug this replaced: summing every local lane told an audio-only provider
// it "runs 4 at a time" because the parallel cloud-CLI lane is wide, when its
- // music renders serialize one at a time.
- it('reports the lane a federated job actually lands on, not a whole-machine sum', async () => {
- state.cloudLaneLimit = 10;
- const status = await getFederatedMediaProviderStatus(config());
+ // music renders serialize one at a time. Widths differ per kind here so a sum
+ // (12), a max (10), and the fail-closed minimum (1) are all distinguishable.
+ it('reports the narrowest lane a negotiated kind lands on, never a sum or a max', async () => {
+ state.laneWidthByKind = { audio: 1, image: 10, video: 1 };
+ const status = await getFederatedMediaProviderStatus(config(), { kinds: ['audio', 'image', 'video'] });
expect(status.queue.concurrency).toBe(1);
+ // And it asks about the job shape the provider actually enqueues: adding a
+ // cloud `mode` would route the probe to a lane no federated job uses.
+ expect(laneConcurrencyFor).toHaveBeenCalledWith({ kind: 'image', params: {} });
+ });
+
+ it('reports the width of the one negotiated kind when only one was asked for', async () => {
+ state.laneWidthByKind = { audio: 4, image: 1, video: 1 };
+ const status = await getFederatedMediaProviderStatus(config());
+ expect(status.queue.concurrency).toBe(4);
});
it('breaks the shared queue down by federated kind, excluding outgoing proxy jobs', async () => {
@@ -238,9 +249,13 @@ describe('federated media provider capacity and idempotency', () => {
audio: { running: 1, queued: 1 },
image: { running: 0, queued: 1 },
});
- // The training job holds a lane but has no bucket, which is why byKind
- // need not sum to totalActive.
- expect(status.queue.totalActive).toBe(4);
+ // byKind is machine-wide while these are the federated share, counted in
+ // the same pass — only job 'a' is owned by a federated caller. The training
+ // job holds a lane but has no bucket, which is why byKind need not sum to
+ // totalActive.
+ expect(status.queue).toMatchObject({
+ providerActive: 1, running: 1, queued: 0, totalActive: 4,
+ });
});
// Reporting image/video occupancy to a consumer that negotiated audio only
diff --git a/server/services/mediaJobQueue/index.js b/server/services/mediaJobQueue/index.js
index 9d9956c065..e3f4837773 100644
--- a/server/services/mediaJobQueue/index.js
+++ b/server/services/mediaJobQueue/index.js
@@ -300,24 +300,6 @@ export function getRunningJob() {
return running;
}
-/**
- * Lane occupancy and queue depth, reported by the queue itself.
- *
- * The lane split (serialized GPU vs. parallel cloud-CLI vs. parallel remote)
- * and each lane's slot count are private to this module, so a caller that
- * counted `listJobs()` by hand would have to re-derive `jobLane` and would
- * drift from it the first time a new cloud mode is added. Capacity questions
- * are answered here for the same reason `isRemoteMediaJob` has one definition.
- *
- * `limit` is the lane's configured concurrency, NOT a queue bound: work over
- * the limit waits rather than being rejected. The federated-provider admission
- * bound is a separate setting (see federatedMediaProvider.js).
- *
- * @returns {{lanes: Record<'gpu'|'cloud'|'remote', {running: number, queued: number, limit: number}>,
- * byKind: Record<string, {running: number, queued: number}>,
- * totals: {running: number, queued: number},
- * runningKind: string|null}}
- */
// One definition of each lane's slot count, shared by getQueueCapacity and
// laneConcurrencyFor so a caller can never read a limit this module has moved.
const laneLimits = () => ({
@@ -343,6 +325,24 @@ export function laneConcurrencyFor(job) {
return laneLimits()[jobLane(job)];
}
+/**
+ * Lane occupancy and queue depth, reported by the queue itself.
+ *
+ * The lane split (serialized GPU vs. parallel cloud-CLI vs. parallel remote)
+ * and each lane's slot count are private to this module, so a caller that
+ * counted `listJobs()` by hand would have to re-derive `jobLane` and would
+ * drift from it the first time a new cloud mode is added. Capacity questions
+ * are answered here for the same reason `isRemoteMediaJob` has one definition.
+ *
+ * `limit` is the lane's configured concurrency, NOT a queue bound: work over
+ * the limit waits rather than being rejected. The federated-provider admission
+ * bound is a separate setting (see federatedMediaProvider.js).
+ *
+ * @returns {{lanes: Record<'gpu'|'cloud'|'remote', {running: number, queued: number, limit: number}>,
+ * byKind: Record<string, {running: number, queued: number}>,
+ * totals: {running: number, queued: number},
+ * runningKind: string|null}}
+ */
export function getQueueCapacity() {
const limits = laneLimits();
const lanes = {