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
fix(mind): report real pause reason and keep last wake error separate (#9506)
atomanticagent0c90b00d92ee
diff --git a/client/src/components/cos/tabs/ConfigTab.jsx b/client/src/components/cos/tabs/ConfigTab.jsxindex 841f9c4f4b..bd9f71cb19 100644--- a/client/src/components/cos/tabs/ConfigTab.jsx+++ b/client/src/components/cos/tabs/ConfigTab.jsx@@ -190,7 +190,7 @@ function PersistentMindStatus({ mind, loaded, error }) {</div>{(error || state?.lastError || state?.pauseReason) && (<p role="status" className="mt-3 rounded-md border border-port-warning/30 bg-port-warning/10 px-3 py-2 text-xs text-port-warning">- {error || state.lastError || state.pauseReason}+ {error || [state.pauseReason, state.lastError && state.lastError !== state.pauseReason ? `Last wake: ${state.lastError}` : null].filter(Boolean).join(' · ')}</p>)}<p className="mt-3 text-xs leading-relaxed text-port-text-muted">diff --git a/client/src/components/cos/tabs/MindStateSidebar.jsx b/client/src/components/cos/tabs/MindStateSidebar.jsxindex 0b32b1fb04..96cee55375 100644--- a/client/src/components/cos/tabs/MindStateSidebar.jsx+++ b/client/src/components/cos/tabs/MindStateSidebar.jsx@@ -42,6 +42,9 @@ export default function MindStateSidebar({: turnProgress.phase === 'thinking' ? `${turnProgress.stage || 'Working through the current turn'}.`: state?.pauseReason || (state?.started ? 'Listening for messages and scheduled wakes.' : 'Configure the AI profile to begin.')}</p>+ {state?.lastError && state.lastError !== state.pauseReason && !state?.contextBudgetBlocked && (+ <p data-testid="mind-last-error" className="mt-1 text-xs text-port-warning">Last wake: {state.lastError}</p>+ )}{state?.contextBudgetBlocked && (<div data-testid="mind-context-budget-actions" className="mt-2 flex flex-wrap gap-2 text-xs"><buttondiff --git a/client/src/components/cos/tabs/MindTab.temporaryRoute.test.jsx b/client/src/components/cos/tabs/MindTab.temporaryRoute.test.jsxindex 480b4ee309..08ab54f03a 100644--- a/client/src/components/cos/tabs/MindTab.temporaryRoute.test.jsx+++ b/client/src/components/cos/tabs/MindTab.temporaryRoute.test.jsx@@ -146,6 +146,22 @@ describe('MindTab temporary thinking sessions', () => {expect(api.resumePersistentMind).not.toHaveBeenCalled();});+ it('shows a system pause reason alongside the last wake failure', async () => {+ api.getPersistentMind.mockResolvedValue(response({+ state: {+ ...response().state,+ status: 'paused',+ pauseReason: 'Agent API pause: OOM safety',+ lastError: 'The last wake was killed (possibly out of memory); local diagnostics have details',+ },+ }));+ renderTab();+ await composerLoaded();++ await waitFor(() => expect(screen.getAllByText('Agent API pause: OOM safety').length).toBeGreaterThan(0));+ expect(screen.getByTestId('mind-last-error').textContent).toMatch(/killed \(possibly out of memory\)/);+ });+it('keeps previewing inert and explains that sending resumes a paused mind', async () => {const user = userEvent.setup();api.getPersistentMind.mockResolvedValue(response({diff --git a/server/lib/README.md b/server/lib/README.mdindex 4bc62268fe..8b5b2ec645 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -83,7 +83,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `mindBundleFormat.js` | Mind bundle format vocabulary, free of node builtins so the browser reads the same definitions (`client/src/lib/mindBundle.js`) — magic/versions/extension, scrypt parameters, export scopes (`PERSISTENT_MIND_BUNDLE_SCOPES`), import groups and their source scopes (`PERSISTENT_MIND_BUNDLE_GROUPS`, `MIND_BUNDLE_GROUP_SCOPES`, `MIND_BUNDLE_GROUP_CHOICES`), size/passphrase bounds, and the named refusal reasons (`MIND_BUNDLE_REFUSALS`, `mindBundleRefusal`). || `mindLocalContextClamp.js` | RAM/GPU safety ceilings for mind-driven local `numCtx` adjustments (CPU-only tiers, free-RAM + PortOS headroom). Pure. || `motionSkills.js` | Optional motion-design agent skill packs (HyperFrames, Remotion, Claude Animation) — `MOTION_SKILL_PACKS` catalog shared by `npm run setup:motion` and the launch-video form, `detectMotionSkills()` finds installed skills under `~/.agents/skills` / `~/.claude/skills`. |-| `persistentMindPublic.js` | `publicPersistentMindState(state)` — the sole client/socket projection of durable mind state: exposes lifecycle fields, queue count, and the derived next wake time; drops queued message bodies/active wake payloads, and replaces free-form provider errors with coarse safe reasons. |+| `persistentMindPublic.js` | `publicPersistentMindState(state)` — the sole client/socket projection of durable mind state: exposes lifecycle fields, queue count, and the derived next wake time; drops queued message bodies/active wake payloads, and replaces free-form provider errors with coarse safe reasons. Non-user pause reasons pass through (credential-scrubbed) instead of reading "Paused by user", and `lastError` (coarse last-wake failure: killed/OOM, canceled, …) stays separate from `pauseReason`. || `persistentMindThinkingPresets.js` | Also owns bounded self-thinking request schemas, durable request normalization, and fixed switching limits. Saved named temporary thinking presets for the persistent mind (exact provider/model/effort alternates to its one home profile): default-empty durable shape, normalization that drops half-pinned entries, strict API schema, whole-list replace merge, preset lookup, strict accepted-selection schema/normalization, and route equality independent of labels. Storage only — saving or selecting a preset starts no inference. || `persistentMindChosenName.js` | Validate and resolve an authoritative chosen-name identity memory, frame first-wake naming, and extract legacy chosen names from protected identity memories (`extractPersistentMindChosenName`, `resolvePersistentMindChosenName`) to drive the Eidoverse CoS join id (e.g. Helm). Presence reconnects on its next world action when the chosen name changes.| `persistentMindUsageLimit.js` | Hard provider usage-limit / quota classifier for Persistent Mind wakes (`classifyPersistentMindProviderError`, `isHardProviderUsageLimitError`), the dedicated autopause reason string, and probe-backoff helpers so a usage-limit pause can auto-recover when the pinned provider is usable again without treating user pauses the same way.diff --git a/server/lib/persistentMindPublic.js b/server/lib/persistentMindPublic.jsindex 8999209b05..aa68375356 100644--- a/server/lib/persistentMindPublic.js+++ b/server/lib/persistentMindPublic.js@@ -8,6 +8,18 @@ import {publicContextBudgetReason,} from './persistentMindContextBudget.js';+// Pauses the human asked for: the default supervisor reason plus the Mind+// page's own label. Anything else (an operator/agent API pause for OOM safety,+// a held policy refusal, ...) is NOT a user pause and must say what it is.+const USER_PAUSE_REASON = /^paused (?:by user|from (?:the )?mind page)\b/i;++// Pause text is operator/system-authored, but a held refusal can echo provider+// output, so scrub anything that looks like a credential before it leaves.+const SECRETISH = /\b(?:sk-[A-Za-z0-9_-]{4,}|bearer\s+\S+|(?:api[_-]?key|token|key|secret|password)\s*[=:]\s*\S+|[A-Za-z0-9+/_-]{32,})/gi;+const scrubReason = (text) => text.replace(SECRETISH, '[redacted]').replace(/\s+/g, ' ').trim();++export const isUserPersistentMindPauseReason = (reason) => typeof reason === 'string' && USER_PAUSE_REASON.test(reason.trim());+const publicReason = (state) => {// A quota autopause is NOT a user action. Saying "Paused by user" there is the// exact confusion this projection exists to prevent: the page would blame the@@ -20,11 +32,38 @@ const publicReason = (state) => {|| publicContextBudgetReason(state.lastError);if (contextBudget) return contextBudget;if (!state.pauseReason) return null;- if (state.status === 'paused') return 'Paused by user';+ if (state.status === 'paused') {+ if (isUserPersistentMindPauseReason(state.pauseReason)) return 'Paused by user';+ return scrubReason(state.pauseReason) || 'Paused by the system';+ }if (state.status === 'degraded' || state.status === 'interrupted') return 'Provider unavailable or wake failed';return 'Waiting for the next eligible wake';};+// Coarse, safe classification of why the last wake failed. Free-form provider+// errors never pass through, but "killed (OOM?)" vs "canceled" vs "generic" is+// the difference between an operator knowing what to fix and not.+const WAKE_FAILURE_LABELS = [+ [/\b(?:SIGKILL|OOM|out of memory|killed|exit(?:ed)? (?:code )?137)\b/i, 'The last wake was killed (possibly out of memory); local diagnostics have details'],+ [/heartbeat expired/i, 'The last wake stopped sending heartbeats and was interrupted'],+ [/orphaned .*after restart|daemon stopped/i, 'The last wake was interrupted by a restart'],+ [/\b(?:cancel(?:l?ed)?|abort(?:ed)?|interrupted)\b/i, 'The last wake was canceled before it completed'],+];++const publicLastError = (state) => {+ if (!state.lastError) return null;+ const contextBudget = publicContextBudgetReason(state.lastError)+ || publicContextBudgetReason(state.pauseReason);+ // Safe: only token counts + recovery hint — never prompts or API keys.+ if (contextBudget) return contextBudget;+ // Older state stored the pause text as lastError too; a pause is not a wake+ // failure, so don't render it as one.+ if (state.status === 'paused' && state.lastError === state.pauseReason+ && !isUsageLimitPauseReason(state.pauseReason)) return null;+ const match = WAKE_FAILURE_LABELS.find(([pattern]) => pattern.test(state.lastError));+ return match ? match[1] : 'The last wake did not complete; local diagnostics have details';+};+// The route the claimed turn is ACTUALLY running on, which is not always the// home profile: a temporary thinking session borrows another one for its single// turn. A field the claim never recorded stays null rather than falling back to@@ -92,13 +131,8 @@ export function publicPersistentMindState(state = {}) {nextEligibleWakeAt: typeof state.nextEligibleWakeAt === 'string' ? state.nextEligibleWakeAt : null,nextWakeAt: nextWakeAt == null ? null : new Date(nextWakeAt).toISOString(),failureCount: Number.isInteger(state.failureCount) ? state.failureCount : 0,- lastError: (() => {- if (!state.lastError) return null;- const contextBudget = publicContextBudgetReason(state.lastError)- || publicContextBudgetReason(state.pauseReason);- // Safe: only token counts + recovery hint — never prompts or API keys.- if (contextBudget) return contextBudget;- return 'The last wake did not complete; local diagnostics have details';- })(),+ // Kept independent of pauseReason: a pause must not hide why the last+ // wake failed, and a failed wake must not be mistaken for the pause cause.+ lastError: publicLastError(state),};}diff --git a/server/lib/persistentMindPublic.test.js b/server/lib/persistentMindPublic.test.jsindex 363678e0ea..5861745d57 100644--- a/server/lib/persistentMindPublic.test.js+++ b/server/lib/persistentMindPublic.test.js@@ -230,4 +230,64 @@ describe('public persistent mind state', () => {expect(projected.pauseReason).toBe(reason);expect(projected.pauseReason).not.toBe('Paused by user');});++ it('passes through a non-user pause reason instead of blaming the user', () => {+ const projected = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true,+ status: 'paused',+ pauseReason: 'Agent API pause: OOM safety',+ }));+ expect(projected.pauseReason).toBe('Agent API pause: OOM safety');+ expect(projected.lastError).toBeNull();+ });++ it('labels the Mind page and default pauses as user pauses', () => {+ for (const pauseReason of ['Paused by user', 'Paused from Mind page', 'Paused from the Mind page']) {+ const projected = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true, status: 'paused', pauseReason,+ }));+ expect(projected.pauseReason).toBe('Paused by user');+ }+ });++ it('scrubs credential-looking text from a passed-through pause reason', () => {+ const projected = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true,+ status: 'paused',+ pauseReason: 'Held refusal: key=sk-EXAMPLE1234 rejected',+ }));+ expect(projected.pauseReason).toContain('Held refusal');+ expect(JSON.stringify(projected)).not.toContain('sk-EXAMPLE');+ });++ it('shows both the pause reason and a coarse last-wake failure', () => {+ const killed = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true,+ status: 'paused',+ pauseReason: 'Agent API pause: OOM safety',+ lastError: 'codex exited with SIGKILL; token=abc123',+ }));+ expect(killed.pauseReason).toBe('Agent API pause: OOM safety');+ expect(killed.lastError).toMatch(/killed \(possibly out of memory\)/);+ expect(JSON.stringify(killed)).not.toContain('abc123');++ const canceled = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true,+ status: 'paused',+ pauseReason: 'Paused from Mind page',+ lastError: 'API run canceled',+ }));+ expect(canceled.pauseReason).toBe('Paused by user');+ expect(canceled.lastError).toBe('The last wake was canceled before it completed');+ });++ it('does not render a legacy pause copied into lastError as a wake failure', () => {+ const projected = publicPersistentMindState(normalizePersistentMindState({+ ...createDefaultPersistentMindState(), enabled: true, started: true,+ status: 'paused',+ pauseReason: 'Paused from Mind page',+ lastError: 'Paused from Mind page',+ }));+ expect(projected.lastError).toBeNull();+ });});diff --git a/server/services/persistentMindSupervisor.js b/server/services/persistentMindSupervisor.jsindex 2a272a7026..d141c8761a 100644--- a/server/services/persistentMindSupervisor.js+++ b/server/services/persistentMindSupervisor.js@@ -397,7 +397,9 @@ async function interruptActiveTurn(reason, status, { retry = false, expectedTurnstatus,pauseReason: reason,failureCount,- lastError: reason,+ // A pause or global hold is not a wake failure: keep the real last+ // error (OOM kill, canceled run, ...) visible next to the pause reason.+ lastError: status === 'paused' || status === 'waiting' ? next.lastError : reason,nextEligibleWakeAt: retry? new Date(Date.now() + persistentMindBackoffMs(failureCount)).toISOString(): null,diff --git a/server/services/persistentMindSupervisor.test.js b/server/services/persistentMindSupervisor.test.jsindex 2d9444bd66..8a734e11e2 100644--- a/server/services/persistentMindSupervisor.test.js+++ b/server/services/persistentMindSupervisor.test.js@@ -515,6 +515,18 @@ describe('persistent mind supervisor', () => {.not.toContain('mind.message.accepted');});+ it('keeps the last wake failure separate from a later pause reason', async () => {+ await supervisor.setPersistentMindEnabled(true);+ await supervisor.startPersistentMind();+ mock.root.persistentMind.lastError = 'Provider process was killed (SIGKILL)';+ await supervisor.pausePersistentMind('Agent API pause: OOM safety');+ expect(mock.root.persistentMind).toMatchObject({+ status: 'paused',+ pauseReason: 'Agent API pause: OOM safety',+ lastError: 'Provider process was killed (SIGKILL)',+ });+ });+it('records pause, stop, and disable boundaries even without an active provider turn', async () => {await supervisor.setPersistentMindEnabled(true);await supervisor.startPersistentMind();