fix(effect-ts): await Effect cleanup during Effection scope teardown#178
fix(effect-ts): await Effect cleanup during Effection scope teardown#178
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds execution tracking and abort capabilities to the Effect runtime. Introduces a pending execution set with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 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: |
b2f2862 to
3aaf6f1
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
effect-ts/effect-runtime.ts (1)
98-188:⚠️ Potential issue | 🔴 CriticalBump version in effect-ts/package.json.
Per
.policies/version-bump.md, source code changes to published packages require a semantic version bump. The changes toeffect-runtime.ts(runtime behavior modifications) must be accompanied by a version increment ineffect-ts/package.json.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@effect-ts/effect-runtime.ts` around lines 98 - 188, The package version for the published package must be bumped to reflect the runtime changes in makeEffectRuntime; open effect-ts/package.json and increment the "version" field following semver (patch/minor/major as appropriate for the breaking/non-breaking change), update any related lockfiles if required, and commit the updated package.json so the change to effect-runtime.ts (function makeEffectRuntime and its runtime behavior) is released with a new package version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@effect-ts/effect-runtime.ts`:
- Around line 98-188: The package version for the published package must be
bumped to reflect the runtime changes in makeEffectRuntime; open
effect-ts/package.json and increment the "version" field following semver
(patch/minor/major as appropriate for the breaking/non-breaking change), update
any related lockfiles if required, and commit the updated package.json so the
change to effect-runtime.ts (function makeEffectRuntime and its runtime
behavior) is released with a new package version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0d85b57b-c637-4cc3-b002-5d234929a175
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
effect-ts/effect-runtime.tspackage.json
3aaf6f1 to
904e824
Compare
When an Effection scope is halted, the action() teardown calls controller.abort() synchronously, but Effect's cleanup (finalizers, acquireRelease) runs asynchronously through promises. This can cause tests to see incomplete cleanup. Fix: Track in-flight Effect executions in a Set. During resource teardown, abort all pending executions and await their settlement before disposing the ManagedRuntime. Gate reject-path propagation from action() when the abort signal is already triggered to prevent spurious FiberFailure errors from reaching Effection.
904e824 to
daeef22
Compare
| if (!signal.aborted) { | ||
| reject(error); |
There was a problem hiding this comment.
runExit should never cause the parent to fail/throw. The action should resolve with an Exit.failCause of an unknown error or something like that.
Motivation
When upgrading to effection 4.1.0-alpha.7 (needed monorepo-wide for
scope.around()andcreateApi()APIs required by@effectionx/durable-streams), two@effectionx/effect-tstests started failing:acquireReleasecleanup incompleteThe root cause:
action()teardown callscontroller.abort()synchronously, but Effect's cleanup (finalizers, acquireRelease) runs asynchronously through promises. The scope destruction proceeds before Effect's promise chain settles.Approach
Set<PendingExecution>within the resource scopefinallyblock), abort all pending executions andyield* until()their settlement before disposing the ManagedRuntimeaction()when the abort signal is already triggered, preventing spuriousFiberFailureerrors from reaching Effectionpnpm.overridesforeffection: "4.1.0-alpha.7"to enable the alpha APIsAll 27 effect-ts tests pass. The 4 remaining failures in the full suite (exec/watch) are pre-existing and unrelated.
Summary by CodeRabbit