Skip to content

Modern Docker Management, Designed for Everyone

fix: preserve duplicate diagnostic log entries (#3390)

Greg96beadb4de22
diff --git a/frontend/src/routes/(app)/settings/diagnostics/diagnostic-log-panel.svelte b/frontend/src/routes/(app)/settings/diagnostics/diagnostic-log-panel.svelte
index 263a0a86c..5e319a71a 100644
--- a/frontend/src/routes/(app)/settings/diagnostics/diagnostic-log-panel.svelte
+++ b/frontend/src/routes/(app)/settings/diagnostics/diagnostic-log-panel.svelte
@@ -16,7 +16,13 @@
let { height = '360px', maxLines = 1000 }: Props = $props();
- let logs = $state<LogEntry[]>([]);
+ interface DisplayLogEntry {
+ id: number;
+ entry: LogEntry;
+ }
+
+ let nextLogId = 0;
+ let logs = $state<DisplayLogEntry[]>([]);
let connected = $state(false);
let autoScroll = $state(true);
let filterText = $state('');
@@ -25,10 +31,10 @@
let ws: ReconnectingWebSocket<LogEntry> | null = null;
const filtered = $derived(
- logs.filter((l) => {
- const lvl = l.level.toLowerCase();
+ logs.filter(({ entry }) => {
+ const lvl = entry.level.toLowerCase();
if (levelFilter !== 'all' && !lvl.startsWith(levelFilter)) return false;
- if (filterText && !l.message.toLowerCase().includes(filterText.toLowerCase())) return false;
+ if (filterText && !entry.message.toLowerCase().includes(filterText.toLowerCase())) return false;
return true;
})
);
@@ -42,7 +48,7 @@
}
function push(entry: LogEntry) {
- logs.push(entry);
+ logs.push({ id: nextLogId++, entry });
if (logs.length > maxLines) logs = logs.slice(logs.length - maxLines);
scrollToBottom();
}
@@ -127,7 +133,8 @@
{#if filtered.length === 0}
<div class="py-6 text-center text-muted-foreground">{m.diagnostics_logs_empty()}</div>
{:else}
- {#each filtered as entry (entry)}
+ {#each filtered as item (item.id)}
+ {@const entry = item.entry}
<div class="flex gap-2 rounded px-1 py-0.5 hover:bg-foreground/5">
<span class="shrink-0 text-muted-foreground tabular-nums">{fmtTime(entry.time)}</span>
<span class={cn('w-12 shrink-0 font-semibold uppercase', levelClass(entry.level))}>{entry.level}</span>
diff --git a/tests/spec/diagnostics-logs.spec.ts b/tests/spec/diagnostics-logs.spec.ts
new file mode 100644
index 000000000..0e041abd3
--- /dev/null
+++ b/tests/spec/diagnostics-logs.spec.ts
@@ -0,0 +1,134 @@
+import { expect, test, type Page } from '@playwright/test';
+
+const duplicateLogEntry = {
+ time: '2026-07-25T02:00:00.000Z',
+ level: 'INFO',
+ message: 'duplicate diagnostic entry'
+};
+
+async function mockDiagnosticsLogsWebSocket(page: Page) {
+ await page.addInitScript((logEntry) => {
+ const browserWindow = globalThis as typeof globalThis & {
+ WebSocket: any;
+ EventTarget: any;
+ Event: any;
+ MessageEvent: any;
+ CloseEvent: any;
+ };
+
+ const NativeWebSocket = browserWindow.WebSocket;
+ const diagnosticsLogsPathPattern = /\/api\/diagnostics\/logs\/stream(?:\?.*)?$/;
+
+ class MockDiagnosticsLogsWebSocket extends browserWindow.EventTarget {
+ static CONNECTING = 0;
+ static OPEN = 1;
+ static CLOSING = 2;
+ static CLOSED = 3;
+
+ url: string;
+ readyState = MockDiagnosticsLogsWebSocket.CONNECTING;
+ bufferedAmount = 0;
+ extensions = '';
+ protocol = '';
+ binaryType = 'blob';
+ onopen: ((event: unknown) => void) | null = null;
+ onmessage: ((event: unknown) => void) | null = null;
+ onerror: ((event: unknown) => void) | null = null;
+ onclose: ((event: unknown) => void) | null = null;
+
+ constructor(url: string | URL) {
+ super();
+ this.url = String(url);
+
+ queueMicrotask(() => {
+ if (this.readyState !== MockDiagnosticsLogsWebSocket.CONNECTING) return;
+
+ this.readyState = MockDiagnosticsLogsWebSocket.OPEN;
+
+ const openEvent = new browserWindow.Event('open');
+ this.dispatchEvent(openEvent);
+ this.onopen?.(openEvent);
+
+ for (let index = 0; index < 2; index += 1) {
+ const messageEvent = new browserWindow.MessageEvent('message', {
+ data: JSON.stringify(logEntry)
+ });
+
+ this.dispatchEvent(messageEvent);
+ this.onmessage?.(messageEvent);
+ }
+ });
+ }
+
+ send(_data?: string | ArrayBufferLike | Blob | ArrayBufferView) {}
+
+ close(code = 1000, reason = '') {
+ if (this.readyState === MockDiagnosticsLogsWebSocket.CLOSED) return;
+
+ this.readyState = MockDiagnosticsLogsWebSocket.CLOSED;
+
+ const closeEvent = new browserWindow.CloseEvent('close', {
+ code,
+ reason,
+ wasClean: true
+ });
+
+ this.dispatchEvent(closeEvent);
+ this.onclose?.(closeEvent);
+ }
+ }
+
+ const PatchedWebSocket = function (
+ this: unknown,
+ url: string | URL,
+ protocols?: string | string[]
+ ) {
+ const urlString = String(url);
+
+ if (diagnosticsLogsPathPattern.test(urlString)) {
+ return new MockDiagnosticsLogsWebSocket(urlString);
+ }
+
+ return protocols === undefined
+ ? new NativeWebSocket(url)
+ : new NativeWebSocket(url, protocols);
+ } as unknown as typeof WebSocket;
+
+ Object.defineProperties(PatchedWebSocket, {
+ CONNECTING: { value: NativeWebSocket.CONNECTING },
+ OPEN: { value: NativeWebSocket.OPEN },
+ CLOSING: { value: NativeWebSocket.CLOSING },
+ CLOSED: { value: NativeWebSocket.CLOSED }
+ });
+
+ PatchedWebSocket.prototype = NativeWebSocket.prototype;
+ browserWindow.WebSocket = PatchedWebSocket;
+ }, duplicateLogEntry);
+}
+
+test.describe('Diagnostics logs', () => {
+ test('renders identical log entries without duplicate-key failure', async ({ page }) => {
+ await mockDiagnosticsLogsWebSocket(page);
+
+ const pageErrors: Error[] = [];
+ let recentLogsRequests = 0;
+
+ page.on('pageerror', (error) => pageErrors.push(error));
+ page.on('request', (request) => {
+ const url = new URL(request.url());
+
+ if (url.pathname === '/api/diagnostics/logs') {
+ recentLogsRequests += 1;
+ }
+ });
+
+ await page.goto('/settings/diagnostics');
+ await page.waitForLoadState('domcontentloaded');
+
+ await expect(page).toHaveURL(/\/settings\/diagnostics$/);
+ await expect(page.getByText('duplicate diagnostic entry', { exact: true })).toHaveCount(2);
+
+ expect(recentLogsRequests).toBe(0);
+ expect(pageErrors.map((error) => error.message).join('\n')).not.toContain('each_key_duplicate');
+ });
+});