Skip to content

mcpx(completion): rate limiter admits before pool validation — unknown server names mint fresh limiter buckets, so the per-server window never binds bogus names and bucket growth is request-rate × window #6978

Closed

Description

@dezren39

Finding

In handleComplete, the completion rate limiter is consulted before the pool lookup validates the requested server — by design, so a refused request never wakes an upstream. But the limiter keys include the requested server name, and CanonicalName passes unknown names through unchanged. So every distinct bogus server value mints fresh limiter buckets: the per-server window (completion.serverPerMinute) can never bind a name that does not exist (each name has its own budget), the per-caller window is also keyed per server spelling, and bucket growth between sweeps is bounded only by request rate × the sweep interval. The handler's own tests demonstrate the ordering: with an unknown server, an admitted request reaches the pool lookup and gets a 400 — after it has already been counted by the limiter.

Evidence

  • Source PR: feat(mcpx): completion rate limit at the /v1 choke point (#2387) #3730 (merged, merge commit e49c0beeb801f21cec7234accf17139d7ed11b79) — limiter placed "after shape validation and before s.reg.Pool(...)".
  • On current main (fc035359245855fd5b3db1d6b85ee60223abcf20, verified via git show origin/main):
    • pkgs/mcpx/internal/daemon/ops.go line 378: if refused := s.completeLimiter.admit([]limitCheck{...}) with keys "caller\x00" + completionCaller(cc) + "\x00" + serverName and "server\x00" + serverName; the pool validation p, ok := s.reg.Pool(req.Server) is only at line 397, after admission.
    • pkgs/mcpx/internal/daemon/registry.go lines 1467–1479: CanonicalName returns nameOrNS unchanged when it matches no pool and no namespace.
    • pkgs/mcpx/internal/daemon/ratelimit.go line 85: admission creates l.buckets[c.Key] = &rateBucket{start: now, n: 1} per new key; expired buckets are swept at most once per minute (lines 77–84) and only on the new-bucket path.
    • pkgs/mcpx/internal/daemon/completion_ratelimit_test.go: TestHandleCompleteRateLimitRefusesBeforePool uses an unknown server and expects admission to precede the pool's 400 — pinning the ordering without pinning any bound on distinct-name buckets.

Why it matters

The per-server window is described in the PR as "the backstop that does not depend on caller identity" — for nonexistent servers it is no backstop at all, and a client spraying distinct bogus server names grows the limiter's in-memory map at request rate for at least a full window per name. Impact is bounded (bogus requests still 400 and never wake an upstream), but the limiter's own state should not be client-shaped: validating the server exists before admission, or not minting buckets for names the registry does not know, closes it without changing the refusal-before-pool guarantee for real servers.

Acceptance criteria

  • Requests naming a server/namespace the registry does not know do not create limiter buckets (e.g. existence is checked before admission, while refusal for known servers still happens before any pool lease is acquired).
  • A handler test pins it: repeated /v1/complete calls with distinct unknown server names leave the limiter's bucket count bounded (or are refused without admission).
  • Existing completion rate-limit tests still pass, including refusal-before-pool for a known server and the canonical-spelling sharing test.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. added
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 7, 2026
  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

    • Agent: repo queue worker, lane code-y
    • Task: task 11362 handed off to the opencode claimant per execution-lane assignment (checkpoint stage handed_off). The claimant's bound opencode session drives this task to its terminal state.
  5. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 lane=code-b task=11362 stage=handed_off — Issue #6978 revalidated fresh: OPEN, no hard-stop labels. Task 11362 (triage) opencode-assigned (lane row 3656); handing off to opencode claimant, parking 1200s.

    🤖 Agent note · handed off

  6. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 10, 2026
  7. 15 remaining items

  8. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up direct (lane code-b)

  10. added
    queue/claimedQueue worker lifecycle state
    and removed on Nov 11, 2026
  11. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (lane code-b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/pr-diff-reviewFiled by the pr-diff-review jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions