Skip to content

fix(cli): detach Windows daemons from caller pipes and jobs - #282

Merged
iuyo5678 merged 2 commits into
mainfrom
iuyo5678/fix-windows-daemon-detach
Sep 20, 2026
Merged

iuyo5678 merged 2 commits into
mainfrom
iuyo5678/fix-windows-daemon-detach

Conversation

@iuyo5678

@iuyo5678 iuyo5678 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Windows background startup can leave captured stdout/stderr open after the launcher exits, and the daemon can die when the host cleans up its Job Object. This change isolates inherited handles, verifies that background daemons are independent of host Jobs, and keeps a launcher's wait deadline separate from shared daemon lifetime.

  • Inherit only dedicated stdio handles through an explicit Win32 handle list, shared with the Windows update helper.
  • Create the daemon suspended, request Job breakaway, and verify it belongs to no Job before resuming it. Restricted hosts receive setup instructions; an existing reachable daemon can still be reused.
  • Use direct startup with one readiness deadline. A timeout or port mismatch returns an error without terminating a running child that other clients may already be using. Children exit on their own initialization/lock failures; Unix children are reaped. Cleanup before a suspended Windows child resumes remains intact.
  • Cover launcher timeout after another client reuses the daemon, timeout before publication, and port mismatch with deterministic real-daemon regressions, without shipping test hooks.
  • Run Windows lifecycle and updater tests in a temporary, same-user WMI test host that verifies it is outside all Jobs. Keep restricted-Job rejection tests in the ordinary CI runner. Separate lifecycle CI from IPC, cancellation and installer checks, continue independent suites after test failures, and upload detailed results.

Validation before this update was committed:

  • The new reused-daemon timeout regression failed on the previous cleanup logic and passed after the fix.
  • Windows: three complete rounds of startup, launcher lifecycle and updater regressions passed. Default-port first-call status, process exit and both pipe EOF checks executed in every round; no cold-start case was skipped.
  • Linux: three real CLI SIGSTOP/SIGCONT experiments confirmed that launcher A times out while client B keeps using the same daemon PID.
  • Linux: workspace tests, strict workspace/all-target Clippy and formatting passed.
  • Windows: restricted-host rejection, IPC, audit, lock, update unit tests, browser interaction and parent cancellation passed. Installer regressions passed on Windows PowerShell 5.1 and PowerShell 7.

GitHub verification: CI run 35455639169 passed on commit 58eb44b. The independent Windows host verified inJob=False and executed all 10 startup tests, 9 launcher lifecycle tests and 3 updater tests successfully. The ordinary Windows runner also passed restricted-Job rejection, cancellation and both PowerShell installer suites. The only ignored tests are subprocess entry points; the default-port cold-start case executed successfully.

Addresses the Windows pipe and Job lifetime failures in #268. Query commands retain their automatic-start defaults; BSK_AUTO_START=0 remains the opt-out. Changing those defaults is outside this change.

Use an explicit standard-handle inheritance list for daemon startup and the
Windows update helper. Require and verify breakaway before resuming a
background daemon, with an actionable error for restrictive host Jobs.

Share direct startup and its readiness deadline across explicit and
automatic entry points, retain child ownership through startup, and reap
Unix children after handoff.

Add native Windows EOF, Job lifetime, concurrency and failure regressions
to CI, and document persistent host setup.

Refs #268
Do not terminate a running child when its launcher cannot confirm startup.
A different client may already be using it, or publication may race the
launcher's deadline. Retain cleanup only before a Windows child resumes.

Add deterministic lifecycle regressions for reuse before timeout, delayed
publication and port mismatch. Run Windows success-path and updater tests
in a same-user WMI test host that verifies it is outside all Jobs, and keep
restricted-host rejection tests in the normal CI runner.

Refs #268
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