Repository navigation
Description
mcpx(completion): completionCaller keys the per-caller rate limit on the daemon's own PID for /v1/exec callers — PIDShared is ignored, so unrelated exec callers share one completion.perMinute budget
Summary
The completion rate limiter added in #2387 (PR #3730) derives its per-caller key from
completionCaller (pkgs/mcpx/internal/daemon/ops.go:443-452):
func completionCaller(cc config.CallContext) string {
switch {
case cc.SessionID != "":
return "session:" + cc.SessionID
case cc.PID > 0:
return "pid:" + strconv.Itoa(cc.PID)
default:
return "call:" + cc.CallID
}
}The cc.PID > 0 arm never checks cc.PIDShared. That flag exists precisely for a PID
that does not identify the caller: callContext sets it when the reported PID is
the daemon's own (pkgs/mcpx/internal/daemon/server.go:1079-1081), which is what every
/v1/exec run reports — the exec service puts the daemon's os.Getpid() in the script
environment as MCPX_PID (pkgs/mcpx/internal/execsvc/execsvc.go:989), and the generated
client forwards it as the x-mcpx-pid header (pkgs/mcpx/internal/codegen/emit.go:722).
config.CallContext documents the doctrine (pkgs/mcpx/internal/config/scope.go:34-39):
a shared PID "is a shared instance key, never caller-private", and CallerOwned guards
its pid arm with !c.PIDShared (scope.go:64). completionCaller is the one consumer
that doesn't.
Verified behavior (this run, main b4c4a99)
Laptop probe ~/git/fleet/probe-2026-11-01-laneB-pidshared/ (verbatim completionCaller
rateLimiter.admit; ops.go md5 7851998d, ratelimit.go md5 f49ba6ff, scope.go md5
34a729d6, all @ b4c4a99):
CASE shared-pid caller A key: "pid:4242"
CASE shared-pid caller B key: "pid:4242"
CASE admit A (limit 1): refused=<nil>
CASE admit B (limit 1): refused=true by completion.perMinute
CTRL own-pid keys: "pid:111" vs "pid:222"; admit C refused=<nil>, admit D refused=<nil>
CTRL session keys: "session:s1" vs "session:s2"
Two distinct session-less exec callers (each with its own per-call id, PIDShared=true)
collapse into the single bucket caller\x00pid:<daemon-pid>\x00<server> used at
ops.go:371. The first caller's admissions exhaust completion.perMinute for every
exec caller of that server until the window rolls; the rest get 429s naming a limit they
never personally consumed.
This also contradicts completionCaller's own doc comment: the per-call fallback is
supposed to leave a caller with nothing stable to bind "effectively unwindowed per
caller" — a session-less exec caller has nothing stable of its own (its PID is the
daemon's), yet it is windowed, collectively with all other exec callers.
Why it matters
- Spurious cross-caller 429s on the completion path for exactly the caller class
(agent exec scripts) that drives the daemon hardest; the failure looks like the
caller's own quota and is undiagnosable from the 429 text. - The per-server window (
completion.serverPerMinute) is the designed backstop for
unbindable callers; the per-caller window silently becoming a second, accidental
aggregate window defeats the two-window design from design(mcpx): completion, finished — one rate limit at the /v1 choke point, relevance-ranked local answers #2386/mcpx: Phase 1 of #2386 — completion rate limit at the /v1 choke point (limiter + completion.* settings, before the pool) #2387.
Acceptance criteria
completionCallertreats aPIDSharedPID as no PID: a session-less caller with
PIDShared=truekeys on its per-call id (call:<CallID>), matchingCallerOwned's
!PIDSharedguard.- Regression tests: two
PIDSharedcontexts with distinct CallIDs get distinct keys
and do not refuse each other at limit 1; own-PID and session keying unchanged
(existingratelimit_test.go/completion_ratelimit_test.gocases still pass). - A handler-level case (following the
TestHandleComplete…pattern) shows one
exec-style caller (daemon PID, no session) no longer 429s a second such caller
undercompletion.perMinutealone.
Dedup / related
- mcpx: Phase 1 of #2386 — completion rate limit at the /v1 choke point (limiter + completion.* settings, before the pool) #2387 (closed) built the limiter; its tests never exercise a
PIDSharedcontext —
noPIDSharedreference exists in the daemon tests. - mcpx: /v1/exec leaves session-scoped servers running, /mcp never rebuilds its surface, /v1/protocol reports the default nativeElicit, stats reads one opencode database #1942 follow-up (in
server.gocomments) established the daemon-PID sharing trap
for instance keys; this is the same trap in the new rate-limit key. - Searched open + closed for
completionCaller,PIDShared completion, and2387:
no existing issue covers this.
Activity
developing-today commentedon Nov 1, 2026
CODE-1525
dezren39 commentedon Nov 1, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 1, 2026
🤖 Agent note · picked up
Merge pull request #3784 from developing-today/creator-b/3783-pidshar…
dezren39 commentedon Nov 1, 2026
🤖 Agent note · done