Skip to content

Commit 1ab36f4

Browse files
PR Batch Testerclaude
andcommitted
fix(server): owned listeners keep the configured URL when its check fails
When the configured preview URL for an owned listener failed its check, the scanner listed the raw http://localhost:<port> instead, dropping the configured scheme and path. The per-subscriber projection now keeps that caller's first configured URL for the listener. Unowned listeners still need a passing check, and no new requests are sent. Also stop calling every passively listed port a browser-ready web server in the preview empty state and the thread details docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4ce5589 commit 1ab36f4

4 files changed

Lines changed: 55 additions & 25 deletions

File tree

‎apps/server/src/preview/PortScanner.test.ts‎

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,19 @@ effectIt.effect("preserves explicit loopback hosts and bounds wildcard rewrites"
185185
effectIt.effect("projects configured paths independently for simultaneous subscribers", () => {
186186
const docsUrl = `http://localhost:${LSOF_TEST_PORT}/docs`;
187187
const adminUrl = `http://localhost:${LSOF_TEST_PORT}/admin`;
188+
let ready = true;
188189
const fetchFn = ((input: Parameters<typeof globalThis.fetch>[0]) => {
189190
const url = String(input);
190191
return Promise.resolve(
191-
url === docsUrl || url === adminUrl
192+
ready && (url === docsUrl || url === adminUrl)
192193
? new Response("app", { headers: { "content-type": "text/html" } })
193194
: new Response("not found", { status: 404 }),
194195
);
195196
}) as typeof globalThis.fetch;
196197
const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn });
197198

198199
return Effect.gen(function* () {
199-
const scanner = yield* PortScanner.PortDiscovery;
200+
const scanner = yield* ownedScanner();
200201
const docsSnapshots: ReadonlyArray<DiscoveredLocalServer>[] = [];
201202
const adminSnapshots: ReadonlyArray<DiscoveredLocalServer>[] = [];
202203
yield* scanner.subscribe({ configuredUrls: [docsUrl], initialSnapshot: [] }, (servers) =>
@@ -209,6 +210,11 @@ effectIt.effect("projects configured paths independently for simultaneous subscr
209210

210211
expect(docsSnapshots.at(-1)?.[0]?.url).toBe(docsUrl);
211212
expect(adminSnapshots.at(-1)?.[0]?.url).toBe(adminUrl);
213+
214+
ready = false;
215+
yield* TestClock.adjust(Duration.seconds(15));
216+
expect(docsSnapshots.at(-1)?.[0]?.url).toBe(docsUrl);
217+
expect(adminSnapshots.at(-1)?.[0]?.url).toBe(adminUrl);
212218
}).pipe(Effect.scoped, Effect.provide(layer));
213219
});
214220

@@ -300,25 +306,43 @@ effectIt.effect("uses the current configured fragment when readiness comes from
300306
}).pipe(Effect.provide(layer));
301307
});
302308

303-
effectIt.effect("probes only a configured HTTPS URL and does not follow its redirects", () => {
304-
const configuredUrl = `https://localhost:${LSOF_TEST_PORT}/app`;
305-
const requests: Array<readonly [string, string | undefined]> = [];
306-
const fetchFn = (async (
307-
input: Parameters<typeof globalThis.fetch>[0],
308-
init?: Parameters<typeof globalThis.fetch>[1],
309-
) => {
310-
requests.push([String(input), init?.redirect]);
311-
return new Response(null, { status: 302, headers: { location: "https://example.com" } });
312-
}) as typeof globalThis.fetch;
313-
const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn });
309+
effectIt.effect(
310+
"probes only a configured HTTPS URL, keeps it for an owned listener when the check fails, and does not follow redirects",
311+
() => {
312+
const configuredUrl = `https://localhost:${LSOF_TEST_PORT}/app`;
313+
const requests: Array<readonly [string, string | undefined]> = [];
314+
let respond = async () =>
315+
new Response(null, { status: 302, headers: { location: "https://example.com" } });
316+
const fetchFn = (async (
317+
input: Parameters<typeof globalThis.fetch>[0],
318+
init?: Parameters<typeof globalThis.fetch>[1],
319+
) => {
320+
requests.push([String(input), init?.redirect]);
321+
return respond();
322+
}) as typeof globalThis.fetch;
323+
const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn });
314324

