[Windows] Worktree creation fails with "Invalid string length" on pnpm Junction cycles
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
- Avoid a full ignored-tree traversal for
AGENTS.override.md; enumerate repository-controlled paths or explicitly reject repeated reparse targets. - Add a hard byte cap or ring buffer to Git subprocess stdout/stderr and terminate with a specific diagnostic when exceeded.
- 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.
1 Comment
Additional validation:
Invalid string lengthexception.git.exeprocess for 35 seconds. No process containing--ignoredorAGENTS.override.mdappeared, and the task completed normally. This supports the finding that the scan is tied to managed-worktree setup rather than general task initialization.--directoryto the exactgit ls-filescommand made the probe complete in about 0.29 seconds instead of recursively traversing Junctions. However, it returned ignored directory entries such asapps/cli/node_modules/, not the requestedAGENTS.override.mdfiles, 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=hoisteddid 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 ofFilename too longwarnings..gitfile stopped traversal for one testednode_modulessubtree, 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.