Skip to content

Add WMI fallback for Windows daemon detachment - #1

Open
gologames wants to merge 2 commits into
mainfrom
fix/windows-daemon-job-detachment
Open

gologames wants to merge 2 commits into
mainfrom
fix/windows-daemon-job-detachment

Conversation

@gologames

Copy link
Copy Markdown
Owner

Summary

Fix Windows daemon startup failures caused by residual Job Object membership.

Related: openai#44503

Investigation

A native probe remained in a Job Object but survived launcher exit and terminal closure. A separate KILL_ON_JOB_CLOSE control confirmed that closing the Job terminated its child.

To test whether checking only the immediate Job is sufficient, the next experiment used this hierarchy:

Outer Job: KILL_ON_JOB_CLOSE, no breakaway
└─ Middle Job: no KILL_ON_JOB_CLOSE, no breakaway
   └─ Inner Job: permits breakaway
      └─ Launcher

A child launched with CREATE_BREAKAWAY_FROM_JOB escaped the inner Job but remained in the middle and outer Jobs. Closing the outer Job terminated it, even though its immediate Job had no KILL_ON_JOB_CLOSE.

The alternative was tested without administrator privileges: WMI created a temporary parent, and the launcher created the child using its own token and that parent. The child:

  • Remained outside all three test Jobs.
  • Preserved the compared token fields and supplied environment variable.
  • Survived temporary-parent exit, launcher exit, and outer-Job closure, while continuing to write to stderr.

A normally launched child in the same experiment terminated when the outer Job closed.

Fix

Keep the direct launch when the child has no remaining Job membership. Otherwise, terminate the child and retry using a temporary WMI-created parent and the original caller's token.

Preserve arguments, environment, working directory, and stdio. Verify the temporary parent's identity through a private named pipe and release it after launch. Apply the fallback to both preflight and daemon startup while retaining elevated-launch rejection.

Validation

  • Clippy passed for codex-app-server-daemon and codex-arg0.
  • All 53 tests passed.
  • Manual testing with an isolated CODEX_HOME confirmed startup, survival after terminal closure, restart, a working CLI conversation, and shutdown.

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