Dashboard › opencode › Distillation
0d88a2b9-f2cc-46fb-8b2c-7ecc4c55d038["lore_tm_v1_jkJIaIZMPM49fHFVyABz-zuHE2EqBsst5mDwCX2Cv60"]
Date: Sep 14, 2026
packages/opencode/src/server/server.ts line 1 imports ./init-projectors as a startup side effect before other imports; the file itself contains no explicit session-continuation or busy-session recovery hook.packages/opencode/src/server/server.ts defines listen(opts) by running listenEffect(opts) with Effect.runPromise; listenEffect starts the listener via startWithPortFallback(opts), resolves its TCP address, constructs the listener URL, configures mDNS, assigns the module-level url, and returns hostname, port, url, and an Effect-based stop.packages/opencode/src/server/server.ts listener startup uses HttpRouter.serve(HttpApiApp.createRoutes(opts), { middleware: disposeMiddleware, disableLogger: true, disableListenLog: true }), provides AppNodeBuilder.build(WebSocketTracker.node), provides the Node HTTP server layer, and installs a fresh ConfigProvider.layer(ConfigProvider.fromEnv()) per listener so later Server.listen() calls observe current process.env rather than Effect’s initially cached environment snapshot.packages/opencode/src/server/server.ts port fallback behavior: when opts.port !== 0, startListener(opts, opts.port) is used; explicit port 0 first tries port 4096, then falls back to any free port by calling startListener(opts, 0) if the first attempt fails.startListener(...) in packages/opencode/src/server/server.ts creates an unsafe Scope, builds listenerLayer(...) with a fresh unsafe memo map, provides HttpApiApp.context, closes the scope on startup error, and captures HttpServer.HttpServer, ListenerServerService, and WebSocketTracker.Service in ListenerState.tcpAddress(...) in packages/opencode/src/server/server.ts accepts only TcpAddress; for any other HTTP server address tag it closes the listener scope and dies with Unexpected HttpServer address tag: ${state.server.address._tag}.packages/opencode/src/server/server.ts: publishing occurs only when opts.mdns is enabled, the port is truthy, and the hostname is not 127.0.0.1, localhost, or ::1; it calls MDNS.publish(port, opts.mdnsDomain), registers cached MDNS.unpublish() as a scope finalizer, and logs mDNS enabled but hostname is loopback; skipping mDNS publish for loopback hosts.packages/opencode/src/server/server.ts caches both force-close and scope-close operations so each runs once; stop(close) first unpublishes mDNS, optionally force-closes active HTTP sockets and tracked WebSockets when close is truthy, then closes the scope and clears the module-level url only if it still matches that listener’s URL.forceClose(...) in packages/opencode/src/server/server.ts concurrently runs state.http.closeAll and state.websockets.closeAll with { concurrency: "unbounded", discard: true }.serverLayer(...) in packages/opencode/src/server/server.ts uses Node’s createServer() and NodeHttpServer.layer(..., { port, host, gracefulShutdownTimeout: "1 second" }); it monkey-patches server.close to track shutdown and invoke server.closeAllConnections() when force-stop is enabled, while ListenerServerService.closeAll sets forceStop = true and immediately closes all connections if graceful shutdown has already started.packages/opencode/src/server/server.ts exports Default, whose lazy ServerApp delegates fetch to HttpApiApp.webHandler().handler(request, HttpApiApp.context) and implements request(...) by resolving non-Request inputs against http://localhost; openapi() returns OpenApi.fromApi(PublicApi), and the module self-reexports with export * as Server from "./server".