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

stop two failed reads unlocking an unattended restart of a busy install

[._.]/ Adam Eivy03c122921f63
diff --git a/server/lib/systemIdle.js b/server/lib/systemIdle.js
index 6dfbb0325e..4adc0b0b80 100644
--- a/server/lib/systemIdle.js
+++ b/server/lib/systemIdle.js
@@ -73,6 +73,11 @@ export function summarizeSystemActivity(snapshot) {
add(`media-queued:${kind}`, `${pluralize(count, mediaNoun(kind))} queued`, count);
}
+ // An explicit `null` means the build list could not be read — not that
+ // nothing is building. Same contract as the agent and mind slices: the value
+ // that unlocks a restart may never be manufactured from a failed read. An
+ // ABSENT key stays "nothing there", per this function's partial-snapshot rule.
+ if (snapshot?.extras?.imageTo3d === null) add('image-to-3d-unreadable', 'Image-to-3D build state unreadable', 1);
const imageTo3d = Array.isArray(snapshot?.extras?.imageTo3d) ? snapshot.extras.imageTo3d.length : 0;
if (imageTo3d > 0) add('image-to-3d', `${pluralize(imageTo3d, 'image-to-3D build')} running`, imageTo3d);
diff --git a/server/lib/systemIdle.test.js b/server/lib/systemIdle.test.js
index aad571f136..7989aaa135 100644
--- a/server/lib/systemIdle.test.js
+++ b/server/lib/systemIdle.test.js
@@ -72,6 +72,16 @@ describe('system idle verdict', () => {
expect(verdict.blockers).toEqual([{ kind: 'agents-unreadable', label: 'CoS agent state unreadable', count: 1 }]);
});
+ // Same rule for the image-to-3D slice: `null` is "the list could not be
+ // read", and an unreadable list must not unlock a restart that would kill a
+ // running build. An ABSENT key still reads as "nothing there".
+ it('refuses to read an unreadable image-to-3D build list as an idle one', () => {
+ const verdict = summarizeSystemActivity(snapshot({ extras: { imageTo3d: null } }));
+ expect(verdict.idle).toBe(false);
+ expect(verdict.blockers).toEqual([{ kind: 'image-to-3d-unreadable', label: 'Image-to-3D build state unreadable', count: 1 }]);
+ expect(summarizeSystemActivity(snapshot({ extras: {} })).idle).toBe(true);
+ });
+
it('counts an update already in flight as activity', () => {
expect(summarizeSystemActivity(snapshot({ update: { inProgress: true } })).idle).toBe(false);
});
diff --git a/server/services/activeProcessing.js b/server/services/activeProcessing.js
index 85073d2121..0073348250 100644
--- a/server/services/activeProcessing.js
+++ b/server/services/activeProcessing.js
@@ -65,9 +65,12 @@ function agentCounts(agents, cosStatus, pendingTaskIds) {
const runningAgents = agents === null ? null : agents.filter((agent) => agent.status === 'running');
const claimedTaskIds = new Set((runningAgents || []).map((agent) => agent.taskId).filter(Boolean));
return {
- trusted: agents !== null || Boolean(cosStatus),
+ // An unreadable pending-task list is its own untrusted reading: zero queued
+ // tasks is the value that unlocks a restart, so it may not come from a
+ // failed read any more than a zero agent count may.
+ trusted: (agents !== null || Boolean(cosStatus)) && pendingTaskIds !== null,
active: runningAgents ? runningAgents.length : (cosStatus?.activeAgents || 0),
- queued: pendingTaskIds.filter((id) => !claimedTaskIds.has(id)).length,
+ queued: pendingTaskIds ? pendingTaskIds.filter((id) => !claimedTaskIds.has(id)).length : 0,
};
}
@@ -82,8 +85,11 @@ function agentCounts(agents, cosStatus, pendingTaskIds) {
export async function getSystemActivity() {
const [jobs, models, pendingTaskIds, agents, mindState] = await Promise.all([
Promise.resolve(listJobs()).then((items) => items.filter((job) => LIVE_STATUSES.has(job.status))),
- listGeneratingModelSummaries().catch(() => []),
- cos.getPendingTaskIds().catch(() => []),
+ // `null` = the read FAILED, distinct from `[]` = read fine, nothing
+ // building. Both of these degrade to the value that unlocks a restart, so
+ // neither may be manufactured from a failed read.
+ listGeneratingModelSummaries().catch(() => null),
+ cos.getPendingTaskIds().catch(() => null),
// `null` = the read FAILED, distinct from `[]` = read fine, no agents. The
// counts degrade differently for the two, so they must stay separable.
cos.getAgents().catch(() => null),
@@ -94,7 +100,9 @@ export async function getSystemActivity() {
const cosStatus = agents === null ? await cos.getStatus().catch(() => null) : null;
const slices = {
jobs: jobs.map(sanitizeJob),
- extras: { imageTo3d: models.map((model) => ({ id: model.id, name: model.name || model.id })) },
+ // `null` survives to the verdict as a blocker; the widget's own
+ // `extras?.imageTo3d || []` already reads it as an empty list.
+ extras: { imageTo3d: models === null ? null : models.map((model) => ({ id: model.id, name: model.name || model.id })) },
agents: agentCounts(agents, cosStatus, pendingTaskIds),
mind: summarizeMind(mindState),
// An App Management update/standardize holds a checkout and restarts PM2
diff --git a/server/services/activeProcessing.test.js b/server/services/activeProcessing.test.js
index 98b6616d7a..c7e32155b4 100644
--- a/server/services/activeProcessing.test.js
+++ b/server/services/activeProcessing.test.js
@@ -59,8 +59,15 @@ describe('active processing snapshot', () => {
const snapshot = await getActiveProcessing();
expect(snapshot.gpu).toMatchObject({ status: 'absent', laneBusy: false, laneKind: null, gpus: [] });
expect(snapshot.extras.imageTo3d).toEqual([]);
+ expect(snapshot.activity.idle).toBe(true);
+ // A FAILED read is not an empty one: it degrades to `null`, and the idle
+ // verdict refuses on it rather than letting an unreadable build list read
+ // as an install with nothing running.
deps.models.mockRejectedValueOnce(new Error('store unavailable'));
- expect((await getActiveProcessing()).extras.imageTo3d).toEqual([]);
+ const degraded = await getActiveProcessing();
+ expect(degraded.extras.imageTo3d).toBeNull();
+ expect(degraded.activity.idle).toBe(false);
+ expect(degraded.activity.blockers).toContainEqual(expect.objectContaining({ kind: 'image-to-3d-unreadable' }));
expect(deps.utilization).not.toHaveBeenCalled();
});
});
@@ -192,4 +199,16 @@ describe('queued agent count', () => {
expect(snapshot.activity.idle).toBe(false);
expect(snapshot.activity.blockers.map(b => b.kind)).toContain('agents-unreadable');
});
+
+ // The pending-task list is its own read. An unreadable one yields zero queued
+ // tasks, and zero queued is the other value that unlocks the restart — so it
+ // carries the same untrusted sentinel a failed agent read does.
+ it('marks the slice untrusted when the pending-task read fails, even with a readable agent list', async () => {
+ deps.tasks.mockRejectedValue(new Error('task store unavailable'));
+ deps.agents.mockResolvedValue([]);
+ const snapshot = await getActiveProcessing();
+ expect(snapshot.agents).toEqual({ trusted: false, active: 0, queued: 0 });
+ expect(snapshot.activity.idle).toBe(false);
+ expect(snapshot.activity.blockers.map(b => b.kind)).toContain('agents-unreadable');
+ });
});