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 an idle day reading as a 100% failure rate and jamming every wake into maintain (#7458)

[._.]/ Adam Eivybe8b01334975
diff --git a/docs/features/persistent-mind-continuous-play.md b/docs/features/persistent-mind-continuous-play.md
index 2a3dc2f84c..d4df742b97 100644
--- a/docs/features/persistent-mind-continuous-play.md
+++ b/docs/features/persistent-mind-continuous-play.md
@@ -24,6 +24,8 @@ Saving a playbook never starts inference. The Mind Context panel exposes the mod
Priority order when signals conflict: a still-sparse Commons always explores first; a high failure rate outranks a peer visit (fix what is broken before going visiting); an active peer outranks routine construction. The picker never reads a wall clock — it degrades to `explore` (the safe default) whenever a signal is unavailable rather than guessing.
+A failure rate only exists when work actually ran. `getTodayActivity()` reports `successRate: 0` for a day with zero completed agents, so the derivation requires a non-empty sample before trusting it: an idle day yields *no* failure signal (falling back to coarse health, then to `null`), never a fabricated 100%. Without that guard every wake before the day's first completed task would claim a 100% failure rate and force `maintain`, starving `construct` and `coordinate` entirely.
+
Each phase template ends by naming itself (e.g. `Phase: Construct`) so the mind states its current phase in the wake's user-visible working note — how Helm and other minds can see which phase produced a given wake. `GET /api/cos/mind/context` also resolves the phase for preview (best-effort; a signal-read failure there falls back to the general loop rather than failing the request).
## Mind-adjustable `numCtx`
diff --git a/server/lib/persistentMindPlaybookPhase.js b/server/lib/persistentMindPlaybookPhase.js
index 0c978bdbe2..232eaa9967 100644
--- a/server/lib/persistentMindPlaybookPhase.js
+++ b/server/lib/persistentMindPlaybookPhase.js
@@ -45,6 +45,27 @@ const clampFractionOrNull = (value) => {
const arrayLength = (value) => (Array.isArray(value) ? value.length : 0);
+/**
+ * A failure rate only exists when work actually ran. `getTodayActivity()`
+ * reports `successRate: 0` for a day with zero completed agents, so trusting
+ * that number unguarded reads an idle morning as a 100% failure rate and jams
+ * every wake into `maintain`. A measured-but-empty sample yields `null`
+ * ("no signal"), never a fabricated rate; a measured zero-failure sample still
+ * correctly yields `0`.
+ */
+const measuredFailureRate = (productivity) => {
+ const succeeded = nonNegativeIntOrNull(productivity?.succeededToday);
+ const failed = nonNegativeIntOrNull(productivity?.failedToday);
+ if (succeeded !== null && failed !== null) {
+ return succeeded + failed > 0 ? failed / (succeeded + failed) : null;
+ }
+ const completed = nonNegativeIntOrNull(productivity?.completedToday);
+ if (completed !== null && completed > 0 && typeof productivity?.successRate === 'number') {
+ return clampFractionOrNull(1 - productivity.successRate / 100);
+ }
+ return null;
+};
+
const healthFailureRate = (health) => {
if (!health || typeof health.status !== 'string') return null;
if (health.status === 'error') return 1;
@@ -73,14 +94,9 @@ export function derivePersistentMindPlaybookPhaseSignals(worldSignals) {
].reduce((total, entries) => total + arrayLength(entries), 0);
const productivity = Array.isArray(worldSignals.productivity) ? worldSignals.productivity[0] : null;
- const succeeded = nonNegativeIntOrNull(productivity?.succeededToday);
- const failed = nonNegativeIntOrNull(productivity?.failedToday);
- const totalToday = succeeded !== null && failed !== null ? succeeded + failed : null;
- const failureRate = totalToday !== null && totalToday > 0
- ? failed / totalToday
- : (typeof productivity?.successRate === 'number'
- ? clampFractionOrNull(1 - productivity.successRate / 100)
- : healthFailureRate(worldSignals.health));
+ // `??` (not `||`) so a measured zero-failure day stays 0 rather than
+ // falling through to the coarse health signal.
+ const failureRate = measuredFailureRate(productivity) ?? healthFailureRate(worldSignals.health);
// "Unread peer contributions" approximated as federated peers currently
// reporting non-steady status (active/attention/error — something changed
diff --git a/server/lib/persistentMindPlaybookPhase.test.js b/server/lib/persistentMindPlaybookPhase.test.js
index 3fe67b30fb..f5ad7f6d63 100644
--- a/server/lib/persistentMindPlaybookPhase.test.js
+++ b/server/lib/persistentMindPlaybookPhase.test.js
@@ -91,7 +91,8 @@ describe('derivePersistentMindPlaybookPhaseSignals', () => {
});
it('falls back to successRate, then to health status, when today counts are unavailable', () => {
- const viaSuccessRate = derivePersistentMindPlaybookPhaseSignals({ productivity: [{ successRate: 80 }] });
+ // successRate is only trustworthy alongside evidence that work ran.
+ const viaSuccessRate = derivePersistentMindPlaybookPhaseSignals({ productivity: [{ completedToday: 5, successRate: 80 }] });
expect(viaSuccessRate.failureRate).toBeCloseTo(0.2);
const viaHealthError = derivePersistentMindPlaybookPhaseSignals({ health: { status: 'error' } });
@@ -104,6 +105,32 @@ describe('derivePersistentMindPlaybookPhaseSignals', () => {
expect(derivePersistentMindPlaybookPhaseSignals({}).failureRate).toBeNull();
});
+ it('reads an idle day as "no failure signal", never as a 100% failure rate', () => {
+ // getTodayActivity() reports successRate: 0 when zero agents ran today.
+ // Trusting that unguarded made every pre-first-task wake claim a 100%
+ // failure rate and forced `maintain`, starving construct/coordinate.
+ const idleDay = { completedToday: 0, succeededToday: 0, failedToday: 0, successRate: 0 };
+
+ expect(derivePersistentMindPlaybookPhaseSignals({ productivity: [idleDay] }).failureRate).toBeNull();
+ expect(derivePersistentMindPlaybookPhaseSignals({ productivity: [idleDay], health: { status: 'healthy' } }).failureRate).toBe(0);
+
+ // End to end: a mid-density Commons on an idle, healthy morning builds.
+ const signals = derivePersistentMindPlaybookPhaseSignals({
+ apps: [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }, { id: 'e' }],
+ productivity: [idleDay],
+ health: { status: 'healthy' },
+ });
+ expect(selectPersistentMindPlaybookPhase(signals).phase).toBe('construct');
+ });
+
+ it('keeps a measured zero-failure day at 0 rather than falling through to health', () => {
+ const signals = derivePersistentMindPlaybookPhaseSignals({
+ productivity: [{ completedToday: 8, succeededToday: 8, failedToday: 0, successRate: 100 }],
+ health: { status: 'attention' },
+ });
+ expect(signals.failureRate).toBe(0);
+ });
+
it('counts only travelable peers reporting non-steady status as active', () => {
const signals = derivePersistentMindPlaybookPhaseSignals({
peers: [