Repository navigation
Conversation
ApprovabilityVerdict: Needs human review This PR introduces a new Windows-specific child process management capability (~500 lines) that changes how processes are terminated with bounded shutdown behavior. New runtime behavior like process lifecycle management warrants human review. You can customize Macroscope's approvability policy. Learn more. |
9241803 to
83a009f
Compare
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
Reviewed the new boundedChildProcessSpawner service module, its layer wiring in bin.ts, and the accompanying test. The implementation follows the canonical module shape (imports, options, helpers, make, layer), acquires the delegate spawner from the Effect environment inside layer, and uses subpath namespace imports. One import-convention deviation in the test file is noted inline.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
This imports the service module's public members (make, layer) as bare named imports, which erases the module namespace at a service boundary. Consider import * as BoundedChildProcessSpawner from "./boundedChildProcessSpawner.ts"; and referring to BoundedChildProcessSpawner.make(...), BoundedChildProcessSpawner.layer(...), and BoundedChildProcessSpawner.ChildProcessShutdownSignal, matching bin.ts and the other service tests in apps/server/src (e.g. processRunner.test.ts, externalLauncher.test.ts).
Posted via Macroscope — Effect Service Conventions
83a009f to
dcbfae3
Compare
CDVolvik
left a comment
There was a problem hiding this comment.
The test that covers the behaviour this PR is named for does not report as skipped on other platforms, it reports as passed:
it.effect("kills a Windows child process tree without blocking scope close", () => {
if (process.platform !== "win32") return Effect.void;Running the file on Linux:
✓ closes the delegate scope after a natural child exit 5ms
✓ preserves unref as an opt-out from scope-owned termination 1ms
✓ bounds explicit handle kill calls and escalates to SIGKILL 2ms
✓ respects an explicit force-kill grace period 4ms
✓ treats a missing pid as stopped when the delegate exit event is stale 1ms
✓ returns from scope close before the delegate finalizer can block 1ms
✓ kills a Windows child process tree without blocking scope close 0ms
Tests 7 passed (7)
The last line is a green check on a run where nothing executed. Anyone reading CI concludes the tree kill is covered. it.effect.skipIf(process.platform !== "win32") reports it as skipped instead, which is the honest signal and costs nothing.
That matters more than usual here, because the tree kill is the only part that cannot be inferred from the other six tests. Those all drive a synthetic handle whose kill just pushes a string into an array, so they verify the escalation state machine rather than that anything dies. On Windows kill() terminates the process it targets, not its descendants, so whether descendantPid actually stops depends entirely on what the delegate spawner does underneath. Has the fixture test been run on a Windows machine? If it has, saying so in the PR body would help, since CI cannot show it.
Smaller thing: shutdown takes childScope and never uses it.
const shutdown = Effect.fn("BoundedChildProcessSpawner.shutdown")(function* (
handle: ChildProcessSpawner.ChildProcessHandle,
childScope: Scope.Closeable,
isReferenced: () => boolean,
) {
if (isReferenced()) {
yield* kill(handle);
}
});The scope is closed by the exitCode fork instead, so the parameter looks like a leftover from an earlier shape. Worth dropping so it does not read as a missed cleanup path.
Also worth a note: sendSignal forks the kill detached and Effect.ignores the result, so a kill that fails outright is indistinguishable from one that is merely slow. Both land on the same logWarning after the full grace window. Given the whole point is bounding shutdown, a failed signal is probably worth logging at the moment it fails rather than only after the timeout.
dcbfae3 to
c80a123
Compare
|
Thank you, updated the PR |
There was a problem hiding this comment.
One finding: the Windows branch in bin.ts selects the runtime layer from a module-scope process.platform read instead of acquiring the host platform from the Effect environment. boundedChildProcessSpawner.ts itself follows the conventions (subpath namespace imports, make + layer, delegate acquired from the environment in layer).
Posted via Macroscope — Effect Service Conventions
| import { sharedServerCommandFlags } from "./cli/config.ts"; | ||
| import { projectCommand } from "./cli/project.ts"; | ||
| import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts"; | ||
| import { serviceCommand } from "./cli/service.ts"; | ||
| import { servicePreflightCommand } from "./cli/servicePreflight.ts"; | ||
|
|
||
| const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer); | ||
| const CliRuntimeLayer = Layer.mergeAll( | ||
| process.platform === "win32" |
There was a problem hiding this comment.
process.platform is read directly in module scope, so the host-platform dependency is hidden from the Effect environment (this is also the only process.platform read left in apps/server/src and the repo's no-global-process-runtime rule flags it). Consider selecting the layer inside the environment via HostProcessPlatform/isHostWindows with Layer.unwrap, matching PtyAdapterLive in server.ts.
Requires adding import { isHostWindows } from "@t3tools/shared/hostProcess";.
-const CliRuntimeLayer = Layer.mergeAll(
- process.platform === "win32"
- ? BoundedChildProcessSpawner.layer().pipe(Layer.provideMerge(NodeServices.layer))
- : NodeServices.layer,
- NetService.layer,
-);
+const CliRuntimeLayer = Layer.mergeAll(
+ Layer.unwrap(
+ Effect.map(isHostWindows, (isWindows) =>
+ isWindows
+ ? BoundedChildProcessSpawner.layer().pipe(Layer.provideMerge(NodeServices.layer))
+ : NodeServices.layer,
+ ),
+ ),
+ NetService.layer,
+);Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c80a1233107e78afd556be06b46577c3927b0128. Configure here.
c80a123 to
556933e
Compare
556933e to
97dd9fa
Compare
|
Closing because we are no longer able to reproduce the shutdown hang against current upstream's process handler. We ran 10 isolated Windows checks on Node 24.13.1 using Effect 4.0.0-rc.115, the version used by upstream main at 9ea9c3d. Scope closure, forceKillAfter, and explicit kill all completed without a hang or timeout, including cases with parent and descendant processes. These checks exercised the process handler, not a full server or provider shutdown, so this does not prove every shutdown path is unaffected. We can revisit this if a concrete reproduction becomes available. |

What Changed
On Windows, wrap the CLI child-process spawner with bounded shutdown behavior.
When a scoped child process does not stop after
SIGTERM, T3 waits up to two seconds before escalating to forced process-tree termination. It then waits one additional second before allowing shutdown to continue with a warning.The wrapper also:
handle.kill()calls;unref()as an opt-out from scope-owned termination;Why
A child process or descendant that fails to exit can otherwise prevent the T3 server from shutting down and leave its console host running.
This revisits the Windows shutdown behavior discussed in #3573 against the current server implementation. The change is limited to Windows and uses Effect's existing Windows process-tree termination behavior.
Verification
Run on Windows with Node 24:
The focused test suite covers:
unref()behavior;forceKillAftergrace period;Expected result:
Checklist
Implemented with GPT-5.6 Sol through the Codex harness.
Note
Add bounded child process shutdown on Windows with SIGTERM/SIGKILL grace periods
BoundedChildProcessSpawnerin boundedChildProcessSpawner.ts, which wraps the existingChildProcessSpawnerservice to enforce a timed shutdown sequence: send an initial signal (default SIGTERM), wait a configurable grace period, escalate to SIGKILL if still running, and log a warning if the process still does not stop.BoundedChildProcessSpawner.layerintoPlatformServicesLive, replacing the default spawner with the bounded implementation.kill(options)calls while the caller scope is open are forwarded unchanged to the delegate; bounded shutdown only triggers on scope close or re-reference after scope close.Macroscope summarized 97dd9fa.
Note
Medium Risk
Touches core process lifecycle on Windows only, but mis-timed kills or scope/finalizer ordering could affect CLI children during shutdown or after unref.
Overview
On Windows only, the server wraps Effect’s
ChildProcessSpawnerwithBoundedChildProcessSpawnerso scoped children cannot block shutdown indefinitely.When the caller scope closes (or a child is re-referenced after close), the wrapper runs bounded termination: SIGTERM, wait up to 2s (
termGraceMs), then SIGKILL with a 1s grace (killGraceMs). Signals are sent in a detached fiber so parent scope finalizers are not held on a stuck delegate cleanup.unref()still opts out of scope-driven kills; explicitkill()while the scope is open is forwarded unchanged.PlatformServicesLiveinserver.tscomposes this layer on top of Bun/Node platform services whenisHostWindowsis true; non-Windows behavior is unchanged.Adds
boundedChildProcessSpawner.test.ts(mocked lifecycle cases plus a Windows integration test for parent + descendant process trees).Reviewed by Cursor Bugbot for commit 97dd9fa. Bugbot is set up for automated code reviews on this repo. Configure here.