Repository navigation
perf(server): linked calls reuse sessions while a tool waits - #26567
Conversation
commented
Oct 28, 2026
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Initialized peer sessions become reusable while a tool call is still waiting or after cancellation. Existing per-request authentication, mode limits, and stale-session recovery remain unchanged. You can add or adjust custom eligibility rules. Learn more. |
commented
Oct 28, 2026
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Cache sessions and validate reuse and renewal apps/server/src/peer/PeerMcpClient.ts, apps/server/src/peer/PeerMcpClient.test.ts |
The client stores a newly opened session before sending the tool request. Tests cover reuse during a pending or completed call, requested mode limits, and reuse of a replacement session after a 404 response. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- pingdotgg/t3code#26344: Sends linked-only requests through
PeerMcpClientand includes a watch that can remain pending while another call reuses the initialized session. - pingdotgg/t3code#23834: Allows MCP requests over ACP while another MCP call is pending, using a different transport implementation.
Suggested labels: bugfix, size:M
Suggested reviewers: juliusmarminge, macroscopeapp
Merge Risk: 
Minimal · up to ddf69
-
The session-reuse change is mergeable on the supplied evidence; no concrete blocking failure is established.
Pre-merge checks: 
4
-
Full details: Description check
-
Explanation
The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the defect, the implementation, scope limits, approval rationale, focused tests, observed results, and known limitations.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Note Written by Verified in a real dev environmentverified as-is at created a project pointing to a real git checkout through the web app. drove chrome with the repo's playwright dependency. two real codex sent concurrent mcp calls through the running source server's production forwarding/client path. a transparent proxy counted actual peer requests without recording credentials: a real codex nearby behavior passed: an blacksmith ran Not verifiednative desktop or ios/android clients, other providers, and wan/relay/tunnel links were not exercised on this linux vm. no whole-app latency, cpu, or memory improvement is claimed; the measured change is the real peer request count. there is no visual code change requiring matching before/after screenshots. the recording was trimmed to remove pairing/loading and inspected. the uploaded mp4 playback and seeking passed in t3's browser; the same clip is embedded above as a gif for github rendering. |


Problem
A linked-environment command can repeat MCP initialization while an earlier call on the same peer is still waiting for its response.
PeerMcpClient.callsaves the initialized session only after the firsttools/callPOST returns response headers. A held thread wait therefore leaves a completed, usable handshake unavailable to other calls.The real T3 MCP peer test reproduces this: once the first held tool has entered its handler, a second command sends three authenticated POSTs—initialize, initialized notification, and tool call—instead of using the session for one tool POST.
Change
Publish the session immediately after
openSessionfinishes its initialized notification, before sending the first tool call. Session lifetime already extends beyond an individual tool request, so cancellation of that request also leaves the initialized session available.The existing missing-session (HTTP 404) renewal remains in place. Each call still resolves its peer and carries its own authentication and mode-limit header. This is a change in the shared server MCP client; web, desktop, mobile, providers and scheduled callers keep their existing paths. No UI, wire contract, route ordering or provider adapter changes.
Scope and approval
Submitted as a small, focused fix for the existing session-reuse defect: a completed handshake was hidden until a tool response arrived. It moves cache publication earlier without adding a cache, locking or a setting. This is a proposed application of the obvious-defect exception, not a claim of prior maintainer approval or an exemption.
This is independent of #26551's failed-address route ordering. Simultaneous calls that arrive during initialization can still create separate sessions; this PR addresses calls arriving after initialization completes.
Verification
apps/server:vp test run src/peer/PeerMcpClient.test.ts src/peer/PeerLinks.test.ts src/peer/PeerForwarding.test.ts— 20 tests pass across three files.reuses an initialized session before its first call finishes, holds the first tool at an explicit Deferred milestone. The next call uses one authenticated POST, applies its narrower mode limits, and preserves the original caller's limits. The cancellation case verifies reuse after the first caller stops. Both cases fail on upstream main with three POSTs instead of one.renews a missing peer session once and reuses its replacementchecks the 404 renewal and subsequent session reuse through the real client with a strict transport fixture.git diff --check, and server typecheck pass. Independent source review found no blocking issue.Current-pin performance experiment: real
PeerMcpClientover loopback HTTP to a strict JSON-RPC fixture with 25 ms per-response delay.PeerLinks.resolveand outcome recording are stubbed, so route probes, SQLite and secret reads are excluded. Counts are recorded before fixture response generation; every result and caller's mode limits are checked. Twelve samples per workload/version, six in each process, with main/incumbent and reversed incumbent/main order. Baseline is upstream125b61954dbba5822a8108c8ca47a4846b4b4328; the published source preservesf13ca86b8bwith that main merged.In the held-first workload, JSON request/response bodies fall from 297/253 bytes to 87/123 bytes per measured call. These counts exclude HTTP/TCP/TLS and tunnel overhead. The production MCP peer test also establishes the three-to-one request reduction without the modeled response delay; its one-off timings are not used as latency evidence.
This is controlled service timing on Windows, Node 24.18.0 and Effect 4.0.5. It does not establish a 71% UI or real-tunnel speedup. Retained-heap snapshots vary with runtime/transport state, so no whole-app memory or CPU saving is claimed. An initialized session can now remain cached after first-call cancellation or transport failure where it previously remained uncached. There are no new cache keys or extra synchronization objects. Real relay/device/browser timing was not measured. This backend change has no UI screenshot.
Model: gpt-6.1-sol through Codex in T3 Code.