Skip to content

[Repo Assist] Fix DelayedSeries.Between to update RangeMin/RangeMax — closes #310#624

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-310-delayed-series-between-sample-87753c6c26a5da53
Mar 16, 2026
Merged

[Repo Assist] Fix DelayedSeries.Between to update RangeMin/RangeMax — closes #310#624
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-310-delayed-series-between-sample-87753c6c26a5da53

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — automated bug fix (Task 3: Issue Investigation and Fix)

Summary

Fixes the bug in #310: lazy series .Between(ds, de).Sample(interval) loads data from the full original range instead of just the restricted window.

The maintainer @dsyme requested this fix in #310 (comment).

Root Cause

DelayedSource.With always forwarded the original rangeMin/rangeMax to the new source, regardless of the range restriction passed in ranges. This had two effects:

  1. KeyRange returned the wrong bounds. DelayedIndex.KeyRange is backed by source.RangeMin/source.RangeMax, so after .Between(ds, de), series.KeyRange still returned (original_min, original_max). The generateKeys function in Series.Sample/resampleUniform calls series.KeyRange to determine the window for which to generate sample keys — so it generated keys across the entire original range.

  2. flattenRanges used the original bounds as overallMin/overallMax. This added spurious boundary segments outside the restriction window into the loader call.

Fix

Added optional rangeMin and rangeMax parameters to DelayedSource.With, and updated DelayedIndexBuilder.GetRange to pass the effective lower/upper bound (fst lo / fst hi) when creating the restricted source.

// Before
member x.With(?loader, ?ranges) =
  DelayedSource<'K, 'V>(scheme, rangeMin, rangeMax, ...)

// After
member x.With(?loader, ?ranges, ?rangeMin, ?rangeMax) =
  DelayedSource<'K, 'V>(scheme, defaultArg rangeMin x.RangeMin, defaultArg rangeMax x.RangeMax, ...)

And in GetRange:

// After
let restrictSource otherRange loader =
  let ranges = Intersect(range, otherRange)
  index.Source.With(ranges=ranges, loader=loader, rangeMin=fst lo, rangeMax=fst hi)

Trade-offs

  • Minimal, surgical change — only 4 lines of production code changed.
  • No behaviour change for the non-restricted case (default args preserve old values).
  • The fix is correct even for nested restrictions (e.g., .Before(40).After(10)): each GetRange call narrows rangeMin/rangeMax further.

Test Status

  • ✅ Added 2 regression tests in LazySeries.fs:
    • KeyRange reflects Between restriction on a lazy series (regression #310)
    • Loader is only called with restricted range after Between (regression #310)
  • ✅ All 573 tests pass
  • ✅ Build succeeded with 0 errors

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

When GetRange restricts a DelayedSeries via Between/After/Before,
the new DelayedSource previously kept the original rangeMin/rangeMax.
This caused two bugs:

1. series.KeyRange returned the full original bounds, so Sample/
   resampleUniform would generate keys for the entire original range
   rather than just the restricted window.

2. flattenRanges received the original bounds as overallMin/overallMax,
   potentially generating spurious boundary segments.

Fix: pass rangeMin=fst lo and rangeMax=fst hi to With() in GetRange,
and add corresponding optional parameters to DelayedSource.With.

Added regression tests:
- KeyRange reflects Between restriction on a lazy series (#310)
- Loader is only called with restricted range after Between (#310)

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 16, 2026 01:06
@dsyme dsyme merged commit 8e3b88e into master Mar 16, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-310-delayed-series-between-sample-87753c6c26a5da53 branch March 16, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant