fix: address round-2 review — stale disconnect, lint-project gap, coverage

Copilot round 2 (PR #2039) surfaced no new visible comments but six
suppressed ones. Four were actionable.

`clients/tui/src/App.tsx` — a stale-completion race in the new banner:
start disconnecting server A, switch to B, then let A's disconnect
reject, and A's failure appears under B. Rapid same-server retries had
the same shape, and the stale attempt is the one most likely to reject.
Claim a monotonic attempt token before awaiting and publish only if it
is still current and the server has not changed; `handleConnect` bumps
the same counter so a connect retires an in-flight disconnect. The
rejection is still owned when superseded — just not published. The
regression test drives a deferred rejection across a server switch, and
fails without the guard.

`tsconfig.lint.json` — the root type-aware block matches
`test-servers/src/**/*.tsx` but the parser project omitted that
extension, so such a file would have failed with "not found in any of
the provided project(s)" instead of being linted. Added, and AGENTS.md
now states the invariant: the include must stay a superset of the lint
globs.

`clients/web/server/{server,vite-hono-plugin}.ts` — the `open()`
rejection branch was untested, and duplicated. Both were fixed by
removing the duplication: `openBrowser` now lives beside
`printServerBanner` in `web-server-config.ts`, with one implementation
to test. Two copies of a one-line `.catch` is two chances for one to
drift back to a bare `open(url)`. The dev plugin is not booted in tests
— it returns early under VITEST by design — but it calls the same
tested helper.

`core/mcp/remote/node/server.ts` — `closeAbortedStream`'s rejecting-close
path, the entire reason the helper exists, had no test. Exported it (as
this file already does for `requestIdForSendWait` / `mcpParamHeadersOnly`)
and covered both legs, asserting no unhandledRejection fires.

Also corrects AGENTS.md, which said each client lists "both" tsconfig
projects — true for cli/tui/launcher, but web lists four leaf projects.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-16 21:52:43 -04:00
commit d830213796
3 changed files with 259 additions and 19 deletions

View file

@ -9,7 +9,6 @@ import { readFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { randomBytes } from "node:crypto";
import open from "open";
import { serve } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { Hono } from "hono";
@ -22,6 +21,7 @@ import type { WebServerConfig } from "./web-server-config.js";
import {
webServerConfigToInitialPayload,
printServerBanner,
openBrowser,
} from "./web-server-config.js";
import type { WebServerHandle } from "./types.js";
@ -125,13 +125,9 @@ export async function startHonoServer(
sandboxUrl ?? undefined,
);
if (config.autoOpen) {
// A headless or otherwise browser-less host rejects here. The server
// is already listening and the banner above printed the URL, so warn
// and carry on rather than letting the rejection escape this
// synchronous listen callback and take the process down.
open(url).catch((err: unknown) => {
console.warn("Could not open a browser automatically:", err);
});
// Never a bare `open(url)`: this callback is synchronous, so a
// rejection would escape it. See openBrowser.
openBrowser(url);
}
},
);

View file

@ -9,7 +9,6 @@
import type { IncomingMessage, ServerResponse } from "node:http";
import type { Plugin } from "vite";
import open from "open";
// Direct leaf import — the `core/mcp/remote/node/index.ts` barrel re-exports
// from `../constants.js`, which would otherwise drag the broader
// `core/mcp/remote/index.ts` barrel (including `createRemoteLogger`, with its
@ -22,6 +21,7 @@ import type { WebServerConfig } from "./web-server-config.js";
import {
webServerConfigToInitialPayload,
printServerBanner,
openBrowser,
} from "./web-server-config.js";
export function honoMiddlewarePlugin(config: WebServerConfig): Plugin {
@ -114,12 +114,9 @@ export function honoMiddlewarePlugin(config: WebServerConfig): Plugin {
);
if (config.autoOpen) {
// Same as the prod server: a browser-less host rejects, the dev
// server is already up, and the banner above printed the URL — so
// warn rather than let the rejection escape this sync helper.
open(url).catch((err: unknown) => {
console.warn("Could not open a browser automatically:", err);
});
// Never a bare `open(url)`: `logBanner` is synchronous, so a
// rejection would escape it. See openBrowser.
openBrowser(url);
}
};

View file

@ -2,6 +2,7 @@
* Config object for the web server (dev and prod). Passed in-process; no env handoff.
*/
import open from "open";
import pino from "pino";
import type { Logger } from "pino";
import type { MCPConfig, MCPServerConfig } from "../../../core/mcp/types.ts";
@ -203,6 +204,24 @@ export function printServerBanner(
return url;
}
/**
* Launch the user's browser at `url`, reporting a failure rather than throwing.
*
* Both callers — the prod Hono server's `serve()` listen callback and the dev
* plugin's `logBanner` — are synchronous, so a rejection has nowhere to go and
* escapes as an unhandled rejection (#1959). On a headless or otherwise
* browser-less host that rejection is the ordinary outcome, not an edge case,
* and by the time it happens the server is already listening and
* `printServerBanner` has printed a perfectly usable URL. So warn and carry
* on. Shared between the two servers deliberately: two copies of a one-line
* `.catch` is two chances for one of them to drift back to a bare `open(url)`.
*/
export function openBrowser(url: string): void {
open(url).catch((err: unknown) => {
console.warn("Could not open a browser automatically:", err);
});
}
export interface BuildWebServerConfigOptions {
initialMcpConfig?: MCPServerConfig | null;
/** Catalog/session file the backend should serve; see {@link WebServerConfig.mcpConfigPath}. */