-
Notifications
You must be signed in to change notification settings - Fork 26.1k
fix(sdk): handle Windows opencode spawn and shutdown #20772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b16015b
fix(sdk): handle opencode child processes on Windows
Hona b0a4238
fix(sdk): bound shutdown waits
Hona d132686
refactor(sdk): inline process handling
Hona 6e5bb73
fix(sdk): narrow Windows spawn change
Hona 3d9fedc
chore: move cross-spawn to workspace catalog
Hona 1803191
fix(sdk): stop cmd wrapper children on Windows
Hona 4073c88
refactor(sdk): extract stop helper and document duplication
Hona 1d4b49e
fix(sdk): clear abort listeners on shutdown
Hona dc7ed46
refactor(sdk): extract abort listener cleanup
Hona bf359d0
fix(sdk): clean up process on timeout or parse error
Hona 99ebd91
fix(sdk): preserve abort reason during startup
Hona b2ea0a5
docs: shorten process duplication notes
Hona 6488637
fix(sdk): preserve node abort semantics
Hona 5566393
refactor(sdk): use abort signal reason directly
Hona a080f8b
fix(sdk): fix PID reuse on Windows and stdout memory leak
Hona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { type ChildProcess } from "node:child_process" | ||
| import { once } from "node:events" | ||
| import launch from "cross-spawn" | ||
|
|
||
| export namespace Process { | ||
| export type Child = ChildProcess & { exited: Promise<void> } | ||
|
|
||
| export type Options = { | ||
| signal?: AbortSignal | ||
| env?: NodeJS.ProcessEnv | ||
| stdio?: "inherit" | "pipe" | ||
| } | ||
|
|
||
| export function spawn(cmd: string, args: string[], opts: Options = {}): Child { | ||
| const proc = launch(cmd, args, { | ||
| signal: opts.signal, | ||
| env: opts.env, | ||
| stdio: opts.stdio, | ||
| windowsHide: process.platform === "win32", | ||
| }) | ||
| const exited = once(proc, "exit").then(() => {}) | ||
| void exited.catch(() => undefined) | ||
|
|
||
| const child = proc as Child | ||
| child.exited = exited | ||
| return child | ||
| } | ||
|
|
||
| export async function stop(proc: Child) { | ||
| if (proc.exitCode !== null || proc.signalCode !== null) return | ||
|
|
||
| if (process.platform === "win32" && proc.pid) { | ||
| const task = launch("taskkill", ["/pid", String(proc.pid), "/T", "/F"], { | ||
| windowsHide: true, | ||
| }) | ||
| const code = await new Promise<number>((resolve) => { | ||
| task.once("exit", (code, signal) => resolve(code ?? (signal ? 1 : 0))) | ||
| task.once("error", () => resolve(1)) | ||
| }) | ||
| if (code === 0) { | ||
| await proc.exited | ||
| return | ||
| } | ||
| } | ||
|
|
||
| proc.kill() | ||
|
Hona marked this conversation as resolved.
Outdated
|
||
| await proc.exited | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.