From 1fa88cdf9db0cbfad26b19eca45f5a0cda85527b Mon Sep 17 00:00:00 2001 From: Gaurav Bhola Date: Mon, 6 Apr 2026 19:30:47 -0700 Subject: [PATCH] fix(web): mux additions trigger refresh; cli: read version from package.json - useSessionEvents: detect unknown ids in mux patches and trigger refresh. Previously additions were filtered out before the membership comparison, so new sessions on a project page only appeared via the 15s stale-refresh path. - cli/index.ts: replace hardcoded "0.1.0" with version from package.json so 'ao --version' stays in sync with releases. --- packages/web/src/hooks/useSessionEvents.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/web/src/hooks/useSessionEvents.ts b/packages/web/src/hooks/useSessionEvents.ts index 4542f43cf..2b8e72996 100644 --- a/packages/web/src/hooks/useSessionEvents.ts +++ b/packages/web/src/hooks/useSessionEvents.ts @@ -209,12 +209,22 @@ export function useSessionEvents( // Note: empty array is intentional — it means all sessions were removed and we // must still run the membership-key comparison to trigger scheduleRefresh(). - dispatch({ type: "snapshot", patches: muxSessions as SSESnapshotEvent["sessions"] }); + // muxSessions is global (all projects). Filter to only sessions in the + // current project-scoped state so we don't trigger spurious refreshes + // when viewing a single-project page. + const currentIds = new Set(sessionsRef.current.map((s) => s.id)); + const scopedMuxSessions = muxSessions.filter((s) => currentIds.has(s.id)); + // The mux feed is global, but the page is project-scoped. We can't tell from + // a mux patch whether an unknown ID belongs to this project — only /api/sessions + // knows. So if we see ANY id we don't have, trigger a refresh to find out. + const hasUnknownIds = muxSessions.some((s) => !currentIds.has(s.id)); + + dispatch({ type: "snapshot", patches: scopedMuxSessions as SSESnapshotEvent["sessions"] }); const currentMembershipKey = createMembershipKey(sessionsRef.current); - const snapshotMembershipKey = createMembershipKey(muxSessions); + const snapshotMembershipKey = createMembershipKey(scopedMuxSessions); - if (currentMembershipKey !== snapshotMembershipKey) { + if (hasUnknownIds || currentMembershipKey !== snapshotMembershipKey) { pendingMembershipKeyRef.current = snapshotMembershipKey; scheduleRefresh(); } else if (Date.now() - lastRefreshAtRef.current >= STALE_REFRESH_INTERVAL_MS) {