Skip to content

MCP host: recycle the tool host after its footprint grows, and rmcp's oversized stdio line #335

Open

Description

@lydakis

#474 bounded what the MCP host holds outside QuickJS's cap: collected output stays within 1 MB, a script may have at most 8 calls in flight, results over 16 MB are refused, and server stderr lines are cut at 1 KB. #481 moved tool answering and MCP out of sonny lookout into the sonny tool-host companion, so a large or slow MCP call no longer shares a process with notification delivery. A soak of 300 scripts, on Linux and on a Mac, found no steady growth.

These edges remain:

  1. rmcp reads a streamable-HTTP server's non-streamed JSON reply with response.bytes(), with no limit. Sonny refuses the result after decoding when it is over 16 MB, but by then the whole body is in memory. This is the one unbounded allocation left. It is upstream (rmcp 3.8). The fix is a body cap in rmcp, or Sonny's own HTTP transport that stops reading past the limit.
  2. Recycling the tool host. After scripts hit QuickJS's 256 MB cap, the macOS footprint stays at about 100 MB, against 20-25 MB at baseline. RSS reads 360+ MB, most of it reclaimable. It is not a leak: leaks finds 0, and malloc_zone_pressure_relief didn't help. Now that the tool host is its own companion, the practical fix is to restart it after a footprint threshold, or after N capped scripts, as Codex recycles its code-mode host. Giving QuickJS an allocator whose arena is freed as a whole is the other option.
  3. rmcp (3.8) drops a stdio line over 16 MiB and leaves the connection open. The call then waits out its 60 s timeout instead of failing at once. This costs time, not memory, and is upstream.

Activity

  1. changed the title [-]Sonny exec: memory edges left after the MCP soak[/-] [+]Sonny exec: script memory stays with the process on macOS (and rmcp's unbounded edges)[/+] on Oct 31, 2026
  2. changed the title [-]Sonny exec: script memory stays with the process on macOS (and rmcp's unbounded edges)[/-] [+]MCP host: unbounded rmcp HTTP body read, and recycling the tool host[/+] on Oct 31, 2026
  3. lydakis commented on Nov 14, 2026

    @lydakis
    OwnerAuthor

    11-14 reconciliation: item 1 is fixed upstream. The pinned rmcp 3.9.0 (Cargo.lock) collects non-streamed HTTP bodies through read_bounded_body (transport/common/client_side_http.rs), which caps JSON replies at 16 MiB and error bodies at 64 KiB before retaining them, and refuses early on a too-large Content-Length.

    Still open: item 2 (recycling the tool host after its footprint grows) and item 3 (rmcp's stdio transport drops a line over 16 MiB, DEFAULT_MAX_LINE_LENGTH, and leaves the connection open, so the call waits out its timeout).


    Generated by Claude Code

  4. changed the title [-]MCP host: unbounded rmcp HTTP body read, and recycling the tool host[/-] [+]MCP host: recycle the tool host after its footprint grows, and rmcp's oversized stdio line[/+] on Nov 20, 2026
  5. lydakis commented on Nov 20, 2026

    @lydakis
    OwnerAuthor

    Title narrowed to what is left. Item 1 (the unbounded HTTP body read) was fixed upstream, as the 11-14 comment says; main now pins rmcp 3.10.0, which keeps that bound. Items 2 (recycling the tool host after its footprint grows) and 3 (rmcp's stdio transport dropping a line over 16 MiB and leaving the call to time out) stay open.


    Generated by Claude Code

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions