Skip to content

feat(mcpx): completion rate limit at the /v1 choke point (#2387) - #3730

Merged
dezren39 merged 4 commits into
mainfrom
queue/5604-2387-completion-rate-limit
Nov 1, 2026
Merged

dezren39 merged 4 commits into
mainfrom
queue/5604-2387-completion-rate-limit

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Implements #2387 — Phase 1 of design #2386: one fixed-window, in-memory rate limiter for completion/complete at the daemon choke point.

Placement. In handleComplete (pkgs/mcpx/internal/daemon/ops.go), after shape validation and before s.reg.Pool(...) — a refused request never acquires a pool lease or wakes an upstream. The caller identity is the callContext the handler already resolves (moved above the pool lookup; session → pid → per-call fallback, documented in completionCaller).

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 the tasks.Window precedent (#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.* beside completion.maxValues): completion.perMinute default 120 (per caller per server), completion.serverPerMinute default 600 (per server across callers — the backstop that does not depend on caller identity). 0 disables that window. Reads are per-request via the existing call settings, so changes take effect without restart. docs/configuration.md regenerated (+2 lines); effect-probe exemptions recorded in internal/settings/effect.go in the protoTasks.perMinute style, 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 through mcpBackend.Complete → Server.complete as a named -32603 (same propagation as the tasks rate window's ErrRateWindow); no new error code.

Tests.

  • Limiter units (ratelimit_test.go, fake clock): limit enforcement, window rollover, count-on-admission across two windows, per-key independence, 0 disables.
  • Handler tests (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 vet clean.
  • go test ./internal/settings: the two tests touching new settings pass (TestTheDocumentationListsEverySetting after regen; no new effect-probe violations). The package's other failures (TestEveryDocumentHasAChapter, TestNoUndeclaredEnvRead, TestTheScriptEnvironmentIsWhatTheCodeSets, TestTheEnvironmentDocIsCurrent, pre-existing probe gaps for model.*/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).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 14:39
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 422bd264-6ad3-4d53-b906-cede3a1cc874
Commits

Reviewing files that changed from the base of the PR and between 3cd23c7 and 7b30a33.

Files selected for processing: 9
  • pkgs/mcpx/docs/configuration.md
  • pkgs/mcpx/internal/daemon/completion_ratelimit_test.go
  • pkgs/mcpx/internal/daemon/ops.go
  • pkgs/mcpx/internal/daemon/ratelimit.go
  • pkgs/mcpx/internal/daemon/ratelimit_test.go
  • pkgs/mcpx/internal/daemon/registry.go
  • pkgs/mcpx/internal/daemon/server.go
  • pkgs/mcpx/internal/settings/effect.go
  • pkgs/mcpx/internal/settings/wire.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:20:02.369049Z 4d8e228 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pkgs/mcpx/internal/daemon/ops.go Resolved
…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
@dezren39

dezren39 commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

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.

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.

1 participant