Files
backnotprop__plannotator/apps/pi-extension/browser-session-error.ts
Syahrul 0d9128794f fix: release pi review ports on session shutdown (#1160)
* fix: release pi review ports on session shutdown

* fix(pi): self-preempt stale sessions on fixed-port contention

A session abandoned without a decision keeps listening on the fixed
remote port in this long-lived process, so the next command's bind
fails (#1159). On a port-in-use or range-exhausted start failure,
stop every tracked browser session and retry once. Also: guard
closeAllConnections for older runtimes, downgrade the superseded
session notification from error to info, and cover the preemption
and stop-drain paths with tests.

* fix(pi): harden session preemption per independent review

Age-gate the preemption sweep so a concurrent command's fresh session
is never stopped, drop the session_shutdown sweep (sessions
deliberately outlive in-process session replacement so cross-session
feedback keeps working; process teardown frees ports anyway), make
server stop() and the sweep exception-safe, register archive sessions
in the registry, type the stopped error instead of matching prose,
handle a stopped plan review without a false startup error, keep the
tests from launching a real browser, and pin the call-site wrappings.

---------

Co-authored-by: Michael Ramos <mdramos8@gmail.com>
2026-08-03 13:25:32 -07:00

14 lines
542 B
TypeScript

/**
* Typed marker for the "browser session was stopped" outcome.
*
* Kept in a zero-import module so index.ts can classify the error
* synchronously without pulling in plannotator-browser.ts's heavy
* server/browser import graph.
*/
export const BROWSER_SESSION_STOPPED = "PlannotatorBrowserSessionStopped";
/** True when an error is the typed stopped-session outcome, not a real failure. */
export function isBrowserSessionStoppedError(err: unknown): boolean {
return err instanceof Error && err.name === BROWSER_SESSION_STOPPED;
}