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: read the world's refusal verdict before counting a controller effect as delivered (#7628)
[._.]/ Adam Eivye8a90191843a
diff --git a/client/src/components/eidoverse/EidoverseControllersPanel.jsx b/client/src/components/eidoverse/EidoverseControllersPanel.jsxindex 9d83cd929b..ba6454001c 100644--- a/client/src/components/eidoverse/EidoverseControllersPanel.jsx+++ b/client/src/components/eidoverse/EidoverseControllersPanel.jsx@@ -57,12 +57,23 @@ function parseJsonObject(text, label) {return { value: parsed };}-/** What the install list needs to tell a user "is this thing alive, and did- * it work" without reasoning over `lastTickOk`/`lastTickReason` itself. */+/**+ * What the install list needs to tell a user "is this thing alive, and did+ * it work" without reasoning over `lastTickOk`/`lastTickReason` itself.+ *+ * `lastDelivery` is a SEPARATE verdict from the step (#7628): a step can+ * succeed while every effect it produced was refused by the world, so a+ * green "Last tick ok" is checked against delivery too before it renders.+ * `lastDelivery.ok === null` means delivery is off or nothing was sent this+ * tick — that still reads as ok, never as a silent failure.+ */function TickOutcome({ install }) {if (install.lastTickOk === null) return <span className="text-gray-500">Never ticked yet</span>;- if (install.lastTickOk) return <span className="text-port-success">Last tick ok</span>;- return <span className="text-port-error">Last tick failed{install.lastTickReason ? `: ${install.lastTickReason}` : ''}</span>;+ if (!install.lastTickOk) return <span className="text-port-error">Last tick failed{install.lastTickReason ? `: ${install.lastTickReason}` : ''}</span>;+ if (install.lastDelivery?.ok === false) {+ return <span className="text-port-error">Delivery refused{install.lastDelivery.reason ? `: ${install.lastDelivery.reason}` : ''}</span>;+ }+ return <span className="text-port-success">Last tick ok</span>;}/**@@ -368,6 +379,7 @@ export default function EidoverseControllersPanel() {<p className="text-gray-400">Installed {formatDateShort(install.installedAt)} by {install.installedBy} ·{' '}{install.consecutiveFailures > 0 ? `${install.consecutiveFailures} consecutive failure(s)` : 'no consecutive failures'}+ {install.consecutiveDeliveryFailures > 0 ? ` · ${install.consecutiveDeliveryFailures} consecutive delivery failure(s)` : ''}</p><ControllerConfigBlock detail={inspected[install.id]} />{inspected[install.id]?.install && (diff --git a/client/src/components/eidoverse/EidoverseControllersPanel.test.jsx b/client/src/components/eidoverse/EidoverseControllersPanel.test.jsxindex 36d27eeb2d..576f56ed9e 100644--- a/client/src/components/eidoverse/EidoverseControllersPanel.test.jsx+++ b/client/src/components/eidoverse/EidoverseControllersPanel.test.jsx@@ -86,6 +86,19 @@ describe('the Eidoverse controllers panel', () => {expect(screen.getByRole('button', { name: /Arm/ })).toBeInTheDocument();});+ // #7628: a step can succeed every tick while the world refuses everything+ // it proposes — this is the shape that used to render as a green+ // "Last tick ok" with no trace of the refusal anywhere in the UI.+ it('shows a delivery refusal instead of a green "Last tick ok" when the step succeeded but the world refused it', async () => {+ listEidoverseControllers.mockResolvedValue(listing([+ install({ deliverEffects: true, lastTickOk: true, lastDelivery: { ok: false, delivered: 0, reason: 'unknown entity id' } }),+ ]));+ await renderPanel();++ expect(screen.getByText(/Delivery refused: unknown entity id/)).toBeInTheDocument();+ expect(screen.queryByText('Last tick ok')).not.toBeInTheDocument();+ });+it('shows an install refusal with its reasons beside the form, without installing anything', async () => {listEidoverseControllers.mockResolvedValue(listing([]));installEidoverseController.mockResolvedValue({diff --git a/server/lib/eidoverseControllers.js b/server/lib/eidoverseControllers.jsindex 78f63905ea..88a41716ef 100644--- a/server/lib/eidoverseControllers.js+++ b/server/lib/eidoverseControllers.js@@ -198,6 +198,12 @@ export const eidoverseControllerRecordSchema = eidoverseControllerInstallSchema.summary: z.string().trim().min(1).max(EIDOVERSE_CONTROLLER_LIMITS.effectTextMax),}).strict()).max(EIDOVERSE_CONTROLLER_LIMITS.recentEffects).default([]),consecutiveFailures: z.number().int().min(0).default(0),+ // A run of ticks whose STEP succeeded but whose delivery into the world was+ // refused (#7628) — tracked separately from `consecutiveFailures`, which+ // only counts a throwing/refusing `step()`. A controller can step cleanly+ // forever while every write it proposes is rejected; this is what lets that+ // pattern disarm too, instead of reporting "ok" indefinitely.+ consecutiveDeliveryFailures: z.number().int().min(0).default(0),// Set when the supervisor disarms a controller itself (repeated failures, a// controller id that no longer resolves). Distinct from `armed: false`// chosen by a human, which carries no reason.@@ -403,9 +409,33 @@ export function summarizeControllerInstall(record, { includeState = false } = {}lastTickOk: record?.lastOutcome ? record.lastOutcome.ok === true : null,lastTickReason: record?.lastOutcome?.reason ?? null,consecutiveFailures: record?.consecutiveFailures ?? 0,+ // Delivery is a SEPARATE verdict from the step (#7628): a step can read+ // `ok: true` while every effect it produced was refused by the world.+ // `null` covers both "delivery is off for this install" and "this tick+ // produced nothing to deliver" — neither is a failure, so neither+ // collapses into `false`.+ lastDelivery: summarizeLastDelivery(record),+ consecutiveDeliveryFailures: record?.consecutiveDeliveryFailures ?? 0,disarmedReason: record?.disarmedReason ?? null,note: record?.note ?? null,recentEffects: (record?.recentEffects ?? []).slice(0, 5),...(includeState ? { config: record?.config ?? {}, state: record?.state ?? {} } : {}),};}++/**+ * The last tick's delivery verdict, distinct from `lastTickOk` (the STEP).+ * `deliverControllerEffects()` in `services/eidoverseControllerRuntime.js`+ * reads the world's own ack/refusal for every effect it sends and folds the+ * result onto `lastOutcome.delivered` / `lastOutcome.deliveryError` — this+ * just reshapes that into the same `{ ok, reason }` verdict shape the rest of+ * the controller surfaces already use.+ */+function summarizeLastDelivery(record) {+ if (record?.deliverEffects !== true) return { ok: null, delivered: 0, reason: null };+ const outcome = record?.lastOutcome;+ // No tick yet, or the tick that ran produced nothing to send — delivery was+ // never attempted, so there is no verdict to report yet.+ if (!outcome || outcome.effects === 0) return { ok: null, delivered: outcome?.delivered ?? 0, reason: null };+ return { ok: outcome.deliveryError === null, delivered: outcome.delivered, reason: outcome.deliveryError };+}diff --git a/server/lib/eidoverseObservation.js b/server/lib/eidoverseObservation.jsindex f48b9858f6..9d9f23efd5 100644--- a/server/lib/eidoverseObservation.js+++ b/server/lib/eidoverseObservation.js@@ -205,14 +205,19 @@ function observePeers(source, byPeer) {** `lastTickOk === null` means the controller has never stepped yet, which is* the normal state one interval after an install and deliberately NOT an- * alarm.+ * alarm. `lastDelivery` is the SEPARATE verdict #7628 added: a step can read+ * `ok: true` while every effect it produced was refused by the world, so a+ * clean step alone does not clear this filter — `lastDelivery.ok === false`+ * is checked too. `lastDelivery.ok === null` (delivery off, or nothing to+ * deliver this tick) is deliberately NOT an alarm either.*/function observeControllers(installs) {if (!Array.isArray(installs)) return null;return installs.filter((install) => install?.disarmedReason|| (install?.consecutiveFailures ?? 0) > 0- || install?.lastTickOk === false)+ || install?.lastTickOk === false+ || install?.lastDelivery?.ok === false).slice(0, MAX_ATTENTION_CONTROLLERS).map((install) => ({id: install.id,@@ -221,6 +226,7 @@ function observeControllers(installs) {lastTickOk: install.lastTickOk ?? null,lastTickReason: install.lastTickReason ?? null,consecutiveFailures: install.consecutiveFailures ?? 0,+ lastDelivery: install.lastDelivery ?? null,disarmedReason: install.disarmedReason ?? null,}));}diff --git a/server/lib/eidoverseObservation.test.js b/server/lib/eidoverseObservation.test.jsindex e08cfc9dcd..ff007a0b2c 100644--- a/server/lib/eidoverseObservation.test.js+++ b/server/lib/eidoverseObservation.test.js@@ -181,6 +181,26 @@ describe('buildEidoverseObservation', () => {expect(third.changes.controllersNeedingAttention).toEqual(['newly-broken']);});+ it('flags a controller whose step is clean but whose delivery the world refused (#7628)', () => {+ // `lastTickOk: true` and `consecutiveFailures: 0` on their own describe a+ // healthy controller — that used to be the whole story. A controller+ // whose every world write is refused steps cleanly forever, so the+ // filter has to read `lastDelivery` too or this never surfaces.+ const installs = [+ {+ id: 'refused-lantern', controllerId: 'lanternKeeper', armed: true, lastTickOk: true, consecutiveFailures: 0,+ lastDelivery: { ok: false, delivered: 0, reason: 'unknown entity id' },+ },+ {+ id: 'delivering-fine', controllerId: 'ambientBeacon', armed: true, lastTickOk: true, consecutiveFailures: 0,+ lastDelivery: { ok: true, delivered: 1, reason: null },+ },+ ];+ const { report } = observe({ controllerInstalls: installs });+ expect(report.controllers.needsAttention.map((entry) => entry.id)).toEqual(['refused-lantern']);+ expect(report.controllers.needsAttention[0].lastDelivery).toEqual({ ok: false, delivered: 0, reason: 'unknown entity id' });+ });+it('bounds the inherited list and says when it truncated', () => {const many = Array.from({ length: 30 }, (_, index) => inheritedFoundation(`peer:alpha:${index}`, PEER_ALPHA));const { report } = observe({ source: { peers: [peerSignal(PEER_ALPHA)] }, foundations: many });diff --git a/server/services/eidoverseControllerRuntime.js b/server/services/eidoverseControllerRuntime.jsindex 9206991041..1321e41e21 100644--- a/server/services/eidoverseControllerRuntime.js+++ b/server/services/eidoverseControllerRuntime.js@@ -209,6 +209,7 @@ export async function installEidoverseController(input, {lastOutcome: null,recentEffects: [],consecutiveFailures: 0,+ consecutiveDeliveryFailures: 0,// A re-install that leaves a controller disarmed keeps the reason it was// disarmed for, so the author is not left looking at a stopped controller// with no explanation. Re-arming answers the reason, so it clears it.@@ -260,7 +261,12 @@ export async function setEidoverseControllerArmed(id, armed, { now = new Date().updatedAt: now,// Re-arming restarts the cadence from now rather than firing immediately// on the next pass against a `nextTickAt` that went stale while paused.- ...(armed === true ? { nextTickAt: nextControllerTickAt(existing, nowMs), consecutiveFailures: 0, disarmedReason: null } : {}),+ ...(armed === true ? {+ nextTickAt: nextControllerTickAt(existing, nowMs),+ consecutiveFailures: 0,+ consecutiveDeliveryFailures: 0,+ disarmedReason: null,+ } : {}),};installs[id] = record;await writeInstalls(installs, storeSchemaVersion);@@ -326,6 +332,16 @@ const afterGateMove = (reason) => async (result) => {* would put that whole subtree in the closure of everything that merely lists* controllers. Neither verb calls an AI provider.*+ * `augmentEidoverseWorld()` never throws on a world refusal (#7454) — the+ * verdict is its RETURN VALUE (`success`, `applied`, per-operation+ * `outcome`), so it must be read, not assumed delivered because the await+ * resolved. #7628 was exactly this: the return value was discarded, so a+ * controller whose every write the world refused counted as delivered every+ * tick, forever. `delivered` here is the world's own committed count+ * (`applied`), never the loop's attempt count, and a `rewritten` operation+ * counts as delivered — the world landed different args, not nothing — only+ * `refused` does not.+ ** @returns {Promise<{ delivered: number, error: string|null }>}*/async function deliverControllerEffects(effects, { signal } = {}) {@@ -333,12 +349,24 @@ async function deliverControllerEffects(effects, { signal } = {}) {if (outbound.length === 0) return { delivered: 0, error: null };const world = await import('./eidoverseWorld.js');let delivered = 0;+ let error = null;for (const effect of outbound) {- if (effect.kind === 'say') await world.sayInEidoverseWorld(effect.text, { signal });- else await world.augmentEidoverseWorld(effect.operations, { signal });- delivered += 1;+ if (effect.kind === 'say') {+ // `sayInEidoverseWorld` has no rewrite/refusal dimension of its own —+ // it either resolves (the world acked it) or throws, which the caller+ // in `deliverPassEffects` already treats as a delivery failure.+ await world.sayInEidoverseWorld(effect.text, { signal });+ delivered += 1;+ continue;+ }+ const result = await world.augmentEidoverseWorld(effect.operations, { signal });+ delivered += result.applied;+ if (result.success === false && error === null) {+ const refusal = result.operations.find((operation) => operation.outcome === 'refused');+ error = refusal?.reason ?? 'Eidoverse refused part of this augment batch.';+ }}- return { delivered, error: null };+ return { delivered, error };}function recordedEffects(existing, effects, { at, tick }) {@@ -487,19 +515,44 @@ async function deliverPassEffects(stepped, { deliver, signal }) {* matches the tick that produced those effects: an install or retire landing* between the two phases has replaced what the delivery was about, and* stamping a delivery count onto it would describe work that record never did.+ *+ * A run of REFUSED deliveries disarms the same way a run of throwing/refusing+ * `step()`s already does (#7628): `consecutiveFailures` only counts the step,+ * so a controller that steps cleanly every tick while the world refuses+ * everything it proposes would otherwise never disarm and never report+ * anything but "ok". `consecutiveDeliveryFailures` is that same clause, keyed+ * on the delivery verdict instead.+ *+ * @returns {Promise<{ gateMoved: boolean }>}*/async function recordDeliveries(deliveries) {- if (deliveries.length === 0) return;- await withStoreLock(async () => {+ if (deliveries.length === 0) return { gateMoved: false };+ return withStoreLock(async () => {const { schemaVersion: storeSchemaVersion, installs } = await readInstalls();let changed = false;+ let gateMoved = false;for (const { id, tick, delivered, error } of deliveries) {const current = installs[id];if (!current || current.lastOutcome?.tick !== tick) continue;- installs[id] = { ...current, lastOutcome: { ...current.lastOutcome, delivered, deliveryError: error } };+ const consecutiveDeliveryFailures = error ? (current.consecutiveDeliveryFailures ?? 0) + 1 : 0;+ const exhausted = error && consecutiveDeliveryFailures >= EIDOVERSE_CONTROLLER_LIMITS.maxConsecutiveFailures;+ if (exhausted) {+ console.error(`❌ ${LOG_PREFIX}: disarming "${id}" — ${consecutiveDeliveryFailures} consecutive delivery failures: ${error}`);+ }+ installs[id] = {+ ...current,+ lastOutcome: { ...current.lastOutcome, delivered, deliveryError: error },+ consecutiveDeliveryFailures,+ ...(exhausted ? {+ armed: false,+ disarmedReason: `disarmed after ${consecutiveDeliveryFailures} consecutive delivery failures: ${error}`,+ } : {}),+ };changed = true;+ gateMoved = gateMoved || exhausted;}if (changed) await writeInstalls(installs, storeSchemaVersion);+ return { gateMoved };});}@@ -557,14 +610,15 @@ async function tickOnce({};});- await recordDeliveries(await deliverPassEffects(pass.stepped, { deliver, signal }));+ const { gateMoved: deliveryGateMoved } = await recordDeliveries(await deliverPassEffects(pass.stepped, { deliver, signal }));- // A pass that disarmed a controller has moved the arming gate, so it- // reconciles for the same reason install and retire do. The reconcile is- // idempotent and re-reads the gate itself, so it correctly does nothing when- // other installs are still armed and stands the supervisor down when the- // disarmed one was the last.- if (pass.gateMoved) await reconcileEidoverseControllerTicks({ reason: 'supervisor-disarm' });+ // A pass that disarmed a controller — whether stepping it failed or, per+ // #7628, delivering its effects into the world did — has moved the arming+ // gate, so it reconciles for the same reason install and retire do. The+ // reconcile is idempotent and re-reads the gate itself, so it correctly+ // does nothing when other installs are still armed and stands the+ // supervisor down when the disarmed one was the last.+ if (pass.gateMoved || deliveryGateMoved) await reconcileEidoverseControllerTicks({ reason: 'supervisor-disarm' });const { stepped: _stepped, gateMoved: _gateMoved, ...result } = pass;return result;diff --git a/server/services/eidoverseControllerRuntime.test.js b/server/services/eidoverseControllerRuntime.test.jsindex 8afef0012f..eba0502bbe 100644--- a/server/services/eidoverseControllerRuntime.test.js+++ b/server/services/eidoverseControllerRuntime.test.js@@ -21,6 +21,7 @@ import { rmSync } from 'node:fs';import { join } from 'node:path';import { z } from 'zod';import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';+import { summarizeControllerInstall } from '../lib/eidoverseControllers.js';vi.mock('../lib/fileUtils.js', async (importOriginal) => makePathsProxy(await importOriginal(), {dataRoot: () => lazyTempDataRoot('portos-eidoverse-controllers-'),@@ -28,6 +29,19 @@ vi.mock('../lib/fileUtils.js', async (importOriginal) => makePathsProxy(await imconst { atomicWrite, readJSONFile } = await import('../lib/fileUtils.js');+// `deliverControllerEffects()` (the default `deliver` the runtime uses when a+// test does not inject its own) lazily imports this module, so mocking it is+// what lets a test drive a REAL world refusal through the REAL delivery path+// instead of only through an injected `deliver` stand-in (#7628).+const { augmentEidoverseWorldMock, sayInEidoverseWorldMock } = vi.hoisted(() => ({+ augmentEidoverseWorldMock: vi.fn(),+ sayInEidoverseWorldMock: vi.fn(),+}));+vi.mock('./eidoverseWorld.js', () => ({+ augmentEidoverseWorld: augmentEidoverseWorldMock,+ sayInEidoverseWorld: sayInEidoverseWorldMock,+}));+const {__resetEidoverseControllerRuntimeForTests,getEidoverseControllerInstall,@@ -73,6 +87,8 @@ async function runSupervisorPasses(passes, { fromMs = 0, everyMs = MINUTE, ...opbeforeEach(() => {rmSync(lazyTempDataRoot('portos-eidoverse-controllers-'), { recursive: true, force: true });__resetEidoverseControllerRuntimeForTests();+ augmentEidoverseWorldMock.mockReset();+ sayInEidoverseWorldMock.mockReset();});afterEach(() => __resetEidoverseControllerRuntimeForTests());@@ -208,6 +224,63 @@ describe('the supervised tick path', () => {expect(record.state.pulses).toBe(1);expect(record.lastOutcome).toMatchObject({ ok: true, delivered: 0, deliveryError: 'world host is down' });});++ // #7628: `augmentEidoverseWorld()` never throws on a world refusal — the+ // verdict is its return value. This drives that refusal through the REAL+ // `deliverControllerEffects()` (no `deliver` override), the seam the old+ // fixture skipped by mocking a throw instead, and follows it all the way to+ // the projection a mind or the panel actually reads.+ it('reads a world refusal instead of counting it as delivered, and disarms after enough of them', async () => {+ augmentEidoverseWorldMock.mockResolvedValue({+ success: false,+ applied: 0,+ operations: [{ verb: 'light', id: 'missing-lantern', outcome: 'refused', proposed: null, committed: null, reason: 'unknown entity id' }],+ });+ await install({+ id: 'lamp-keeper', controllerId: 'lantern-keeper', deliverEffects: true, tickIntervalMs: MINUTE,+ config: { relightEveryTicks: 1, lanterns: [{ id: 'missing-lantern', pos: [0, 2, 0] }] },+ });++ await runSupervisorPasses(3);++ expect(augmentEidoverseWorldMock).toHaveBeenCalledTimes(3);+ const record = await getEidoverseControllerInstall('lamp-keeper');+ // The step succeeded every tick — #7628's whole point is that this alone+ // used to be reported as "ok" with no trace of the refusal anywhere.+ expect(record.lastOutcome.ok).toBe(true);+ expect(record.lastOutcome).toMatchObject({ delivered: 0, deliveryError: 'unknown entity id' });+ expect(record.consecutiveDeliveryFailures).toBe(3);+ // A run of refused deliveries disarms exactly like a run of failed steps.+ expect(record.armed).toBe(false);+ expect(record.disarmedReason).toMatch(/3 consecutive delivery failures: unknown entity id/);+ expect(isEidoverseControllerSupervisorRegistered()).toBe(false);++ // The projection every reader (route, mind tool, panel) actually consumes+ // carries the refusal as its own verdict, separate from the tick.+ const summary = summarizeControllerInstall(record);+ expect(summary.lastTickOk).toBe(true);+ expect(summary.lastDelivery).toEqual({ ok: false, delivered: 0, reason: 'unknown entity id' });+ });++ it('does not disarm on a rewritten delivery — the world landed different args, not nothing', async () => {+ augmentEidoverseWorldMock.mockResolvedValue({+ success: true,+ applied: 1,+ operations: [{ verb: 'light', id: 'plaza-lantern', outcome: 'rewritten', proposed: { id: 'plaza-lantern' }, committed: { id: 'plaza-lantern', pos: [0, 1, 0] } }],+ });+ await install({+ id: 'lamp-keeper', controllerId: 'lantern-keeper', deliverEffects: true, tickIntervalMs: MINUTE,+ config: { relightEveryTicks: 1, lanterns: [{ id: 'plaza-lantern', pos: [0, 2, 0] }] },+ });++ await runSupervisorPasses(3);++ const record = await getEidoverseControllerInstall('lamp-keeper');+ expect(record.lastOutcome).toMatchObject({ ok: true, delivered: 1, deliveryError: null });+ expect(record.consecutiveDeliveryFailures).toBe(0);+ expect(record.armed).toBe(true);+ expect(summarizeControllerInstall(record).lastDelivery).toEqual({ ok: true, delivered: 1, reason: null });+ });});describe('a controller that goes wrong', () => {