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 Workloads memory selection on current observations

pulse-triage[bot]19a0ff9b96cc
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index bc7fd8b5aa..6e21bcf283 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -37,6 +37,30 @@ touch through the existing drawer, checks long-name bounds, and rejects the curr
parent with the same static fixture. No dev compiler or old terminated preview
is replayed. Native recovery remains separate.
+### Workloads memory selection follows its displayed observation
+
+Memory sorting and numeric search use the same selected observation policy as
+Workloads row and drawer labels. Proxmox memory needs an explicit current state
+and usable original observation time. Last-known, unavailable, missing, future
+or unrecognised evidence cannot participate as current capacity; a reported
+current zero still can. Resource Last seen and QEMU disk-read deferrals cannot
+renew or withdraw independently observed memory. Valid unannotated unrelated
+platform readings retain their numeric behaviour.
+
+In either sort direction non-current or missing values follow all current
+readings, with the existing name/identity tiebreak. Host-capacity sorting first
+qualifies guest memory, then requires a finite non-negative comparison and a
+usable host total/used value; missing host capacity is not zero. Numeric search
+continues to compare guest usage percent, independently of the host display
+basis. Name search and OR conditions retain access to the whole inventory;
+same-identity source replacement updates selection without new collection.
+
+`workloadSelectors.test.ts`, its branch companion, `searchQuery.test.ts` and
+its branch companions, and `memoryObservation.test.ts` cover current/retained/
+unknown/invalid states, zero, original-time validity, host-share comparison,
+independent disk state and refresh membership. These are presentation/selection
+invariants, not native guest recovery, alert changes or release availability.
+
**Memory freshness is preserved at the Workloads row boundary.**
`GuestRow.tsx` qualifies selected memory once per reactive reading using the
diff --git a/frontend-modern/browser-verification/c51a25340c78bab2.json b/frontend-modern/browser-verification/c51a25340c78bab2.json
new file mode 100644
index 0000000000..2d1174fed4
--- /dev/null
+++ b/frontend-modern/browser-verification/c51a25340c78bab2.json
@@ -0,0 +1,57 @@
+{
+ "version": 1,
+ "result": "passed",
+ "base_sha": "a6c9dc363e61e8e4f28d56250a0d6ba65d4233e5",
+ "changed_paths": [
+ "frontend-modern/src/components/Workloads/useWorkloadsState.ts",
+ "frontend-modern/src/components/Workloads/workloadSelectors.ts",
+ "frontend-modern/src/utils/memoryObservation.ts",
+ "frontend-modern/src/utils/searchQuery.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/Workloads/useWorkloadsState.ts": "942fa16b2a0b4d441a30792ab4cbffd1ba7af330c1b13ca53bda49b1279cd30e",
+ "frontend-modern/src/components/Workloads/workloadSelectors.ts": "d3bb79cc24977f1697ed4c7671c7034108007a6701ebe747395bc3375bbdb5ad",
+ "frontend-modern/src/utils/memoryObservation.ts": "dd3893b35623a3fa098b252a29c6c8201bd8834788e924b54e5f7f571addd79d",
+ "frontend-modern/src/utils/searchQuery.ts": "56f908833ff3a13fddd4270221f8ce881056082937c56b73143983a034260b2c"
+ },
+ "routes": [
+ "/proxmox?tab=workloads (synthetic canonical snapshot through production useWorkloads/useWorkloadsState/WorkloadsSurface/SearchInput/GuestRow at /tmp/memory-selection/index.html)"
+ ],
+ "states": [
+ "Current QEMU, Proxmox and linked-agent memory; measured zero; last-known, unavailable, missing and unannotated legacy memory",
+ "Guest/host display bases; absent host capacity; independent QEMU disk deferral; original observation unchanged by Last seen; same-identity fresh replacement"
+ ],
+ "interactions": [
+ "Production memory header sort ascending/descending using pointer and touch; only current readings precede retained/missing values",
+ "Numeric high/zero filters, name and OR inventory access, focused Escape reset",
+ "Host-capacity sorting through the real page-owned callback: missing capacity is last; numeric search still uses guest percent",
+ "Original observation and stable identity preserved on refresh; a fresh observation restores numeric membership and keeps input focus"
+ ],
+ "viewports": [
+ {
+ "width": 1365,
+ "height": 900
+ },
+ {
+ "width": 390,
+ "height": 844
+ }
+ ],
+ "verified_at": "2026-10-09T15:55:20.856475+00:00",
+ "browsers": [
+ {
+ "engine": "desktop",
+ "version": "141.0.7390.37"
+ },
+ {
+ "engine": "phone",
+ "version": "26.0"
+ }
+ ],
+ "playwright_version": "1.56.1",
+ "evidence": {
+ "result": "Retained lane outcome: evidence/browser-result.json",
+ "screenshots": "Eight inspected desktop/phone captures in evidence/BROWSER.tar.xz",
+ "limits": "Synthetic canonical snapshot, production useWorkloads mapper, useWorkloadsState host-capacity comparator, WorkloadsSurface/GuestRow/header/SearchInput and CSS. Memory-basis control and snapshot replacements are fixture inputs. No authenticated App, live guest, thaw, native collector, installed/released or physical-device acceptance."
+ }
+}
diff --git a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov.test.ts b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov.test.ts
index dcbca3ac35..da262db713 100644
--- a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov.test.ts
@@ -37,17 +37,37 @@ const makeGuest = (i: number, overrides?: Partial<WorkloadGuest>): WorkloadGuest
describe('workloadSelectors (branch coverage)', () => {
describe('createWorkloadSortComparator', () => {
- it('sorts by memory usage in both directions and falls back to 0 for null memory', () => {
+ it('sorts current memory in both directions and keeps missing memory last', () => {
const guests = [
makeGuest(1, {
id: 'high',
name: 'high-mem',
- memory: { total: 100, used: 80, free: 20, usage: 0.8 },
+ memory: {
+ total: 100,
+ used: 80,
+ free: 20,
+ usage: 80,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(2, {
id: 'low',
name: 'low-mem',
- memory: { total: 100, used: 10, free: 90, usage: 0.1 },
+ memory: {
+ total: 100,
+ used: 10,
+ free: 90,
+ usage: 10,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(3, {
id: 'null',
@@ -62,24 +82,44 @@ describe('workloadSelectors (branch coverage)', () => {
expect(memAsc).not.toBeNull();
expect(memDesc).not.toBeNull();
- // null-mem (0) < low-mem (0.1) < high-mem (0.8)
- expect([...guests].sort(memAsc!).map((g) => g.id)).toEqual(['null', 'low', 'high']);
+ // Missing is not a measured zero, in either direction.
+ expect([...guests].sort(memAsc!).map((g) => g.id)).toEqual(['low', 'high', 'null']);
expect([...guests].sort(memDesc!).map((g) => g.id)).toEqual(['high', 'low', 'null']);
});
- it('treats memory.usage of 0 as 0 via the || fallback', () => {
+ it('preserves a current measured zero', () => {
const guests = [
makeGuest(1, {
id: 'a',
name: 'alpha',
cpu: 0.5,
- memory: { total: 100, used: 0, free: 100, usage: 0 },
+ memory: {
+ total: 100,
+ used: 0,
+ free: 100,
+ usage: 0,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(2, {
id: 'b',
name: 'beta',
cpu: 0.5,
- memory: { total: 100, used: 50, free: 50, usage: 0.5 },
+ memory: {
+ total: 100,
+ used: 50,
+ free: 50,
+ usage: 0.5,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
];
@@ -92,12 +132,32 @@ describe('workloadSelectors (branch coverage)', () => {
makeGuest(1, {
id: 'large-allocation',
name: 'large-allocation',
- memory: { total: 100, used: 60, free: 40, usage: 60 },
+ memory: {
+ total: 100,
+ used: 60,
+ free: 40,
+ usage: 60,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(2, {
id: 'large-host-share',
name: 'large-host-share',
- memory: { total: 100, used: 20, free: 80, usage: 20 },
+ memory: {
+ total: 100,
+ used: 20,
+ free: 80,
+ usage: 20,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
];
const hostShare = new Map([
diff --git a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov0712b.test.ts b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov0712b.test.ts
index 8de5ae9e08..a7104cfdc9 100644
--- a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov0712b.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.branchcov0712b.test.ts
@@ -59,7 +59,7 @@ describe('workloadSelectors (branch coverage 2)', () => {
expect([...guests].sort(desc).map((g) => g.id)).toEqual(['high', 'low']);
});
- it('treats null memory as 0 via the `a.memory ? ... : 0` ternary false arm', () => {
+ it('keeps missing memory after current memory', () => {
const guests = [
makeGuest(1, {
id: 'null-mem',
@@ -69,34 +69,74 @@ describe('workloadSelectors (branch coverage 2)', () => {
makeGuest(2, {
id: 'big-mem',
name: 'big-mem',
- memory: { total: 100, used: 80, free: 20, usage: 0.8 },
+ memory: {
+ total: 100,
+ used: 80,
+ free: 20,
+ usage: 80,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
];
const asc = createWorkloadSortComparator('memory', 'asc')!;
- // null-mem -> 0 < 0.8
- expect([...guests].sort(asc).map((g) => g.id)).toEqual(['null-mem', 'big-mem']);
+ // Missing is not a measured zero.
+ expect([...guests].sort(asc).map((g) => g.id)).toEqual(['big-mem', 'null-mem']);
});
- it('coerces memory.usage of 0 to 0 via the `|| 0` fallback and tiebreaks equals', () => {
+ it('preserves current zero and the existing equal-value tiebreak', () => {
const guests = [
makeGuest(1, {
id: 'b',
name: 'beta',
- memory: { total: 100, used: 0, free: 100, usage: 0 },
+ memory: {
+ total: 100,
+ used: 0,
+ free: 100,
+ usage: 0,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(2, {
id: 'a',
name: 'alpha',
- memory: { total: 100, used: 0, free: 100, usage: 0 },
+ memory: {
+ total: 100,
+ used: 0,
+ free: 100,
+ usage: 0,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
makeGuest(3, {
id: 'c',
name: 'gamma',
- memory: { total: 100, used: 50, free: 50, usage: 0.5 },
+ memory: {
+ total: 100,
+ used: 50,
+ free: 50,
+ usage: 50,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
}),
];
const asc = createWorkloadSortComparator('memory', 'asc')!;
- // a,b both 0 -> equal numeric -> tiebreak (alpha<beta); c=0.5 last
+ // Measured zero retains the existing name tiebreak.
expect([...guests].sort(asc).map((g) => g.id)).toEqual(['a', 'b', 'c']);
});
diff --git a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
index 4c33dd824e..24453df670 100644
--- a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
import type { WorkloadGuest, WorkloadType } from '@/types/workloads';
import {
computeWorkloadIOEmphasis,
@@ -1141,3 +1141,125 @@ describe('current guest disk selection', () => {
expect(select([lxc], 'disk>90')).toEqual([lxc]);
});
});
+
+describe('memory selection preserves displayed observation provenance', () => {
+ const guest = (id: string, usage: number, state = 'current'): WorkloadGuest =>
+ makeGuest(1, {
+ id,
+ name: id,
+ type: 'qemu',
+ workloadType: 'vm',
+ memory: {
+ total: 100,
+ used: usage,
+ free: 100 - usage,
+ usage,
+ observation: { state, source: 'guest-agent-meminfo', observedAt: '2026-10-08T00:00:00Z' },
+ },
+ });
+ const inventory = () => {
+ const unknown = guest('unknown', 99);
+ unknown.memory.observation = undefined;
+ const missing = guest('missing', 0);
+ missing.memory = undefined as unknown as WorkloadGuest['memory'];
+ return [
+ guest('retained', 99, 'last-known'),
+ unknown,
+ guest('current-high', 90),
+ guest('unavailable', 0, 'unavailable'),
+ missing,
+ guest('current-zero', 0),
+ guest('current-low', 10),
+ ];
+ };
+
+ it.each(['asc', 'desc'] as const)(
+ 'keeps only current readings before retained and missing memory in %s order',
+ (direction) => {
+ const compare = createWorkloadSortComparator('memory', direction)!;
+ expect(
+ inventory()
+ .sort(compare)
+ .map((row) => row.id),
+ ).toEqual([
+ ...(direction === 'asc'
+ ? ['current-zero', 'current-low', 'current-high']
+ : ['current-high', 'current-low', 'current-zero']),
+ 'missing',
+ 'retained',
+ 'unavailable',
+ 'unknown',
+ ]);
+ },
+ );
+
+ it('qualifies host-share values before invoking the page-owned comparison', () => {
+ const memoryValue = vi.fn((row: WorkloadGuest) => (row.id === 'current-high' ? 5 : 50));
+ const compare = createWorkloadSortComparator('memory', 'desc', { memoryValue })!;
+ expect(
+ inventory()
+ .sort(compare)
+ .map((row) => row.id),
+ ).toEqual([
+ 'current-low',
+ 'current-zero',
+ 'current-high',
+ 'missing',
+ 'retained',
+ 'unavailable',
+ 'unknown',
+ ]);
+ expect(
+ memoryValue.mock.calls.every(([row]) => row.memory.observation?.state === 'current'),
+ ).toBe(true);
+ });
+
+ it.each([undefined, null, NaN, Infinity, -1])(
+ 'keeps a missing or invalid host-share value (%s) last in either direction',
+ (value) => {
+ const rows = [guest('zero', 0), guest('missing-host', 75), guest('high', 90)];
+ const memoryValue = (row: WorkloadGuest) =>
+ row.id === 'missing-host' ? value : row.memory.usage;
+ for (const direction of ['asc', 'desc'] as const) {
+ const compare = createWorkloadSortComparator('memory', direction, { memoryValue })!;
+ expect([...rows].sort(compare).map((row) => row.id)).toEqual([
+ ...(direction === 'asc' ? ['zero', 'high'] : ['high', 'zero']),
+ 'missing-host',
+ ]);
+ }
+ },
+ );
+
+ it('keeps current memory independent of QEMU disk-read deferral', () => {
+ const value = guest('current', 90);
+ value.diskStatusReason = 'prev-vm-locked';
+ value.lock = 'backup';
+ const compare = createWorkloadSortComparator('memory', 'desc')!;
+ expect([guest('low', 10), value].sort(compare).map((row) => row.id)).toEqual([
+ 'current',
+ 'low',
+ ]);
+ });
+
+ it('updates numeric membership on same-identity source replacement without losing inventory access', () => {
+ const rows = inventory();
+ const filter = (searchTerm: string) =>
+ filterWorkloads({
+ guests: rows,
+ viewMode: 'all',
+ statusMode: 'all',
+ searchTerm,
+ selectedNode: null,
+ selectedHostHint: null,
+ selectedKubernetesContext: null,
+ }).map((row) => row.id);
+ expect(filter('memory>85')).toEqual(['current-high']);
+ expect(filter('memory=0')).toEqual(['current-zero']);
+ expect(filter('name:retained')).toEqual(['retained']);
+ expect(filter('memory>85 OR name:retained')).toEqual(['retained', 'current-high']);
+ rows[0] = { ...rows[0], lastSeen: '2026-10-09T15:00:00Z' };
+ expect(filter('memory>85')).toEqual(['current-high']);
+ rows[0] = guest('retained', 99);
+ expect(filter('memory>85')).toEqual(['retained', 'current-high']);
+ });
+});
diff --git a/frontend-modern/src/components/Workloads/useWorkloadsState.ts b/frontend-modern/src/components/Workloads/useWorkloadsState.ts
index 4c8351cc27..06711d5d49 100644
--- a/frontend-modern/src/components/Workloads/useWorkloadsState.ts
+++ b/frontend-modern/src/components/Workloads/useWorkloadsState.ts
@@ -429,12 +429,18 @@ export function useWorkloadsState(props: WorkloadsSurfaceProps) {
createWorkloadSortComparator(sortKey() || '', sortDirection(), {
memoryValue: (guest) => {
if (workloadMemoryDisplayBasis() !== 'host') {
- return guest.memory?.usage ?? 0;
+ return guest.memory?.usage;
}
const hostTotal =
memoryParentNodeByGuestId()[getCanonicalWorkloadId(guest)]?.memory?.total ?? 0;
- const used = guest.memory?.used ?? 0;
- return hostTotal > 0 && Number.isFinite(used) ? (used / hostTotal) * 100 : 0;
+ const used = guest.memory?.used;
+ return Number.isFinite(hostTotal) &&
+ hostTotal > 0 &&
+ typeof used === 'number' &&
+ Number.isFinite(used) &&
+ used >= 0
+ ? (used / hostTotal) * 100
+ : null;
},
}),
);
diff --git a/frontend-modern/src/components/Workloads/workloadSelectors.ts b/frontend-modern/src/components/Workloads/workloadSelectors.ts
index 7fc47c3e3c..5e9f9c8a38 100644
--- a/frontend-modern/src/components/Workloads/workloadSelectors.ts
+++ b/frontend-modern/src/components/Workloads/workloadSelectors.ts
@@ -22,6 +22,7 @@ import {
} from '@/utils/workloads';
import { getWorkloadTypePresentation } from '@/utils/workloadTypePresentation';
import { getWorkloadGuestDiskRead } from '@/utils/workloadGuestPresentation';
+import { getCurrentWorkloadMemoryUsage } from '@/utils/memoryObservation';
import {
getKubernetesContextKey,
getWorkloadHostHintCandidates,
@@ -336,6 +337,12 @@ export const createWorkloadSortComparator = (
numeric: true,
sensitivity: 'base',
});
+ const memorySortValue = (guest: WorkloadGuest): number | null => {
+ const usage = getCurrentWorkloadMemoryUsage(guest);
+ if (usage === null) return null;
+ const value = options.memoryValue ? options.memoryValue(guest) : usage;
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
+ };
return (a: WorkloadGuest, b: WorkloadGuest): number => {
let aVal: SortValue = null;
@@ -348,8 +355,8 @@ export const createWorkloadSortComparator = (
aVal = getWorkloadCPUPercent(a.cpu) ?? 0;
bVal = getWorkloadCPUPercent(b.cpu) ?? 0;
} else if (sortKey === 'memory') {
- aVal = options.memoryValue ? (options.memoryValue(a) ?? 0) : a.memory?.usage || 0;
- bVal = options.memoryValue ? (options.memoryValue(b) ?? 0) : b.memory?.usage || 0;
+ aVal = memorySortValue(a);
+ bVal = memorySortValue(b);
} else if (sortKey === 'disk') {
aVal = getDiskUsagePercent(a);
bVal = getDiskUsagePercent(b);
diff --git a/frontend-modern/src/utils/__tests__/memoryObservation.test.ts b/frontend-modern/src/utils/__tests__/memoryObservation.test.ts
index 26dfd44258..32cf942165 100644
--- a/frontend-modern/src/utils/__tests__/memoryObservation.test.ts
+++ b/frontend-modern/src/utils/__tests__/memoryObservation.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it, vi, afterEach } from 'vitest';
import type { WorkloadGuest } from '@/types/workloads';
-import { getWorkloadMemoryObservationPresentation } from '../memoryObservation';
+import {
+ getCurrentWorkloadMemoryUsage,
+ getWorkloadMemoryObservationPresentation,
+} from '../memoryObservation';
const guest = (changes: Partial<WorkloadGuest> = {}): WorkloadGuest =>
({
@@ -90,3 +93,82 @@ describe('selected workload memory observation', () => {
},
);
});
+
+describe('current workload memory selection', () => {
+ const current = (changes: Partial<WorkloadGuest> = {}) =>
+ guest({
+ memory: {
+ ...guest().memory,
+ observation: { state: 'current', source: 'guest-agent-meminfo', observedAt },
+ },
+ ...changes,
+ });
+
+ it.each([
+ undefined,
+ { state: 'last-known', source: 'guest-agent-meminfo', observedAt },
+ { state: 'unavailable', source: 'agent', observedAt },
+ { state: 'future-state', source: 'agent', observedAt },
+ { state: 'current', source: 'agent' },
+ { state: 'current', source: 'agent', observedAt: 'invalid' },
+ { state: 'current', source: 'agent', observedAt: '1970-01-01T00:00:00Z' },
+ { state: 'current', source: 'agent', observedAt: '2099-01-01T00:00:00Z' },
+ ])('does not select unqualified memory evidence (%j)', (observation) => {
+ const input = current({ memory: { ...guest().memory, observation } });
+ expect(getCurrentWorkloadMemoryUsage(input)).toBeNull();
+ expect(getWorkloadMemoryObservationPresentation(input)?.state).not.toBe('current');
+ });
+
+ it.each([undefined, -1, 101, NaN, Infinity])('does not select invalid usage (%s)', (usage) => {
+ const input = current();
+ input.memory = { ...input.memory, usage } as WorkloadGuest['memory'];
+ expect(getCurrentWorkloadMemoryUsage(input)).toBeNull();
+ });
+
+ it('keeps zero current and does not format a label for numeric selection', () => {
+ const input = current();
+ input.memory = { ...input.memory, used: 0, free: 100, usage: 0 };
+ const iso = vi.spyOn(Date.prototype, 'toISOString');
+ expect(getCurrentWorkloadMemoryUsage(input)).toBe(0);
+ expect(iso).not.toHaveBeenCalled();
+ });
+
+ it.each(['guest-agent-meminfo', 'agent', 'status-mem'])(
+ 'selects current %s memory independently of a QEMU disk deferral',
+ (source) => {
+ const input = current({
+ diskStatusReason: 'prev-vm-locked',
+ lock: 'backup',
+ agentStale: true,
+ });
+ input.memory.observation!.source = source;
+ expect(getCurrentWorkloadMemoryUsage(input)).toBe(25);
+ },
+ );
+
+ it('cannot use current metadata to revive unavailable telemetry', () => {
+ const input = current();
+ input.memory.usageUnavailable = true;
+ expect(getCurrentWorkloadMemoryUsage(input)).toBeNull();
+ input.memory.usageUnavailable = false;
+ input.telemetryAvailability = {
+ cpu: true,
+ memory: false,
+ disk: true,
+ networkIO: true,
+ diskIO: true,
+ uptime: true,
+ };
+ expect(getCurrentWorkloadMemoryUsage(input)).toBeNull();
+ });
+
+ it.each([
+ { type: 'vm', platformScopes: ['vmware-vsphere'] },
+ { type: 'docker', vmid: 0, node: '', instance: '' },
+ ])('preserves valid unannotated unrelated workloads (%j)', (changes) => {
+ expect(getCurrentWorkloadMemoryUsage(guest(changes))).toBe(25);
+ const input = current(changes);
+ input.memory.observation!.state = 'last-known';
+ expect(getCurrentWorkloadMemoryUsage(input)).toBeNull();
+ });
+});
diff --git a/frontend-modern/src/utils/__tests__/searchQuery.branchcov.test.ts b/frontend-modern/src/utils/__tests__/searchQuery.branchcov.test.ts
index 54e2a34504..f372e02c7b 100644
--- a/frontend-modern/src/utils/__tests__/searchQuery.branchcov.test.ts
+++ b/frontend-modern/src/utils/__tests__/searchQuery.branchcov.test.ts
@@ -109,25 +109,37 @@ describe('evaluateMetricCondition — field switch branches (via evaluateFilterS
expect(evaluateFilterStack(guestWithout(['cpu']), single(metric('cpu', '<', 1)))).toBe(true);
});
- it('memory: falsy/missing memory yields 0', () => {
- // memory null -> guest.memory falsy -> 0; 0 > -1 true
+ it('memory: falsy/missing memory is not a measured zero', () => {
+ // Missing usage never satisfies a numeric comparison.
expect(
evaluateFilterStack(
makeGuest({ memory: null as unknown as VM['memory'] }),
single(metric('memory', '>', -1)),
),
- ).toBe(true);
- // memory key absent -> 0; 0 <= 0 true
+ ).toBe(false);
+ // An absent field cannot satisfy zero equality either.
expect(evaluateFilterStack(guestWithout(['memory']), single(metric('memory', '<=', 0)))).toBe(
- true,
+ false,
);
});
- it('memory: compares the raw usage value when present', () => {
+ it('memory: compares a current reported percentage', () => {
expect(
evaluateFilterStack(
- makeGuest({ memory: { usage: 900, total: 1000, used: 900, free: 100 } }),
- single(metric('memory', '>', 500)),
+ makeGuest({
+ memory: {
+ usage: 90,
+ total: 1000,
+ used: 900,
+ free: 100,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
+ }),
+ single(metric('memory', '>', 85)),
),
).toBe(true);
});
diff --git a/frontend-modern/src/utils/__tests__/searchQuery.branchcov0712b.test.ts b/frontend-modern/src/utils/__tests__/searchQuery.branchcov0712b.test.ts
index 0ca13d079f..8531a75f83 100644
--- a/frontend-modern/src/utils/__tests__/searchQuery.branchcov0712b.test.ts
+++ b/frontend-modern/src/utils/__tests__/searchQuery.branchcov0712b.test.ts
@@ -225,11 +225,23 @@ describe('evaluateMetricCondition — field-switch arms (via evaluateFilterStack
});
describe('memory field', () => {
- it('reads usage when present and compares with `<`', () => {
+ it('reads a current percentage and compares with `<`', () => {
expect(
evaluateFilterStack(
- makeGuest({ memory: { usage: 900, total: 1000, used: 900, free: 100 } }),
- single(metric('memory', '<', 1000)),
+ makeGuest({
+ memory: {
+ usage: 90,
+ total: 1000,
+ used: 900,
+ free: 100,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
+ }),
+ single(metric('memory', '<', 95)),
),
).toBe(true);
});
diff --git a/frontend-modern/src/utils/__tests__/searchQuery.test.ts b/frontend-modern/src/utils/__tests__/searchQuery.test.ts
index c226fe0e93..566b3c925b 100644
--- a/frontend-modern/src/utils/__tests__/searchQuery.test.ts
+++ b/frontend-modern/src/utils/__tests__/searchQuery.test.ts
@@ -244,11 +244,23 @@ describe('evaluateFilterStack', () => {
expect(result).toBe(false);
});
- it('evaluates memory usage threshold (absolute value)', () => {
- const vm = createVM({ memory: { usage: 1800, total: 2000, used: 1800, free: 200 } });
- const stack = parseFilterStack('memory<2000');
+ it('evaluates current memory percentage threshold', () => {
+ const vm = createVM({
+ memory: {
+ usage: 90,
+ total: 2000,
+ used: 1800,
+ free: 200,
+ observation: {
+ state: 'current',
+ source: 'status-mem',
+ observedAt: '2026-10-08T00:00:00Z',
+ },
+ },
+ });
+ const stack = parseFilterStack('memory<95');
const result = evaluateFilterStack(vm, stack);
- expect(result).toBe(true); // 1800 < 2000
+ expect(result).toBe(true); // 90% < 95%
});
it('evaluates disk usage threshold', () => {
@@ -503,3 +515,91 @@ describe('disk filter freshness and unknown values', () => {
expect(matches(retained, 'name:retained')).toBe(true);
});
});
+
+describe('memory filters use current percentages, not retained capacity or missing zero', () => {
+ const guest = (memory: WorkloadGuest['memory']): WorkloadGuest =>
+ ({
+ id: 'fixture-memory',
+ name: 'retained-memory',
+ vmid: 101,
+ node: 'pve1',
+ instance: 'fixture',
+ type: 'qemu',
+ memory,
+ }) as WorkloadGuest;
+ const current = (usage: number): WorkloadGuest['memory'] => ({
+ usage,
+ total: 100,
+ used: usage,
+ free: 100 - usage,
+ observation: { state: 'current', source: 'agent', observedAt: '2026-10-08T00:00:00Z' },
+ });
+ const matches = (row: WorkloadGuest, query: string) =>
+ evaluateFilterStack(row, parseFilterStack(query));
+
+ it.each(['>0', '>=0', '<100', '<=100', '=0', '==0'])(
+ 'does not match memory%s for non-current or missing readings',
+ (comparison) => {
+ const rows = [
+ guest(undefined as unknown as WorkloadGuest['memory']),
+ guest({ ...current(0), usageUnavailable: true }),
+ guest({ ...current(95), observation: undefined }),
+ guest({
+ ...current(95),
+ observation: { state: 'last-known', source: 'agent', observedAt: '2026-10-08T00:00:00Z' },
+ }),
+ guest({ ...current(0), observation: { state: 'unavailable', source: 'agent' } }),
+ guest({
+ ...current(95),
+ observation: { state: 'current', source: 'agent', observedAt: 'invalid' },
+ }),
+ guest({
+ ...current(95),
+ observation: { state: 'current', source: 'agent', observedAt: '2099-01-01T00:00:00Z' },
+ }),
+ ...[-1, NaN, Infinity, 101].map((usage) => guest(current(usage))),
+ ];
+ const telemetryMissing = guest(current(0));
+ telemetryMissing.telemetryAvailability = {
+ cpu: true,
+ memory: false,
+ disk: true,
+ networkIO: true,
+ diskIO: true,
+ uptime: true,
+ };
+ rows.push(telemetryMissing);
+ for (const row of rows) expect(matches(row, `memory${comparison}`)).toBe(false);
+ },
+ );
+
+ it('preserves valid zero and all percentage operators for a current reading', () => {
+ expect(matches(guest(current(0)), 'memory=0')).toBe(true);
+ const row = guest(current(90));
+ for (const query of [
+ 'memory>85',
+ 'memory>=90',
+ 'memory<95',
+ 'memory<=90',
+ 'memory=90',
+ 'memory==90',
+ ]) {
+ expect(matches(row, query)).toBe(true);
+ }
+ expect(matches(row, 'memory<90')).toBe(false);
+ expect(matches(row, 'memory>90')).toBe(false);
+ });
+
+ it('keeps text access and unrelated platform readings without inventing provenance', () => {
+ const row = guest({ ...current(95), observation: { state: 'last-known', source: 'agent' } });
+ expect(matches(row, 'memory>85 OR name:retained')).toBe(true);
+ expect(matches(row, 'memory>85 AND name:retained')).toBe(false);
+ const vmware = {
+ ...guest({ ...current(90), observation: undefined }),
+ platformScopes: ['vmware-vsphere'],
+ };
+ expect(matches(vmware, 'memory>85')).toBe(true);
+ const docker = { ...vmware, type: 'docker', vmid: 0, platformScopes: ['docker'] };
+ expect(matches(docker, 'memory>85')).toBe(true);
+ });
+});
diff --git a/frontend-modern/src/utils/memoryObservation.ts b/frontend-modern/src/utils/memoryObservation.ts
index f034e58838..47ee1a273a 100644
--- a/frontend-modern/src/utils/memoryObservation.ts
+++ b/frontend-modern/src/utils/memoryObservation.ts
@@ -19,6 +19,69 @@ export interface MemoryObservationPresentation {
message: string;
}
+const isMemoryPercent = (value: unknown): value is number =>
+ typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100;
+
+const memoryObservationTime = (observation: MemoryObservation | undefined): number | null => {
+ const timestamp =
+ typeof observation?.observedAt === 'string' ? Date.parse(observation.observedAt) : NaN;
+ return Number.isFinite(timestamp) && timestamp > 0 && timestamp <= Date.now() ? timestamp : null;
+};
+
+// Selection and labels classify the same source-owned observation. Numeric
+// selection does not need to allocate a source/date label for every comparison.
+const memoryObservationState = (
+ value: number | undefined,
+ observation: MemoryObservation | undefined,
+ timestamp: number | null,
+): MemoryObservationPresentation['state'] =>
+ !isMemoryPercent(value) || observation?.state === 'unavailable'
+ ? 'unavailable'
+ : observation?.state === 'last-known'
+ ? 'last-known'
+ : observation?.state === 'current' && timestamp !== null
+ ? 'current'
+ : 'unknown';
+
+const requiresWorkloadMemoryObservation = (guest: WorkloadGuest): boolean => {
+ const nonProxmoxVMware =
+ guest.platformScopes?.includes('vmware-vsphere') &&
+ !guest.platformScopes.includes('proxmox-pve');
+ return (
+ !nonProxmoxVMware &&
+ (guest.type === 'qemu' ||
+ guest.type === 'lxc' ||
+ guest.platformScopes?.includes('proxmox-pve') ||
+ (guest.vmid > 0 && Boolean(guest.node && guest.instance)))
+ );
+};
+
+// A retained or unknown reading remains visible in the inventory, but is not
+// current capacity. Last seen, disk deferral and a host-share callback cannot
+// supply missing memory provenance. Unannotated unrelated platforms keep their
+// numeric behaviour, including measured zero.
+export const getCurrentWorkloadMemoryUsage = (guest: WorkloadGuest): number | null => {
+ const memory = guest.memory;
+ if (
+ guest.telemetryAvailability?.memory === false ||
+ memory?.usageUnavailable ||
+ !isMemoryPercent(memory?.usage)
+ ) {
+ return null;
+ }
+ if (
+ (memory.observation || requiresWorkloadMemoryObservation(guest)) &&
+ memoryObservationState(
+ memory.usage,
+ memory.observation,
+ memoryObservationTime(memory.observation),
+ ) !== 'current'
+ ) {
+ return null;
+ }
+ return memory.usage;
+};
+
const memorySourceLabels: Record<string, string> = {
'guest-agent-meminfo': 'QEMU guest agent',
'guest-agent-meminfo-derived': 'QEMU guest agent',
@@ -43,27 +106,19 @@ export const getMemoryObservationPresentation = (
// Unannotated unrelated platforms retain their existing behaviour. Legacy
// Proxmox readings lack authority to assert current freshness.
if (!requiresObservation && !observation) return null;
- const timestamp =
- typeof observation?.observedAt === 'string' ? Date.parse(observation.observedAt) : NaN;
- const validTime = Number.isFinite(timestamp) && timestamp > 0 && timestamp <= Date.now();
- const state =
- typeof value !== 'number' ||
- !Number.isFinite(value) ||
- value < 0 ||
- value > 100 ||
- observation?.state === 'unavailable'
- ? 'unavailable'
- : observation?.state === 'last-known'
- ? 'last-known'
- : observation?.state === 'current' && validTime
- ? 'current'
- : 'unknown';
+ const timestamp = memoryObservationTime(observation);
+ const state = memoryObservationState(value, observation, timestamp);
// Most table rows are current and need no cue. Qualify them identically,
// but avoid building source/date strings that will never be rendered.
if (state === 'current' && options.includeCurrent === false) return null;
- const observed = validTime
- ? new Date(timestamp).toISOString().replace('T', ' ').replace('.000Z', 'Z').replace('Z', ' UTC')
- : null;
+ const observed =
+ timestamp !== null
+ ? new Date(timestamp)
+ .toISOString()
+ .replace('T', ' ')
+ .replace('.000Z', 'Z')
+ .replace('Z', ' UTC')
+ : null;
const label =
state === 'current'
? 'Current'
@@ -95,14 +150,10 @@ export const getWorkloadMemoryObservationPresentation = (
guest.telemetryAvailability?.memory !== false && !guest.memory?.usageUnavailable
? usage
: undefined;
- const nonProxmoxVMware =
- guest.platformScopes?.includes('vmware-vsphere') &&
- !guest.platformScopes.includes('proxmox-pve');
- const proxmoxGuest =
- !nonProxmoxVMware &&
- (guest.type === 'qemu' ||
- guest.type === 'lxc' ||
- guest.platformScopes?.includes('proxmox-pve') ||
- (guest.vmid > 0 && Boolean(guest.node && guest.instance)));
- return getMemoryObservationPresentation(value, guest.memory?.observation, proxmoxGuest, options);
+ return getMemoryObservationPresentation(
+ value,
+ guest.memory?.observation,
+ requiresWorkloadMemoryObservation(guest),
+ options,
+ );
};
diff --git a/frontend-modern/src/utils/searchQuery.ts b/frontend-modern/src/utils/searchQuery.ts
index df192bcff6..f2efb42438 100644
--- a/frontend-modern/src/utils/searchQuery.ts
+++ b/frontend-modern/src/utils/searchQuery.ts
@@ -1,6 +1,7 @@
import type { WorkloadGuest } from '@/types/workloads';
import { getWorkloadCPUPercent, resolveWorkloadType } from '@/utils/workloads';
import { getWorkloadGuestDiskRead } from '@/utils/workloadGuestPresentation';
+import { getCurrentWorkloadMemoryUsage } from '@/utils/memoryObservation';
// Exclusion-aware split of a free-text search. Terms prefixed with `-` hide
// matching rows ("-watchtower" hides anything whose haystack contains
@@ -156,9 +157,12 @@ function evaluateMetricCondition(guest: FilterableItem, condition: MetricConditi
case 'cpu':
value = getWorkloadCPUPercent('cpu' in guest ? guest.cpu : undefined) ?? 0;
break;
- case 'memory':
- value = 'memory' in guest && guest.memory ? guest.memory.usage : 0;
+ case 'memory': {
+ const usage = getCurrentWorkloadMemoryUsage(guest);
+ if (usage === null) return false;
+ value = usage;
break;
+ }
case 'disk': {
// Missing and retained reads are not zero (or current capacity).
// Preserve the same provider/linked-agent freshness rule as the row.