RFC: Add ResamplerStack to coordinate stacked resamplers #1348
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR proposes a solution to the stacked resampler timing issue. I'm opening this as an RFC to discuss the approach before finalizing.
Problem
When resampling already-resampled data (e.g., 1s samples → 15min aggregates), there's a race condition at window boundaries. If both resamplers fire at the same moment, the higher-level resampler may process BEFORE the lower-level one has emitted its boundary sample.
Minimal reproduction
Impact
sumormax: error compoundsProposed Solution
This PR adds:
Resampler.trigger(timestamp)- Allows external control of when resampling occurs, without waiting for the internal timer.ResamplerStack- Coordinates multiple resamplers:Usage
Alternatives Considered
Add
asyncio.sleep(0)yields insideResampler.resample()- Tried this but it doesn't reliably solve the problem because both resamplers enter the timer loop before either processes.Emit samples slightly before window boundary - Would require changing timestamp semantics.
Use open intervals (samples at exactly window_end go to next window) - Breaking change to current behavior.
Have higher-level resamplers wait longer - Fragile, doesn't guarantee ordering.
Questions for Discussion
Is
ResamplerStackthe right abstraction? Should this be handled differently?Should the continuous mode use
WallClockTimerinstead ofTimerfor better alignment?Should we also provide a way to automatically detect stacked resamplers (e.g., via channel inspection)?
Is exporting
Resamplerpublicly the right approach, or should users only useResamplerStack?