Skip to content

remote-client: isSessionNotFound is tightly coupled to SDK error shape #10

Description

@OpenCodeEngineer

Found while reviewing #8.

src/daemon/remote-client.ts:145-151:

function isSessionNotFound(err: unknown): boolean {
  if (!err || typeof err !== 'object') return false;
  const code = (err as {code?: unknown}).code;
  return code === 404;
}

This relies on the SDK's StreamableHTTPError.code being the HTTP status. If the SDK ever changes that field — e.g. to the JSON-RPC error code (-32001) or wraps the error in another type — the retry path silently regresses and users see a raw "Session not found" instead of the transparent reconnect that sticky sessions are designed to deliver.

The current test fixture matches this exact shape so a regression wouldn't be caught.

Suggested fix:

import {StreamableHTTPError} from '@modelcontextprotocol/sdk/client/streamableHttp.js';

function isSessionNotFound(err: unknown): boolean {
  if (err instanceof StreamableHTTPError) {
    return err.code === 404 || /Session not found/i.test(err.message);
  }
  return false;
}

Add a test case where the server returns a JSON-RPC -32001 envelope without an HTTP 404 so this contract is locked in.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions