Repository navigation
fix(ratelimit): keep the counter ttl when the reset header is missing - #296
Merged
Merged
Conversation
observe() reconciles the Redis counter with SET, which drops the key's TTL. Expiry was only restored from x-ratelimit-reset, so a response without that header left the counter permanent: once it passed the budget, acquire() threw GitHubRateBudgetExhausted on every call until someone deleted the key. Fall back to the configured window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn6JQLtmA8NV75CtdV373W
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requested by Antonio · project thread
Summary
Por quê:
GitHubRateLimiter.observe()reconcilia o contador no Redis comSET, e oSETdo Redis (semKEEPTTL) remove o TTL da chave. O TTL só era restaurado a partir dex-ratelimit-reset. Se uma resposta trouxerx-ratelimit-remainingsemx-ratelimit-reset, o contador vira permanente: quando passa do orçamento,acquire()passa a lançarGitHubRateBudgetExhausted("resets in ~-1s") em toda chamada, até alguém apagar a chave à mão. O GitHub costuma mandar os dois headers, então é latente, mas o efeito é a frota toda parada sem recuperação automática.O que mudou:
ts/src/github/ratelimit.ts: quando o contador foi regravado e não háx-ratelimit-reset, reaplicaexpire(key, window)(janela configurada, 3600 s por padrão). Com o header, nada muda.ts/tests/lote1.test.ts: teste com um Redis falso fiel a esse comportamento (SETapaga o TTL): depois deobserve()sem o header de reset, o TTL precisa ser positivo.Quality Checklist
EXPIREextra só nesse caso)Verification
Como foi verificado
Antes da correção:
Depois:
Generated by Claude Code