[macOS] .worktreeinclude causes worktree creation to fail with "Invalid string length" in repositories with large ignored trees
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
Codex version
ChatGPT desktop app 26.831.21537 (build 7579)
Bundled Codex CLI: 0.153.0-alpha.5
Platform
- macOS 26.6.2 (25G83), arm64
- Apple Git 2.50.1
What issue are you seeing?
When a repository contains .worktreeinclude and has enough ignored/generated paths, managed worktree creation fails after git worktree add has completed successfully:
[info] Starting worktree creation
Preparing worktree (detached HEAD <sha>)
HEAD is now at <sha> <commit subject>
[stderr] Invalid string length
No task is created, although the detached Git worktree exists and is valid.
Inspection of the packaged desktop application indicates that .worktreeinclude processing runs both of these commands in the source checkout:
git ls-files --others --ignored --exclude-standard -z
git ls-files --others --ignored --exclude-from=.worktreeinclude -z
The first command enumerates every ignored path in the repository. Its complete stdout is captured as a JavaScript string before being split and intersected with the filtered result.
In the observed reproduction:
- The first command produced more than 512 MiB of path names.
buffer.constants.MAX_STRING_LENGTHwas 536,870,888 bytes.- The
.worktreeinclude-filtered command produced less than 1 KiB. - Git checkout, hooks, object connectivity, and the resulting worktree were otherwise valid.
Once the unfiltered output exceeds V8's maximum string length, worktree creation fails with Invalid string length.
Steps to reproduce
-
Create or use a Git repository containing a
.worktreeincludefile with one ignored local file. -
Populate an ignored generated-output directory with enough nested files or sufficiently long paths that this command emits more than V8's string limit:
git ls-files --others --ignored --exclude-standard -z | wc -c -
Start a new Codex Desktop task using a managed worktree.
-
Observe that Git creates the detached worktree successfully.
-
Observe
Invalid string lengthbefore the task is registered.
Expected behavior
Codex should enumerate and copy only ignored files matching .worktreeinclude without materializing every ignored pathname in one JavaScript string.
Large ignored build or dependency directories should not prevent worktree creation when none of their contents match .worktreeinclude.
Actual behavior
The presence of .worktreeinclude triggers an unbounded repository-wide ignored-file listing. When its stdout exceeds V8's string limit, post-checkout processing fails and the otherwise valid worktree is unusable from Codex.
Workarounds
Either of these avoids the failure, but neither is durable:
- Remove
.worktreeinclude. - Delete or clean enough ignored generated output before creating each worktree.
Suggested fix
Avoid collecting the complete unfiltered ignored-file listing.
One approach would be:
- Enumerate candidates using
.worktreeinclude. - Validate those candidates as genuinely ignored using a bounded or streaming
git check-ignore --stdin -z. - Stream or cap all Git subprocess output so a repository cannot exceed V8's single-string limit.
- Preserve a retryable task record when post-checkout copying fails.
Related issues
- #28381 reports a similar unbounded ignored-tree scan for
AGENTS.override.md, but it manifests as a long hang. - #38949 reports
Invalid string lengthduring worktree post-processing on Windows due to cyclic junction traversal, without.worktreeinclude.
This report intentionally omits repository names, local paths, branch names, commit hashes, configuration values, and application-specific directory names.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the .worktreeinclude post-checkout path and the two Git commands shown in the report; inspect how their NUL-delimited stdout is collected and split. Reproduce with the provided git ls-files size check, then verify that large ignored trees no longer cause Invalid string length, matching files are still copied, and task creation remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, javascript, rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100