From 7a3e28b96a2c8db7082020e61822aa6a6c4cc0f9 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 22:53:54 -0500 Subject: [PATCH 1/3] fix(j5): a server the person turned off no longer reads "loading" in the Inbox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit J5's read sources treated a disabled server's "available" phase as still loading, so the Inbox, its count and web's J5 pages showed ": loading…" for it forever. They now skip disabled servers, as upstream's thread and project lists do, and read "available" as not connecting. Co-Authored-By: Claude Opus 5.5 --- .../client-runtime/src/j5/readSources.test.ts | 54 ++++++++++++++++++- packages/client-runtime/src/j5/readSources.ts | 11 ++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/packages/client-runtime/src/j5/readSources.test.ts b/packages/client-runtime/src/j5/readSources.test.ts index 18320a6044aa9..2725cd5ba71e8 100644 --- a/packages/client-runtime/src/j5/readSources.test.ts +++ b/packages/client-runtime/src/j5/readSources.test.ts @@ -53,6 +53,56 @@ it("keeps unsupported, authentication failure, and not-yet-connected states dist resolveJ5ReadSource({ ...source, phase: "connecting", result: AsyncResult.initial(false) }) .status, ).toBe("loading"); + // "available" is a server nothing is connecting to, so it is not loading. + expect( + resolveJ5ReadSource({ ...source, phase: "available", result: AsyncResult.initial(false) }) + .status, + ).toBe("offline"); +}); + +it("leaves out a server the person turned off, and reads one still starting up as loading", () => { + type Input = Parameters>>[0]; + const on = EnvironmentId.make("on"); + const off = EnvironmentId.make("off"); + const starting = EnvironmentId.make("starting"); + const reads: Array = []; + const sources = createJ5ReadSourcesAtom>({ + label: "test:j5-read-sources-disabled", + capability: "j5ProjectLedger", + catalogValueAtom: Atom.make({ + isReady: true, + entries: new Map([ + [on, { target: { label: "On" }, enabled: true }], + [off, { target: { label: "Off" }, enabled: false }], + [starting, { target: { label: "Starting" }, enabled: true }], + ]), + }) as unknown as Input["catalogValueAtom"], + stateAtom: (id) => + Atom.make( + id === on + ? AsyncResult.success({ phase: "connected" }) + : id === off + ? AsyncResult.success({ phase: "available", desired: false }) + : AsyncResult.initial(true), + ) as unknown as ReturnType, + configValueAtom: (id) => + Atom.make( + id === starting ? null : { environment: { capabilities: { j5ProjectLedger: true } } }, + ) as unknown as ReturnType, + queryAtom: (id) => + Atom.make(() => { + reads.push(id); + return id === on + ? AsyncResult.success, unknown>(["row"]) + : AsyncResult.initial, unknown>(true); + }), + }); + const result = AtomRegistry.make().get(sources).sources; + expect(result.map((entry) => [entry.environmentLabel, entry.status])).toEqual([ + ["On", "ready"], + ["Starting", "loading"], + ]); + expect(reads).not.toContain(off); }); it("shows environment labels only once items span more than one environment", () => { @@ -77,7 +127,7 @@ const readSourceFor = ( capability: capability as Input["capability"], catalogValueAtom: Atom.make({ isReady: true, - entries: new Map([[environmentId, { target: { label: "Remote" } }]]), + entries: new Map([[environmentId, { target: { label: "Remote" }, enabled: true }]]), }) as unknown as Input["catalogValueAtom"], stateAtom: () => Atom.make(AsyncResult.success({ phase: "connected" })) as unknown as ReturnType< @@ -131,7 +181,7 @@ it("shows nothing from a server once its connection is known to be a guest's", ( capability: "j5ProjectLedger", catalogValueAtom: Atom.make({ isReady: true, - entries: new Map([[source.environmentId, { target: { label: "Remote" } }]]), + entries: new Map([[source.environmentId, { target: { label: "Remote" }, enabled: true }]]), }) as unknown as Input["catalogValueAtom"], stateAtom: () => Atom.make(AsyncResult.success({ phase: "connected" })) as unknown as ReturnType< diff --git a/packages/client-runtime/src/j5/readSources.ts b/packages/client-runtime/src/j5/readSources.ts index 13cc877dfe7f7..2207ed7a500b5 100644 --- a/packages/client-runtime/src/j5/readSources.ts +++ b/packages/client-runtime/src/j5/readSources.ts @@ -4,7 +4,7 @@ import * as Option from "effect/Option"; import { AsyncResult, Atom } from "effect/reactivity"; import type { SupervisorConnectionState } from "../connection/model.ts"; -import type { EnvironmentCatalogState } from "../state/connections.ts"; +import { type EnvironmentCatalogState, enabledEnvironmentIds } from "../state/connections.ts"; /** Environment labels are noise until a read model actually spans more than one environment. */ export const spansMultipleEnvironments = ( @@ -50,7 +50,7 @@ export function resolveJ5ReadSource(input: { const status = unsupported ? "unsupported" : !connected - ? input.phase === "connecting" || input.phase === "available" + ? input.phase === "connecting" ? "loading" : "offline" : failure !== null @@ -77,6 +77,7 @@ export function resolveJ5ReadSource(input: { /** * Merge read models through the existing catalog; each source keeps its own data and failure state. + * A server the person turned off is left out, as upstream's thread and project lists leave it out. * A server whose config does not report the capability has no J5 ledger: its source is unsupported * and this read is never made. */ @@ -99,7 +100,8 @@ export function createJ5ReadSourcesAtom(input: { return Atom.make((get) => { const catalog = get(input.catalogValueAtom); const sources: Array> = []; - for (const [environmentId, entry] of catalog.entries) { + for (const environmentId of enabledEnvironmentIds(catalog)) { + const entry = catalog.entries.get(environmentId)!; const state = Option.getOrNull(AsyncResult.value(get(input.stateAtom(environmentId)))); const config = get(input.configValueAtom(environmentId)); const guest = input.guestAtom !== undefined && get(input.guestAtom(environmentId)); @@ -112,7 +114,8 @@ export function createJ5ReadSourcesAtom(input: { resolveJ5ReadSource({ environmentId, environmentLabel: entry.target.label, - phase: state?.phase ?? "available", + // Before its supervisor publishes, an enabled server is starting to connect. + phase: state?.phase ?? "connecting", ...(supported === undefined ? {} : { supported }), guest, result: From 11f33c3a62997482177e382f74ee17e18a0fbdf4 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:02:24 -0500 Subject: [PATCH 2/3] fix(j5): a server retrying after a failure reads offline, not loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream presents a connection attempt after a failure as reconnecting, and its query fails rather than waits. J5's read sources now read that attempt as offline, so a server that keeps retrying no longer switches between "loading…" and "offline". Co-Authored-By: Claude Opus 5.5 --- .../client-runtime/src/j5/readSources.test.ts | 18 ++++++++++++++++-- packages/client-runtime/src/j5/readSources.ts | 5 ++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/client-runtime/src/j5/readSources.test.ts b/packages/client-runtime/src/j5/readSources.test.ts index 2725cd5ba71e8..5b22889a0d312 100644 --- a/packages/client-runtime/src/j5/readSources.test.ts +++ b/packages/client-runtime/src/j5/readSources.test.ts @@ -53,6 +53,15 @@ it("keeps unsupported, authentication failure, and not-yet-connected states dist resolveJ5ReadSource({ ...source, phase: "connecting", result: AsyncResult.initial(false) }) .status, ).toBe("loading"); + // A retry after a failure is reconnecting, as upstream presents it, not a first load. + expect( + resolveJ5ReadSource({ + ...source, + phase: "connecting", + reconnecting: true, + result: AsyncResult.initial(false), + }).status, + ).toBe("offline"); // "available" is a server nothing is connecting to, so it is not loading. expect( resolveJ5ReadSource({ ...source, phase: "available", result: AsyncResult.initial(false) }) @@ -60,11 +69,12 @@ it("keeps unsupported, authentication failure, and not-yet-connected states dist ).toBe("offline"); }); -it("leaves out a server the person turned off, and reads one still starting up as loading", () => { +it("leaves out a server the person turned off, and reads only a first connection as loading", () => { type Input = Parameters>>[0]; const on = EnvironmentId.make("on"); const off = EnvironmentId.make("off"); const starting = EnvironmentId.make("starting"); + const retrying = EnvironmentId.make("retrying"); const reads: Array = []; const sources = createJ5ReadSourcesAtom>({ label: "test:j5-read-sources-disabled", @@ -75,6 +85,7 @@ it("leaves out a server the person turned off, and reads one still starting up a [on, { target: { label: "On" }, enabled: true }], [off, { target: { label: "Off" }, enabled: false }], [starting, { target: { label: "Starting" }, enabled: true }], + [retrying, { target: { label: "Retrying" }, enabled: true }], ]), }) as unknown as Input["catalogValueAtom"], stateAtom: (id) => @@ -83,7 +94,9 @@ it("leaves out a server the person turned off, and reads one still starting up a ? AsyncResult.success({ phase: "connected" }) : id === off ? AsyncResult.success({ phase: "available", desired: false }) - : AsyncResult.initial(true), + : id === retrying + ? AsyncResult.success({ phase: "connecting", attempt: 4, lastFailure: {} }) + : AsyncResult.initial(true), ) as unknown as ReturnType, configValueAtom: (id) => Atom.make( @@ -101,6 +114,7 @@ it("leaves out a server the person turned off, and reads one still starting up a expect(result.map((entry) => [entry.environmentLabel, entry.status])).toEqual([ ["On", "ready"], ["Starting", "loading"], + ["Retrying", "offline"], ]); expect(reads).not.toContain(off); }); diff --git a/packages/client-runtime/src/j5/readSources.ts b/packages/client-runtime/src/j5/readSources.ts index 2207ed7a500b5..48b2fb79b3c12 100644 --- a/packages/client-runtime/src/j5/readSources.ts +++ b/packages/client-runtime/src/j5/readSources.ts @@ -39,6 +39,8 @@ export function resolveJ5ReadSource(input: { readonly environmentId: EnvironmentId; readonly environmentLabel: string; readonly phase: SupervisorConnectionState["phase"]; + /** A connection attempt after a failure, which upstream presents as reconnecting. */ + readonly reconnecting?: boolean; readonly supported?: boolean; readonly guest?: boolean; readonly result: AsyncResult.AsyncResult; @@ -50,7 +52,7 @@ export function resolveJ5ReadSource(input: { const status = unsupported ? "unsupported" : !connected - ? input.phase === "connecting" + ? input.phase === "connecting" && input.reconnecting !== true ? "loading" : "offline" : failure !== null @@ -116,6 +118,7 @@ export function createJ5ReadSourcesAtom(input: { environmentLabel: entry.target.label, // Before its supervisor publishes, an enabled server is starting to connect. phase: state?.phase ?? "connecting", + reconnecting: state !== null && (state.attempt > 1 || state.lastFailure !== null), ...(supported === undefined ? {} : { supported }), guest, result: From 9d27f18fc916700bce366a391f0f9c85be8e05a3 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:09:17 -0500 Subject: [PATCH 3/3] =?UTF-8?q?fix(j5):=20a=20server=20retrying=20after=20?= =?UTF-8?q?a=20failure=20says=20"reconnecting=E2=80=A6",=20as=20upstream?= =?UTF-8?q?=20does?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream presents a retry after a failure, and the wait before the next one, as reconnecting. A J5 source in that state keeps reading as offline, so saved rows stay, but its line now says ": reconnecting…". "offline." stays for a client with no network. Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/j5/inbox.ts | 4 +- .../client-runtime/src/j5/readSources.test.ts | 59 +++++++++++++++---- packages/client-runtime/src/j5/readSources.ts | 11 +++- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/packages/client-runtime/src/j5/inbox.ts b/packages/client-runtime/src/j5/inbox.ts index 03624b04aa704..3c1a18b1845e9 100644 --- a/packages/client-runtime/src/j5/inbox.ts +++ b/packages/client-runtime/src/j5/inbox.ts @@ -80,7 +80,9 @@ export function j5SourceNotice(source: J5ReadSource): string | null { case "loading": return `${source.environmentLabel}: loading…`; case "offline": - return `${source.environmentLabel}: offline${source.data === null ? "" : " (showing saved results)"}.`; + return source.reconnecting === true + ? `${source.environmentLabel}: reconnecting…${source.data === null ? "" : " (showing saved results)."}` + : `${source.environmentLabel}: offline${source.data === null ? "" : " (showing saved results)"}.`; case "unsupported": return source.guest === true ? `${source.environmentLabel}: not shared with you.` diff --git a/packages/client-runtime/src/j5/readSources.test.ts b/packages/client-runtime/src/j5/readSources.test.ts index 5b22889a0d312..0a2ef59df4a4d 100644 --- a/packages/client-runtime/src/j5/readSources.test.ts +++ b/packages/client-runtime/src/j5/readSources.test.ts @@ -53,15 +53,41 @@ it("keeps unsupported, authentication failure, and not-yet-connected states dist resolveJ5ReadSource({ ...source, phase: "connecting", result: AsyncResult.initial(false) }) .status, ).toBe("loading"); - // A retry after a failure is reconnecting, as upstream presents it, not a first load. + // A retry after a failure, or the wait before one, is reconnecting, as upstream presents it: not + // a first load, and its line uses upstream's word. A client with no network reads offline. + const retrying = resolveJ5ReadSource({ + ...source, + phase: "connecting", + reconnecting: true, + result: AsyncResult.success(["cached-row"]), + }); + expect(retrying).toMatchObject({ status: "offline", data: ["cached-row"] }); + expect(j5SourceNotice(retrying)).toBe("Remote: reconnecting… (showing saved results)."); expect( - resolveJ5ReadSource({ - ...source, - phase: "connecting", - reconnecting: true, - result: AsyncResult.initial(false), - }).status, - ).toBe("offline"); + j5SourceNotice( + resolveJ5ReadSource({ + ...source, + phase: "connecting", + reconnecting: true, + result: AsyncResult.initial(false), + }), + ), + ).toBe("Remote: reconnecting…"); + expect( + j5SourceNotice( + resolveJ5ReadSource({ + ...source, + phase: "backoff", + reconnecting: true, + result: AsyncResult.initial(false), + }), + ), + ).toBe("Remote: reconnecting…"); + expect( + j5SourceNotice( + resolveJ5ReadSource({ ...source, phase: "offline", result: AsyncResult.initial(false) }), + ), + ).toBe("Remote: offline."); // "available" is a server nothing is connecting to, so it is not loading. expect( resolveJ5ReadSource({ ...source, phase: "available", result: AsyncResult.initial(false) }) @@ -75,6 +101,7 @@ it("leaves out a server the person turned off, and reads only a first connection const off = EnvironmentId.make("off"); const starting = EnvironmentId.make("starting"); const retrying = EnvironmentId.make("retrying"); + const waiting = EnvironmentId.make("waiting"); const reads: Array = []; const sources = createJ5ReadSourcesAtom>({ label: "test:j5-read-sources-disabled", @@ -86,6 +113,7 @@ it("leaves out a server the person turned off, and reads only a first connection [off, { target: { label: "Off" }, enabled: false }], [starting, { target: { label: "Starting" }, enabled: true }], [retrying, { target: { label: "Retrying" }, enabled: true }], + [waiting, { target: { label: "Waiting" }, enabled: true }], ]), }) as unknown as Input["catalogValueAtom"], stateAtom: (id) => @@ -96,7 +124,9 @@ it("leaves out a server the person turned off, and reads only a first connection ? AsyncResult.success({ phase: "available", desired: false }) : id === retrying ? AsyncResult.success({ phase: "connecting", attempt: 4, lastFailure: {} }) - : AsyncResult.initial(true), + : id === waiting + ? AsyncResult.success({ phase: "backoff", attempt: 4, lastFailure: {} }) + : AsyncResult.initial(true), ) as unknown as ReturnType, configValueAtom: (id) => Atom.make( @@ -111,10 +141,13 @@ it("leaves out a server the person turned off, and reads only a first connection }), }); const result = AtomRegistry.make().get(sources).sources; - expect(result.map((entry) => [entry.environmentLabel, entry.status])).toEqual([ - ["On", "ready"], - ["Starting", "loading"], - ["Retrying", "offline"], + expect( + result.map((entry) => [entry.environmentLabel, entry.status, j5SourceNotice(entry)]), + ).toEqual([ + ["On", "ready", null], + ["Starting", "loading", "Starting: loading…"], + ["Retrying", "offline", "Retrying: reconnecting…"], + ["Waiting", "offline", "Waiting: reconnecting…"], ]); expect(reads).not.toContain(off); }); diff --git a/packages/client-runtime/src/j5/readSources.ts b/packages/client-runtime/src/j5/readSources.ts index 48b2fb79b3c12..ccc0bf66d3d2d 100644 --- a/packages/client-runtime/src/j5/readSources.ts +++ b/packages/client-runtime/src/j5/readSources.ts @@ -28,6 +28,8 @@ export interface J5ReadSource { readonly refreshing: boolean; /** Set when the source is unsupported because the connection is a guest's, not for the server's age. */ readonly guest?: true; + /** Set when an offline source is retrying after a failure, which upstream calls reconnecting. */ + readonly reconnecting?: true; } export interface J5ReadSources { @@ -39,7 +41,7 @@ export function resolveJ5ReadSource(input: { readonly environmentId: EnvironmentId; readonly environmentLabel: string; readonly phase: SupervisorConnectionState["phase"]; - /** A connection attempt after a failure, which upstream presents as reconnecting. */ + /** A retry after a failure, or the wait before one, which upstream presents as reconnecting. */ readonly reconnecting?: boolean; readonly supported?: boolean; readonly guest?: boolean; @@ -74,6 +76,7 @@ export function resolveJ5ReadSource(input: { : "The environment request failed.", refreshing: connected && input.result.waiting, ...(input.guest === true ? { guest: true as const } : {}), + ...(status === "offline" && input.reconnecting === true ? { reconnecting: true as const } : {}), }; } @@ -118,7 +121,11 @@ export function createJ5ReadSourcesAtom(input: { environmentLabel: entry.target.label, // Before its supervisor publishes, an enabled server is starting to connect. phase: state?.phase ?? "connecting", - reconnecting: state !== null && (state.attempt > 1 || state.lastFailure !== null), + // Upstream's `presentConnectionState` rule for "Reconnecting". + reconnecting: + state !== null && + (state.phase === "backoff" || + (state.phase === "connecting" && (state.attempt > 1 || state.lastFailure !== null))), ...(supported === undefined ? {} : { supported }), guest, result: