Skip to content

Stop child process spawns and kills from flashing console windows on Windows - #7154

Merged
tim-smart merged 3 commits into
Effect-TS:mainfrom
CDVolvik:fix/windows-hide-child-process-console
Aug 9, 2026
Merged

Stop child process spawns and kills from flashing console windows on Windows#7154
tim-smart merged 3 commits into
Effect-TS:mainfrom
CDVolvik:fix/windows-hide-child-process-console

Conversation

@CDVolvik

@CDVolvik CDVolvik commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Type

  • Bug Fix

Description

On Windows, spawning a child process or killing a process group can create a console window. In an app that polls providers and shells out to git, this shows up as bursts of black windows flashing on screen.

Two causes in NodeChildProcessSpawner:

  • spawn never passed windowsHide, which Node defaults to false, so spawning a console executable such as git or gh creates a conhost window.
  • killProcessGroup and killProcessGroupOnExit run taskkill through NodeChildProcess.exec, and exec always wraps its argument in %ComSpec% /d /s /c. Every process group kill therefore spawns a cmd.exe.

The exec wrapper is easy to confirm:

taskkill via exec()      -> spawnfile: C:\WINDOWS\system32\cmd.exe
taskkill via execFile()  -> spawnfile: taskkill

detached: true is left alone. Windows gives a detached child its own console on purpose, so hiding it would break callers that want a visible console process. detached already defaults to false on Windows, so the noisy paths are still covered.

Validation

  • pnpm check
  • pnpm lint
  • pnpm vitest run --project @effect/platform-node-shared: this package already fails 66 of 114 on Windows. The same run on an unmodified main fails identically, so none of those come from this change.

I did not add a test. The package has no seam for asserting the options handed to NodeChildProcess.spawn, and mocking the module looked out of keeping with the surrounding tests. Happy to add one if you would rather have it.

Interactive verification in a real Windows console remains external.

Related

Reported downstream in pingdotgg/t3code#2537, where a 5 minute provider refresh and per-command git cleanup produce a repeating burst of flashes.

@changeset-bot

changeset-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 04f2049

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/platform-node-shared Patch
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • taskkill via execFile + windowsHide: truekillProcessGroup and killProcessGroupOnExit no longer route through cmd.exe (exec), so Windows process-group kills stop spawning a console window.
  • windowsHide on spawn — console-app children (e.g. git) are spawned hidden unless the caller explicitly set detached: true, whose new-console intent is preserved.
  • Changeset — patch for @effect/platform-node-shared.

I verified the Windows mechanics against Node/libuv/MSDN sources. The execFile swap is the right call: execFile pipes stdio, so windowsHide maps to CREATE_NO_WINDOW (libuv applies it only when no stdio fd is inherited), suppressing the conhost window for taskkill; a child spawned with stdio: "inherit" from a console-attached parent still renders output because libuv then skips CREATE_NO_WINDOW entirely. Bare taskkill (no extension, no path) resolves via libuv's search_path in execFile exactly as it did through exec, and non-zero-exit error semantics (error.code) are preserved, so the Effect.fail behavior is unchanged. The detached === true exclusion is also sound — MSDN states CREATE_NO_WINDOW is ignored when combined with DETACHED_PROCESS, so hiding a detached child would be a silent no-op anyway. On non-Windows windowsHide is a documented no-op, and both spawn paths in this file (StandardCommand, PipedCommand) route through the changed options, so coverage is complete for this spawner. The node:child_process fork/spawn handler for detached defaults also lines up with the existing computed detached value.

No test was added — Windows-only behavior with no seam for asserting spawn options, and any test would not run on Linux CI; the author already flagged this. Mergeable as-is.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix it ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.92 KB 6.92 KB 0.00 KB (0.00%)
batching.ts 9.72 KB 9.72 KB 0.00 KB (0.00%)
brand.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
cache.ts 10.63 KB 10.63 KB 0.00 KB (0.00%)
config.ts 20.91 KB 20.91 KB 0.00 KB (0.00%)
differ.ts 19.77 KB 19.77 KB 0.00 KB (0.00%)
http-client.ts 21.55 KB 21.55 KB 0.00 KB (0.00%)
logger.ts 10.84 KB 10.84 KB 0.00 KB (0.00%)
metric.ts 8.86 KB 8.86 KB 0.00 KB (0.00%)
optic.ts 6.68 KB 6.68 KB 0.00 KB (0.00%)
pubsub.ts 14.90 KB 14.90 KB 0.00 KB (0.00%)
queue.ts 11.57 KB 11.57 KB 0.00 KB (0.00%)
schedule.ts 10.74 KB 10.74 KB 0.00 KB (0.00%)
schema-class.ts 19.48 KB 19.48 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.41 KB 29.41 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.63 KB 25.63 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.58 KB 13.58 KB 0.00 KB (0.00%)
schema-string.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.38 KB 15.38 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.00 KB 24.00 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.74 KB 18.74 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.57 KB 18.57 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.43 KB 18.43 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.59 KB 22.59 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.08 KB 19.08 KB 0.00 KB (0.00%)
schema.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
stm.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
stream.ts 9.67 KB 9.67 KB 0.00 KB (0.00%)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — the core Windows-console fix remains sound, and the new windowsHide option is deterministic and genuinely exercised by the added tests. Two minor notes inline.

Reviewed changes

  • Added CommandOptions.windowsHide — an independent Windows console-hiding option that defaults to hiding non-detached children (options.windowsHide ?? !detached).
  • Extracted buildSpawnOptions (exported helper) and a shared taskkill wrapper used by both kill paths.
  • Added exact-output unit tests for buildSpawnOptions covering the Windows defaults and the independent windowsHide override — these assertions can fail, so they pin the behavior.
  • Rewrote the changeset description to match the new option surface.

I re-traced the defaulting matrix against the previously-approved commit: every Windows case is unchanged, and the only non-Windows shift (windowsHide truefalse when detached is unset) is a no-op since libuv ignores windowsHide on non-Windows platforms.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/effect/src/unstable/process/ChildProcess.ts
Comment thread packages/platform-node-shared/src/NodeChildProcessSpawner.ts Outdated
@tim-smart
tim-smart enabled auto-merge (squash) August 9, 2026 22:14
@tim-smart
tim-smart merged commit e74c302 into Effect-TS:main Aug 9, 2026
13 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants