[Windows] Worktree creation fails with "Invalid string length" on pnpm Junction cycles

Open 💬 1 comment Opened Aug 17, 2026 by Ornn8

Codex version

Codex Desktop 26.803.10989.0 on Windows 11 x64.

What happened

Creating a managed worktree failed after git worktree add had already completed:

[info] Starting worktree creation
Preparing worktree (detached HEAD 234a2d3eab)
Updating files: 100% (7460/7460), done.
HEAD is now at 234a2d3eab ...
[stderr] Invalid string length

No task/thread was persisted, so there was nothing to resume or retry. Automatic cleanup of old managed worktrees did not help.

Root cause and reproduction

Inspection of the packaged Desktop app showed that worktree setup performs this local post-checkout scan to locate ignored AGENTS.override.md files:

git -C <repo> ls-files --others --ignored --exclude-standard -z -- ':(glob)**/AGENTS.override.md'

The repository uses normal pnpm workspace Junctions. A dependency cycle is represented like this:

apps/cli/node_modules/@scope/core
  -> vendor/core
vendor/core/node_modules/@scope/include
  -> vendor/include
vendor/include/node_modules/@scope/core
  -> vendor/core

Although node_modules/ is ignored, --ignored makes Git traverse the Junction graph. Git continuously emits Filename too long warnings for recursively expanding paths.

In a controlled reproduction, the exact scan command emitted 29,163,485 bytes of stderr in 126.7 seconds and was still running when terminated. Codex appears to accumulate or concatenate the unbounded subprocess output until V8 throws Invalid string length.

Other observations:

  • The repository was clean and had no .worktreeinclude.
  • It had about 7,460 tracked files / 46.5 MiB, with no unusually large tracked file.
  • Only three worktrees were registered, so this was not a worktree-count limit.
  • The failed worktree itself was valid and checked out at the requested detached HEAD.
  • The failure happened in local post-processing before the new task was durably created.

Expected behavior

  • Worktree setup should not follow cyclic or repeated directory reparse targets while locating ignored AGENTS.override.md.
  • Git subprocess stdout and stderr should be bounded or streamed with a fixed cap.
  • A post-checkout metadata-scan failure should preserve a durable task/setup record with a retry or continue-without-copy option.

Suggested fixes

  1. Avoid a full ignored-tree traversal for AGENTS.override.md; enumerate repository-controlled paths or explicitly reject repeated reparse targets.
  2. Add a hard byte cap or ring buffer to Git subprocess stdout/stderr and terminate with a specific diagnostic when exceeded.
  3. Persist the pending task before post-checkout scanning so setup failures can be retried.

Privacy

This report omits the Windows username, absolute local paths, repository name, task IDs, and raw logs.

View original on GitHub ↗

1 Comment

Ornn8 · 11 days ago

Additional validation:

  • The 29,163,485-byte figure in the report is a measured output rate/sample, not the eventual V8 failure threshold. The failing Desktop run did not expose the exact accumulated byte count at the moment of the Invalid string length exception.
  • I created a normal local Codex task in an existing checkout that already contained the real pnpm Junction cycle and monitored every git.exe process for 35 seconds. No process containing --ignored or AGENTS.override.md appeared, and the task completed normally. This supports the finding that the scan is tied to managed-worktree setup rather than general task initialization.
  • Adding --directory to the exact git ls-files command made the probe complete in about 0.29 seconds instead of recursively traversing Junctions. However, it returned ignored directory entries such as apps/cli/node_modules/, not the requested AGENTS.override.md files, so it is not a semantics-preserving one-line replacement. It may still be useful as the first phase of a bounded two-phase lookup.
  • pnpm install --config.node-linker=hoisted did not eliminate this trigger in a workspace repository. The resulting installation contained 2,346 Junctions (mostly workspace links), and the exact scan still generated megabytes of Filename too long warnings.
  • A valid nested .git file stopped traversal for one tested node_modules subtree, but a multi-workspace repository has many such roots. Sprinkling repository sentinels throughout dependency directories would alter Git semantics and is not a suitable general workaround.