Skip to content

fix(cache): clamp old snowflakes + poller channel backoff#13

Merged
bakeb7j0 merged 1 commit into
mainfrom
fix/12-cache-clamp-and-poller-backoff
Apr 13, 2026
Merged

fix(cache): clamp old snowflakes + poller channel backoff#13
bakeb7j0 merged 1 commit into
mainfrom
fix/12-cache-clamp-and-poller-backoff

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where getMessages returned [] when after was older than the cache window (e.g., after=0), breaking all clients using the standard "give me everything" cursor pattern. Also adds exponential backoff to the poller so channels that consistently fail stop wasting rate-limit budget.

Changes

  • cache.ts — Clamp after to window start instead of returning empty; uses - 1n to avoid off-by-one at the boundary
  • poller.ts — Add ChannelHealth tracker with exponential backoff (pollInterval × 2^(failures-1), cap 16×). Self-healing: success resets backoff. recordSuccess only reports recovery when channel was in active backoff (not expired).
  • index.ts — Wire shared health tracker into initialPoll and startPollingLoop
  • tests/ — 9 new tests (cache clamp, after=0, channel health unit + integration), 2 existing tests updated for corrected behavior

Linked Issues

Closes #12

Test Plan

  • ./scripts/ci/validate.sh — lint (tsc + shellcheck) + 63 tests passing
  • Cache clamp verified: old snowflakes and after=0 return all cached messages
  • Backoff verified: failed channels skipped on subsequent polls, recovery clears state
  • Code review: off-by-one fixed, false "recovered" log fixed, cap test strengthened

… backoff

getMessages returned [] when `after` was older than the cache window,
breaking clients using after=0 ("give me everything"). Now clamps to
the window start so all cached messages are returned.

Adds ChannelHealth tracker to the poller with exponential backoff
(pollInterval × 2^(failures-1), cap 16×) so channels that consistently
fail (403/404) stop wasting rate-limit budget. Self-healing on success.

Closes #12

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bakeb7j0 bakeb7j0 merged commit f410e3a into main Apr 13, 2026
4 checks passed
@bakeb7j0 bakeb7j0 deleted the fix/12-cache-clamp-and-poller-backoff branch April 13, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cache): clamp old snowflakes instead of returning empty + add poller channel backoff

1 participant