{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-sse-event-id-reuse-from-corrupting-resumed-mcp-sessions-after-a-transport-level-reconnect",
  "title": "Which invariants prevent SSE event-ID reuse from corrupting resumed MCP sessions after a transport-level reconnect",
  "date_of_record": "2026 November 30",
  "scope": "Applies to MCP servers using HTTP-native transport where a single SSE stream carries multiplexed JSON-RPC responses/notifications for one logical session across multiple `GET /sse` reconnects with `Last-Event-ID` resumption. Does not cover stdio transport, stateless HTTP POST-only servers, or WebSocket transports that handle their own framing.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-event-id-reuse-from-corrupting-resumed-mcp-sessions-after-a-transport-level-reconnect.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-event-id-reuse-from-corrupting-resumed-mcp-sessions-after-a-transport-level-reconnect.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-event-id-reuse-from-corrupting-resumed-mcp-sessions-after-a-transport-level-reconnect.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1810,
    "python_slice_tokens": 421,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There is a difference between *resuming a stream* and *resuming a session*. HTTP `Last-Event-ID` semantics only guarantee \"deliver events strictly after the ID you last saw.\" They say nothing about whether the event IDs you saw belonged to the same logical session, the same in-flight request set, or the same server process. MCP servers commonly conflate thes...",
    "what_was_observed": "A server multiplexed responses for N concurrent tool calls over one SSE stream. Event IDs were assigned from a per-process atomic counter (`event_id = next(counter)`). The mapping `event_id -> (session_id, payload)` lived in an in-memory ring buffer of the last 10,000 events. When a client's TCP connection died mid-tool-call (proxy idle timeout at 60s while a `long_running_analysis` tool ran for 90s), the client reco...",
    "condition_of_validity": "Resumption is only safe when all of the following hold simultaneously: - **ID namespace is session-scoped, not process-scoped.** Event IDs must be opaque tokens that encode or reference `(session_id, session_epoch, sequence)` where `session_epoch` increments on every server restart or session re-initialization. A bare integer counter satisfies none of this. ...",
    "decision_boundary": "The boundary is: **does the reconnect preserve the identity of the logical session, or does it merely preserve the byte stream?** - If the server's `Last-Event-ID` handler can prove the ID belongs to the *current* session epoch and is still retained → resume is valid; pending futures remain live. - If the ID belongs to a *prior* epoch, or is evicted, or the ...",
    "operational_effect": "Without these invariants, the observable symptoms are: (a) tool results delivered to the wrong pending request under concurrent load, (b) indefinite hangs after buffer eviction during long tool calls, (c) post-restart replay of stale session events into a live context window, corrupting the agent's working memory with results from a prior conversation. All t..."
  },
  "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": "4fec68fa469eaa0d1e8ab3f8da2849cda43bf34bf3aa20c654d7588d539bb874",
    "verified_classes": [
      "SessionResumeViolation",
      "EventToken",
      "ResumeGate"
    ],
    "verified_functions": [
      "handle_reconnect",
      "encode",
      "decode",
      "__init__",
      "validate_resume"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "SessionResumeViolation"
    ],
    "sample_fail_closed_invariants": [
      "assert handle_reconnect(gate, '7.4999.deadbeefdeadbeef') == 4999"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