315-
return Effect.gen(function* () {
316-
const scanner = yield* ownedScanner();
317-
const servers = yield* scanner.scan([configuredUrl]);
318-
expect(servers).toMatchObject([{ pid: 1234, url: configuredUrl }]);
319-
expect(requests).toEqual([[configuredUrl, "manual"]]);
320-
}).pipe(Effect.provide(layer));
321-
});
325+
return Effect.gen(function* () {
326+
const scanner = yield* ownedScanner();
327+
expect(yield* scanner.scan([configuredUrl])).toMatchObject([
328+
{ pid: 1234, url: configuredUrl },
329+
]);
330+
331+
respond = async () => new Response("unavailable", { status: 503 });
332+
yield* TestClock.adjust(Duration.seconds(15));
333+
expect(yield* scanner.scan([configuredUrl])).toMatchObject([
334+
{ pid: 1234, url: configuredUrl },
335+
]);
336+
337+
respond = () => Promise.reject(new TypeError("fetch failed"));
338+
yield* TestClock.adjust(Duration.seconds(15));
339+
expect(yield* scanner.scan([configuredUrl])).toMatchObject([
340+
{ pid: 1234, url: configuredUrl },
341+
]);
342+
expect(requests).toEqual(Array.from({ length: 3 }, () => [configuredUrl, "manual"]));
343+
}).pipe(Effect.provide(layer));
344+
},
345+
);
322346

323347
effectIt.effect("discovers owned listeners without sending HTTP or TLS probes", () => {
324348
const owned = `p1234\ncnode\nn[::1]:${LSOF_TEST_PORT}\n`;

‎apps/server/src/preview/PortScanner.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,22 @@ const projectWebProbeSnapshot = (
192192
configuredUrls: ReadonlyArray<string>,
193193
): ReadonlyArray<DiscoveredLocalServer> => {
194194
const visibleByServer = new Map<string, DiscoveredLocalServer>();
195+
const firstConfiguredByServer = new Map<string, string>();
195196
for (const raw of normalizeConfiguredUrls(configuredUrls)) {
196197
const url = new URL(raw);
197198
const port = urlPort(url);
198199
const serverKey = localServerKey(url.hostname, port);
200+
if (!firstConfiguredByServer.has(serverKey)) firstConfiguredByServer.set(serverKey, raw);
199201
if (visibleByServer.has(serverKey)) continue;
200202
const configured = snapshot.configured.get(webProbeCacheKey(raw));
201203
if (configured) visibleByServer.set(serverKey, { ...configured, url: raw });
202204
}
205+
// An owned listener whose configured check failed still opens at this caller's configured URL.
203206
for (const server of snapshot.discovered) {
204207
const key = localServerKey(server.host, server.port);
205-
if (!visibleByServer.has(key)) visibleByServer.set(key, server);
208+
if (visibleByServer.has(key)) continue;
209+
const configuredUrl = firstConfiguredByServer.get(key);
210+
visibleByServer.set(key, configuredUrl ? { ...server, url: configuredUrl } : server);
206211
}
207212
return [...visibleByServer.values()].toSorted((left, right) => left.port - right.port);
208213
};

‎apps/web/src/components/preview/PreviewEmptyState.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function PreviewEmptyState({
4040
</EmptyMedia>
4141
<EmptyTitle>No preview yet</EmptyTitle>
4242
<EmptyDescription>
43-
Type a URL above, or run a dev script. Browser-ready localhost servers will show up here
43+
Type a URL above, or run a dev script. Local servers this thread starts will show up here
4444
automatically.
4545
</EmptyDescription>
4646
</Empty>

‎docs/user/thread-sidebar.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,10 @@ Expand a tool call in the conversation to see its full command and output.
270270
Summaries shorten shell wrappers and can still describe the latest call after it
271271
finishes; the call's own result shows its status.
272272

273-
On web and desktop, the thread details card lists the web servers that the
274-
thread's terminals or its Claude agent started, with their ports. A server the
275-
agent started stays listed after the agent's turn ends.
273+
On web and desktop, the thread details card lists the local servers that the
274+
thread's terminals or its Claude agent started, with their ports. Not every one
275+
serves a web page. A server the agent started stays listed after the agent's
276+
turn ends.
276277
Select a server to open it in the browser panel. **Stop** ends the server's job
277278
and keeps the agent, the terminal, and T3 Code running. Stop needs terminal
278279
access to the environment and is not available on Windows.

0 commit comments

Comments
 (0)