From 3b0e413e962a77e28da8896b287581742c46b2bb Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 3 Mar 2026 19:56:23 -0500 Subject: [PATCH] Handle valid null frames and 0-bar cases in backfill Add guards for empty-array and zero-bar-diff cases in the TSP backfill loops to avoid crashes and allow graceful loop termination. In `maybe_fill_null_segments()`, - add `array.size == 0` guard in `maybe_fill_null_segments()` to detect valid (venue closure) gaps from the backend; add a warning + bp + break for this case. - add TODO that we should likely be filling nulls with the close price for the gap's duration. In `start_backfill()`, - expand the "0 bars after diff" warning msg with `backfill_until_dt` and `end_dt_param` context. - mask the `await tractor.pause()` and add a `break` to avoid blocking the backfill loop. (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/tsp/_history.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/piker/tsp/_history.py b/piker/tsp/_history.py index 0edfaf2e..aa332fec 100644 --- a/piker/tsp/_history.py +++ b/piker/tsp/_history.py @@ -251,10 +251,20 @@ async def maybe_fill_null_segments( end_dt=end_dt, ) + if array.size == 0: + log.warning( + f'Valid gap from backend ??\n' + f'{end_dt} -> {start_dt}\n' + ) + # ?TODO? do we want to remove the nulls and push + # the close price here for the gap duration? + await tractor.pause() + break + if ( - frame_start_dt := ( - from_timestamp(array['time'][0]) - ) < backfill_until_dt + frame_start_dt := (from_timestamp(array['time'][0])) + < + backfill_until_dt ): log.error( f'Invalid frame_start !?\n' @@ -616,10 +626,17 @@ async def start_backfill( else: log.warning( - '0 BARS TO PUSH after diff!?\n' + f'0 BARS TO PUSH after diff!?\n' f'{next_start_dt} -> {last_start_dt}' + f'\n' + f'This might mean we rxed a gap frame which starts BEFORE,\n' + f'backfill_until_dt: {backfill_until_dt}\n' + f'end_dt_param: {end_dt_param}\n' + ) - await tractor.pause() + # XXX, to debug it and be sure. + # await tractor.pause() + break # Check if we're about to exceed buffer capacity BEFORE # attempting the push