Skip to content

Clean up sessions after legacy initialize parsing fails #1357

Open

Description

@dux-web

Problem

A legacy Streamable HTTP initialize response can include an MCP session ID in
its response headers while its JSON or SSE payload is malformed or empty. The
client currently parses the initialize payload before its normal session
cleanup state is established. If parsing fails, the worker exits without
sending the bounded DELETE for the session that the server already created.

The same gap exists when Auto lifecycle discovery falls back to legacy
initialize.

Proposed direction

  • Capture the raw session ID from a JSON or SSE initialize response before
    parsing it.
  • Retain the headers that were actually used for that initialize request.
  • If initialize parsing fails, run the existing bounded DELETE behavior before
    returning the parse error.
  • On successful parsing and protocol negotiation, replace that provisional
    cleanup state with the normal negotiated session cleanup state.
  • Cover both direct legacy initialization and discovery fallback.

This proposal is deliberately limited to initialize parse failures. Draft
#1267 introduces a broader run_session/outer-cancellation lifecycle and also
centralizes cleanup. The focused change would not copy that refactor, stalled
body handling, or its cancellation suite. I would be happy to fold the narrow
case into #1267 instead if that is the preferred direction.

Planned validation

Source-module transport tests would supply malformed and empty initialize SSE
streams carrying a raw session ID. Direct initialize and Auto fallback cases
would verify failure plus exactly one DELETE for that raw session.

Would maintainers prefer this focused fix as a separate PR or as a test and
delta on #1267?

Activity

  1. added
    bugSomething is not working
    P2Medium: important but non-blocking improvement
    T-transportTransport layer changes
    ready for workIssue is well-defined and ready to be picked up
    on Oct 14, 2026
  2. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    @bolinfest is on triage rotation this week and is the reviewer for this one.

    Codex labeled this bug / P2 (T-transport). Please confirm or correct those labels.

    Automated triage. Labels are a first pass and the assigned maintainer has the final say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Medium: important but non-blocking improvementT-transportTransport layer changesbugSomething is not workingready for workIssue is well-defined and ready to be picked up

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions