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-codemultiaddrs
parent
4e3cd7f986
commit
76f199df3b
|
|
@ -577,6 +577,25 @@ async def start_backfill(
|
|||
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
|
||||
# condition
|
||||
try:
|
||||
|
|
@ -597,6 +616,14 @@ async def start_backfill(
|
|||
next_prepend_index = next_prepend_index - ln
|
||||
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:
|
||||
_ve = ve
|
||||
log.error(
|
||||
|
|
|
|||
Loading…
Reference in New Issue