Repository navigation
fix(pi): a busy fixed port no longer crashes Pi when a second annotate opens - #1733
Merged
Merged
Conversation
…xed port cannot crash Pi With PLANNOTATOR_PORT set in a local Pi session, a second /plannotator-annotate while a review was open killed Pi with exit 1: the agent terminal's WebSocketServer (ws) was attached to the http server before listen, re-emits every server 'error' as its own, and has no handler, so the first EADDRINUSE became an unhandled 'error' before listenOnPort's retry and the self-preemption that takes the port over could run. Remote mode never crashed only because the agent terminal is off there. The bridge is now created once the port is bound, and a failed bind disposes the client lease and AI runtime (not the process-wide file browser watchers, which belong to the open sessions). The local fixed-port case now behaves like remote mode: the new command takes the port over from the stale session. The plannotator tool's fixed-port refusal is unchanged.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a local Pi session with
PLANNOTATOR_PORTset (not remote mode), opening a second/plannotator-annotatewhile a review is open killed Pi with exit code 1:This reproduces on 0.28.4 and 0.28.5, with Pi 0.85.1 and 1.0.2.
Cause
apps/pi-extension/server/serverAnnotate.tsattached the annotate agent terminal's WebSocket server to the http server beforelistenOnPortran. ThewsWebSocketServerre-emits every http servererroras its own. It has noerrorhandler, and the@plannotator/webtuiwrapper does not expose the instance, so nothing can add one. So the firstEADDRINUSEbecame an unhandlederrorevent, and it killed the process before two things could run:listenOnPortstartServerWithSelfPreemption, which takes the port overRemote mode never crashed only because the agent terminal is off there.
Fix
wslistener, so a busy port is an ordinary rejection.server.close()doesn't free port — next annotate/review fails with EADDRINUSE #1159 self-preemption), and Pi stays up.plannotatortool's fixed-port refusal (fixedPortBusyText).Bun.serveupgrades rather than awsserver, and a busy fixed port fails cleanly withPortInUseError(checked with a real port:Port 19681 in use after 5 retries, and the first session keeps serving).Tests
apps/pi-extension/server/annotate-fixed-port.test.ts, which uses real ports:PLANNOTATOR_PORTrejects with the port-in-use error, and the open session keeps serving. On main this test fails with the unhandledemitError.startServerWithSelfPreemptiontakes the port over for a second annotate session, with the agent terminal enabled.bun test apps/pi-extension: 438 pass.bun run typecheck(includesvendor.sh): clean.npm pack --dry-runinapps/pi-extension: OK.-e, local mode withPLANNOTATOR_PORT, two/plannotator-annotatein a row (harness/tmp/pi0281/fixport-verify.mjs):WebSocketServerEADDRINUSEtrace.