Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep REST recovery out of socket delta baselines

pulse-triage[bot]795a16fb85bd
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index b4dc13e48a..e89a6dff48 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -6779,13 +6779,16 @@ as `activeAlertsDelta`, with one boundary held fixed: the client applies
alert deltas immediately on arrival — alert lifecycle truth never waits for
the operator-input idle gate that defers resource work. An entry that cannot
key by id drops the whole field back to plain whole-payload diffing, and a
-client without a baseline ignores the delta and heals on the next full
-payload, so the keyed path can never corrupt either array. Per-resource
-static metadata dedupes through state-level catalogs: `capabilityCatalog`,
-`policyCatalog`, and `aiSafeSummaryCatalog` hold the distinct blobs,
-resources carry `capabilitiesRef`/`policyRef`/`aiSafeSummaryRef`, and
-ingestion expands refs back to the inline shape so consumers never see the
-dedupe. Inline values remain valid from producers that carry no catalogs.
+client without a socket-owned baseline ignores the delta and requests the
+same throttled full-state recovery used by resources. REST recovery may
+refresh the displayed projection but never becomes a socket delta baseline,
+so the keyed path cannot patch independently constructed state or corrupt
+either array. Per-resource static metadata dedupes through state-level
+catalogs: `capabilityCatalog`, `policyCatalog`, and `aiSafeSummaryCatalog`
+hold the distinct blobs, resources carry
+`capabilitiesRef`/`policyRef`/`aiSafeSummaryRef`, and ingestion expands refs
+back to the inline shape so consumers never see the dedupe. Inline values
+remain valid from producers that carry no catalogs.
That same install-command payload continuity now also applies when auth is
optional: copied install and upgrade commands must omit token arguments
entirely on token-optional Pulse instances rather than serializing a fake
diff --git a/frontend-modern/src/stores/__tests__/websocket-unified.test.ts b/frontend-modern/src/stores/__tests__/websocket-unified.test.ts
index e3efcaec0f..a357b87ee6 100644
--- a/frontend-modern/src/stores/__tests__/websocket-unified.test.ts
+++ b/frontend-modern/src/stores/__tests__/websocket-unified.test.ts
@@ -1139,7 +1139,7 @@ describe('websocket store unified resource contract', () => {
}
});
- it('ignores infrastructure deltas that arrive without a projection baseline', async () => {
+ it('requests recovery for infrastructure deltas without a projection baseline', async () => {
const { store, dispose } = await createStoreHarness();
try {
await waitForOpenTick();
@@ -1152,6 +1152,7 @@ describe('websocket store unified resource contract', () => {
},
});
expect(store.state.connectedInfrastructure).toEqual([]);
+ expect(sentMessageTypes()).toContain('requestData');
} finally {
dispose();
}
@@ -1253,7 +1254,7 @@ describe('websocket store unified resource contract', () => {
}
});
- it('ignores alert deltas that arrive without an alert baseline', async () => {
+ it('requests recovery for alert deltas without an alert baseline', async () => {
const { store, dispose } = await createStoreHarness();
try {
await waitForOpenTick();
@@ -1265,6 +1266,7 @@ describe('websocket store unified resource contract', () => {
},
});
expect(store.state.activeAlerts).toEqual([]);
+ expect(sentMessageTypes()).toContain('requestData');
} finally {
dispose();
}
@@ -1383,6 +1385,12 @@ describe('websocket store unified resource contract', () => {
apiFetchJSONMock.mockResolvedValue({
lastUpdate: 500,
resources: [{ id: 'agent-host-1', type: 'agent', name: 'host-1', lastSeen: 100 }],
+ connectedInfrastructure: [
+ { id: 'infra-1', name: 'host-1', status: 'online', lastSeen: 100 },
+ ],
+ activeAlerts: [
+ { id: 'alert-1', type: 'cpu', level: 'warning', resourceId: 'agent-host-1', value: 85 },
+ ],
});
const { store, dispose } = await createStoreHarness();
@@ -1392,9 +1400,12 @@ describe('websocket store unified resource contract', () => {
emitRawMessage(frameOfExactly(MAX_INBOUND_WEBSOCKET_MESSAGE_BYTES + 1));
await flushMicrotasks();
expect(store.state.resources).toHaveLength(1);
+ expect(store.state.connectedInfrastructure[0]?.lastSeen).toBe(100);
+ expect(store.state.activeAlerts[0]?.level).toBe('warning');
// The server's withheld snapshot and this later REST response are not
- // guaranteed to be identical, so the delta must not patch the REST copy.
+ // guaranteed to be identical, so none of the socket deltas may patch
+ // their corresponding REST copies.
emitMessage({
type: 'rawData',
data: {
@@ -1402,6 +1413,12 @@ describe('websocket store unified resource contract', () => {
resourceDelta: {
upserts: [{ id: 'agent-host-1', lastSeen: 200 }],
},
+ connectedInfrastructureDelta: {
+ upserts: [{ id: 'infra-1', lastSeen: 200 }],
+ },
+ activeAlertsDelta: {
+ upserts: [{ id: 'alert-1', level: 'critical', value: 99 }],
+ },
},
});
await flushMicrotasks();
@@ -1409,6 +1426,9 @@ describe('websocket store unified resource contract', () => {
expect(store.state.resources).toHaveLength(1);
expect(store.state.resources[0]?.lastSeen).toBe(100);
expect(store.state.resources[0]?.name).toBe('host-1');
+ expect(store.state.connectedInfrastructure[0]?.lastSeen).toBe(100);
+ expect(store.state.activeAlerts[0]?.level).toBe('warning');
+ expect(store.state.activeAlerts[0]?.value).toBe(85);
expect(sentMessageTypes()).not.toContain('requestData');
} finally {
dispose();
diff --git a/frontend-modern/src/stores/websocket.ts b/frontend-modern/src/stores/websocket.ts
index 979661dcdf..4aa962b1b2 100644
--- a/frontend-modern/src/stores/websocket.ts
+++ b/frontend-modern/src/stores/websocket.ts
@@ -1021,19 +1021,30 @@ export function createWebSocketStore(url: string) {
const connectedInfrastructure = Array.isArray(message.data.connectedInfrastructure)
? (message.data.connectedInfrastructure as ConnectedInfrastructureItem[])
: [];
- // A full payload re-establishes the projection baseline the way
- // a full resource snapshot re-establishes rawServerResources.
- rawConnectedInfrastructure = structuredClone(connectedInfrastructure);
pendingInfrastructureIds.clear();
- pendingInfrastructureFull = true;
- if (
- typeof document !== 'undefined' &&
- document.visibilityState !== 'hidden' &&
- isOperatorInputActive()
- ) {
- scheduleDeferredResourceFlush();
+ if (source === 'websocket') {
+ // Only a socket payload shares the server's per-client delta
+ // lineage. A REST recovery is an independently built display
+ // snapshot and must never become the baseline for later socket
+ // patches.
+ rawConnectedInfrastructure = structuredClone(connectedInfrastructure);
+ pendingInfrastructureFull = true;
+ if (
+ typeof document !== 'undefined' &&
+ document.visibilityState !== 'hidden' &&
+ isOperatorInputActive()
+ ) {
+ scheduleDeferredResourceFlush();
+ } else {
+ syncInfrastructureStore();
+ }
} else {
- syncInfrastructureStore();
+ rawConnectedInfrastructure = null;
+ pendingInfrastructureFull = false;
+ setState(
+ 'connectedInfrastructure',
+ reconcile(structuredClone(connectedInfrastructure), { key: 'id' }),
+ );
}
} else if (
'connectedInfrastructureDelta' in message.data &&
@@ -1057,9 +1068,9 @@ export function createWebSocketStore(url: string) {
} else {
syncInfrastructureStore();
}
+ } else {
+ requestFullStateRecovery(connectionId);
}
- // No baseline: leave the current projection; the next full
- // payload (reconnect or snapshot) re-establishes it.
}
if (message.data.metrics !== undefined) setState('metrics', message.data.metrics);
if (message.data.performance !== undefined)
@@ -1193,8 +1204,9 @@ export function createWebSocketStore(url: string) {
message.data.activeAlerts && Array.isArray(message.data.activeAlerts)
? (message.data.activeAlerts as Alert[])
: [];
- // A full payload re-establishes the keyed alert baseline.
- rawActiveAlerts = structuredClone(alertsArray);
+ // Only the socket can establish the server-owned keyed baseline.
+ // REST recovery still refreshes the displayed alerts below.
+ rawActiveAlerts = source === 'websocket' ? structuredClone(alertsArray) : null;
const newAlerts: Record<string, Alert> = {};
alertsArray.forEach((alert: Alert) => {
newAlerts[alert.id] = alert;
@@ -1221,9 +1233,9 @@ export function createWebSocketStore(url: string) {
}
lastActiveAlertsPayload = newAlerts;
applyActiveAlerts(alertsEnabled ? newAlerts : {});
+ } else {
+ requestFullStateRecovery(connectionId);
}
- // No baseline: leave current alerts; the next full payload
- // (reconnect or snapshot) re-establishes it.
}
// Sync recently resolved alerts
if (message.data.recentlyResolved !== undefined) {
@@ -1278,6 +1290,13 @@ export function createWebSocketStore(url: string) {
// client's delta baseline. Invalidate any prior baseline before REST
// hydration and remain delta-free until a full socket snapshot lands.
rawServerResources = null;
+ deferredResourceIds.clear();
+ deferredResourceKeys.clear();
+ deferredResourceDeltaQueue.length = 0;
+ rawConnectedInfrastructure = null;
+ pendingInfrastructureIds.clear();
+ pendingInfrastructureFull = false;
+ rawActiveAlerts = null;
oversizedSnapshotObserved = true;
logger.warn('Server withheld an oversized state payload. Recovering over REST', {
supersedes: message.data.supersedes,
@@ -1465,7 +1484,7 @@ export function createWebSocketStore(url: string) {
if (now - lastFullStateRecoveryAt < 30000) return;
lastFullStateRecoveryAt = now;
- logger.warn('Received resource delta without a full snapshot baseline. Requesting full state');
+ logger.warn('Received keyed delta without a socket snapshot baseline. Requesting full state');
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'requestData' }));
}
@@ -1528,6 +1547,16 @@ export function createWebSocketStore(url: string) {
// 32 MiB guard trips around 12000 resources). Recover over REST rather
// than waiting for a baseline-less delta to notice, otherwise the first
// paint on a large estate is an empty UI.
+ // The frame may supersede any of the keyed projections. Once it is
+ // dropped, none of their socket lineages are safe to patch further.
+ rawServerResources = null;
+ deferredResourceIds.clear();
+ deferredResourceKeys.clear();
+ deferredResourceDeltaQueue.length = 0;
+ rawConnectedInfrastructure = null;
+ pendingInfrastructureIds.clear();
+ pendingInfrastructureFull = false;
+ rawActiveAlerts = null;
oversizedSnapshotObserved = true;
lastServerActivityAt = Date.now();
requestFullStateRecovery(connectionId);