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.

Render live system logs once per frame with bounded pending work

pulse-triage[bot]6a6649382491
diff --git a/frontend-modern/browser-verification/a19cd4c408f9ddbe.json b/frontend-modern/browser-verification/a19cd4c408f9ddbe.json
new file mode 100644
index 0000000000..b8fefed964
--- /dev/null
+++ b/frontend-modern/browser-verification/a19cd4c408f9ddbe.json
@@ -0,0 +1,50 @@
+{
+ "version": 1,
+ "base_sha": "25329b1e71082a237f9299f7ac8fc9b098196e4a",
+ "verified_at": "2026-10-09T08:40:41Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/components/Settings/SystemLogsPanel.tsx",
+ "frontend-modern/src/components/Settings/useSystemLogsPanelState.ts",
+ "frontend-modern/src/utils/systemLogsPresentation.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/Settings/SystemLogsPanel.tsx": "ee4c146cc9c1caefcc1421e79ede8d585cee5ef9690fa51652d6941038e5804f",
+ "frontend-modern/src/components/Settings/useSystemLogsPanelState.ts": "4ee722c9a69f8e1ebaf52566907c36d7c6a74b50f555013b33ed488611b1df71",
+ "frontend-modern/src/utils/systemLogsPresentation.ts": "b9103776025c027006ea670b3f1fc05143f7a0e97abb355070d282f0eb24b3c7"
+ },
+ "routes": [
+ "/settings/support?side=parent (isolated support-logs component fixture)",
+ "/settings/support?side=final (isolated support-logs component fixture)"
+ ],
+ "viewports": [
+ {
+ "width": 1440,
+ "height": 1000
+ },
+ {
+ "width": 390,
+ "height": 844
+ }
+ ],
+ "states": [
+ "Production SystemLogsPanel, state hook, presentation helpers, shared controls and CSS, not the full app shell; EventSource and level/CSRF responses are synthetic and contain no live logs. Playwright 1.56.1, matching the integration lock; desktop Chromium light and phone WebKit dark.",
+ "Eight received lines: parent performs eight scroll-height reads/writes, final one per animation frame, same ordered rows and no horizontal overflow. Final rows have no entrance animation; the shared Support Bundle button has a nontransparent background in both themes.",
+ "After pause/clear/resume, a bounded 1007-line fixture retains lines 7 through 1006: exactly 1000 in arrival order, one measurement/write and scrolled to bottom in both browsers. Paused arrivals are discarded, pending Clear lines never reappear, initial and cleared empty states remain usable.",
+ "Late delivery after unmount schedules no work and the stream closes once. Visible copy explains latest-1000 retention, discarded paused lines and local-only clearing. Six final-content captures inspected after paint settlement, including before/after light desktop and dark phone; text, controls, footer and keyboard focus are readable.",
+ "Bounded component/scheduler acceptance only: no Debug reenabling, live installation, profiling, native load, PBS GUI-cause reproduction, protected publication or release acceptance."
+ ],
+ "interactions": [
+ "Deliver eight synthetic lines together, inspect frame-scoped request and scroll counters and visible row geometry after paint.",
+ "Pause with a pending accepted line, drop paused arrivals, use keyboard Clear and Resume, then verify latest-1000 retention and no overflow.",
+ "Clear another pending line before its render frame; select Warn through mocked API only, verify Support Bundle remains present, unmount and send a late synthetic message."
+ ],
+ "screenshot_sha256": {
+ "chromium-parent-lines.png": "9121799f37c090b219d7188ad3c3c8976e4a72353168a678dcd84d4b69c158ed",
+ "chromium-final-lines.png": "48307b76a234f411698b6a724500f983c49bc567c951aa00cf7f3e693b9fc3f5",
+ "chromium-final-bounded.png": "5ed84f25f02c94f1d8c4ff05c7c1d41f0c643d5dd0761793e08e7e0b0a7d9abb",
+ "webkit-parent-lines.png": "3a4cb28be8ae099e4d85663450a2135b47ca2c11cbaee5cd9f6a542db326ad41",
+ "webkit-final-lines.png": "fa0386c72f403e8675b405dd452d0d20ca63e98e1740e635457d2aba8ca27f68",
+ "webkit-final-bounded.png": "428758f1e47addcacb365c15845200cba1a0cd58e5b19cce968d9bd10784118f"
+ }
+}
diff --git a/frontend-modern/src/components/Settings/SystemLogsPanel.tsx b/frontend-modern/src/components/Settings/SystemLogsPanel.tsx
index 24cb89bcd4..07f9d7b533 100644
--- a/frontend-modern/src/components/Settings/SystemLogsPanel.tsx
+++ b/frontend-modern/src/components/Settings/SystemLogsPanel.tsx
@@ -13,6 +13,7 @@ import Play from 'lucide-solid/icons/play';
import Trash2 from 'lucide-solid/icons/trash-2';
import Terminal from 'lucide-solid/icons/terminal';
import { FormSelect } from '@/components/shared/FormSelect';
+import { Button } from '@/components/shared/Button';
import { useSystemLogsPanelState } from './useSystemLogsPanelState';
export const SystemLogsPanel: Component = () => {
@@ -59,13 +60,15 @@ export const SystemLogsPanel: Component = () => {
<Trash2 size={18} />
</button>
<div class="h-6 w-px bg-surface-hover mx-2"></div>
- <button
+ <Button
onClick={state.handleDownload}
- class="min-h-11 sm:min-h-9 flex items-center space-x-2 px-3 py-2.5 bg-primary-600 text-white rounded-md hover:bg-primary-700 text-sm font-medium transition-colors"
+ variant="primaryFlat"
+ size="settingsAction"
+ class="gap-2"
>
<Download size={16} />
<span>{SYSTEM_LOGS_PANEL_COPY.downloadLabel}</span>
- </button>
+ </Button>
</div>
</div>
</div>
@@ -78,7 +81,7 @@ export const SystemLogsPanel: Component = () => {
>
<For each={state.logs()}>
{(log) => (
- <div class="animate-enter border-b border-border-subtle last:border-0 pb-0.5 mb-0.5 hover:bg-surface-hover px-1 -mx-1 rounded-sm">
+ <div class="border-b border-border-subtle last:border-0 pb-0.5 mb-0.5 hover:bg-surface-hover px-1 -mx-1 rounded-sm">
<span class={getSystemLogLineClass(log)}>{log}</span>
</div>
)}
@@ -99,6 +102,7 @@ export const SystemLogsPanel: Component = () => {
{streamPresentation().label}
</span>
</div>
+ <p class="text-xs text-muted px-1 pt-2">{SYSTEM_LOGS_PANEL_COPY.bufferHelp}</p>
</div>
</OperationsPanel>
</div>
diff --git a/frontend-modern/src/components/Settings/__tests__/SystemLogsPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/SystemLogsPanel.test.tsx
index 7f9a25ad63..6a07c6fbac 100644
--- a/frontend-modern/src/components/Settings/__tests__/SystemLogsPanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/SystemLogsPanel.test.tsx
@@ -20,6 +20,14 @@ describe('SystemLogsPanel architecture', () => {
expect(diagnosticsPanelSource).toContain('flex min-h-11 sm:min-h-9 items-center');
expect(systemLogsPanelSource).toContain('form-select min-h-11 sm:min-h-9');
expect(systemLogsPanelSource).toContain('min-h-11 sm:min-h-9 min-w-11 sm:min-w-9');
- expect(systemLogsPanelSource).toContain('min-h-11 sm:min-h-9 flex items-center');
+ expect(systemLogsPanelSource).toContain('size="settingsAction"');
+ });
+
+ it('keeps new lines immediately readable and support download on the themed button', () => {
+ expect(systemLogsPanelSource).not.toContain('animate-enter');
+ expect(systemLogsPanelSource).toContain('<Button');
+ expect(systemLogsPanelSource).toContain('variant="primaryFlat"');
+ expect(systemLogsPanelSource).not.toContain('bg-primary-600');
+ expect(systemLogsPanelSource).toContain('SYSTEM_LOGS_PANEL_COPY.bufferHelp');
});
});
diff --git a/frontend-modern/src/components/Settings/__tests__/useSystemLogsPanelState.test.tsx b/frontend-modern/src/components/Settings/__tests__/useSystemLogsPanelState.test.tsx
new file mode 100644
index 0000000000..131e562221
--- /dev/null
+++ b/frontend-modern/src/components/Settings/__tests__/useSystemLogsPanelState.test.tsx
@@ -0,0 +1,219 @@
+import { For, createEffect } from 'solid-js';
+import { cleanup, render } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { useSystemLogsPanelState } from '../useSystemLogsPanelState';
+
+const mocks = vi.hoisted(() => ({ api: vi.fn(), success: vi.fn(), error: vi.fn() }));
+vi.mock('@/utils/apiClient', () => ({ apiFetchJSON: mocks.api }));
+vi.mock('@/stores/notifications', () => ({
+ notificationStore: { success: mocks.success, error: mocks.error },
+}));
+vi.mock('@/utils/logger', () => ({ logger: { debug: vi.fn(), error: vi.fn() } }));
+
+class FixtureEventSource {
+ static instances: FixtureEventSource[] = [];
+ onmessage: ((event: MessageEvent<string>) => void) | null = null;
+ onerror: (() => void) | null = null;
+ close = vi.fn();
+ constructor(readonly url: string) {
+ FixtureEventSource.instances.push(this);
+ }
+ send(data: string) {
+ this.onmessage?.(new MessageEvent('message', { data }));
+ }
+}
+
+let frames: Map<number, FrameRequestCallback>;
+let nextFrame: number;
+const flushAsync = async () => {
+ await Promise.resolve();
+ await Promise.resolve();
+ await Promise.resolve();
+};
+const flushFrame = () => {
+ const callbacks = [...frames.values()];
+ frames.clear();
+ callbacks.forEach((callback) => callback(0));
+};
+
+async function mount() {
+ let state!: ReturnType<typeof useSystemLogsPanelState>;
+ const publish = vi.fn();
+ const view = render(() => {
+ state = useSystemLogsPanelState();
+ createEffect(() => {
+ publish(state.logs());
+ });
+ return (
+ <div ref={state.setLogContainer}>
+ <For each={state.logs()}>{(line) => <div>{line}</div>}</For>
+ </div>
+ );
+ });
+ const container = view.container.firstElementChild as HTMLDivElement;
+ const measure = vi.fn(() => container.childElementCount * 20);
+ const scroll = vi.fn();
+ Object.defineProperty(container, 'scrollHeight', { get: measure });
+ Object.defineProperty(container, 'scrollTop', { set: scroll });
+ await flushAsync();
+ publish.mockClear();
+ return {
+ state,
+ view,
+ container,
+ measure,
+ scroll,
+ publish,
+ stream: FixtureEventSource.instances[0],
+ };
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ FixtureEventSource.instances = [];
+ frames = new Map();
+ nextFrame = 0;
+ vi.stubGlobal('EventSource', FixtureEventSource);
+ vi.stubGlobal(
+ 'requestAnimationFrame',
+ vi.fn((callback: FrameRequestCallback) => {
+ frames.set(++nextFrame, callback);
+ return nextFrame;
+ }),
+ );
+ vi.stubGlobal(
+ 'cancelAnimationFrame',
+ vi.fn((id: number) => {
+ frames.delete(id);
+ }),
+ );
+ mocks.api.mockResolvedValue({ level: 'info' });
+});
+
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+});
+
+describe('live system log rendering', () => {
+ it('publishes and scrolls once per frame, after the accepted rows render', async () => {
+ const { state, stream, measure, scroll, publish, container } = await mount();
+ stream.send('first');
+ stream.send('second');
+ stream.send('third');
+ expect(state.logs()).toEqual([]);
+ expect(requestAnimationFrame).toHaveBeenCalledTimes(1);
+ expect(measure).not.toHaveBeenCalled();
+ expect(publish).not.toHaveBeenCalled();
+ flushFrame();
+ expect(state.logs()).toEqual(['first', 'second', 'third']);
+ expect(container.childElementCount).toBe(3);
+ expect(publish).toHaveBeenCalledTimes(1);
+ expect(measure).toHaveBeenCalledTimes(1);
+ expect(scroll).toHaveBeenCalledWith(60);
+ stream.send('next frame');
+ flushFrame();
+ expect(publish).toHaveBeenCalledTimes(2);
+ expect(state.logs().at(-1)).toBe('next frame');
+ });
+
+ it('bounds a frame-starved pending buffer and retains the newest 1,000 in arrival order', async () => {
+ const { state, stream, measure, publish } = await mount();
+ for (let index = 0; index < 1007; index += 1) stream.send(`line-${index}`);
+ expect(frames.size).toBe(1);
+ expect(measure).not.toHaveBeenCalled();
+ flushFrame();
+ expect(state.logs()).toEqual(Array.from({ length: 1000 }, (_, index) => `line-${index + 7}`));
+ expect(publish).toHaveBeenCalledTimes(1);
+ stream.send('last-a');
+ stream.send('last-b');
+ flushFrame();
+ expect(state.logs()).toEqual([
+ ...Array.from({ length: 998 }, (_, index) => `line-${index + 9}`),
+ 'last-a',
+ 'last-b',
+ ]);
+ });
+
+ it('keeps already accepted lines on pause, drops paused arrivals and resumes without replay', async () => {
+ const { state, stream } = await mount();
+ stream.send('before pause');
+ state.togglePaused();
+ expect(state.logs()).toEqual(['before pause']);
+ expect(state.isPaused()).toBe(true);
+ expect(frames.size).toBe(0);
+ stream.send('discarded while paused');
+ flushFrame();
+ expect(state.logs()).toEqual(['before pause']);
+ state.togglePaused();
+ stream.send('after resume');
+ flushFrame();
+ expect(state.logs()).toEqual(['before pause', 'after resume']);
+ expect(stream.close).not.toHaveBeenCalled();
+ });
+
+ it('clears both visible and pending lines without closing the stream or resurrecting them', async () => {
+ const { state, stream } = await mount();
+ stream.send('visible');
+ flushFrame();
+ stream.send('pending');
+ state.clearLogs();
+ flushFrame();
+ expect(state.logs()).toEqual([]);
+ expect(frames.size).toBe(0);
+ stream.send('after clear');
+ flushFrame();
+ expect(state.logs()).toEqual(['after clear']);
+ state.togglePaused();
+ state.clearLogs();
+ expect(state.isPaused()).toBe(true);
+ expect(state.logs()).toEqual([]);
+ expect(stream.close).not.toHaveBeenCalled();
+ });
+
+ it('cancels pending rendering and closes the stream when the panel unmounts', async () => {
+ const { state, stream, view, measure } = await mount();
+ stream.send('pending at unmount');
+ const staleCallback = [...frames.values()][0];
+ view.unmount();
+ expect(frames.size).toBe(0);
+ expect(stream.close).toHaveBeenCalledTimes(1);
+ staleCallback(0);
+ stream.send('late message');
+ expect(state.logs()).toEqual([]);
+ expect(measure).not.toHaveBeenCalled();
+ expect(requestAnimationFrame).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not open a stream if the panel unmounts during its initial level request', async () => {
+ let finish!: (value: { level: string }) => void;
+ mocks.api.mockReturnValue(
+ new Promise((resolve) => {
+ finish = resolve;
+ }),
+ );
+ const { view, state } = await mount();
+ expect(state.isLoading()).toBe(true);
+ view.unmount();
+ finish({ level: 'info' });
+ await flushAsync();
+ expect(FixtureEventSource.instances).toHaveLength(0);
+ });
+
+ it('keeps level fetch/change and their error handling independent of render scheduling', async () => {
+ const { state, stream } = await mount();
+ expect(stream.url).toBe('/api/logs/stream');
+ expect(state.level()).toBe('info');
+ expect(state.isLoading()).toBe(false);
+ await state.handleLevelChange('warn');
+ expect(mocks.api).toHaveBeenLastCalledWith('/api/logs/level', {
+ method: 'POST',
+ body: JSON.stringify({ level: 'warn' }),
+ });
+ expect(mocks.success).toHaveBeenCalledWith('Log level set to warn');
+ mocks.api.mockRejectedValueOnce(new Error('fixture unavailable'));
+ await state.handleLevelChange('error');
+ expect(state.level()).toBe('warn');
+ expect(mocks.error).toHaveBeenCalledWith('Failed to set log level');
+ });
+});
diff --git a/frontend-modern/src/components/Settings/useSystemLogsPanelState.ts b/frontend-modern/src/components/Settings/useSystemLogsPanelState.ts
index 0766d0cae1..ce5853da80 100644
--- a/frontend-modern/src/components/Settings/useSystemLogsPanelState.ts
+++ b/frontend-modern/src/components/Settings/useSystemLogsPanelState.ts
@@ -14,6 +14,22 @@ export function useSystemLogsPanelState() {
let logContainer: HTMLDivElement | undefined;
let eventSource: EventSource | null = null;
let disposed = false;
+ let renderFrame: number | null = null;
+ // A bounded ring also caps pending work when a background tab stops frames.
+ // Receiving a line never clones the visible buffer or forces layout.
+ let pendingLogs: string[] = [];
+ let pendingCount = 0;
+ let pendingNext = 0;
+
+ const resetPending = () => {
+ pendingLogs = [];
+ pendingCount = 0;
+ pendingNext = 0;
+ if (renderFrame !== null) {
+ cancelAnimationFrame(renderFrame);
+ renderFrame = null;
+ }
+ };
const setLogContainer = (element: HTMLDivElement | undefined) => {
logContainer = element;
@@ -25,6 +41,21 @@ export function useSystemLogsPanelState() {
}
};
+ const flushPendingLogs = () => {
+ if (disposed || pendingCount === 0) return;
+ const incoming = Array.from(
+ { length: pendingCount },
+ (_, index) => pendingLogs[(pendingNext - pendingCount + MAX_LOGS + index) % MAX_LOGS],
+ );
+ resetPending();
+ setLogs((prev) => [
+ ...prev.slice(Math.max(0, prev.length + incoming.length - MAX_LOGS)),
+ ...incoming,
+ ]);
+ // Solid updates the rows synchronously; measure after the single publish.
+ scrollToBottom();
+ };
+
const fetchLevel = async () => {
try {
const res = (await apiFetchJSON('/api/logs/level')) as { level?: string };
@@ -42,15 +73,15 @@ export function useSystemLogsPanelState() {
eventSource.onmessage = (event) => {
if (disposed || isPaused()) return;
- setLogs((prev) => {
- const next = [...prev, event.data];
- if (next.length > MAX_LOGS) {
- return next.slice(next.length - MAX_LOGS);
- }
- return next;
- });
-
- scrollToBottom();
+ pendingLogs[pendingNext] = event.data;
+ pendingNext = (pendingNext + 1) % MAX_LOGS;
+ pendingCount = Math.min(pendingCount + 1, MAX_LOGS);
+ if (renderFrame === null) {
+ renderFrame = requestAnimationFrame(() => {
+ renderFrame = null;
+ flushPendingLogs();
+ });
+ }
};
eventSource.onerror = () => {
@@ -78,10 +109,13 @@ export function useSystemLogsPanelState() {
};
const togglePaused = () => {
+ // Lines accepted before Pause belong in the view; paused arrivals do not.
+ if (!isPaused()) flushPendingLogs();
setIsPaused((prev) => !prev);
};
const clearLogs = () => {
+ resetPending();
setLogs([]);
};
@@ -96,6 +130,7 @@ export function useSystemLogsPanelState() {
onCleanup(() => {
disposed = true;
+ resetPending();
if (eventSource) {
eventSource.close();
eventSource = null;
diff --git a/frontend-modern/src/utils/__tests__/systemLogsPresentation.test.ts b/frontend-modern/src/utils/__tests__/systemLogsPresentation.test.ts
index f769098ca2..f83c21f11b 100644
--- a/frontend-modern/src/utils/__tests__/systemLogsPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/systemLogsPresentation.test.ts
@@ -16,6 +16,8 @@ describe('systemLogsPresentation', () => {
clearTitle: 'Clear Log Output',
downloadLabel: 'Support Bundle',
emptyState: 'Waiting for log output.',
+ bufferHelp:
+ 'This view keeps only the latest 1,000 received lines. Paused lines are not collected. Clearing the view does not delete server logs.',
});
expect(SYSTEM_LOG_LEVEL_OPTIONS).toEqual([
{ value: 'debug', label: 'Debug' },
diff --git a/frontend-modern/src/utils/systemLogsPresentation.ts b/frontend-modern/src/utils/systemLogsPresentation.ts
index dbdd47bc2a..1ecd8f961e 100644
--- a/frontend-modern/src/utils/systemLogsPresentation.ts
+++ b/frontend-modern/src/utils/systemLogsPresentation.ts
@@ -17,6 +17,8 @@ export const SYSTEM_LOGS_PANEL_COPY = {
clearTitle: 'Clear Log Output',
downloadLabel: 'Support Bundle',
emptyState: 'Waiting for log output.',
+ bufferHelp:
+ 'This view keeps only the latest 1,000 received lines. Paused lines are not collected. Clearing the view does not delete server logs.',
} as const;
export const SYSTEM_LOG_LEVEL_OPTIONS: readonly SystemLogLevelOption[] = [