Skip to content

fix(cli): detach Windows daemon from parent Job Object - #129

Open
ao-kamal wants to merge 1 commit into
SawyerHood:mainfrom
ao-kamal:ergo/windows-job-detach
Open

fix(cli): detach Windows daemon from parent Job Object#129
ao-kamal wants to merge 1 commit into
SawyerHood:mainfrom
ao-kamal:ergo/windows-job-detach

Conversation

@ao-kamal

Copy link
Copy Markdown

Summary

On Windows, spawn_daemon currently Command::spawns node as a child of the CLI process. Agent harnesses (Claude Code, Grok Build) wrap that CLI in a Job Object with KILL_ON_JOB_CLOSE. When the tool command ends, Windows kills the daemon and every managed Chromium. Named-page login cookies stay on disk under ~/.dev-browser/browsers/, but the window is gone.

Unix already called setsid(). This PR does the Windows equivalent:

  1. CREATE_BREAKAWAY_FROM_JOB | CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS | CREATE_NO_WINDOW
  2. If breakaway is denied (ERROR_ACCESS_DENIED / 5) — some harness jobs omit JOB_OBJECT_LIMIT_BREAKAWAY_OK — fall back to WMI Win32_Process.Create so the parent is WmiPrvSE, outside the job.

Idle-timeout (#124) is unrelated and already on main. This is only daemon lifetime.

Test plan

  • cargo test quote_windows (quoting helper)
  • Windows: from a Job Object that allows breakaway, dev-browser status twice — same daemon pid / growing uptime
  • Windows: from a Job Object that denies breakaway (Grok Build / Claude Code tool shell), same check — daemon still alive after the command returns
  • --connect / idle-timeout behavior unchanged

Agent harnesses (Claude Code, Grok Build) put the CLI in a Job Object with KILL_ON_JOB_CLOSE. When the command ends, the daemon and every managed Chromium die, so named-page login state vanishes even though profiles stay on disk.

Unix already called setsid(). Windows now requests CREATE_BREAKAWAY_FROM_JOB (plus a detached new process group). If breakaway is denied (Access Denied / error 5), spawn via WMI Win32_Process.Create so WmiPrvSE is the parent and the daemon survives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant