Add buffer capacity checks to backfill loop

Prevent `ValueError` from negative prepend index in
`start_backfill()` by checking buffer space before push
attempts. Truncate incoming frame if needed and stop gracefully
when buffer full.

Also,
- add pre-push capacity check with frame truncation logic
- stop backfill when `next_prepend_index <= 0`
- log warnings for capacity exceeded and buffer-full conditions

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
multiaddrs
Gud Boi 2026-01-27 23:52:00 -05:00
parent 4e3cd7f986
commit 76f199df3b
1 changed files with 27 additions and 0 deletions

View File

@ -577,6 +577,25 @@ async def start_backfill(
f'{next_start_dt} -> {last_start_dt}' f'{next_start_dt} -> {last_start_dt}'
) )
# Check if we're about to exceed buffer capacity BEFORE
# attempting the push
if next_prepend_index - ln < 0:
log.warning(
f'Backfill would exceed buffer capacity!\n'
f'next_prepend_index: {next_prepend_index}\n'
f'frame size: {ln}\n'
f'Truncating to fit remaining space..\n'
)
# only push what fits
to_push = to_push[-(next_prepend_index):]
ln = len(to_push)
if ln == 0:
log.warning(
'No space left in buffer, stopping backfill!'
)
break
# bail gracefully on shm allocation overrun/full # bail gracefully on shm allocation overrun/full
# condition # condition
try: try:
@ -597,6 +616,14 @@ async def start_backfill(
next_prepend_index = next_prepend_index - ln next_prepend_index = next_prepend_index - ln
last_start_dt = next_start_dt last_start_dt = next_start_dt
# Stop if we've hit buffer start
if next_prepend_index <= 0:
log.warning(
f'Reached buffer start (index={next_prepend_index}), '
f'stopping backfill'
)
break
except ValueError as ve: except ValueError as ve:
_ve = ve _ve = ve
log.error( log.error(