Skip to content

v2.3.0 (Windows): kill-on-close Job Object kills detached processes started via Start-Process when owning command/session ends #64457

Closed as duplicate

Description

@povs2012

v2.3.0 (Windows): process daemon's kill-on-close Job Object silently kills detached child processes (Start-Process) when the owning command/session lifecycle ends

Environment

Summary

Since v2.3.0, every local shell command runs inside a Windows Job Object created with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE and no breakaway flags. Any child the command spawns — including "detached" processes created via PowerShell Start-Process — inherits job membership and is kernel-killed (TerminateJobObject) when the job is closed/terminated.

This breaks a common agent workflow: starting long-lived dev servers/services from a shell command and expecting them to outlive the command/session. It worked on ≤2.2.x (old spawner only used taskkill /T /F on explicit kill) and silently broke in 2.3.0.

Source evidence (v2.3.0)

packages/process-daemon/src/service/pipe/windows.rs:

  • Job::new() → CreateJobObjectW + SetInformationJobObject(JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE)
  • create_process() → PROC_THREAD_ATTRIBUTE_JOB_LIST, comment: "with no breakaway flags" (neither BREAKAWAY_OK nor SILENT_BREAKAWAY_OK is set)
  • terminate() → TerminateJobObject(job, 1) — kills the whole tree
  • reap() → "Closing the job alone kills anything still in it."

PR #62978 also states the behavior change explicitly: leftover background processes of a command are "SIGKILLed when the command is evicted or removed (today they survive)" — eviction triggers include the 25-command cap, the 7-day sweep, and opencode service restart / stop ("still stop everything").

Local verification

On 2.3.0 / Windows:

  1. Agent shell command runs Start-Process ping -n 600 127.0.0.1 -WindowStyle Hidden -PassThru → PID survives after the command exits ✓
  2. IsProcessInJob(pid, NULL) via kernel32 → TRUE for both foreground- and background-command-spawned processes (they are inside a job)
  3. Same check for a process created via WMI Win32_Process.Create → parent is WmiPrvSE.exe, outside the daemon's command chain (documented by MS: "Child processes created using Win32_Process.Create are not associated with the [caller's] job")

Real-world incident

Agent started 7 Spring Boot services via a test-runner script (Start-Process -WindowStyle Hidden, stdout/stderr redirected). All 7 were killed at the same second the Playwright run finished and the owning session went idle — no crash dumps (hs_err), no WER events, no graceful shutdown logs, business logs normal up to the last line. Happened twice in one evening; each death coincided with a session/host lifecycle boundary (opencode service restart, script end + session idle transition).

Expected vs actual

  • Expected: a process detached via Start-Process survives command completion and session/host recycling (≤2.2.x behavior)
  • Actual: it stays in the kill-on-close job and dies silently whenever the owning command is evicted/removed or the service restarts

Workarounds found

  1. Spawn via WMI: Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = '...' } (escapes the job chain; note: no env inheritance, no built-in stdout redirect — wrap with cmd /c "... > out.log 2>&1")
  2. Scheduled tasks (schtasks) or NSSM/WinSW services
  3. Avoid opencode service restart/stop while agent-started services are running
  4. Downgrade to 2.2.7

There is no config flag to disable the daemon or its job semantics (checked OPENCODE_* env vars and config schema).

Suggestion

Either allow breakaway (JOB_OBJECT_LIMIT_BREAKAWAY_OK + spawn detached children with CREATE_BREAKAWAY_FROM_JOB), or provide an opt-out (per-command flag or global setting) so agents can start long-lived processes that survive the session — this was a documented, relied-upon pattern on ≤2.2.x.

Activity

  1. opencodejr commented on Nov 17, 2026

    @opencodejr
    Contributor

    Thanks for the thorough write-up and the source analysis.

    I think this is a duplicate of #64177. That issue reports the same 2.3.0 regression: processes a finished shell command leaves running are killed later, when the daemon evicts or removes that command. It was reported on Linux; your report is the Windows Job Object side of it.

    The fix for it, #64266, covers Windows too. After a command exits successfully, the daemon now turns off kill-on-close and releases the job, so processes started with Start-Process should keep running after eviction or removal. One caveat: if the command exits with a non-zero code, the job is still terminated right away. A test-runner script that fails (for example, a failing Playwright run) would therefore still take the services it started with it. If you still need a way for long-lived processes to survive that case, please mention it on #64177.

    Related issues, ordered by likelihood:

    I'm closing this issue now as a duplicate of #64177. Please add any further details there, especially if this still happens once you're on a build that includes #64266. Replying here will reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions