From 6b8011228efcab06cc9a1ef735941ef73314dace Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 9 Dec 2025 03:21:59 +0000 Subject: [PATCH] fix(presence): always seed self entry and log counts --- src/infra/control-channel.ts | 4 +++- src/infra/system-presence.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/infra/control-channel.ts b/src/infra/control-channel.ts index 8500f8ec6..0b7847527 100644 --- a/src/infra/control-channel.ts +++ b/src/infra/control-channel.ts @@ -172,7 +172,9 @@ export async function startControlChannel( break; } case "system-presence": { - respond(listSystemPresence()); + const pres = listSystemPresence(); + logDebug?.(`control: system-presence count=${pres.length}`); + respond(pres); break; } default: diff --git a/src/infra/system-presence.ts b/src/infra/system-presence.ts index edbfe12be..ec521661c 100644 --- a/src/infra/system-presence.ts +++ b/src/infra/system-presence.ts @@ -50,6 +50,15 @@ function initSelfPresence() { entries.set(key, selfEntry); } +function ensureSelfPresence() { + // If the map was somehow cleared (e.g., hot reload or a new worker spawn that + // skipped module evaluation), re-seed with a local entry so UIs always show + // at least the current relay. + if (entries.size === 0) { + initSelfPresence(); + } +} + initSelfPresence(); function parsePresence(text: string): SystemPresence { @@ -78,6 +87,7 @@ function parsePresence(text: string): SystemPresence { } export function updateSystemPresence(text: string) { + ensureSelfPresence(); const parsed = parsePresence(text); const key = parsed.host?.toLowerCase() || parsed.ip || parsed.text.slice(0, 64); @@ -85,5 +95,6 @@ export function updateSystemPresence(text: string) { } export function listSystemPresence(): SystemPresence[] { + ensureSelfPresence(); return [...entries.values()].sort((a, b) => b.ts - a.ts); }