Repository navigation
feat(mcpx): completion rate limit at the /v1 choke point (#2387) - #3730
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 32 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 325dd927cb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…pletion.perMinute + completion.serverPerMinute (#2387) -- their effects are covered by the internal/daemon handler tests named in their exemptions, in the established protoTasks/artifacts exemption style
|
Queue task 5604 (lane A): deliberate EffectExemptionPin raise 188 → 190 in 7b30a33, recorded here per the ratchet rule — the two new exemptions are this PR's completion.perMinute + completion.serverPerMinute, whose effects are covered by the internal/daemon handler tests named in their exemption entries (429 before the pool at the limit; per-server window binds across callers; canonical-spelling regression test), in the established protoTasks/artifacts exemption style. Verified on the laptop: TestEffectExemptionsOnlyShrink passes; the daemon rate-limit tests pass; the remaining settings failures (TestEveryDocumentHasAChapter, TestNoUndeclaredEnvRead, TestEverySettingHasAnEffectProbeOrAnExemption, TestTheScriptEnvironmentIsWhatTheCodeSets, TestTheEnvironmentDocIsCurrent) fail identically on clean main (verified in a detached main worktree this shift) and the mcpx workflow is red on main itself since the #2878 Complete-signature change — pre-existing, not this PR. |
Implements #2387 — Phase 1 of design #2386: one fixed-window, in-memory rate limiter for
completion/completeat the daemon choke point.Placement. In
handleComplete(pkgs/mcpx/internal/daemon/ops.go), after shape validation and befores.reg.Pool(...)— a refused request never acquires a pool lease or wakes an upstream. The caller identity is thecallContextthe handler already resolves (moved above the pool lookup; session → pid → per-call fallback, documented incompletionCaller).Limiter. New
internal/daemon/ratelimit.go: a generic fixed-window limiter (keys + limits in, verdict out — nothing completion-shaped, per the design's #1554 reuse ask), following thetasks.Windowprecedent (#2333) with atomic multi-window admission: all windows are checked first and only then all counted, so a refusal consumes quota in no window (count-on-admission). Zero value is ready to use; buckets sweep at most once per minute.Settings (hot,
completion.*besidecompletion.maxValues):completion.perMinutedefault 120 (per caller per server),completion.serverPerMinutedefault 600 (per server across callers — the backstop that does not depend on caller identity).0disables that window. Reads are per-request via the existing call settings, so changes take effect without restart.docs/configuration.mdregenerated (+2 lines); effect-probe exemptions recorded ininternal/settings/effect.goin theprotoTasks.perMinutestyle, pointing at the handler tests.Refusal shape. HTTP 429 naming the exhausted limit, e.g.
completion rate limit: completion.perMinute allows 120 per minute for this caller and server. The MCP surface inherits it unchanged throughmcpBackend.Complete→Server.completeas a named-32603(same propagation as the tasks rate window'sErrRateWindow); no new error code.Tests.
ratelimit_test.go, fake clock): limit enforcement, window rollover, count-on-admission across two windows, per-key independence, 0 disables.completion_ratelimit_test.go): with an unknown server, an admitted request reaches the pool lookup (400) while a refused one is 429 — proving refusal happens before the pool; per-server window binds across callers; hot change to 0 disables on the next request.go test ./internal/daemon— full package passes (101s).go vetclean.go test ./internal/settings: the two tests touching new settings pass (TestTheDocumentationListsEverySettingafter regen; no new effect-probe violations). The package's other failures (TestEveryDocumentHasAChapter,TestNoUndeclaredEnvRead,TestTheScriptEnvironmentIsWhatTheCodeSets,TestTheEnvironmentDocIsCurrent, pre-existing probe gaps formodel.*/proto.*/script.*) fail identically on clean main — verified by running them against the pristine checkout.Out of scope per the packet: ranking (#2388), register truth-up (#2389).
Queue task 5604 (repo-health-code-pilot, lane B).
Need help on this PR? Tag
@codesmith-botwith what you need.