Skip to content

[WRONG BRANCH] fix(adapters): terminate Windows coding-agent process trees - #476

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-codebuddy-process-orphaning
Draft

[WRONG BRANCH] fix(adapters): terminate Windows coding-agent process trees#476
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-codebuddy-process-orphaning

Conversation

@luvs01

@luvs01 luvs01 commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Motivation

  • On Windows, npm .cmd/.bat shims launch cmd.exe as the direct child while the real CLI becomes a descendant, and killing only the tracked child leaves credential-bearing descendant CLIs running after cancellation or timeout.

Description

  • Add an injectable Windows process-tree terminator (killWindowsProcessTree) and a default implementation that calls the absolute taskkill.exe /PID <pid> /T /F via execFileSync to reliably kill a process tree on Windows.
  • Invoke the injected/default tree terminator in runCodingAgentTurn's kill() path when platform === "win32" and child.pid is available, and fall back to the existing child.kill SIGTERM/SIGKILL ladder if tree termination fails or is unavailable.
  • Use a resolved platform value consistently when producing commandInvocation to keep Windows shim handling coherent with the termination choice.
  • Add a focused regression test (tests/providers/codebuddy-adapter.test.ts) that simulates a Windows .cmd shim and verifies the abort path calls the process-tree terminator and does not rely on a direct-child signal; minor test scaffolding was adjusted to expose a fake child's pid for the assertion.

Testing

  • Ran focused adapter and win-exec tests with bun test tests/providers/codebuddy-adapter.test.ts tests/providers/qoder-adapter.test.ts tests/windows/win-exec.test.ts, and the focused suite passed (47 tests passed).
  • Ran bun run typecheck and bun run privacy:scan, both of which passed.
  • Ran the full test suite (bun run test) in this environment; the change's focused tests remained green but the full parallel run surfaced unrelated integration failures in other areas (149 failures and 1 error) that are not caused by this adapters change.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T02:39:20.693379Z 7979ffe PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 48043219-77fe-4d30-a2e2-d2a41bb16d4a


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7979ffe805

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const MAX_STDERR_BYTES = 8 * 1024;

function killWindowsProcessTree(pid: number): void {
const taskkill = `${process.env.SystemRoot ?? "C:\\Windows"}\\System32\\taskkill.exe`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve taskkill without trusting SystemRoot

When OpenCodex is launched with a poisoned SystemRoot value, this constructs an absolute-looking path under the attacker-controlled directory and executes its taskkill.exe on the first abort or timeout with the proxy user's privileges and inherited environment. The repository already provides resolveTrustedWindowsTaskkillExe(), backed by GetSystemDirectoryW, specifically to avoid selecting system executables through caller-controlled environment variables; use that resolver or the same trusted-resolution logic here.

AGENTS.md reference: AGENTS.md:L357-L363

Useful? React with 👍 / 👎.

Comment on lines +214 to +216
if (platform === "win32" && child.pid !== undefined) {
try {
(deps.killWindowsProcessTree ?? killWindowsProcessTree)(child.pid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify the child is still live before invoking taskkill

When the direct child has emitted exit but close is delayed by an inherited stdio handle, child.pid remains populated even though that PID is no longer owned by this ChildProcess. The grace timer can enter this branch after Windows has recycled the PID, causing /T /F to terminate an unrelated process and its descendants; gate the PID-based kill on child.exitCode === null or an explicit exit flag before calling taskkill. Microsoft documents /T as ending the specified process and its child processes.

AGENTS.md reference: src/AGENTS.md:L17-L20

Useful? React with 👍 / 👎.

@github-actions github-actions Bot changed the title fix(adapters): terminate Windows coding-agent process trees [WRONG BRANCH] fix(adapters): terminate Windows coding-agent process trees Sep 10, 2026
@github-actions

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again.

@github-actions
github-actions Bot marked this pull request as draft September 10, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant