✨ Add configurable process shutdown policies - #230
Conversation
|
Warning Review limit reached
Next review available in: 56 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThe process API adds ChangesProcess lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant ProcessImplementation
participant ChildProcess
participant ShutdownMiddleware
Caller->>ProcessImplementation: exited()
ChildProcess-->>ProcessImplementation: exit event
ProcessImplementation-->>Caller: ExitStatus
Caller->>ProcessImplementation: shutdown handling
ProcessImplementation->>ShutdownMiddleware: provide ProcessShutdownApi
ShutdownMiddleware->>ProcessImplementation: shutdown()
ProcessImplementation->>ChildProcess: terminate process tree
ChildProcess-->>ProcessImplementation: close after stdio closure
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@process/src/exec/posix.ts`:
- Around line 116-123: Declare the return type of the exited generator in
process/src/exec/posix.ts (lines 116-123) as Operation<ExitStatus>. Apply the
same explicit return type to the corresponding exited generator in
process/src/exec/win32.ts (lines 138-145), preserving their existing behavior.
In `@process/src/exec/types.ts`:
- Around line 21-32: Document the spawn-error contract for Process.exited()
consistently: in process/src/exec/types.ts lines 21-32, update the exited()
JSDoc to state that spawn failures reject the operation and that evaluating it
again replays the same error; in process/README.md lines 137-165, add this
failure and replay behavior to the lifecycle documentation; and in
process/README.md lines 252-258, include the same behavior in the Process
interface summary.
In `@process/test/exec.test.ts`:
- Around line 76-98: Update the test imports used by the “.exited” test suite to
use the Node.js test runner utilities from `@effectionx/bdd` instead of
Vitest-backed describe, it, and expect, while preserving the existing test
behavior and assertions.
In `@process/test/fixtures/stdio-descendant.ts`:
- Around line 4-13: Make the descendant fixture expose a deterministic
termination mechanism for the spawned interval process, while preserving its
inherited stdio and exit behavior. In process/test/fixtures/stdio-descendant.ts
lines 4-13, add the mechanism and ensure the descendant can be terminated; in
process/test/exec.test.ts lines 101-119, invoke it from a finally path and await
descendant cleanup before the test returns so all async work is scope-owned.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7369afd8-9cfb-45e3-a887-4d125e3af549
📒 Files selected for processing (8)
process/CHANGELOG.mdprocess/README.mdprocess/package.jsonprocess/src/exec/posix.tsprocess/src/exec/types.tsprocess/src/exec/win32.tsprocess/test/exec.test.tsprocess/test/fixtures/stdio-descendant.ts
Motivation
Closes #228.
Process.join()andProcess.expect()wait for Node's child-processcloseevent, so a descendant that retains inherited stdout or stderr can keep process
teardown pending after the direct command exits. Shutdown needs an
application-defined way to decide whether that remaining lifetime is expected
or should be forcefully reclaimed. A fixed timeout cannot represent process
health, drain state, descendant ownership, or other application context.
Approach
shutdown: "graceful" | "forced" | ProcessShutdownPolicytoexec()options; omission remains graceful.
SIGTERMfor the POSIX process group, orCtrl-C plus stdin closure on Windows.
SIGKILLon POSIX ortaskkill /T /FonWindows.
"graceful"or"forced".{ exit }operation containing thedirect command's
ExitStatus, without exposing it as a second public Processlifetime API.
closure cancels a pending policy;
"graceful"keeps waiting;"forced"escalates. A policy error also escalates so teardown cannot strand the tree.
taskkillin a teardown-owned task so cancellation of the policythat selected it cannot cancel hard termination.
@effectionx/processfrom0.8.1to0.9.0.The dynamic form can observe both process and application state without an
arbitrary grace period:
If descendants finish and release captured output while
untilForceIsRequired()is pending, the policy is canceled and teardown endsgracefully.
Explicit non-goals
Exec.join({ settle: "exit" }), now or as a plannedfollow-up.
yield* yield* exec().Process.exited(); direct exit is policy state, not asecond meaning for the public Process operation.
Validation
pnpm test— 386 passed, 6 skippedpnpm test process/test/exec.test.ts— 29 passedpnpm checkpnpm buildpnpm lintpnpm fmt:checkpnpm syncgit diff --check