Skip to content

refactor(engine): add SparseWriter decorator for zero-region interception (#2132) - #4000

Merged
oferchen merged 2 commits into
masterfrom
refactor/sparse-writer-decorator-2132
May 13, 2026
Merged

oferchen merged 2 commits into
masterfrom
refactor/sparse-writer-decorator-2132

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Refactors SparseWriter from a concrete fs::File wrapper with region-based API into a generic SparseWriter<W: Write + Seek> decorator that transparently intercepts write calls to scan for zero regions
  • Adds ZeroScanStrategy enum (SIMD-accelerated default, byte-level alternative) for configurable zero-detection
  • Adds SparseWriteStats for tracking bytes written, bytes seeked, and zero runs detected
  • Wires the decorator into the whole-file copy path (copy_file_contents_sparse), replacing manual SparseWriteState management
  • Delta transfer path retains write_sparse_chunk for its interleaved literal/block-match I/O pattern
  • Adds 20 tests covering all-zero, all-nonzero, mixed data, buffer boundaries, statistics tracking, strategy parity, Write trait usage, seek flushing, and real file I/O

Test plan

  • All existing sparse tests pass (zero-run detection, hole punching, state machine)
  • New decorator tests: all-zero produces only seeks, all-nonzero produces only writes
  • Mixed data correctly splits seeks and writes with content verification
  • Zero runs at buffer boundaries accumulated across multiple write calls
  • Statistics tracking accurate throughout write lifecycle
  • SIMD and byte-level strategies produce identical output
  • Write trait usable polymorphically
  • Seek flushes pending zeros before repositioning
  • Real file I/O produces correct sparse content
  • CI: fmt, clippy, nextest, all platforms

…tion (#2132)

Replace the concrete `SparseWriter` (wrapping `fs::File` with region-based
API) with a generic `SparseWriter<W: Write + Seek>` decorator that
transparently intercepts write calls to detect and skip zero regions.

Key changes:
- SparseWriter<W> implements Write + Seek, scanning for zero runs in
  each write call and accumulating them as pending seeks
- Configurable ZeroScanStrategy: SIMD-accelerated (default) or byte-level
- SparseWriteStats tracks bytes written, bytes seeked, zero runs detected
- Single-seek-per-zero-run invariant maintained across write boundaries
- Whole-file copy path wired through SparseWriter decorator
- Delta transfer path retains write_sparse_chunk for interleaved I/O
Remove boolean arg from SparseWriter::new(), replace write_region()
with write_all(), remove integer arg from finish(), and rename
file()/file_mut() to inner()/inner_mut().
@oferchen
oferchen merged commit 45c6d1d into master May 13, 2026
38 of 39 checks passed
@oferchen
oferchen deleted the refactor/sparse-writer-decorator-2132 branch May 14, 2026 14:58
oferchen added a commit that referenced this pull request May 18, 2026
…tion (#2132) (#4000)

* refactor(engine): add SparseWriter decorator for zero-region interception (#2132)

Replace the concrete `SparseWriter` (wrapping `fs::File` with region-based
API) with a generic `SparseWriter<W: Write + Seek>` decorator that
transparently intercepts write calls to detect and skip zero regions.

Key changes:
- SparseWriter<W> implements Write + Seek, scanning for zero runs in
  each write call and accumulating them as pending seeks
- Configurable ZeroScanStrategy: SIMD-accelerated (default) or byte-level
- SparseWriteStats tracks bytes written, bytes seeked, zero runs detected
- Single-seek-per-zero-run invariant maintained across write boundaries
- Whole-file copy path wired through SparseWriter decorator
- Delta transfer path retains write_sparse_chunk for interleaved I/O

* fix: update SparseWriter tests to match refactored decorator API

Remove boolean arg from SparseWriter::new(), replace write_region()
with write_all(), remove integer arg from finish(), and rename
file()/file_mut() to inner()/inner_mut().
oferchen added a commit that referenced this pull request Jun 10, 2026
Bundles the PIP-LESSONS series (#4000-#4003) as a single docs change:

- docs/design/pip-7-lessons-learned.md captures the broader lesson from
  the PIP-7 receiver-corruption defect. The defect post-mortem already
  lives in pip-7-parallel-receive-delta-receiver-corruption-2026-05-22.md;
  this new doc generalises it: sequential-ordering unit tests passed,
  the corruption only surfaced under adversarial chunk arrival at the
  dispatch boundary. The discipline applies to every future concurrent
  path (DASYNC, RUSSH-ASY, ASY-G, DG-series races): ship adversarial-
  ordering stress fuzz BEFORE flipping default-on.

- fuzz/fuzz_targets/parallel_receive_delta_adversarial.rs drives
  ParallelDeltaApplier with adversarial chunk orderings and asserts a
  SHA-256 oracle against the sequential reference.

- fuzz/corpus/parallel_receive_delta_adversarial/ seeds the corpus with
  the two known regression shapes:
    - pip_7_threshold_trip.bin: the threshold-trip mid-batch ordering
      that caught PIP-7 (file_0 dispatched after later files).
    - dg_3_slot_recycle_race.bin: the reverse-interleaved ordering that
      stresses the slot-recycle race shape from the DG-3 series.

- fuzz/Cargo.toml: adds engine and sha2 deps for the new target.
oferchen added a commit that referenced this pull request Jun 10, 2026
…ry (#5596)

Bundles the PIP-LESSONS series (#4000-#4003) as a single docs change:

- docs/design/pip-7-lessons-learned.md captures the broader lesson from
  the PIP-7 receiver-corruption defect. The defect post-mortem already
  lives in pip-7-parallel-receive-delta-receiver-corruption-2026-05-22.md;
  this new doc generalises it: sequential-ordering unit tests passed,
  the corruption only surfaced under adversarial chunk arrival at the
  dispatch boundary. The discipline applies to every future concurrent
  path (DASYNC, RUSSH-ASY, ASY-G, DG-series races): ship adversarial-
  ordering stress fuzz BEFORE flipping default-on.

- fuzz/fuzz_targets/parallel_receive_delta_adversarial.rs drives
  ParallelDeltaApplier with adversarial chunk orderings and asserts a
  SHA-256 oracle against the sequential reference.

- fuzz/corpus/parallel_receive_delta_adversarial/ seeds the corpus with
  the two known regression shapes:
    - pip_7_threshold_trip.bin: the threshold-trip mid-batch ordering
      that caught PIP-7 (file_0 dispatched after later files).
    - dg_3_slot_recycle_race.bin: the reverse-interleaved ordering that
      stresses the slot-recycle race shape from the DG-3 series.

- fuzz/Cargo.toml: adds engine and sha2 deps for the new target.
oferchen added a commit that referenced this pull request Aug 24, 2026
…tion (#2132) (#4000)

* refactor(engine): add SparseWriter decorator for zero-region interception (#2132)

Replace the concrete `SparseWriter` (wrapping `fs::File` with region-based
API) with a generic `SparseWriter<W: Write + Seek>` decorator that
transparently intercepts write calls to detect and skip zero regions.

Key changes:
- SparseWriter<W> implements Write + Seek, scanning for zero runs in
  each write call and accumulating them as pending seeks
- Configurable ZeroScanStrategy: SIMD-accelerated (default) or byte-level
- SparseWriteStats tracks bytes written, bytes seeked, zero runs detected
- Single-seek-per-zero-run invariant maintained across write boundaries
- Whole-file copy path wired through SparseWriter decorator
- Delta transfer path retains write_sparse_chunk for interleaved I/O

* fix: update SparseWriter tests to match refactored decorator API

Remove boolean arg from SparseWriter::new(), replace write_region()
with write_all(), remove integer arg from finish(), and rename
file()/file_mut() to inner()/inner_mut().
oferchen added a commit that referenced this pull request Aug 24, 2026
…tion (#2132) (#4000)

* refactor(engine): add SparseWriter decorator for zero-region interception (#2132)

Replace the concrete `SparseWriter` (wrapping `fs::File` with region-based
API) with a generic `SparseWriter<W: Write + Seek>` decorator that
transparently intercepts write calls to detect and skip zero regions.

Key changes:
- SparseWriter<W> implements Write + Seek, scanning for zero runs in
  each write call and accumulating them as pending seeks
- Configurable ZeroScanStrategy: SIMD-accelerated (default) or byte-level
- SparseWriteStats tracks bytes written, bytes seeked, zero runs detected
- Single-seek-per-zero-run invariant maintained across write boundaries
- Whole-file copy path wired through SparseWriter decorator
- Delta transfer path retains write_sparse_chunk for interleaved I/O

* fix: update SparseWriter tests to match refactored decorator API

Remove boolean arg from SparseWriter::new(), replace write_region()
with write_all(), remove integer arg from finish(), and rename
file()/file_mut() to inner()/inner_mut().
oferchen added a commit that referenced this pull request Aug 24, 2026
…ry (#5596)

Bundles the PIP-LESSONS series (#4000-#4003) as a single docs change:

- docs/design/pip-7-lessons-learned.md captures the broader lesson from
  the PIP-7 receiver-corruption defect. The defect post-mortem already
  lives in pip-7-parallel-receive-delta-receiver-corruption-2026-05-22.md;
  this new doc generalises it: sequential-ordering unit tests passed,
  the corruption only surfaced under adversarial chunk arrival at the
  dispatch boundary. The discipline applies to every future concurrent
  path (DASYNC, RUSSH-ASY, ASY-G, DG-series races): ship adversarial-
  ordering stress fuzz BEFORE flipping default-on.

- fuzz/fuzz_targets/parallel_receive_delta_adversarial.rs drives
  ParallelDeltaApplier with adversarial chunk orderings and asserts a
  SHA-256 oracle against the sequential reference.

- fuzz/corpus/parallel_receive_delta_adversarial/ seeds the corpus with
  the two known regression shapes:
    - pip_7_threshold_trip.bin: the threshold-trip mid-batch ordering
      that caught PIP-7 (file_0 dispatched after later files).
    - dg_3_slot_recycle_race.bin: the reverse-interleaved ordering that
      stresses the slot-recycle race shape from the DG-3 series.

- fuzz/Cargo.toml: adds engine and sha2 deps for the new target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant