memorix icon indicating copy to clipboard operation
memorix copied to clipboard

HTTP MCP idle session close (30min) is silent; clients hang or handshake-fail

Open RaviTharuma opened this issue 3 months ago • 2 comments

Description

The HTTP control plane closes idle MCP sessions after 30 minutes (MEMORIX_SESSION_TIMEOUT_MS, logged as HTTP session idle timeout: 30min). The close is only written to background.log. MCP clients (Grok, Claude, Codex) do not get a visible protocol error, so:

  • in-flight or next tool calls hang or handshake_failed
  • the chat looks stalled and then just ends
  • users report “Memorix froze the chat for ~30 minutes”

This matches the log line:

[memorix] Session <id> timed out (idle 30min), closing
[memorix] HTTP session closed: <id>

On 2026-08-12 ~23:24 Grok recorded mcp_server_failed / handshake_failed for memorix at http://127.0.0.1:3211/mcp immediately around a control-plane restart / session close.

Steps to Reproduce

  1. memorix serve-http --port 3211
  2. Connect a long-lived HTTP MCP client (Grok / Claude) and complete a tool call.
  3. Leave the chat idle for 30+ minutes (or set MEMORIX_SESSION_TIMEOUT_MS lower).
  4. Issue another tool call on the same MCP session id.

Expected Behavior

  • Idle close should be configurable and documented.
  • The server should reject the next request with a fast, explicit MCP/HTTP error (session expired, 404/400) so the client can re-initialize.
  • Ideally send a session-closed notification before tearing down.

Actual Behavior

Clients often hang or fail handshake. Grok default tool timeout is 6000s, so a dead session can freeze a turn for a very long time. Users see “30 min stall then chat died” with no Memorix error in the UI.

Stale session probe against 1.4.3: unknown mcp-session-id returns HTTP 400 in ~1ms (good). The failure mode is the already-connected client whose session was closed under it, or whose stream was half-open.

Environment

  • Memorix 1.4.3 HTTP control plane
  • macOS, multiple concurrent clients (Grok ×3, Claude, Codex) on :3211
  • Default idle timeout 1800000ms

Additional Context

Grok and similar hosts keep one HTTP MCP session for the whole chat. 30 minutes of user thinking or a long non-Memorix tool run is enough to trip this.

Please document MEMORIX_SESSION_TIMEOUT_MS and consider a longer default (or no idle kill) for control-plane mode, plus a clean initialize recovery path.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

Same investigation as #196 (store hang), #198 (cwd bind), #199 (402 retries), #200 (timeout abort).

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

1.6.1 已发。HTTP MCP 会话默认保留 12 小时;过期或旧 session id 会快速返回 404,并明确提示客户端重新 initialize,不再表现成静默挂起或模糊的握手失败。这个场景也进了回归测试。

AVIDS2 avatar Aug 17 '26 04:08 AVIDS2