GeezerVison is showing github.com — fix(cli): move the WSL service port out of the Windows reserved range by neriousy · Pull Request #66613 · anomalyco/opencode
Conversation
neriousy
commented
Nov 26, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #62532
Earlier attempts: #54988, #62533, #62904
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
WSL forwards its localhost ports to the same port on Windows. That makes the Windows port reservations apply to WSL too, and 49374 often lands in a block Hyper-V/WinNAT reserves at boot. The service still binds fine inside WSL, but Windows can't reach it, so opencode pair links fail.
- WSL (detected from the kernel release,
microsoft) now defaults to the 0x6000 block: 0xC0DE → 0x60DE = 24798, local → 24799. It's below 32768 like Windows' 28894, but a different block, so a Windows service and a WSL service don't fight over the shared loopback.
- On WSL the first password (service start,
service get password or service set password) is written together with the port, so a new setup keeps 24798 even if the default changes later.
- Backwards compat: that makes a WSL config with a password but no port one an older build wrote, so it keeps
49374 without saving it. Existing pairings, machine links, tunnels and bookmarks keep working, and a later release can still move those setups.
- macOS, Linux and Windows don't change.
--port and service set port still win.
- Docs list the WSL port and the
service set port 24798 move for older setups.
No flag, it's a fix.
How did you verify your code works?
bun test test/service.test.ts in packages/cli: 35 pass. New tests cover the WSL ports, the old-port fallback and recording the port only on WSL.
bun typecheck in packages/cli.
- Not run on a real WSL host yet.
Screenshots / recordings
n/a
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #50672
Public API: changes the default service port on WSL from 49374 to 24798 for new setups and saves it in the service config with the first password (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not verified on a real WSL host: this needs Windows with WSL2 and port reservations, and the sandbox is Linux only. service.test.ts passes (34 pass, 1 skip). The type check passes with tsc -b; the typecheck script itself fails here with Script not found "check".
Public API: the default service port on WSL changes from 49374 to 24798 (local: 49375 → 24799) for new setups, and on WSL the service now writes port into service.json on its first default-port start. --port and service set port still win, and macOS, Linux and Windows don't change, so this is backwards compatible.
Main concern (inline): the old-port fallback keeps every existing WSL install on 49374. That includes the setup in #62532 and anyone else hitting this today. recordPort then pins that port in the config, so those users stay on it until they run service set port. Also, a password is not a reliable sign of an older setup: service get password and service set password write one before the service has ever run.
Related: #50672
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
// WSL services set up before WSL got its own default have a password but no recorded port. They keep 0xC0DE, the port
|
|
|
// their pairings, tunnels and saved links use.
|
|
|
export function servicePort(config: Info, channel = OPENCODE_CHANNEL, platform = hostPlatform()) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This keeps every existing WSL install, so in practice everyone currently hitting #62532, on 49374. Then recordPort (server-process.ts:160) writes 49374 into the config the first time the new build starts. After that, these users can only move by running service set port, and a later default change can't help them either. That's the opposite of what the comment on recordPort intends.
If keeping old links working matters more than moving people off the broken port, can we at least skip recordPort when this fallback picks the port? Then the only cost is staying on 49374 for now, rather than being pinned there. Alternatively, move everyone to 24798 and accept that saved links break once; 49374 doesn't work from Windows anyway after a reboot that reserves it.
Also, password !== undefined isn't a reliable sign of an older setup. opencode service get password (via password()) and service set password both write a password before the service has ever run, so a new install can be wrongly treated as an old one and land on 49374.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both points from my earlier thread are fixed. A WSL setup from an older build keeps 49374 without saving it, so a later release can still move it. On WSL, the first password (from a service start, service get password or service set password) is now saved together with the WSL default port, so a password alone no longer marks a new setup as an older one. Nothing new from these commits.
Still not checked on a real WSL host. With the new commits, service.test.ts passes (34 pass, 1 skip) and tsc -b passes.
Public API: same as before. The default service port on WSL changes from 49374 to 24798 (local: 49375 → 24799) for new setups, and on WSL port is now written into service.json together with the first password. Backwards compatible.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|