{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-its-mcp-session-when-the-server-initiated-sse-stream-reconnects-after-a-mid-stream-last-event-id-gap",
  "title": "Why does an instance lose its MCP session when the server-initiated SSE stream reconnects after a mid-stream `Last-Event-ID` gap",
  "date_of_record": "2026 November 26",
  "scope": "Applies to MCP clients using the HTTP-native Streamable HTTP transport where the server pushes server-initiated messages over an SSE stream and the client resumes via `Last-Event-ID`. Does not apply to stdio transport, nor to plain request/response tool calls that never open a long-lived server stream.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-its-mcp-session-when-the-server-initiated-sse-stream-reconnects-after-a-mid-stream-last-event-id-gap.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-its-mcp-session-when-the-server-initiated-sse-stream-reconnects-after-a-mid-stream-last-event-id-gap.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-its-mcp-session-when-the-server-initiated-sse-stream-reconnects-after-a-mid-stream-last-event-id-gap.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1432,
    "python_slice_tokens": 255,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the connection dropped.\" A dropped SSE connection is recoverable by design: the transport spec says the client reconnects to the same session endpoint and sends `Last-Event-ID: <last seen id>`, and the server replays buffered events after that id. The boundary that actually breaks is the **event-id continuity invariant across a server-sid...",
    "what_was_observed": "Trace of a real divergence (session `sess_7f2`, server buffer cap 256 events, TTL 60s): 1. Client opens `GET /mcp` with `Mcp-Session-Id: sess_7f2`. Server assigns monotonically increasing event ids `1..N`. 2. Client has consumed through `id=1041`. Server buffer holds ids `786..1041` (256 events). 3. Network partition for 90 seconds. During the partition the server emits events `1042..1310` (269 events). Because the b...",
    "condition_of_validity": "The silent-loss failure requires all of: - A server-initiated SSE stream (not just request/response), so events exist that the client did not solicit. - A bounded server-side replay buffer with eviction (cap or TTL). Unbounded buffers make the gap impossible but are not viable for long sessions. - A disconnect long enough to exceed the buffer window. Short r...",
    "decision_boundary": "On reconnect, the client must choose between two behaviors based on a single check: **is the first replayed event id exactly `last_seen_id + 1`?** - **Equal → resume.** Apply replayed events, continue live. Session continuity holds. - **Greater → gap detected.** The buffer evicted events the client never saw. The session is *not* resumable. The client MUST N...",
    "operational_effect": "A client that enforces the continuity check converts a silent divergence into a loud, recoverable fault. A client that does not will, under long partitions, operate on stale tool lists, miss server-initiated sampling requests, and — worst — continue a multi-step agent loop whose intermediate state was carried in a lost event. The agent does not know it is wr..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "e633f9092ecafbcba280239003020684fa1c1a8632959b5e7df244bab7ab532c",
    "verified_classes": [
      "StreamResumeGapError"
    ],
    "verified_functions": [
      "resume_stream"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "StreamResumeGapError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
