Skip to content

CLI not able to work with very large files - RangeError: Invalid string length #662

@jannikkraemer

Description

@jannikkraemer

Describe the bug

Bug: Copilot CLI crashes with RangeError: Invalid string length when scanning large files

Describe the bug

Problem

When asking GitHub Copilot CLI to create a plan (no code changes requested), the CLI begins scanning project context and appears to attempt reading a very large .json file (~500+ MB).
During this scan, Copilot enters a failure loop and repeatedly prints:

RangeError: Invalid string length

The command never completes and the terminal becomes partially unresponsive due to the continuous error spam.


Actual Behavior

  • Copilot attempts to load the entire large JSON file into memory.
  • The CLI loops with RangeError: Invalid string length.
  • Error repeats indefinitely.
  • No timeout or graceful abort.
  • The terminal becomes partially unresponsive until restarted or task is aborted with Ctrl + c.

Affected version

0.0.365 Commit: 76d0881

Steps to reproduce the behavior

Steps to Reproduce

  1. Run a Copilot CLI request similar to:

    Okay, the current script is only fetching data up to which date? How can I also get the November data? Right now, it has all projects cached, and I want to avoid the following:
    1. Re-running the script from scratch (it takes days)
    2. Losing any historic data (I fetched the last 12 months, but I would like to keep all that data and, from now on, only fetch the missing recent data).
    
    Don’t start working on anything yet — instead, create a plan with ideas that I can refine with you first.
    
  2. Copilot starts collecting context:

    ✔ Glob "fetch_historic_data/**/*.go"
      └ No matches found
    ✔ Read fetch_historic.sh
      └ 63 lines read
    ✔ Read cache_status.sh
      └ 154 lines read
    ✔ Grep "AddDate"
      └ 12 lines found
    ✔ Read main.go:2300–2420
      └ 126 lines read
    ✔ Grep "cache/monthly"
      └ 1 line found
    ○ Grep "monthly"
    
  3. Copilot attempts to read a very large JSON file (>500 MB).

  4. The CLI enters a repeated error loop:

    ✘ RangeError: Invalid string length
    ✘ RangeError: Invalid string length
    ✘ RangeError: Invalid string length
    ...
    

Expected behavior

Expected Behavior

  • Copilot should ignore extremely large non-code files (e.g., >50 MB),
    or
  • limit the amount of context scanned,
    or
  • fail once with a clear, actionable error message instead of looping.

Additional context

Additional Context

  • The .json file is not relevant to the AI task but lives in a project subdirectory.
  • The Copilot CLI currently has no mechanism to exclude or size-limit context scanning.

Copilot CLI Version

0.0.365
Commit: 76d0881

Environment

  • OS: macOS
  • Machine: Apple M4 Pro, 24 GB RAM
  • Terminal: macOS built-in Terminal
  • Project: Go-based hobby project with a cache/ directory containing large JSON files
  • Largest file: ~500+ MB .json

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions