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
refactor: compare CoS widget snapshots structurally, not by a field list
[._.]/ Adam Eivy2a0405954215
diff --git a/client/src/components/CosDashboardWidget.jsx b/client/src/components/CosDashboardWidget.jsxindex e2c52e0ab1..f5dd38cc79 100644--- a/client/src/components/CosDashboardWidget.jsx+++ b/client/src/components/CosDashboardWidget.jsx@@ -15,8 +15,31 @@ import {import * as api from '../services/api';import { useSocketResource } from '../hooks/useSocketResource';import { useTimeTick } from '../hooks/useTimeTick';+import { sameJsonShape } from '../lib/sameJsonShape';import { timeAgo, formatWeekdayDate, formatCount } from '../utils/formatters';+/**+ * The snapshot minus its volatile, unrendered fields. `status.lastEvaluation`+ * is stamped on every daemon evaluation; `task.completedRelative` is the+ * server's relative-time label, which the widget replaces with a client-side+ * `timeAgo(task.completedAt)` refreshed by its own minute tick.+ */+const comparableSnapshot = (snapshot) => {+ if (!snapshot) return snapshot;+ const { summary, recentTasks } = snapshot;+ return {+ ...snapshot,+ summary: summary && {+ ...summary,+ status: summary.status && { ...summary.status, lastEvaluation: undefined },+ },+ recentTasks: recentTasks && {+ ...recentTasks,+ tasks: recentTasks.tasks?.map(({ completedRelative: _volatile, ...task }) => task),+ },+ };+};+const RESOURCE_EVENTS = ['cos:day:changed', 'cos:tasks:changed', 'cos:tasks:user:changed', 'cos:tasks:cos:changed', 'cos:agent:spawned', 'cos:agent:updated', 'cos:agent:completed', 'cos:agents:changed', 'cos:status', 'cos:status:paused', 'cos:status:resumed', 'cos:learning:changed'];/**@@ -40,92 +63,14 @@ const CosDashboardWidget = memo(function CosDashboardWidget() {return { summary, learningSummary, recentTasks, activityCalendar };}, {namespace: 'cos', events: RESOURCE_EVENTS,- // Re-render only when one of the aggregated counts actually moves —- // running agents, completed/failed counts, queue depth, learning- // success rate, every visible recent-task field, every per-day heatmap- // cell, and the heatmap summary. Without this- // guard each invalidation re-renders the activity heatmap + recent tasks list- // even when nothing changed.- //- // Recent-tasks comparison walks every rendered field per row (id,- // description, taskType, app, durationFormatted, success). The relative-- // time label is rendered client-side from `task.completedAt` via timeAgo- // and refreshed by the useTimeTick(60000) below, so the server's- // `task.completedRelative` string is intentionally ignored — it ships in- // the payload but would freeze across unchanged snapshots if we used it.- //- // Heatmap comparison walks every cell's (date, tasks, isToday) tuple plus- // summary totals — the per-day distribution can shift without changing- // top-level totals (e.g. a run moving from one day to another in- // late-arriving telemetry).- compare: (prev, next) => {- if (!prev) return false;- const prevTasks = prev.recentTasks?.tasks;- const nextTasks = next.recentTasks?.tasks;- const prevLen = prevTasks?.length ?? 0;- const nextLen = nextTasks?.length ?? 0;- if (prevLen !== nextLen) return false;- for (let i = 0; i < prevLen; i++) {- const a = prevTasks[i];- const b = nextTasks[i];- if (- a?.id !== b?.id- || a?.success !== b?.success- || a?.description !== b?.description- || a?.taskType !== b?.taskType- || a?.app !== b?.app- || a?.durationFormatted !== b?.durationFormatted- // completedAt is the input to timeAgo(...) below — if the server- // corrects a task's completion time without changing other fields- // (rare but possible) we want the relative-time label to refresh- // immediately, not on the next minute tick.- || a?.completedAt !== b?.completedAt- ) return false;- }- // Heatmap weeks: array of arrays of {date, tasks, isToday, isFuture}.- // Compare every cell — a single boundary-cross (isToday rolls from one- // date to the next) flips the comparator naturally because (date,- // isToday) on the prior+next today differ.- const prevWeeks = prev.activityCalendar?.weeks;- const nextWeeks = next.activityCalendar?.weeks;- const prevWeeksLen = prevWeeks?.length ?? 0;- const nextWeeksLen = nextWeeks?.length ?? 0;- if (prevWeeksLen !== nextWeeksLen) return false;- for (let w = 0; w < prevWeeksLen; w++) {- const pw = prevWeeks[w];- const nw = nextWeeks[w];- if ((pw?.length ?? 0) !== (nw?.length ?? 0)) return false;- for (let d = 0; d < pw.length; d++) {- const pd = pw[d];- const nd = nw[d];- if (- pd?.date !== nd?.date- || pd?.tasks !== nd?.tasks- || pd?.isToday !== nd?.isToday- ) return false;- }- }- return (- prev.summary?.status?.running === next.summary?.status?.running- && prev.summary?.status?.paused === next.summary?.status?.paused- && prev.summary?.today?.succeeded === next.summary?.today?.succeeded- && prev.summary?.today?.failed === next.summary?.today?.failed- && prev.summary?.today?.running === next.summary?.today?.running- && prev.summary?.today?.completed === next.summary?.today?.completed- && prev.summary?.today?.timeWorked === next.summary?.today?.timeWorked- && prev.summary?.queue?.total === next.summary?.queue?.total- && prev.summary?.queue?.pendingApprovals === next.summary?.queue?.pendingApprovals- && prev.learningSummary?.overallSuccessRate === next.learningSummary?.overallSuccessRate- && prev.learningSummary?.skipped === next.learningSummary?.skipped- && prev.learningSummary?.status === next.learningSummary?.status- && prev.learningSummary?.totalCompleted === next.learningSummary?.totalCompleted- && prev.recentTasks?.summary?.total === next.recentTasks?.summary?.total- && prev.recentTasks?.summary?.succeeded === next.recentTasks?.summary?.succeeded- && prev.activityCalendar?.summary?.totalTasks === next.activityCalendar?.summary?.totalTasks- && prev.activityCalendar?.summary?.activeDays === next.activityCalendar?.summary?.activeDays- && prev.activityCalendar?.maxTasks === next.activityCalendar?.maxTasks- );- },+ // Re-render only when the snapshot actually changed. Structural equality+ // (as #11664 did for useSystemActivity) rather than a hand-written field+ // list: a rendered field the list forgot was silently frozen across+ // invalidations (#12036). The fields the server recomputes on every read+ // but this widget never renders are dropped first, so a tick of the+ // daemon's evaluation clock or a server-side relative-time label does not+ // re-render the heatmap and task list by itself.+ compare: (prev, next) => prev != null && sameJsonShape(comparableSnapshot(prev), comparableSnapshot(next)),});const { summary, learningSummary, recentTasks, activityCalendar } = dashData ?? {};diff --git a/client/src/components/CosDashboardWidget.test.jsx b/client/src/components/CosDashboardWidget.test.jsxindex 797dfdda0b..b6c1237c44 100644--- a/client/src/components/CosDashboardWidget.test.jsx+++ b/client/src/components/CosDashboardWidget.test.jsx@@ -44,6 +44,37 @@ beforeEach(() => {mockUseSocketResource.mockReturnValue({ data: snapshot, loading: false, error: null });});+describe('CosDashboardWidget snapshot comparator', () => {+ const captureCompare = () => {+ renderWidget();+ const options = mockUseSocketResource.mock.calls.at(-1)[1];+ expect(options.compare).toBeTypeOf('function');+ return options.compare;+ };+ const withPatch = (patch) => patch(structuredClone(snapshot));++ it('treats an identical snapshot as unchanged and a null previous as changed', () => {+ const compare = captureCompare();+ expect(compare(snapshot, structuredClone(snapshot))).toBe(true);+ expect(compare(null, snapshot)).toBe(false);+ });++ it('re-renders for any rendered field, including ones no field list ever named', () => {+ const compare = captureCompare();+ // avgTasksPerActiveDay is rendered in the heatmap summary row but was+ // absent from the hand-written comparator this replaced.+ expect(compare(snapshot, withPatch((s) => { s.activityCalendar.summary.avgTasksPerActiveDay = 3.5; return s; }))).toBe(false);+ expect(compare(snapshot, withPatch((s) => { s.recentTasks.tasks[0].description = 'Renamed'; return s; }))).toBe(false);+ expect(compare(snapshot, withPatch((s) => { s.summary.today.succeeded = 5; return s; }))).toBe(false);+ });++ it('ignores the volatile fields the widget never renders', () => {+ const compare = captureCompare();+ expect(compare(snapshot, withPatch((s) => { s.summary.status.lastEvaluation = '2026-07-13T10:05:00.000Z'; return s; }))).toBe(true);+ expect(compare(snapshot, withPatch((s) => { s.recentTasks.tasks[1].completedRelative = '21m ago'; return s; }))).toBe(true);+ });+});+describe('CosDashboardWidget recent-task outcomes', () => {it('names each outcome in text and exposes the expander state', () => {renderWidget();