Skip to content

mcpx(completion): completionCaller ignores PIDShared — session-less /v1/exec callers all share the daemon PID's completion.perMinute budget #3783

Closed

Description

@dezren39

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

Acceptance criteria

  • completionCaller treats a PIDShared PID as no PID: a session-less caller with
    PIDShared=true keys on its per-call id (call:<CallID>), matching CallerOwned's
    !PIDShared guard.
  • Regression tests: two PIDShared contexts with distinct CallIDs get distinct keys
    and do not refuse each other at limit 1; own-PID and session keying unchanged
    (existing ratelimit_test.go / completion_ratelimit_test.go cases 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
    under completion.perMinute alone.

Dedup / related

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
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 1, 2026
  2. developing-today commented on Nov 1, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run, Sun 2026-11-01 10:20 CST
    • Found via: filed this run
    • Task: Filed after verifying on main b4c4a99 with a laptop probe (verbatim completionCaller + rateLimiter.admit): two session-less PIDShared callers collapse to one pid: key and the second is refused at limit 1; own-PID and session controls distinct. A triage packet is enqueued on repo-health-code-pilot.
    • Expectation: effort/s — triage confirms on current main and routes the fix (PIDShared falls through to the per-call key, plus regression tests per the issue's acceptance criteria).
    • Links: evidence in the issue body; probe ~/git/fleet/probe-2026-11-01-laneB-pidshared/ (laptop)
  4. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run, Sun 2026-11-01 10:20 CST; triage task 5722 cancelled for self-assignment
    • Found via: self-assigned during new-issue-creator run (guarded self-solve, lifecycle protocol §4 — one-condition fix, verified by probe this run)
    • Task: Fix completionCaller to ignore a PIDShared PID (fall through to the per-call key) and add regression tests; branch creator-b/3783-pidshared-completion, PR to follow.
    • Expectation: effort/s — done = PR merged with the daemon package's rate-limit tests green on the laptop.
    • Links: probe ~/git/fleet/probe-2026-11-01-laneB-pidshared/ (laptop); packet packets/packet-3783-triage.json
  5. added
    work/self-assignedAn agent grabbed this item directly, outside the queue
    and removed on Nov 1, 2026
  6. added a commit that references this issue on Nov 1, 2026
  7. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run, Sun 2026-11-01 10:20 CST; triage task 5722 cancelled for self-assignment
    • Found via: self-assigned during new-issue-creator run (guarded self-solve, lifecycle protocol §4)
    • Task: Fixed — PR fix(mcpx): completionCaller ignores a PIDShared PID (#3783) #3784 merged as 3cbab2d: completionCaller's PID arm now requires !cc.PIDShared, so session-less /v1/exec callers key on their per-call id instead of sharing the daemon PID's completion.perMinute budget.
    • Expectation: done — laptop verification: targeted daemon tests PASS (TestCompletionCaller|TestHandleComplete|TestRateLimiter, -count=1), new tests failing-first verified against unpatched main, gofmt clean. Issue closed by the merge (Fixes marker).
    • Links: PR fix(mcpx): completionCaller ignores a PIDShared PID (#3783) #3784; probe ~/git/fleet/probe-2026-11-01-laneB-pidshared/ (laptop); branch creator-b/3783-pidshared-completion (deleted on merge)
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/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions