Skip to content

CRITICAL: Uncaught Exception - write EOF crash when MCP response exceeds buffer #793

Description

@PabloJustDevelops

Summary

Command Code crashes with "write EOF" uncaught exception when an MCP tool returns a very large response (~670K characters). The crash happens in the stream writing code when the payload exceeds the buffer capacity.

Expected Behavior

Command Code should handle large MCP responses gracefully by either truncating the response to fit the buffer, using proper chunked streaming, or returning a controlled error message instead of crashing.

Actual Behavior

Command Code throws an uncaught exception and terminates:
- Error: write EOF
- Stack: WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:19)
- Trace ID: c5f17b594a2313360360eafa56039939

Image

Steps to reproduce the issue

Steps to reproduce:

  1. Add Engraphis MCP: cmd mcp add --scope user --env ENGRAPHIS_DB_PATH="C:\Users\your_user.engraphis\engraphis.db" engraphis -- engraphis mcp
  2. Call engraphis_execute_action with query "x query" in workspace "whatever-workspace", k=whatever-model-calls
  3. MCP returns a huge response (~670K characters) exceeding the token budget
  4. Command Code crashes immediately

Command Code Version

1.44.0

Operating System

Windows

Terminal/IDE

Orca

Shell

cmd.exe

Session file (optional)

Dropped as a json because you can't drop on jsonl

command-code-session-57ad15f5.json

Fix prompt (optional)

Fix prompt:

The crash occurs in the MCP response handling when a tool returns a payload larger than the Node.js stream buffer can handle (~670K chars in this case).

Where: MCP tool execution and response streaming code, likely in the tool call handler that writes results back to the agent.

What's correct:
  1. Add a size check before writing MCP responses - if response exceeds a safe threshold (e.g., 1MB), either:
    - Truncate with a warning message
    - Stream in chunks using proper backpressure handling

  2. Wrap the write operation in a try/catch to return a controlled error instead of crashing

  3. Ensure the write stream is properly drained before closing
    How to check:

    1. Reproduce by calling any MCP tool that returns a very large response (>500K chars)
    2. Verify Command Code doesn't crash and either:
      • Returns the full response successfully, OR
      • Returns a graceful error: "Response too large (X bytes). Use token_budget to limit response size."
    3. Check that normal-sized responses still work as before

Additional context

The crash happened while using Engraphis MCP for project context recall. The response was truncated at ~671K characters, suggesting the write stream failed when handling the large payload.

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

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions