You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parent: #10107. Closes the unticked acceptance boxes of #8509 ("OpenCode's TUI worker starts, serves requests, reloads, and terminates cleanly"; "parser/diff worker smoke tests").
Facts
TUI server worker — packages/opencode/src/cli/cmd/tui.ts:210-214: new Worker(file, { env: Object.fromEntries(...) }) where file = await target() (tui.ts:52-56: define OPENCODE_WORKER_PATH else new URL("../tui/worker.ts", import.meta.url)). Entry packages/opencode/src/cli/tui/worker.ts. Parent talks over Rpc.client<typeof rpc>(worker) (structured-clone messages), client.call("reload") on SIGUSR2 (tui.ts:216-220), client.call("shutdown") + worker.terminate() on stop (tui.ts:224-230). The worker hosts the whole server/session runtime (Effect, sqlite, providers) — i.e. most of the graph executes on the worker thread.
OpenTUI tree-sitter worker — @opentui/core/chunk-bun-t2myhmwd.js:8398new Worker(workerPath) with workerPath from define OTUI_TREE_SITTER_WORKER_PATH else import.meta.resolve("@opentui/core/parser.worker") (:8464). Entry @opentui/core/parser.worker.js (Emscripten loader + grammars, runtime/AOT (refines #8508): Emscripten main+side-module loading (web-tree-sitter + grammars) and wasm-bindgen (photon) for OpenCode v1.18.30 #10102). Inside the worker the code uses nodeparentPort from node:worker_threads (parser.worker.js:3621, chunk:8203) while the parent uses the Web Worker API: both shapes must interoperate.
thread-stream (thread-stream/index.js:72, pino transport) — only on the GitLab login path via fastify; low priority.
Also: write-file-atomic only reads worker_threads.isMainThread; source-map-support checks isMainThread (Code Mode path).
Worker options: env (full copy of process.env), terminate(), error/exit events, postMessage structured clone of the RPC payloads used by packages/opencode/src/cli/tui/worker.ts (plain objects, arrays, strings, Uint8Array), parentPort.on("message") inside the worker.
Async-context/GC: the worker runs the Effect runtime and sqlite; confirm moving-GC roots and native handles are per-thread safe (ws/pty/sqlite handles created on the worker).
Signals: SIGUSR2 reload path.
Acceptance
Native binary TUI boots: worker starts, first RPC round-trip completes, first frame renders.
kill -USR2 <pid> triggers client.call("reload") without crashing; Ctrl-C shuts down within the 5 s timeout and exits 0.
A reduced fixture (parent .ts + worker .ts using new URL("./w.ts", import.meta.url) and a parentPort-style worker) is added to crates/perry/tests and passes on macOS and Linux.
Parent: #10107. Closes the unticked acceptance boxes of #8509 ("OpenCode's TUI worker starts, serves requests, reloads, and terminates cleanly"; "parser/diff worker smoke tests").
Facts
packages/opencode/src/cli/cmd/tui.ts:210-214:new Worker(file, { env: Object.fromEntries(...) })wherefile = await target()(tui.ts:52-56: defineOPENCODE_WORKER_PATHelsenew URL("../tui/worker.ts", import.meta.url)). Entrypackages/opencode/src/cli/tui/worker.ts. Parent talks overRpc.client<typeof rpc>(worker)(structured-clone messages),client.call("reload")onSIGUSR2(tui.ts:216-220),client.call("shutdown")+worker.terminate()on stop (tui.ts:224-230). The worker hosts the whole server/session runtime (Effect, sqlite, providers) — i.e. most of the graph executes on the worker thread.@opentui/core/chunk-bun-t2myhmwd.js:8398new Worker(workerPath)withworkerPathfrom defineOTUI_TREE_SITTER_WORKER_PATHelseimport.meta.resolve("@opentui/core/parser.worker")(:8464). Entry@opentui/core/parser.worker.js(Emscripten loader + grammars, runtime/AOT (refines #8508): Emscripten main+side-module loading (web-tree-sitter + grammars) and wasm-bindgen (photon) for OpenCode v1.18.30 #10102). Inside the worker the code uses nodeparentPortfromnode:worker_threads(parser.worker.js:3621,chunk:8203) while the parent uses the WebWorkerAPI: both shapes must interoperate.thread-stream/index.js:72, pino transport) — only on the GitLab login path via fastify; low priority.Also:
write-file-atomiconly readsworker_threads.isMainThread;source-map-supportchecksisMainThread(Code Mode path).Scope
new URL(relative, import.meta.url);import.meta.resolve(pkg-subpath)— compile: build-time defines (--define, Bun.build semantics) and the no-define fallbacks OpenCode relies on (import.meta.resolve,new URL(..., import.meta.url)) #10101), compiled as separate native entries packaged with the binary (per AOT: compile and register Web Worker entry modules used by full-source OpenCode #8509).Workeroptions:env(full copy ofprocess.env),terminate(), error/exit events,postMessagestructured clone of the RPC payloads used bypackages/opencode/src/cli/tui/worker.ts(plain objects, arrays, strings, Uint8Array),parentPort.on("message")inside the worker.SIGUSR2reload path.Acceptance
kill -USR2 <pid>triggersclient.call("reload")without crashing; Ctrl-C shuts down within the 5 s timeout and exits 0..ts+ worker.tsusingnew URL("./w.ts", import.meta.url)and aparentPort-style worker) is added tocrates/perry/testsand passes on macOS and Linux.