Skip to content

feat(cli): --load-connections spreads a load run over many sessions - #2791

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/feat/2746-load-connections
Oct 25, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/feat/2746-load-connections

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2746

What

--load-connections <n> (default 1) spreads a --load run over n independent connections (sessions) to the same server — same resolved transport, headers and OAuth — and reports one combined summary. It answers what a single-session run cannot: per-session state, session setup cost, connection limits and contention that only shows up across sessions.

Decisions on the issue's open questions

  • stdio: rejected. Over stdio every connection spawns its own server process, so n connections would test n isolated servers, not one server under n sessions. --load-connections above 1 against a stdio server fails with exit 1 before anything connects. Loosening this later is non-breaking; tightening it would not be.
  • --load-concurrency is the total across all connections (as is --load-rate), so both keep their existing meaning. Worker i is pinned to connection i % n, which splits workers as evenly as the counts allow. --load-connections may not exceed --load-concurrency (default concurrency included): a connection with no worker would carry no calls and would only inflate the session count the run claims to have tested.
  • Connect cost is kept out of latency. All extra connections are opened, concurrently, before the clock starts. Their connect times are reported on their own as connections.connectMs (a latency distribution). The first connection is excluded because the CLI opens it before any load run.
  • Connect failures are reported apart from call errors. A failed connect does not abort the run. The run goes ahead on the connections that did open, and the failures go under connections.failed / connections.errorMessages, never into errors / errorRate. A server refusing its Nth session is exactly what this mode is for finding. errorRate and latencyMs.p99 keep their meaning: calls only.
  • OAuth. Extra connections connect stored-auth-only, after the primary connection has completed any login the run needed, so n connections never start n interactive flows. They share the process-wide in-memory OAuth store, so a token refreshed by one is visible to the rest. Two connections hitting an expired token at the same instant can each try a refresh. A single connection under --load-concurrency already has that same exposure; it is not new here. Against a server that rotates refresh tokens, the losing refresh may surface as call errors. The README says so. Adding single-flight refresh would mean changing SDK-owned auth plumbing, which is out of scope.
  • Teardown. Every extra connection is disconnected in a finally. The disconnects are settled independently, so one failing teardown neither hides another nor replaces the summary or error. An extra that fails mid-connect is disconnected by the factory that made it.

Default unchanged

With --load-connections absent or 1, the run is exactly the old path (runLoad on the primary connection) and the summary is byte-identical. The new connections object is added only when more than one connection is requested. A test pins this.

Shape

  • core/cli/handlers/load-test.ts: connections in LoadOptions / resolveLoadOptions. runLoad hands each call its worker index. The new runLoadAcrossConnections holds all of the orchestration (open before the clock, pin workers, tally connect failures, close in finally). runToolLoad takes an optional openConnection factory.
  • clients/cli/src/cli.ts: the InspectorClient options are named so an openLoadConnection factory can build identical clients. The factory goes to runToolLoad. There is also the flag, its bound check, and the stdio check at the top of callMethod. The stdio check sits there, rather than at parse time, because the server's transport is only resolved later.
  • clients/cli/README.md: flag row, plus the multi-connection section in "Load testing a tool".

Tests

Engine unit tests cover even spread and pinning, extras closed but never the primary, closing on a thrown run and a failing close, partial and total connect failure, connect time kept out of latency, and the missing-factory guard. CLI tests cover three distinct Mcp-Session-Ids against the HTTP test server, --load-connections 1 leaving the summary unchanged, and the stdio, bound and requires --load rejections. load-test.ts is at 100% lines and functions and 98.9% branches; cli.ts is at 99.4% lines.

npm run local:gate: green.

🤖 Generated with Claude Code

…2746)

--load ran every call over the one connection the CLI opened, so it could
not show how a server behaves with many clients at once. --load-connections
<n> opens n independent InspectorClient connections over the same resolved
transport, headers and OAuth, pins worker i to connection i % n, and reports
one combined summary.

- HTTP/SSE only: over stdio each connection would spawn its own server.
- --load-concurrency (and --load-rate) stay totals across connections, and
  --load-connections may not exceed --load-concurrency.
- Extras are opened concurrently before the clock starts; their connect
  times are reported apart, in connections.connectMs.
- A failed connect is counted under connections, never as a call error; the
  run goes ahead on the connections that opened.
- Extras connect stored-auth-only and are disconnected in a finally.
- The default (1) leaves the summary byte-identical: the connections field
  appears only above one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 25, 2026
@cliffhall
cliffhall requested a balanced review from Copilot October 25, 2026 02:00

Copilot AI 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.

🟢 Approval recommended

No blocking issues remain in connection lifecycle handling, worker routing, validation, or single-connection compatibility.

No open issues 🎉

What changed in this PR

Adds opt-in multi-session load testing to the one-shot CLI, using the shared load engine while preserving the default single-connection behavior.

Changes:

  • Adds --load-connections with HTTP/SSE-only validation and a limit tied to total concurrency.
  • Distributes workers across connections, reports setup timing and connection failures separately, and cleans up extra connections.
  • Documents the behavior and adds engine and CLI tests for session routing, lifecycle handling, validation, and compatibility.
File Description
core/​cli/​handlers/​load-test.ts Adds connection orchestration, worker routing, and combined connection metrics.
clients/​cli/​src/​cli.ts Wires the flag, validation, and stored-auth-only connection factory.
clients/​cli/​README.md Documents multi-session behavior, metrics, and OAuth limitations.
clients/​cli/​__tests__/​load-test.test.ts Covers orchestration, distinct HTTP sessions, failures, and default compatibility.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 was clean (no inline comments, no headline findings, no suppressed comments), so per pr-flow 7c no further round is requested.

@cliffhall
cliffhall merged commit 702b38e into v2/main Oct 25, 2026
11 checks passed
@cliffhall
cliffhall deleted the v2/feat/2746-load-connections branch October 25, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI --load: multi-connection mode (--load-connections) to test many sessions, not one

2 participants