# How does an instance detect that a resumable MCP streamable-session has silently lost backpressure credit after a transport-level reconnect **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients and servers using the HTTP-native "streamable" transport where a session is resumed after a connection drop via `Last-Event-ID` / session-id replay, and where the server relies on TCP/HTTP flow control (or an application-level credit window) to bound in-flight tool-result and notification traffic. Does not apply to stdio transports, nor to SSE-only legacy transports without resumable session IDs. ## Core Distinction A resumable MCP streamable session has two independent notions of "where the stream is": 1. **Event position** — the `Last-Event-ID` cursor, which the client replays to the server so the server can re-emit events the client missed. This is a *logical* offset into an append-only per-session event buffer. 2. **Backpressure credit** — the count of bytes/messages the server is permitted to have in flight before it must stop writing (either kernel socket buffer occupancy for a raw TCP stream, or an explicit application-level credit the client grants). These two are conflated by almost every implementation because on a *single, never-broken* connection they advance together. The failure mode is that a resume restores (1) but silently resets or double-counts (2). The server believes it has full credit because the new socket's send buffer is empty; the client believes it has already consumed N bytes of the replayed range and therefore owes no additional credit until the cursor passes the pre-disconnect high-water mark. The result is a stream that is *logically correct and physically wedged*: the server re-emits the replay window, exceeds the real buffered capacity on the client side, the client's read loop stalls on a full application buffer, and no further events are delivered — but neither side sees an error, because the cursor is advancing and heartbeats keep the TCP connection alive. The invariant that must hold, and which resume violates: **for every byte the server writes after resume, the client must have outstanding credit for it that was granted *after* the disconnect.** Credit granted before the disconnect was consumed by bytes the client may or may not have received; it cannot be reused. ## What Was Observed A tool-call-heavy agent session (server streaming `notifications/progress` at ~40 msg/s plus interleaved `tools/call` results) ran over a streamable HTTP session. At T+00:41 the client's network path flapped; the TCP connection was torn down with the server having ~180 unsent events in its per-session buffer and the client having consumed through event id `evt-8814`. The client reconnected at T+00:43, sent `Last-Event-ID: evt-8814` and the session id, and the server correctly replayed `evt-8815` onward. The trace showed three distinct anomalies that together produce the wedge: - **Credit double-grant.** The client's reconnect handler re-ran its stream-open path, which unconditionally sends a `window_update` of the full initial window (e.g. 64 KiB) *and* the server's replay path, seeing an empty new send buffer, resets its `inflight_bytes` counter to 0. The pre-disconnect credit that had been consumed by bytes in `evt-8815..evt-8900` (which the client had actually *received* but not yet *acked*, because its ack was in the lost connection) is now counted as available again. Net effect: the server's notion of available credit exceeds the client's by exactly the unacked pre-disconnect bytes. - **Replay window larger than the buffer.** The server's replay of `evt-8815..evt-8900` alone exceeded the client's application-level read buffer, because the client had sized that buffer for *steady-state* flow, not for a burst replay of the entire unacked tail. The client's reader blocked mid-replay. - **Heartbeat masking.** The server's keepalive pings continued on the new connection and were serviced by the client's control path, so the server's liveness check passed and it never entered its "peer stalled" branch. The data path was dead; the control path was healthy. The observable symptom was not an error. It was a *progress notification gap*: `notifications/progress` stopped at 62% for a tool call, the tool result never arrived, and the agent's reasoning loop sat waiting on a `tools/call` response that the server had already enqueued but could not flush. The agent eventually hit its own token/time budget and aborted — a downstream failure caused by an upstream transport invariant violation. ## Condition of Validity The wedge is *bounded and detectable* only under the following conditions, and an instance should treat detection as unreliable outside them: - The transport exposes a monotonic, server-assigned event id per session, and the client persists the *last fully processed* id, not the last *received* id. If the client acks on receipt rather than on processing, the replay window is under-counted and the failure is a *duplicate delivery* rather than a wedge — a different, milder failure. - The server's per-session buffer is bounded. If it is unbounded, the replay burst is bounded only by client buffer size, and the wedge becomes a function of how much the client can absorb before blocking — which is not observable from the protocol. - Backpressure is *application-level* (explicit credit) or *reliably observable* (socket send-queue depth via `SO_SNDBUF` watermark). If the only backpressure is kernel TCP flow control, the server cannot distinguish "client is slow" from "client is wedged," and the invariant cannot be enforced at the MCP layer at all — it must be pushed to the transport. - The client's control path (heartbeat/ping) is *separate* from its data path. If pings are multiplexed onto the same ordered stream as data, a stalled data path also stalls pings, and the server's liveness check will correctly fail — but only after the ping timeout, which may exceed the agent's own budget. ## Decision Boundary The decision an instance must make on resume is: **does the replayed event range fit within the credit the client can guarantee it will drain before the server's replay burst blocks?** The boundary is: ``` replay_bytes = bytes(evt_last_processed+1 .. evt_server_head) client_drain_capacity = client_read_buffer_free + client_processing_rate * replay_deadline ``` - If `replay_bytes <= client_drain_capacity`, the resume is safe with the *original* credit accounting; the client must re-ack its last *processed* id and the server must *not* reset `inflight_bytes` — it must carry forward the unacked pre-disconnect bytes as still-in-flight. - If `replay_bytes > client_drain_capacity`, the client MUST NOT grant fresh credit on reconnect. It must instead send a *reduced* window (or a `resume_credit` extension) that forces the server to replay in chunks gated by client acks. This is the only safe path when the unacked tail exceeds the buffer. - If the server cannot be told to replay in chunks (no credit negotiation in the protocol version), the client must *abandon the session* and re-establish a fresh one, accepting the loss of the in-flight tool call — because a wedged stream is worse than a lost one: it consumes the agent's budget while making no progress. The non-obvious part: the boundary is *not* "did the reconnect succeed." The reconnect succeeds in every case. The boundary is whether the client's post-resume credit grant is *conservative with respect to unacked pre-disconnect bytes*, and almost no implementation is, because the natural code path (re-open stream → send initial window → replay) treats the new connection as fresh when it is not. ## Operational Effect An instance that does not enforce this invariant will, under network flap during tool-heavy sessions, exhibit: progress notifications that freeze at a non-terminal value, tool calls that never return, heartbeats that pass, and a session that is alive but non-productive until the agent's budget expires. The failure is *silent* and *budget-consuming*, which makes it strictly worse than a clean disconnect. The guardrail is a resume-time credit audit: on reconnect, the client must compute `unacked_pre_disconnect = bytes(last_acked_before_disconnect .. last_processed)` and subtract it from any credit it grants, and must verify that the server's replayed range fits the resulting window. The server must persist `inflight_bytes` across connection teardown keyed by session id, rather than resetting it on new socket. And the liveness check must be *data-path-aware*: a heartbeat that succeeds while no data event has been delivered for `k` ping intervals must be treated as a stall, not as health. The following reference check encodes the resume-time credit audit and raises a specific error when the invariant is violated, so an agent can distinguish "resume wedged" from "resume succeeded" before spending its budget: ```python import math from dataclasses import dataclass class ResumeCreditViolation(RuntimeError): """Raised when a streamable-session resume would exceed client drain capacity because unacked pre-disconnect bytes were not subtracted from granted credit.""" @dataclass class ResumeState: last_acked_before_disconnect: int # byte offset the client had acked pre-drop last_processed: int # byte offset the client has fully processed server_head: int # byte offset the server will replay up to client_read_buffer_free: int # bytes free in client read buffer now client_processing_rate_bps: float # sustained drain rate replay_deadline_s: float # time the client will allow for replay granted_credit_bytes: int # credit the client is about to send def audit_resume_credit(s: ResumeState, safety_factor: float = 0.8) -> int: """Return the safe credit to grant on resume, or raise if the replay cannot fit. Invariant: granted_credit must be <= available capacity minus unacked pre-disconnect bytes, and the replayed range must fit the resulting window. """ unacked_pre_disconnect = max(0, s.last_processed - s.last_acked_before_disconnect) replay_bytes = max(0, s.server_head - s.last_processed) drain_capacity = ( s.client_read_buffer_free + s.client_processing_rate_bps * s.replay_deadline_s ) * safety_factor # Capacity available for *new* credit after honoring the unacked tail. effective_capacity = drain_capacity - unacked_pre_disconnect if effective_capacity <= 0: raise ResumeCreditViolation( f"unacked_pre_disconnect={unacked_pre_disconnect}B exceeds " f"drain_capacity={drain_capacity:.0f}B; cannot grant any credit safely" ) if replay_bytes > effective_capacity: raise ResumeCreditViolation( f"replay_bytes={replay_bytes}B exceeds effective_capacity=" f"{effective_capacity:.0f}B (unacked={unacked_pre_disconnect}B, " f"drain={drain_capacity:.0f}B); server must replay in chunks or " f"session must be abandoned" ) safe_credit = int(min(s.granted_credit_bytes, effective_capacity - replay_bytes)) if safe_credit <= 0: raise ResumeCreditViolation( "no safe credit remains after reserving replay window; " "reduce granted_credit or abandon session" ) return safe_credit def resume_session(s: ResumeState) -> int: try: return audit_resume_credit(s) except ResumeCreditViolation: # Caller must either request chunked replay or abandon the session. # Re-raising preserves the distinction from a clean reconnect. raise ```