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: a failed update must not report a successful dispatch, and an unreadable agent state must not read as idle
[._.]/ Adam Eivye216e92c0d5d
diff --git a/client/src/components/apps/tabs/AutoUpdatePanel.jsx b/client/src/components/apps/tabs/AutoUpdatePanel.jsxindex 75cd5d7d2d..d9c38bd657 100644--- a/client/src/components/apps/tabs/AutoUpdatePanel.jsx+++ b/client/src/components/apps/tabs/AutoUpdatePanel.jsx@@ -63,7 +63,12 @@ export default function AutoUpdatePanel() {if (!draft) return null;const save = async (patch) => {+ // Clamp before sending, not just on blur: `onChange` writes whatever is in+ // the number input to the draft, so an empty or out-of-range field the user+ // never blurred rides along on the NEXT save (a channel click, a checkbox)+ // and the strict schema 400s the whole thing.const next = { ...draft, ...patch };+ next.minIntervalHours = Math.min(bounds.max, Math.max(bounds.min, Number(next.minIntervalHours) || bounds.min));setDraft(next);setSaving(true);const saved = await api.patchSettingsSlice('autoUpdate', next).catch((err) => {diff --git a/server/lib/systemIdle.js b/server/lib/systemIdle.jsindex 94640584f6..6dfbb0325e 100644--- a/server/lib/systemIdle.js+++ b/server/lib/systemIdle.js@@ -76,9 +76,13 @@ export function summarizeSystemActivity(snapshot) {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);- const activeAgents = Number(snapshot?.agents?.active) || 0;+ // Same contract as the mind slice below: an unreadable agent state is not an+ // empty one, and zero agents is exactly the value that unlocks a restart.+ const agentState = snapshot?.agents;+ if (agentState?.trusted === false) add('agents-unreadable', 'CoS agent state unreadable', 1);+ const activeAgents = Number(agentState?.active) || 0;if (activeAgents > 0) add('agents-running', `${pluralize(activeAgents, 'CoS agent')} running`, activeAgents);- const queuedAgents = Number(snapshot?.agents?.queued) || 0;+ const queuedAgents = Number(agentState?.queued) || 0;if (queuedAgents > 0) add('agents-queued', `${pluralize(queuedAgents, 'CoS task')} queued`, queuedAgents);const mind = snapshot?.mind;diff --git a/server/lib/systemIdle.test.js b/server/lib/systemIdle.test.jsindex 88f876b9ae..aad571f136 100644--- a/server/lib/systemIdle.test.js+++ b/server/lib/systemIdle.test.js@@ -4,7 +4,7 @@ import { describeActivityBlockers, summarizeSystemActivity } from './systemIdle.const snapshot = (overrides = {}) => ({jobs: [],extras: { imageTo3d: [] },- agents: { active: 0, queued: 0 },+ agents: { trusted: true, active: 0, queued: 0 },mind: { trusted: true, thinking: false, queued: 0, status: 'idle' },appOperations: [],update: { inProgress: false },@@ -64,6 +64,14 @@ describe('system idle verdict', () => {expect(verdict.blockers).toEqual([{ kind: 'mind-unreadable', label: 'Persistent Mind state unreadable', count: 1 }]);});+ // Zero agents is what unlocks the unattended restart, so "could not read the+ // agent state" must never reach the verdict as "no agents".+ it('refuses to read an unreadable agent state as an idle one', () => {+ const verdict = summarizeSystemActivity(snapshot({ agents: { trusted: false, active: 0, queued: 0 } }));+ expect(verdict.idle).toBe(false);+ expect(verdict.blockers).toEqual([{ kind: 'agents-unreadable', label: 'CoS agent state unreadable', count: 1 }]);+ });+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.jsindex ec26762a68..85073d2121 100644--- a/server/services/activeProcessing.js+++ b/server/services/activeProcessing.js@@ -52,11 +52,20 @@ function summarizeMind(snapshot) {* readable (`agents === null`), there is no claim set to subtract — fall back to* `getStatus()`'s own tally rather than reporting zero active agents while still* counting their tasks as queued, which would understate BOTH numbers at once.+ *+ * And when BOTH reads failed, `active` is 0 because nothing could be counted —+ * not because nothing is running. `trusted: false` says which, so the idle+ * verdict can refuse instead of reading that zero as an empty install and+ * restarting out from under a live agent (the contract the Persistent Mind+ * slice already keeps). The queued count is unaffected: the pending-task list+ * is a separate read, and with no claim set to subtract it over-reports rather+ * than under-reports, which is the safe direction for a gate.*/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),active: runningAgents ? runningAgents.length : (cosStatus?.activeAgents || 0),queued: pendingTaskIds.filter((id) => !claimedTaskIds.has(id)).length,};diff --git a/server/services/activeProcessing.test.js b/server/services/activeProcessing.test.jsindex 03a9a91842..98b6616d7a 100644--- a/server/services/activeProcessing.test.js+++ b/server/services/activeProcessing.test.js@@ -43,7 +43,7 @@ describe('active processing snapshot', () => {expect(snapshot.gpu.gpus[0]).toMatchObject({ utilizationPercent: 44, memoryUsedMib: 1000 });expect(snapshot.extras.imageTo3d).toEqual([{ id: 'mesh-1', name: 'Fake mesh' }, { id: 'mesh-2', name: 'mesh-2' }]);expect(snapshot.extras.ollama).toEqual([{ id: 'model-1', name: 'Fake model' }]);- expect(snapshot.agents).toEqual({ active: 2, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: true, active: 2, queued: 1 });expect(deps.status).not.toHaveBeenCalled();});@@ -147,14 +147,14 @@ describe('queued agent count', () => {deps.tasks.mockResolvedValue(['task-spawning', 'task-waiting']);deps.agents.mockResolvedValue([{ id: 'agent-1', status: 'running', taskId: 'task-spawning' }]);const snapshot = await getActiveProcessing();- expect(snapshot.agents).toEqual({ active: 1, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: true, active: 1, queued: 1 });});it('still counts a pending task whose agent already completed', async () => {deps.tasks.mockResolvedValue(['cos-task-1']);deps.agents.mockResolvedValue([{ id: 'agent-1', status: 'completed', taskId: 'cos-task-1' }]);const snapshot = await getActiveProcessing();- expect(snapshot.agents).toEqual({ active: 0, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: true, active: 0, queued: 1 });});// A failed agent read is not an empty one. Collapsing the two would report@@ -165,7 +165,7 @@ describe('queued agent count', () => {deps.tasks.mockResolvedValue(['task-1']);deps.agents.mockRejectedValue(new Error('state unreadable'));const snapshot = await getActiveProcessing();- expect(snapshot.agents).toEqual({ active: 3, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: true, active: 3, queued: 1 });expect(deps.status).toHaveBeenCalledTimes(1);});@@ -175,16 +175,21 @@ describe('queued agent count', () => {deps.tasks.mockResolvedValue(['task-1']);deps.agents.mockResolvedValue([]);const snapshot = await getActiveProcessing();- expect(snapshot.agents).toEqual({ active: 0, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: true, active: 0, queued: 1 });expect(deps.status).not.toHaveBeenCalled();});- it('preserves pending tasks when both agent and fallback status reads fail', async () => {+ // Both reads failing means "could not count", not "nothing is running" — and+ // zero active agents is exactly the value that unlocks an unattended restart.+ // The pending-task list is a separate read, so its count survives.+ it('marks the slice untrusted when both agent reads fail, and still blocks idle', async () => {deps.tasks.mockResolvedValue(['task-1']);deps.agents.mockRejectedValue(new Error('state unreadable'));deps.status.mockRejectedValue(new Error('status unavailable'));const snapshot = await getActiveProcessing();- expect(snapshot.agents).toEqual({ active: 0, queued: 1 });+ expect(snapshot.agents).toEqual({ trusted: false, active: 0, queued: 1 });expect(deps.status).toHaveBeenCalledTimes(1);+ expect(snapshot.activity.idle).toBe(false);+ expect(snapshot.activity.blockers.map(b => b.kind)).toContain('agents-unreadable');});});diff --git a/server/services/appUpdateRunner.js b/server/services/appUpdateRunner.jsindex 3075f4b5cc..e77bc7cbb9 100644--- a/server/services/appUpdateRunner.js+++ b/server/services/appUpdateRunner.js@@ -31,11 +31,12 @@ import { PORTOS_APP_ID } from '../lib/appIdentity.js';* @param {boolean} [params.acknowledgeFork]* @param {boolean} [params.acknowledgePersistentMindImageBackup]* @returns {Promise<- * | {ok: false, reason: 'not-found'|'duplicate'|'refused', appId: string|null, code: string|null, message: string}+ * | {ok: false, reason: 'not-found'|'duplicate'|'refused'|'failed', appId: string|null, code: string|null, message: string}* | {ok: true}* >}- * Every refusal carries a rendered `message`; a caller decides only WHERE it- * goes (the dispatching socket, or a log line), never how it reads.+ * Every failure carries a rendered `message`; a caller decides only WHERE it+ * goes (the dispatching socket, or a log line), never how it reads. `failed`+ * is the one the io bus has ALREADY reported — the socket stays quiet for it.*/export async function runAppUpdate({io,@@ -122,9 +123,20 @@ export async function runAppUpdate({console.log(`✅ Update complete for ${app.name}`);}- // The run's own outcome is already on the io bus (`app:update:complete` /- // `app:update:error`) and in the history ledger, which is where both callers- // read it from — so the return says only "this dispatch was accepted".+ // `ok` must mean the update actually RAN, not merely that it was dispatched.+ // An unattended caller stamps its cooldown off this answer, so reporting a+ // thrown or failed update as `ok` would suppress every retry for the whole+ // interval while nothing had happened. `updateApp` returns+ // `success: true` on the self-update hand-off too, so one check covers both.+ if (failure || !result?.success) {+ return {+ ok: false,+ reason: 'failed',+ appId: app.id,+ code: failure?.code || null,+ message: failure?.message || 'The update did not complete',+ };+ }return { ok: true };} finally {if (operatingAppId && !result?.selfUpdateStarted) endAppOperation(io, operatingAppId);diff --git a/server/services/autoUpdateScheduler.test.js b/server/services/autoUpdateScheduler.test.jsindex d89f660411..a99b8bc53d 100644--- a/server/services/autoUpdateScheduler.test.js+++ b/server/services/autoUpdateScheduler.test.js@@ -91,6 +91,17 @@ describe('automatic update dispatch', () => {await runAutoUpdateTick({ io: {} });expect(deps.recordRuntime).toHaveBeenCalledWith(expect.objectContaining({ lastRunAt: expect.any(String) }));});++ // The cooldown is stamped off this answer, so an update that did not run must+ // not report one — otherwise one failed dispatch suppresses every retry for+ // the whole interval while nothing has happened.+ it('does not start the cooldown when the update failed to run', async () => {+ deps.settings.mockResolvedValue({ autoUpdate: { enabled: true, channel: 'main', minIntervalHours: 6 } });+ deps.appUpdate.mockResolvedValue({ ok: false, reason: 'failed', message: 'the update did not complete' });+ const result = await runAutoUpdateTick({ io: {} });+ expect(result).toMatchObject({ ran: false, reason: 'launch-failed' });+ expect(deps.recordRuntime).not.toHaveBeenCalledWith(expect.objectContaining({ lastRunAt: expect.any(String) }));+ });});describe('automatic update gates', () => {diff --git a/server/services/updateRepoReadiness.js b/server/services/updateRepoReadiness.jsindex ab666bfa82..854783eb0d 100644--- a/server/services/updateRepoReadiness.js+++ b/server/services/updateRepoReadiness.js@@ -53,7 +53,13 @@ const REASON_LABELS = {'wrong-branch': 'the checkout is not on the default branch',};-const describe = (code) => REASON_LABELS[code] || code;+/** What each mechanical remedy will do, for a verdict that has no blocking reason. */+const REPAIRABLE_LABELS = {+ 'restore-lockfiles': 'auto-generated lockfiles need restoring',+ 'checkout-default': 'the checkout needs switching back to the default branch',+};++const describe = (code) => REASON_LABELS[code] || REPAIRABLE_LABELS[code] || code;/** Absolute paths only — a relative path would resolve against the server's cwd. */const resolveRepoPath = (repoPath) => (isAbsolute(repoPath || '') ? repoPath : PATHS.root);@@ -105,7 +111,12 @@ export async function checkUpdateRepoReadiness({ repoPath, fetch = false } = {})// one: there is nothing for an agent to resolve if git itself is the// problem.needsAgent: reasons.length > 0 && !reasons.includes('git-unreadable'),- summary: reasons.length ? reasons.map(describe).join('; ') : null,+ // A repairable-only verdict is still `ready: false`, and the panel renders+ // `summary` for anything not ready — leaving it null there made the UI fall+ // back to a generic "wrong branch" line that named the wrong cause.+ summary: reasons.length+ ? reasons.map(describe).join('; ')+ : repairable.length ? repairable.map(describe).join('; ') : null,};};diff --git a/server/sockets/apps.js b/server/sockets/apps.jsindex a24c7eece8..2aff91fb3f 100644--- a/server/sockets/apps.js+++ b/server/sockets/apps.js@@ -84,6 +84,10 @@ export const registerAppHandlers = (socket, io) => {acknowledgePersistentMindImageBackup: data.acknowledgePersistentMindImageBackup === true,});if (outcome.ok) return;+ // A 'failed' outcome already went out on the io bus as app:update:error /+ // app:update:complete from inside the runner; re-emitting it here would+ // overwrite that message with a second, less specific one.+ if (outcome.reason === 'failed') return;socket.emit('app:update:error', {appId: outcome.appId,code: outcome.code,