Fix port conflicts for concurrent sessions by dynamically assigning ports#2156
Merged
GeorgeNgMsft merged 15 commits intomainfrom Apr 9, 2026
Merged
Fix port conflicts for concurrent sessions by dynamically assigning ports#2156GeorgeNgMsft merged 15 commits intomainfrom
GeorgeNgMsft merged 15 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves agent shutdown/startup robustness to reduce port-collision (EADDRINUSE) failures and to better clean up spawned processes/servers.
Changes:
- Add explicit
EADDRINUSEhandling when starting the Montage route server and the Browser agent’sBaseServer. - Ensure Montage view process is terminated during context close.
- Add
closeAgentContextto the Browser agent to stop the websocket server and kill spawned processes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ts/packages/agents/montage/src/route/route.ts | Wraps listen() to capture and report EADDRINUSE / server start failures |
| ts/packages/agents/montage/src/agent/montageActionHandler.ts | Kills viewProcess on context close to avoid leakage |
| ts/packages/agents/browser/src/views/server/core/baseServer.ts | Rejects start() on port-in-use instead of silently hanging/never resolving |
| ts/packages/agents/browser/src/agent/browserActionHandler.mts | Adds closeAgentContext to stop websocket server and kill spawned processes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Set exit code instead of calling exit directly. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…be a critical exception
…icrosoft/TypeAgent into dev/georgeng/fix_as_easddr_use
…, rather than naive incremental retries
…icrosoft/TypeAgent into dev/georgeng/fix_as_easddr_use
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
ts/packages/dispatcher/dispatcher/src/context/appAgentManager.ts:529
manifest.localViewagents now storerecord.port = 0, which is treated as a real port elsewhere (e.g. activity handling openshttp://localhost:0/whenopenLocalViewis requested). Consider keepingrecord.portasundefineduntil the view server reports its actual bound port viasetLocalHostPort(), and separately pass0only as the requested listen port when initializing/spawning the view server.
const port = manifest.localView ? 0 : undefined;
if (port !== undefined) {
debug(`Dynamic port (OS-assigned) reserved for ${appAgentName}`);
}
const record: AppAgentRecord = {
name: appAgentName,
provider,
actions: new Set(),
schemas: new Set(),
schemaErrors,
commands: false,
manifest,
port,
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…dler success reporting to the right place
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.
Goal
Eliminate port conflicts when multiple TypeAgent sessions start concurrently by switching from pre-assigned static ports to OS-assigned dynamic ports. Agents now bind on port 0 and report their actual bound port back to the dispatcher via IPC.
Also cleanup server startup/exit for browser & montage agents.
Summary