Repository navigation
Description
What happens
Under OpenCode 2.3.0, a Cursor background shell (background_shell_spawn_args, or a soft-background shell_stream_args after its foreground window) is stopped partway through. The terminal record stays status: running with no footer, and the provider posts "Background shell N ended without reporting an exit code; its supervisor stopped before the command finished". How long the job lives depends on how many other shell commands run in that OpenCode instance: 3 to 68 minutes on a busy machine. On one host it hit 83 of 173 background shells in a day on 2.3.0, and 0 of 109 the day before on 2.2.x.
Why
OpenCode 2.3.0 runs Unix shell-tool commands through its process daemon ("Shell commands now survive server handoffs"). The daemon:
- spawns each command with
process_group(0)(packages/process-daemon/src/service/pipe/unix.rs, theCommandbuilder), - keeps the exited leader unreaped so its PGID stays reserved,
- keeps the last
EXITED_LIMIT = 25exited commands per shell service (packages/core/src/shell.ts), and when it forgets the oldest,Shell.remove→pty.terminatePipe→ daemonProcess::kill→killpg(pid, SIGKILL). The comment there: "This also kills what is left of its group, even after a successful exit, which a spawned command would leave running".
createManagedTerminal (src/terminal-runner.ts) starts the supervisor with
nohup "$cursor_runner" "$cursor_job/runner.sh" >"$cursor_job/launcher.log" 2>&1 </dev/null &so runner.sh (and its updater and watchdog subshells) stay in the launcher's process group. 25 shell exits later the daemon SIGKILLs that group. The supervisor dies without finalizing, group.sh's lifeline watcher sees EOF and stops the payload (command-exit 143), and the provider reports the lost supervisor. A live probe showed the supervisor's PGID equal to the launcher, which was [sh] <defunct> with parent opencode-pty daemon.
Repro without OpenCode
# launcher as a group leader, as the daemon runs it
setsid sh -c "$LAUNCHER" # a backgroundSpawn launcher for: sleep 5; echo done
kill -KILL -<launcher pid> # what the daemon does once 25 later commands have exited
# 7fa8f95 / upstream 2ea6994: the record stays "running"; the job is goneFix we use (fork branch fix/supervisor-own-session, nkoynov/cursor-opencode-provider@7fa8f95...fix/supervisor-own-session)
- Start the runner in its own session where
setsidexists (nohup setsid "$cursor_runner" …;setsiddoesn't fork for a non-leader child, so$!stays the supervisor). Withoutsetsid(macOS) nothing changes. - Keep cancellation: the launcher holds the only write end of a
handoffFIFO and writesdetachedon every normal exit (spawn handle, window exit, timeout, handoff). A watcher in the supervisor that reads EOF withoutdetached(Stop, tool timeout, any kill of the launcher) TERMs the supervisor, which stops the command and finalizes the record asaborted/ 143, also when the launch is cancelled beforeready. - The unmanaged
buildBackgroundShellCommandfallback also usessetsid; the unmanaged soft-background fallback still shares the launcher's group.
Tests: launcher as group leader → group SIGKILL after exit (spawn and soft handoff, sh/bash/zsh) keeps the job running to its real exit code; group SIGKILL, group TERM and launcher-only TERM during the foreground window, and before ready, give an aborted record with no orphans. Checked on a VM with OpenCode 2.3.0: a 400 s background job outlived 30 later foreground shells and completed with exit 0 (it died on the old build); Stop during a soft-background window still aborts the command.
Happy to open a PR against main if you want it.
Activity
nkoynov commentedon Nov 17, 2026
OpenCode fixed the delayed kill on their side: anomalyco/opencode#64266 (opencode-pty 0.6.0) and #64251 (core pins it, merged to
devtoday, so it ships after 2.3.0). The daemon now reaps a command when it exits; if the command succeeded, whatever it left behind keeps running, and if it failed, the group gets SIGTERM at exit and anything still alive is killed 3 s later. So the supervisor won't die partway any more once that release is out, but 2.3.0 users still hit this, and starting the supervisor in its own session still keeps it out of the failed-command case.fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…
fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…
fix(shell): rebuild past Cursor's own shell traffic and keep backgrou…