refactor(server): simplify listener lifecycle#27413
Merged
Merged
Conversation
a3aa1f4 to
eccd81e
Compare
eccd81e to
6fd0cda
Compare
The forceRequested Ref + trailing re-yield of forceCloseOnce only forced graceful stops to wait for a concurrent force-close's WebSocketTracker cleanup. The scope close already triggers closeAllConnections via the serverRef.forceStop flag, so all callers observe the same end state without it.
Add the previously-untested edge cases: - port: 0 prefers 4096 when free - port: 0 falls back to a random port when 4096 is taken - mDNS is skipped on loopback hostnames - mDNS publishes on non-loopback hostnames and unpublishes on stop(true) - mDNS unpublishes on graceful stop() via the scope finalizer
d782361 to
fb62bc6
Compare
rustybret
pushed a commit
to rustybret/opencode
that referenced
this pull request
May 15, 2026
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.
Summary
Server.listento a Promise facade over an Effect-native listener lifecycle with named startup, port fallback, mDNS, force-close, and stop helpers.Effect.cachedonce-only shutdown effects and register mDNS cleanup on the listener scope.ExperimentalHttpApiServertoHttpApiApp.opencode.server.backendroute middleware that was only useful during the old backend split.Sent HTTP responselogs to stderr.Testing
bunx prettier --write src/server/server.ts src/server/routes/instance/httpapi/server.ts test/server/httpapi-ui.test.ts test/server/httpapi-listen.test.ts test/server/httpapi-cors.test.tsfrompackages/opencodebunx oxlint packages/opencode/src/server/server.ts packages/opencode/src/server/routes/instance/httpapi/server.ts packages/opencode/test/server/httpapi-ui.test.ts packages/opencode/test/server/httpapi-listen.test.ts packages/opencode/test/server/httpapi-cors.test.tsfrom repo root (warnings only in pre-existing listen-test assertions)bun typecheckfrompackages/opencodebun test --timeout 30000 test/server/httpapi-listen.test.ts test/server/httpapi-cors.test.ts test/server/httpapi-ui.test.tsfrompackages/opencode6fd0cda3eviabun devand verified the current PR branch no longer printsSent HTTP responselogs during startup or/statusorigin/dev...origin/refactor/server-listener-lifecyclefor API surface, behavioral equivalence, safety/edge cases, test coverage, and dead-code cleanup.Notes
bun turbo typecheckwas attempted with the repo-pinned Bun 1.3.13, but still fails in unrelatedpackages/coreBun/DOM response typings.port: 0prefers-4096 fallback path. Both are preserved by inspection; testing them would require extra global stubbing or port coordination.