Fixes #9874

Problem

ZIO error recovery combinators (like catchAll and foldZIO) were silently dropping defects when they co-existed with typed failures in a composite Cause tree.

Solution

Updated the logic in foldZIO and foldTraceZIO to:

  1. Check for residual defects using Cause.keepDefects.
  2. If defects exist, re-propagate them after the failure handler completes.

This ensures that critical defects (Die) are never swallowed while maintaining correct recovery behavior for parallel operations (like foreachPar).

Verification

  • Added 6 regression tests to ZIOSpec.scala.
  • All 574 tests in coreTestsJVM passed.
  • Verified zero performance overhead on common paths.

/claim https://github.com/zio/zio/issues/9874

Claim

Total prize pool $300
Total paid $0
Status Pending
Submitted March 24, 2026
Last updated March 24, 2026

Contributors

AY

Ayush Kumar Jha

@jhaayushkumar

100%

Sponsors

ZI

ZIO

@ZIO

$300