Skip to content

Reasonix Desktop: model switch breaks codegraph daemon (EPIPE + stale named pipe on Windows) #723

@guoke1991

Description

@guoke1991

Description

When switching models in Reasonix Desktop, the codegraph built-in MCP server fails to restart with the error "1 MCP server(s) failed to start: codegraph". This occurs because the Windows named pipe used by the codegraph daemon becomes stale after the connection is abruptly broken during a model switch.

Environment

  • Reasonix Desktop: latest (from C:\Users\jihongfeng\AppData\Local\Programs\Reasonix\reasonix-desktop.exe)
  • codegraph: v0.9.7 (bundled with Reasonix at C:\Users\jihongfeng\AppData\Local\Reasonix\codegraph\v0.9.7\)
  • OS: Windows x64
  • Node.js: v24.12.0 (bundled with codegraph)

Steps to Reproduce

  1. Start Reasonix Desktop. codegraph daemon starts normally - daemon.log shows Listening on \\.\pipe\codegraph-xxx (pid N, v0.9.7)
  2. Switch models in Reasonix (e.g. from deepseek-flash to deepseek-pro)
  3. The old codegraph daemon receives socket error: write EPIPE and exits
  4. The new Reasonix session attempts to start a new codegraph daemon
  5. But the old named pipe \\.\pipe\codegraph-0822707c9dc94e58 remains on Windows in a half-disconnected state
  6. The new daemon fails to bind ? Reasonix shows "1 MCP server(s) failed to start: codegraph"

Root Cause

Reasonix Desktop creates a new tab/session when switching models, but it disconnects from the existing codegraph daemon without cleaning up the Windows named pipe. On Windows, named pipes are not automatically destroyed when the client disconnects abruptly. When Reasonix tries to launch a new codegraph daemon using the same pipe name, the stale pipe prevents binding.

The codegraph daemon itself works perfectly - it's just the pipe handover that's broken.

Evidence

daemon.log (after model switch):

[CodeGraph daemon] Listening on \\.\pipe\codegraph-0822707c9dc94e58 (pid 12292, v0.9.7). Idle timeout 300000ms.
[CodeGraph MCP] File watcher active - graph will auto-sync on changes
[CodeGraph daemon] socket error: write EPIPE

Stale named pipe persists on Windows:

\\.\pipe\codegraph-0822707c9dc94e58  ? remains after daemon exits

codegraph standalone works fine - tested independently:

codegraph status ? 4,909 files, 113,970 nodes, 296.39 MB, healthy ?
codegraph serve --mcp ? starts and accepts MCP connections normally ?

Suggested Fix

In Reasonix Desktop, when switching models/sessions:

  1. Gracefully shut down the codegraph daemon (send SIGTERM or call codegraph commands to cleanly exit) instead of abruptly disconnecting the pipe
  2. Or ensure the Windows named pipe is properly cleaned up after disconnection
  3. Or have codegraph generate a new random pipe name per session, avoiding reuse of stale pipes

Workaround

In config.toml, set [codegraph] enabled = false to disable the built-in codegraph server. This avoids the error but loses code intelligence features.

Note to maintainers

This is a Reasonix Desktop integration issue, not a codegraph core bug. However, codegraph could also help by:

  • Detecting stale named pipes on startup and cleaning them up
  • Using a unique pipe name per daemon instance (e.g. append a random suffix)
  • Handling the EPIPE more gracefully and attempting reconnection

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