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

[issue-11664] Compare activity snapshots structurally (#11691)

atomanticagent131ca265db4d
diff --git a/client/src/components/dashboard/ActiveProcessingWidget.test.jsx b/client/src/components/dashboard/ActiveProcessingWidget.test.jsx
index cdd555b31e..a74f58de01 100644
--- a/client/src/components/dashboard/ActiveProcessingWidget.test.jsx
+++ b/client/src/components/dashboard/ActiveProcessingWidget.test.jsx
@@ -1,9 +1,9 @@
-import { render, screen, cleanup, act } from '@testing-library/react';
+import { render, screen, cleanup, act, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import ActiveProcessingWidget from './ActiveProcessingWidget';
-import { sameProcessingSnapshot, __resetSystemActivityForTests } from '../../hooks/useSystemActivity';
+import { __resetSystemActivityForTests } from '../../hooks/useSystemActivity';
const handlers = new Map();
vi.mock('../../services/socket', () => ({
@@ -130,8 +130,6 @@ describe('ActiveProcessingWidget', () => {
expect(screen.getByText('2:05')).toBeInTheDocument();
expect(screen.getByText('LLM')).toBeInTheDocument();
expect(screen.getByRole('link', { name: /Ollama loaded · example:7b/ })).toHaveTextContent('1 GB · GPU');
- // Replacing one active run with another must repaint even when count stays 1.
- expect(sameProcessingSnapshot({ llm: { active: 1, runs: [{ runId: 'a' }] } }, { llm: { active: 1, runs: [{ runId: 'b' }] } })).toBe(false);
});
it('shows external Ollama loads from telemetry even when PortOS is idle', async () => {
@@ -162,10 +160,30 @@ describe('ActiveProcessingWidget', () => {
expect(mockGetSystemActivity).toHaveBeenCalled();
});
- it('recognizes queue movement while ignoring server timestamps', () => {
- const base = { updatedAt: '2026-01-01T00:00:00Z', jobs: [{ id: 'job-1', status: 'queued', position: 2 }], agents: {}, gpu: {}, extras: {} };
- expect(sameProcessingSnapshot(base, { ...base, updatedAt: '2026-01-01T00:00:03Z' })).toBe(true);
- expect(sameProcessingSnapshot(base, { ...base, jobs: [{ ...base.jobs[0], position: 1 }] })).toBe(false);
- expect(sameProcessingSnapshot(undefined, base)).toBe(false);
+ it('replaces rows when app operations and the mind lifecycle change between reads', async () => {
+ const initial = {
+ ...idle,
+ appOperations: [{ appId: 'example', appName: 'Old App', type: 'update' }],
+ mind: { thinking: true, thinkingSince: new Date(Date.now() - 600_000).toISOString() },
+ activity: { idle: false, activeCount: 1, queuedCount: 0, blockers: [] },
+ };
+ mockGetSystemActivity.mockResolvedValueOnce(initial);
+ renderWidget();
+
+ expect(await screen.findByRole('link', { name: /Old App · update/ })).toBeInTheDocument();
+ const originalMindText = screen.getByRole('link', { name: /Persistent Mind is thinking/ }).textContent;
+
+ mockGetSystemActivity.mockResolvedValueOnce({
+ ...initial,
+ appOperations: [{ appId: 'example', appName: 'New App', type: 'update' }],
+ mind: { ...initial.mind, thinkingSince: new Date(Date.now() - 50_000).toISOString() },
+ });
+ act(() => handlers.get('system:activity')());
+
+ expect(await screen.findByRole('link', { name: /New App · update/ })).toBeInTheDocument();
+ expect(screen.queryByRole('link', { name: /Old App · update/ })).not.toBeInTheDocument();
+ await waitFor(() => {
+ expect(screen.getByRole('link', { name: /Persistent Mind is thinking/ }).textContent).not.toBe(originalMindText);
+ });
});
});
diff --git a/client/src/hooks/useSystemActivity.js b/client/src/hooks/useSystemActivity.js
index 3e9a8fd897..1bb25cc2df 100644
--- a/client/src/hooks/useSystemActivity.js
+++ b/client/src/hooks/useSystemActivity.js
@@ -1,6 +1,7 @@
import { useCallback, useSyncExternalStore } from 'react';
import * as api from '../services/api';
import socket from '../services/socket';
+import { sameJsonShape } from '../lib/sameJsonShape';
import { subscribeVisibility } from './useVisibilityEvent.js';
/**
@@ -20,39 +21,7 @@ import { subscribeVisibility } from './useVisibilityEvent.js';
export const SYSTEM_ACTIVITY_COALESCE_MS = 50;
-export const sameProcessingSnapshot = (a, b) => {
- if (!a || !b) return a === b;
- return a.agents?.active === b.agents?.active
- && a.agents?.queued === b.agents?.queued
- && a.agents?.trusted === b.agents?.trusted
- && a.gpu?.status === b.gpu?.status
- && a.gpu?.laneBusy === b.gpu?.laneBusy
- && a.gpu?.gpus?.[0]?.utilizationPercent === b.gpu?.gpus?.[0]?.utilizationPercent
- && a.mind?.thinking === b.mind?.thinking
- && a.mind?.queued === b.mind?.queued
- && a.mind?.status === b.mind?.status
- && a.mind?.trusted === b.mind?.trusted
- && a.llm?.active === b.llm?.active
- && a.llm?.trusted === b.llm?.trusted
- && JSON.stringify(a.llm?.runs) === JSON.stringify(b.llm?.runs)
- && JSON.stringify(a.ollama) === JSON.stringify(b.ollama)
- && a.backup?.inProgress === b.backup?.inProgress
- && a.update?.inProgress === b.update?.inProgress
- && a.activity?.idle === b.activity?.idle
- && a.activity?.activeCount === b.activity?.activeCount
- && a.activity?.queuedCount === b.activity?.queuedCount
- && (a.appOperations || []).length === (b.appOperations || []).length
- && JSON.stringify(a.renders || []) === JSON.stringify(b.renders || [])
- && a.jobs?.length === b.jobs?.length
- && (a.extras?.imageTo3d || []).length === (b.extras?.imageTo3d || []).length
- && (a.jobs || []).every((job, index) => job?.id === b.jobs[index]?.id
- && job?.status === b.jobs[index]?.status
- && job?.progress === b.jobs[index]?.progress
- && job?.position === b.jobs[index]?.position
- && job?.statusMsg === b.jobs[index]?.statusMsg)
- && (a.extras?.imageTo3d || []).every((item, index) => item?.id === b.extras?.imageTo3d?.[index]?.id
- && item?.name === b.extras?.imageTo3d?.[index]?.name);
-};
+export const sameProcessingSnapshot = sameJsonShape;
const EMPTY = { snapshot: null, status: 'unknown', error: null };
@@ -84,8 +53,13 @@ function read() {
publish({ snapshot: state.snapshot, status: 'error', error: new Error('Invalid system activity') });
return;
}
- const nextSnapshot = state.snapshot && sameProcessingSnapshot(state.snapshot, snapshot) ? state.snapshot : snapshot;
- publish({ snapshot: nextSnapshot, status: 'ready', error: null });
+ if (state.snapshot && sameProcessingSnapshot(state.snapshot, snapshot)) {
+ if (state.status !== 'ready' || state.error !== null) {
+ publish({ snapshot: state.snapshot, status: 'ready', error: null });
+ }
+ return;
+ }
+ publish({ snapshot, status: 'ready', error: null });
}).catch((error) => {
if (started !== generation) return;
const err = error instanceof Error ? error : new Error(String(error ?? 'System activity read failed'));
diff --git a/client/src/hooks/useSystemActivity.test.jsx b/client/src/hooks/useSystemActivity.test.jsx
index 81a051339e..1a87a2c1f2 100644
--- a/client/src/hooks/useSystemActivity.test.jsx
+++ b/client/src/hooks/useSystemActivity.test.jsx
@@ -63,6 +63,33 @@ describe('useSystemActivity', () => {
expect(result.current.snapshot.activity.idle).toBe(false);
});
+ it('keeps the published state for an identical payload and publishes new top-level slices', async () => {
+ vi.useFakeTimers();
+ let renders = 0;
+ const { result } = renderHook(() => {
+ renders += 1;
+ return useSystemActivity();
+ });
+ await act(async () => { await Promise.resolve(); });
+ const readyState = result.current;
+ const readyRenderCount = renders;
+
+ await act(async () => {
+ fire('system:activity');
+ await vi.advanceTimersByTimeAsync(SYSTEM_ACTIVITY_COALESCE_MS);
+ });
+ expect(result.current).toBe(readyState);
+ expect(renders).toBe(readyRenderCount);
+
+ getSystemActivity.mockResolvedValue({ ...idle, backup: { inProgress: true } });
+ await act(async () => {
+ fire('system:activity');
+ await vi.advanceTimersByTimeAsync(SYSTEM_ACTIVITY_COALESCE_MS);
+ });
+ expect(result.current.snapshot.backup).toEqual({ inProgress: true });
+ expect(result.current).not.toBe(readyState);
+ });
+
it('reconciles a missed frame when the socket reconnects', async () => {
const { result } = renderHook(() => useSystemActivity());
await act(async () => { await Promise.resolve(); });