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

address review (opencode): replay a state-unchanged controller tick instead of throwing on it

[._.]/ Adam Eivyba4fabe16e6d
diff --git a/server/lib/eidoverseFoundationSandbox.js b/server/lib/eidoverseFoundationSandbox.js
index d073987f97..05dbf7d258 100644
--- a/server/lib/eidoverseFoundationSandbox.js
+++ b/server/lib/eidoverseFoundationSandbox.js
@@ -130,7 +130,18 @@ function controllerSandbox({ body, definition, definitionId, contributionId }) {
return {
worldState: definition.createState(scenarioConfig),
controller: {
- step: (worldState, tick) => definition.step(worldState, { tick, config: scenarioConfig }).state,
+ // `outcome?.state === undefined` mirrors `runControllerStep()`'s own
+ // rule, and has to: a step that returns nothing (or returns effects
+ // with no `state`) is asserting "this tick changed no state", which
+ // is ordinary for a controller that acts every Nth tick. Reading
+ // `.state` off the result directly would throw on the live contract
+ // and fail the promote gate for a controller that runs correctly —
+ // an assay verdict about something other than the real tick path,
+ // which is the very thing this module exists to stop.
+ step: (worldState, tick) => {
+ const outcome = definition.step(worldState, { tick, config: scenarioConfig });
+ return outcome?.state === undefined ? worldState : outcome.state;
+ },
// Every disturbance in the suite is an ENVIRONMENT event; a
// controller that keeps its durable state in `state` survives all
// three, and the round-trip proves it holds no in-process handle.
diff --git a/server/lib/eidoverseFoundationSandbox.test.js b/server/lib/eidoverseFoundationSandbox.test.js
index 7be566d267..01ad2f37bf 100644
--- a/server/lib/eidoverseFoundationSandbox.test.js
+++ b/server/lib/eidoverseFoundationSandbox.test.js
@@ -159,6 +159,38 @@ describe('deriving the assay sandbox from a foundation body', () => {
expect(replayed.reasons.join(' ')).toMatch(/pulses was/);
});
+ it('replays a step that returns nothing as "this tick changed no state", exactly as the live path does', async () => {
+ // `runControllerStep()` documents a bare `return` (and a `{ effects }`
+ // with no `state`) as "left the state unchanged". A gate that read
+ // `.state` off the outcome threw on that contract, so a controller that
+ // ticks correctly in production failed the promote gate — an assay verdict
+ // about a tick path the install does not actually run.
+ const intermittent = {
+ id: 'every-other-beacon',
+ title: 'Every-other beacon',
+ summary: 'Only writes state on alternate ticks.',
+ configSchema: z.object({}).strict(),
+ createState: () => ({ ticks: 0, pulses: 0 }),
+ step: (state, { tick }) => {
+ if (tick % 2 === 0) return undefined; // nothing at all
+ if (tick % 3 === 0) return { effects: [] }; // effects, no state
+ return { state: { ...state, ticks: state.ticks + 1, pulses: state.pulses + 1 } };
+ },
+ invariants: [function countersStayIntegers(state) {
+ return (Number.isInteger(state.ticks) && Number.isInteger(state.pulses)) || { ok: false, reason: 'counters left the integers' };
+ }],
+ };
+
+ const derived = await foundationSandbox(
+ { kind: 'controller', id: 'every-other-beacon', body: { controller: { definitionId: 'every-other-beacon', config: {} } } },
+ { findControllerDefinition: async (id) => (id === 'every-other-beacon' ? intermittent : null) },
+ );
+
+ expect(derived.refusal).toBeNull();
+ const replayed = runResilienceAssay(derived.contribution, { disturbances: RESILIENCE_DISTURBANCES });
+ expect(replayed.pass).toBe(true);
+ });
+
it('refuses a kind with no derivation and a body that is not an object', async () => {
expect((await foundationSandbox({ kind: 'mystery', id: 'x', body: {} }, resolvers)).refusal).toMatch(/has no sandbox derivation/);
expect((await foundationSandbox({ kind: 'schema', id: 'x', body: null }, resolvers)).refusal).toMatch(/no body to replay/);