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

fix: push Eidoverse projection progress instead of polling (#8536)

[._.]/ Adam Eivy62ea3372dfd0
diff --git a/client/src/pages/Eidoverse.jsx b/client/src/pages/Eidoverse.jsx
index 8de06c203d..ac811389a1 100644
--- a/client/src/pages/Eidoverse.jsx
+++ b/client/src/pages/Eidoverse.jsx
@@ -12,6 +12,7 @@ import {
import { Link, useLocation, useNavigate } from 'react-router';
import PageHeader from '../components/PageHeader';
import BrailleSpinner from '../components/BrailleSpinner';
+import { useSocketResource } from '../hooks/useSocketResource';
import useEidoverseFrame from '../hooks/useEidoverseFrame';
import EidoverseWorldDrawer from '../components/eidoverse/EidoverseWorldDrawer';
import EidoverseTravel from '../components/eidoverse/EidoverseTravel';
@@ -32,6 +33,8 @@ import {
} from '../services/api';
const silent = { silent: true };
+const PROJECTION_EVENTS = ['eidoverse:projection'];
+const readProjection = () => getEidoverseWorldProjectionStatus(silent);
const RUNNING_STATUSES = new Set(['online', 'launching', 'unknown']);
const FRESH_WORLD_VISIBLE_CHECKPOINTS = new Set([
'environment-complete',
@@ -177,8 +180,6 @@ export default function Eidoverse() {
const requestGeneration = useRef(0);
const configDraftRevision = useRef(0);
const savedDraftRevision = useRef(0);
- const projectionPollGeneration = useRef(0);
- const projectionPollTimer = useRef(null);
const [phase, setPhase] = useState('loading');
const [error, setError] = useState('');
const [hostUrl, setHostUrl] = useState('');
@@ -199,6 +200,18 @@ export default function Eidoverse() {
const [settingsOpen, setSettingsOpen] = useState(false);
const [iframeReady, setIframeReady] = useState(false);
+ const { data: projectionProgress, updateData: updateProjectionProgress } = useSocketResource(readProjection, {
+ events: PROJECTION_EVENTS, enabled: phase === 'ready', immediate: false,
+ });
+ useEffect(() => {
+ if (!projectionProgress) return;
+ setWorldState(current => current ? {
+ ...current,
+ projection: projectionProgress.projection || current.projection,
+ design: projectionProgress.design ? { ...current.design, ...projectionProgress.design } : current.design,
+ } : current);
+ }, [projectionProgress]);
+
const markConfigDirty = useCallback(() => {
configDraftRevision.current += 1;
setDraftDirty(true);
@@ -223,6 +236,7 @@ export default function Eidoverse() {
);
const applyWorldResponse = useCallback((updated, { replaceDraft = true } = {}) => {
+ updateProjectionProgress(null);
setWorldState((current) => current
? { ...current, ...updated, identity: updated.identity || updated.human || current.identity }
: updated);
@@ -236,7 +250,7 @@ export default function Eidoverse() {
savedDraftRevision.current = configDraftRevision.current;
setDraftDirty(false);
}
- }, []);
+ }, [updateProjectionProgress]);
const prepare = useCallback(() => {
const generation = ++requestGeneration.current;
@@ -318,24 +332,9 @@ export default function Eidoverse() {
setProjectionError('');
const submittedRevision = configDraftRevision.current;
const submittedDraftWasClean = submittedRevision === savedDraftRevision.current;
- const pollGeneration = ++projectionPollGeneration.current;
- const poll = () => {
- if (projectionPollGeneration.current !== pollGeneration) return;
- getEidoverseWorldProjectionStatus(silent).then((status) => {
- if (projectionPollGeneration.current !== pollGeneration) return;
- setWorldState((current) => current ? {
- ...current,
- projection: status.projection || current.projection,
- design: status.design ? { ...current.design, ...status.design } : current.design,
- } : current);
- }).catch(() => {}).finally(() => {
- if (projectionPollGeneration.current === pollGeneration) {
- projectionPollTimer.current = setTimeout(poll, 750);
- }
- });
- };
- projectionPollTimer.current = setTimeout(poll, 750);
return projectEidoverseWorld(silent).then((result) => {
+ // A progress read begun before the mutation response must not regress it.
+ updateProjectionProgress(null);
const replaceDraft = submittedDraftWasClean
&& configDraftRevision.current === submittedRevision;
setWorldState((current) => current ? {
@@ -356,16 +355,12 @@ export default function Eidoverse() {
setProjectionStatus('error');
setProjectionError(reason?.message || 'PortOS could not project its current state into Eidoverse.');
const failedStatus = await getEidoverseWorldStatus(silent).catch(() => null);
- if (failedStatus) applyWorldResponse(failedStatus, { replaceDraft: false });
- throw reason;
- }).finally(() => {
- if (projectionPollGeneration.current === pollGeneration) {
- projectionPollGeneration.current += 1;
- clearTimeout(projectionPollTimer.current);
- projectionPollTimer.current = null;
+ if (failedStatus) {
+ applyWorldResponse(failedStatus, { replaceDraft: false });
}
+ throw reason;
});
- }, [applyWorldResponse]);
+ }, [applyWorldResponse, updateProjectionProgress]);
useEffect(() => {
if (phase !== 'ready' || !hostUrl) return undefined;
@@ -377,8 +372,6 @@ export default function Eidoverse() {
prepare();
return () => {
requestGeneration.current += 1;
- projectionPollGeneration.current += 1;
- clearTimeout(projectionPollTimer.current);
};
}, [prepare]);
diff --git a/client/src/pages/Eidoverse.test.jsx b/client/src/pages/Eidoverse.test.jsx
index 8a0cd55a9b..d2a0c06055 100644
--- a/client/src/pages/Eidoverse.test.jsx
+++ b/client/src/pages/Eidoverse.test.jsx
@@ -1,5 +1,5 @@
// @vitest-environment-options {"settings":{"navigation":{"disableChildFrameNavigation":true}}}
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router';
@@ -19,6 +19,13 @@ vi.mock('../services/api', () => ({
updateEidoverseWorldConfig: vi.fn(),
}));
+vi.mock('../services/socket', async () => {
+ const { EventEmitter } = await import('node:events');
+ return { default: new EventEmitter() };
+});
+import socket from '../services/socket';
+afterEach(() => { vi.useRealTimers(); vi.restoreAllMocks(); });
+
vi.mock('../components/BrailleSpinner', () => ({
default: ({ text }) => <span>{text}</span>,
}));
@@ -653,7 +660,7 @@ describe('Eidoverse hosted page', () => {
await awaitEnabled(refresh);
});
- it('keeps a fresh-world curtain up until the dawn environment is applied', async () => {
+ it('pushes projection progress without polling and reconciles once on reconnect and tab show', async () => {
let resolveProjection;
api.getEidoverseWorldStatus.mockResolvedValueOnce({
...worldResponse,
@@ -670,6 +677,10 @@ describe('Eidoverse hosted page', () => {
fireEvent.load(frame);
expect(screen.getByText(/Preparing the PortOS systems garden/)).toBeInTheDocument();
+ vi.useFakeTimers();
+ const visibility = vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('visible');
+ await act(async () => { await vi.advanceTimersByTimeAsync(3000); });
+ expect(api.getEidoverseWorldProjectionStatus).not.toHaveBeenCalled();
api.getEidoverseWorldProjectionStatus.mockResolvedValue({
projection: worldResponse.projection,
design: {
@@ -677,22 +688,45 @@ describe('Eidoverse hosted page', () => {
reconciliation: { status: 'applying', checkpoint: 'environment-complete' },
},
});
- await waitFor(
- () => expect(screen.queryByText(/Preparing the PortOS systems garden/)).not.toBeInTheDocument(),
- { timeout: 2500 },
- );
+ await act(async () => { socket.emit('eidoverse:projection', {}); });
+ expect(screen.queryByText(/Preparing the PortOS systems garden/)).not.toBeInTheDocument();
expect(api.getEidoverseWorldStatus).toHaveBeenCalledOnce();
- expect(api.getEidoverseWorldProjectionStatus).toHaveBeenCalled();
+ expect(api.getEidoverseWorldProjectionStatus).toHaveBeenCalledTimes(1);
+ await act(async () => { socket.emit('connect'); });
+ expect(api.getEidoverseWorldProjectionStatus).toHaveBeenCalledTimes(2);
+ visibility.mockReturnValue('hidden');
+ fireEvent(document, new Event('visibilitychange'));
+ await act(async () => { socket.emit('eidoverse:projection', {}); });
+ expect(api.getEidoverseWorldProjectionStatus).toHaveBeenCalledTimes(2);
+ visibility.mockReturnValue('visible');
+ await act(async () => { fireEvent(document, new Event('visibilitychange')); });
+ expect(api.getEidoverseWorldProjectionStatus).toHaveBeenCalledTimes(3);
+
+ // A read already in flight cannot overwrite the completed mutation response.
+ let finishOldRead;
+ api.getEidoverseWorldProjectionStatus.mockReturnValueOnce(new Promise(resolve => { finishOldRead = resolve; }));
+ await act(async () => { socket.emit('eidoverse:projection', {}); });
await act(async () => {
resolveProjection({
success: true,
projection: worldResponse.projection,
presence: { connected: true },
- design,
+ design: { ...design, reconciliation: { status: 'complete', checkpoint: 'projection-committed' } },
recipe,
});
});
+ await act(async () => {
+ finishOldRead({
+ projection: { lastSummary: null },
+ design: { lastAppliedVersion: null, reconciliation: { status: 'applying', checkpoint: 'plan-ready' } },
+ });
+ });
+ expect(screen.getByRole('button', { name: 'Refresh world' })).toBeEnabled();
+ expect(screen.queryByText(/Preparing the PortOS systems garden/)).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'World controls' }));
+ fireEvent.click(screen.getByRole('tab', { name: 'Updates & Advanced' }));
+ expect(screen.getByText('projection-committed')).toBeInTheDocument();
});
it('resets one semantic district without clearing the full world design', async () => {
diff --git a/server/lib/socketEventContracts.js b/server/lib/socketEventContracts.js
index 6d766aa186..22bc39c0bf 100644
--- a/server/lib/socketEventContracts.js
+++ b/server/lib/socketEventContracts.js
@@ -57,6 +57,11 @@ export const SOCKET_EVENT_CONTRACTS = Object.freeze({
additionalProperties: false,
},
},
+ 'eidoverse:projection': {
+ direction: 'server-to-client',
+ summary: 'Payload-free invalidation after persisted Eidoverse world changes; clients read projection progress through the authenticated API.',
+ payloadSchema: { type: 'object', additionalProperties: false, properties: {} },
+ },
'jev:policy': {
direction: 'server-to-client',
summary: 'Invalidate Jev integration policy after settings persistence or restore invalidation; no settings content.',
diff --git a/server/services/eidoverseWorld.js b/server/services/eidoverseWorld.js
index 8f3d8e9a44..356a704049 100644
--- a/server/services/eidoverseWorld.js
+++ b/server/services/eidoverseWorld.js
@@ -8,6 +8,7 @@
* external checkout or calls an AI provider.
*/
+import { eidoverseWorldEvents } from './eidoverseWorldEvents.js';
import { scrubSecretTokens } from '../lib/secretText.js';
import { buildEidoverseCitySurface } from '../lib/eidoverseCitySurface.js';
import { eidoverseModelBounds } from '../lib/eidoverseCityLayout.js';
@@ -361,6 +362,7 @@ async function mutateState(mutator) {
const result = await mutator(state);
await ensureDir(DATA_DIR);
await atomicWrite(STATE_FILE, state);
+ eidoverseWorldEvents.emit('updated');
return result;
});
}
diff --git a/server/services/eidoverseWorld.runtime.test.js b/server/services/eidoverseWorld.runtime.test.js
index 4fd267a636..abbb27767f 100644
--- a/server/services/eidoverseWorld.runtime.test.js
+++ b/server/services/eidoverseWorld.runtime.test.js
@@ -1,3 +1,4 @@
+import { eidoverseWorldEvents } from './eidoverseWorldEvents.js';
import { createHash } from 'node:crypto';
import { homedir, hostname, userInfo } from 'node:os';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -348,6 +349,22 @@ describe('Eidoverse private-world lifecycle', () => {
});
}, 60_000);
+ it('announces persisted configuration and projection checkpoints without record payloads', async () => {
+ const checkpoints = [];
+ const onUpdate = vi.fn(() => checkpoints.push(mocks.persistedState?.reconciliation?.checkpoint));
+ eidoverseWorldEvents.on('updated', onUpdate);
+ try {
+ await world.updateEidoverseWorldConfig({ humanName: 'Example User' });
+ expect(onUpdate).toHaveBeenCalledWith();
+ await world.projectEidoverseWorld();
+ expect(checkpoints).toContain('applying-environment');
+ expect(checkpoints.at(-1)).toBe('projection-committed');
+ for (const args of onUpdate.mock.calls) expect(args).toEqual([]);
+ } finally {
+ eidoverseWorldEvents.off('updated', onUpdate);
+ }
+ });
+
it('reads projection progress without runtime, app-registry, or library probes', async () => {
await world.ensureEidoverseWorldConfig();
fetch.mockClear();
diff --git a/server/services/eidoverseWorldEvents.js b/server/services/eidoverseWorldEvents.js
new file mode 100644
index 0000000000..dc6acc9508
--- /dev/null
+++ b/server/services/eidoverseWorldEvents.js
@@ -0,0 +1,4 @@
+import { EventEmitter } from 'node:events';
+
+// Invalidate persisted progress without broadcasting world records or identity.
+export const eidoverseWorldEvents = new EventEmitter();
diff --git a/server/services/socket.js b/server/services/socket.js
index e699ff5a7d..a8e2b59597 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -37,6 +37,7 @@ import { videoGenEvents } from './videoGen/events.js';
import { audioGenEvents } from './audioGen/events.js';
import { aiStatusEvents } from './aiStatusEvents.js';
import { usageBackfillEvents } from './usageBackfillEvents.js';
+import { eidoverseWorldEvents } from './eidoverseWorldEvents.js';
import { layaMlxEvents } from './layaMlxEvents.js';
import { providerQuotaEvents } from './providerQuotaEvents.js';
import { wireProactiveTriggers } from './voice/proactiveTriggers.js';
@@ -248,6 +249,7 @@ function setupEventForwarding() {
modelLifecycleEvents.on('threejs-model:changed', data => ioInstance?.emit('threejs-model:changed', data));
meatspaceEvents.on('death-clock:changed', data => ioInstance?.emit('meatspace:death-clock:changed', data));
usageBackfillEvents.on('updated', () => ioInstance?.emit('usage-backfill:updated', {}));
+ eidoverseWorldEvents.on('updated', () => ioInstance?.emit('eidoverse:projection', {}));
layaMlxEvents.on('updated', () => ioInstance?.emit('laya:status', {}));
providerQuotaEvents.on('updated', () => ioInstance?.emit('provider-quota:updated', {}));
setupCosEventForwarding();
diff --git a/server/services/socket.test.js b/server/services/socket.test.js
index 4eb4ab0891..222afcfdb2 100644
--- a/server/services/socket.test.js
+++ b/server/services/socket.test.js
@@ -8,6 +8,7 @@ import { fableLoomRunEvents } from './fableLoom/runEvents.js';
import { trainingEvents } from './loraTraining/events.js';
import { authEvents } from './auth.js';
import { usageBackfillEvents } from './usageBackfillEvents.js';
+import { eidoverseWorldEvents } from './eidoverseWorldEvents.js';
import { layaMlxEvents } from './layaMlxEvents.js';
import { providerQuotaEvents } from './providerQuotaEvents.js';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
@@ -156,6 +157,7 @@ describe('socket.js — initSocket', () => {
authEvents.removeAllListeners('sessions:revoked-all');
meatspaceEvents.removeAllListeners();
modelLifecycleEvents.removeAllListeners();
+ eidoverseWorldEvents.removeAllListeners();
layaMlxEvents.removeAllListeners();
providerQuotaEvents.removeAllListeners();
usageBackfillEvents.removeAllListeners();
@@ -211,6 +213,12 @@ describe('socket.js — initSocket', () => {
expect(io.emitted).toEqual([['jev:policy', {}]]);
});
+ it('invalidates Eidoverse projection progress without world content', () => {
+ io.emitted.length = 0;
+ eidoverseWorldEvents.emit('updated', { world: 'Example private world' });
+ expect(io.emitted).toEqual([['eidoverse:projection', {}]]);
+ });
+
it('forwards Laya status without experiment content', () => {
io.emitted.length = 0;
layaMlxEvents.emit('updated', { premise: 'Example private experiment' });