Skip to content

tui: worker terminate races in-flight RPC and current-swap; thread-mode closed promise never resolves #401

Closed

Description

@mdev34-lab

Severity: medium | global review pass P3.

packages/opencode/src/cli/tui/worker-process.ts:154-161,196,253-272: terminate() sets stopping, disconnect(), kill(SIGTERM), awaits exited - but if terminate runs between launch() and exited registration while current was swapped to a replacement after a crash, disconnect/kill hits the stale child and the new child stays orphaned. The thread path createThreadWorker.terminate (:272) is sync worker.terminate() with no await and signal is a no-op: tui.ts:261 await worker.terminate() returns immediately while the thread is still flushing Rpc.emit("global.event"), and the closed promise (resolved only via worker.onerror) never resolves in thread mode, leaking the onExit error toast.

Repro: crash the worker then immediately Ctrl-C; two current processes, closed hangs, onExit not called in thread mode. Fix size: small (capture childToKill=current before swap; await both exited and the thread terminate promise; make the signal no-op explicit).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions