fix(rate-limit): warn once when the key ceiling binds; correct eviction policy docs - #314
Open
claudegoogl-sudo wants to merge 1 commit into
Open
fix(rate-limit): warn once when the key ceiling binds; correct eviction policy docs#314claudegoogl-sudo wants to merge 1 commit into
claudegoogl-sudo wants to merge 1 commit into
Conversation
…iction The store comment claimed the oldest-first eviction policy "drops the coldest keys, not the hottest". The store evicts FIFO by first insertion: a long-lived hot key inserted before a flood is evicted before cold keys inserted after it. The module header, the DEFAULT_SLIDING_WINDOW_MAX_KEYS doc, and the record() contract now say exactly that. Ceiling eviction was also silent. It now emits a single logger.warn per store instance on the first eviction, naming the limiter and the ceiling via a new optional store `name`. Repeat evictions stay silent so a key flood cannot become a log flood. The webhook limiter names its three bucket stores (endpoint, ip, verified-endpoint) and the wake limiter names its store. No change to eviction or limiting behaviour. Co-Authored-By: Paperclip <noreply@paperclip.ing>
claudegoogl-sudo
force-pushed
the
chore/rate-limit-eviction-observability
branch
from
September 8, 2026 01:27
3a49791 to
9a183da
Compare
11 tasks
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.
Follows
CONTRIBUTING.mdPR template — sections present: Thinking Path, Linked Issues or Issue Description (path B, enhancement labels), What Changed, Verification, Risks, Model Used, Checklist.Thinking Path
Linked Issues or Issue Description
No public GitHub issue exists for this internal hardening follow-up. Framed as an Enhancement per
.github/ISSUE_TEMPLATE/enhancement.yml:Pre-submission checklist
What existing behavior does this improve?
The sliding-window rate-limit store (
server/src/services/sliding-window-rate-limit-store.ts): the accuracy of its eviction-policy documentation, and observability when themaxKeysceiling binds.Subsystem affected
server/ — REST API & orchestration services
Current behavior
When a new key pushes the live-key map over
maxKeys, the store evicts the first-inserted live key and logs nothing. The module comment claims the policy "drops the coldest keys, not the hottest". That is wrong: the store is FIFO by first insertion, not LRU. A long-lived hot key inserted before a flood is evicted before cold keys inserted after it.Proposed behavior
The comment states FIFO-by-first-insertion accurately. The first ceiling eviction per store instance emits exactly one warning naming the limiter and the ceiling:
Repeat evictions stay silent, so a key flood cannot become a log flood.
Reason and benefit
A binding ceiling means the live working set no longer fits. That is the one signal that the ceiling is mis-tuned or that a key-flood attack is in flight. Without a log line that state is invisible. The corrected comment stops future maintainers from reasoning about the store as an LRU cache.
Breaking changes
None. Eviction order, limiting decisions, and the store API shape are unchanged. The new
nameoption is optional and defaults to a generic store name.What Changed
server/src/services/sliding-window-rate-limit-store.ts: corrected the FIFO claims in the module header, theDEFAULT_SLIDING_WINDOW_MAX_KEYSdoc, and therecord()contract. Added an optionalnameoption. Added a once-per-instancelogger.warnon the first ceiling eviction with{ limiter, maxKeys }context.server/src/services/plugin-webhook-rate-limit.ts: names its three storesplugin-webhook:endpoint,plugin-webhook:ip, andplugin-webhook:verified-endpoint.server/src/services/plugin-wake-rate-limit.ts: names its storeplugin-wake.server/src/__tests__/sliding-window-rate-limit-store.test.ts: new "eviction observability" tests. Two evictions produce exactly one warning. No warning when the ceiling never binds. A fresh store instance warns again.Verification
node_modules/.bin/vitest run server/src/__tests__/sliding-window-rate-limit-store.test.ts server/src/__tests__/plugin-webhook-rate-limit.test.ts server/src/__tests__/plugin-wake-rate-limit.test.ts— 3 test files passed, 64 tests passed (21 store, 43 webhook limiter, wake limiter included).pnpm --filter @paperclipai/server typecheck(tsc --noEmit) — exit 0.warnwas called exactly once after two separate ceiling evictions, assert the warning context equals{ limiter, maxKeys }, and assert no warning before any eviction.Risks
Low risk. The only runtime change is one log line per store instance, plus a
loggerimport into the store module. Eviction order, map-size behaviour, and limiting decisions are untouched. All pre-existing rate-limit tests pass without modification.Model Used
Checklist
Fixes: #/Closes #/Refs #OR (b) described the issue in-PR following the relevant issue template#NNN/github.com/paperclipai/paperclipURLs)docs/...,fix/...) and contains no internal Paperclip ticket id or instance-derived details