From a305afbc76a3adb6a985876489995be88b9f0d85 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Wed, 24 Jun 2026 23:17:26 +0800 Subject: [PATCH] fix(webui): observable projector wedge + tighten non-array fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round-2 follow-up. Two small holes flagged by the adversarial review of the connection-diff-loop projector: - A projector that starts throwing only after a shape regression would wedge the diff baseline silently — no publishes, no log, the only symptom is the dashboard's connections card freezing until restart. Latch a one-shot console.error on the first throw so the failure is visible without re-running the loop locally. - The non-array fallback at the projector site in server.ts returned `acc.adapters` verbatim, which would re-introduce volatile fields if the snapshot shape ever drifts. Tighten to `[]`. Also documented the deliberate trade-off: per-second adapter `detail` rotation (client count, last-delivery HH:MM:SS) refreshes on the next SSE push or the 30s REST reconcile rather than in real time. The user's original bugs were about process/account edges (which DO push instantly); detail-string freshness was not in scope. If it becomes one, surface client-count as a structured AdapterStatus field instead of parsing the localised `detail`. 437/437 core green. --- packages/core/src/webui/connection-diff-loop.ts | 16 +++++++++++++++- packages/core/src/webui/server.ts | 13 ++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/core/src/webui/connection-diff-loop.ts b/packages/core/src/webui/connection-diff-loop.ts index 17d01e49..7413fd20 100644 --- a/packages/core/src/webui/connection-diff-loop.ts +++ b/packages/core/src/webui/connection-diff-loop.ts @@ -39,6 +39,11 @@ export function startConnectionDiffLoop(opts: ConnectionDiffLoopOptions): Connec let lastSerialized = ''; let haveBaseline = false; let disposed = false; + // One-shot diagnostic latch: a projector that starts throwing only after + // a shape regression would otherwise wedge the baseline silently — no + // publishes, no log, no symptom besides "the dashboard's connections + // card stops updating". Surface it ONCE so the failure is visible. + let warnedProjectorThrew = false; const tick = (): void => { if (disposed) return; @@ -54,8 +59,17 @@ export function startConnectionDiffLoop(opts: ConnectionDiffLoopOptions): Connec let comparable: unknown; try { comparable = opts.pickComparable ? opts.pickComparable(snap) : snap; - } catch { + } catch (err) { // A buggy projector must not crash the diff loop or wedge baseline. + // But silent wedge is its own bug class — log the FIRST occurrence + // so an operator can find it without re-running the loop locally. + if (!warnedProjectorThrew) { + warnedProjectorThrew = true; + // Static logger import avoided to keep the loop self-contained; + // stderr is good enough for a once-per-process latch. + // eslint-disable-next-line no-console + console.error('[connection-diff-loop] pickComparable threw — connections SSE diff will wedge until restart:', err); + } return; } const serialized = JSON.stringify(comparable); diff --git a/packages/core/src/webui/server.ts b/packages/core/src/webui/server.ts index 6742048e..56ca2157 100644 --- a/packages/core/src/webui/server.ts +++ b/packages/core/src/webui/server.ts @@ -345,6 +345,14 @@ export async function initWebUI( // status, which captures every transition the dashboard actually // renders differently. The SSE handler still ships the FULL snapshot // (with `detail`) — it's only the diff key that's pruned. + // + // Trade-off: the rendered detail string (e.g. "3 个客户端", "上次推送 + // 14:53:01") only refreshes on the next SSE push or on the 30s REST + // reconcile — not in real time. The user's original reported bugs were + // about process / account edges (which DO push instantly); refreshing + // adapter detail strings at sub-second cadence wasn't required. If it + // becomes one, surface client-count as a structured field on + // AdapterStatus and include it in the comparable. if (listener.stateBus) { // Handle deliberately discarded — initWebUI has no shutdown path; the // loop's setInterval is .unref'd so it doesn't pin the event loop. @@ -356,12 +364,15 @@ export async function initWebUI( return (snap as Array<{ uin: string; nickname?: string; adapters?: unknown[] }>).map((acc) => ({ uin: acc.uin, nickname: acc.nickname, + // Empty fallback when `adapters` is not an array — never the + // raw value, which could re-introduce volatile fields verbatim + // if the snapshot shape ever drifts. adapters: Array.isArray(acc.adapters) ? acc.adapters.map((a: unknown) => { const o = a as { name?: string; kind?: string; status?: string }; return { name: o.name, kind: o.kind, status: o.status }; }) - : acc.adapters, + : [], })); }, intervalMs: 500,