Skip to content

[Bug]: the CLI aborts with an unhandled Node exception when the workspace path is 259 characters or longer on Windows #617

Open

Description

@Ralle1976

Labels requested: bug, needs-triage, cli

Product or interface

CLI - headless

The same code path serves the interactive TUI (runtime-agent-product.ts:130 → local-agent-config-builder.ts:250 → environment-prompt-composer.ts:24), so the TUI is affected as well — I report it under the headless CLI because that is how I reproduced it.

Version

  • Installed: mcode --version → 0.7.8
  • Published: npm view @minimax-ai/code version → 0.7.8
  • Source paths verified against tag v0.7.2 (c6c7f28) and against main @ 2dd8829 — the defect is present in both.

Node.js v24.18.0, pnpm 9.12.0.

Platform

Windows

OS version and architecture

Windows 11 x64 (build 26200), Node v24.18.0. LongPathsEnabled = 0x1 (see below — it does not help here).

Issue area

File / workspace / path / encoding

What happens

When the workspace directory reaches the Windows limit for a child process's working directory, the CLI does not report an error — it dies. The process terminates with an unhandled Node 'error' event and a raw stack trace, and --diagnostics-dir produces nothing usable (execution_started only), because the failure happens outside the runtime's error handling.

The failure is not a promise rejection, so the try/catch around the awaited call never sees it.

Steps to reproduce

  1. Create a directory whose absolute path is 259 characters long (258 works, 259 fails).

  2. Run:

    mcode exec --cwd "<that directory>" --output-format text "Reply with exactly: PONG"
    
  3. Observe: no answer, but a Node stack trace.

Expected and actual behavior

  • Expected: the run fails with a readable message (for example, that the workspace path exceeds the Windows limit for child processes) and exits in a controlled way with a documented exit code.
  • Actual: the process aborts with Error: read ENOTCONN (errno: -4053, code: 'ENOTCONN', syscall: 'read') on an unhandled 'error' event of a net.Socket, exit code 1.

Measured threshold

Measured on this host by handing the working directory to execFile directly:

working-directory length result
255 OK
258 OK
259 spawn git ENOENT
260, 261, 262, 265 spawn git ENOENT

The boundary matches Windows semantics: CreateProcessW limits lpCurrentDirectory to MAX_PATH, so 259 characters plus the terminating NUL is the last that fits.

Why LongPathsEnabled does not help

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled was 0x1 on this machine and the failure still occurred exactly at the boundary above. The limit applies to the child process's working directory, not to the file paths passed to it, so the long-path opt-in does not lift it.

Where it happens

// packages/local-runtime-v2/src/service/workspace/operations/git-process.ts:33-43
const result = await execFile(
  'git',
  ['-c', 'core.quotePath=false', '--no-optional-locks', ...args],
  {
    cwd: resolve(workspace),
    encoding: 'utf-8',
    env: gitEnv(),
    maxBuffer: GIT_MAX_BUFFER,
    ...
  },
);

The call comes from packages/local-runtime-v2/src/service/workspace/operations/changes.ts:292 (isGitRepo → git(['rev-parse', '--is-inside-work-tree'])).

Node creates child.stdout / child.stderr as net.Socket instances over the pipe handles, and the execFile path attaches no 'error' listener to them. The first read therefore raises ENOTCONN as an 'error' event on a socket — not as a rejection — so it reaches the process as an uncaught exception.

Two further places have the same gap:

  • the v1 layer: packages/local-runtime/src/files/git-process.ts:19-24, called from packages/local-runtime/src/files/api.ts:1411;
  • the streaming variant in the same file, git-process.ts:62-115, which uses spawn and listens on child.stdout / child.stderr without an 'error' handler.

Redacted error summary

node:events:487
      throw er; // Unhandled 'error' event
      ^

Error: read ENOTCONN
    at tryReadStart (node:net:776:20)
    at Socket._read (node:net:791:5)
    at Readable.read (node:internal/streams/readable:741:12)
    at Socket.read (node:net:845:39)
    at new Socket (node:net:501:12)
    at Object.Socket (node:net:366:41)
    at createSocket (node:internal/child_process:337:14)
    at ChildProcess.spawn (node:internal/child_process:475:23)
    at spawn (node:child_process:796:9)
    at execFile (node:child_process:349:17)
Emitted 'error' event on Socket instance at:
  errno: -4053,
  code: 'ENOTCONN',
  syscall: 'read'

Suggested direction and prepared fix

The two things I would expect to be needed are both in a prepared branch: a readable diagnostic instead of a stack trace, and the missing error handling.

Branch: fix/git-process-long-workspace-path (commits 630e221 and e00af01, based on main @ 2dd8829)

  1. Preflight before the child is created. The check has to happen before the spawn, because the failure surfaces asynchronously on the stdio socket and cannot be caught by a try/catch around the promise. The new helper findWindowsWorkingDirectoryOverflow in packages/shared/src/windows-working-directory.ts reports the overflow, and the call sites in packages/local-runtime-v2/src/service/workspace/operations/git-process.ts and packages/local-runtime/src/files/git-process.ts return the error result before starting a child.
  2. The stdio pipes get an 'error' listener. A child that fails to start leaves its pipes unconnected, and the sockets then report read ENOTCONN on their own. Without a listener that terminates the host process — the spawn variant in the same file is covered by the same treatment.
  3. The message reaches the user. The TUI and headless entry points (packages/tui/src/cli/workspace-path.ts, packages/tui/src/headless/invocation.ts, packages/tui/src/cli/run-acp-command.ts, packages/tui/src/tui/launcher.ts) report the condition before the runtime starts.

On this host the behaviour changes from an uncaught exception to a controlled failure:

mcode exec --cwd "<260 characters>" --output-format text "Reply with exactly: PONG"
→ exit code 2
   mcode exec failed: Workspace path exceeds the Windows limit for child processes (260 characters; maximum 258). …

A short path is unaffected (exit 0).

Tests

  • test/windows-workspace-path.test.mjs (registered in the windows suite) — the end-to-end behaviour through the CLI entry point: 10 tests green on this host.
  • packages/shared/test/unit/windows-working-directory.test.ts — the overflow detection itself: 5 tests green.
  • Before the fix, the same test run ended in an uncaught Error: read ENOTCONN and a non-zero exit code; after it, the run is green.

pnpm check:source and pnpm typecheck pass on the branch.

One place I did not change

packages/agent-tools/src/desktop/local-rg-runner.ts starts rg with the same working directory and has the same error class. It is outside the three places this issue describes, so I left it alone rather than widening the change — but it is worth a look, because the same overflow would apply there.

Before submitting

  • I have searched existing issues.
  • I have included my version and removed sensitive information.

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions