DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

🐛 Bug Report: GitHub loader's truncated-tree fallback ignores the skip list and the file size cap

Open Avi112005 opened this issue 1 month ago • 2 comments

📜 Description

When GitHub's recursive tree API returns "truncated": true (very large repos), GitHubLoader._list_candidate_files falls back to fetch_repo_files, which walks /contents/ directory by directory. That fallback has two problems:

  1. It descends into every directory, including the vendored/generated ones in SKIP_DIRECTORIES (node_modules, vendor, dist, .git, ...). Each costs one GitHub API call, even though every file under them is thrown away later by select_files.
  2. It returns paths only, and the caller passes select_files([(p, 0) for p in paths]), so every file has size 0 and GITHUB_INGEST_MAX_FILE_BYTES is never applied, even though the /contents/ listing includes each file's size.

So on exactly the large repos that hit this path, ingestion burns rate limit on vendored folders and indexes oversized blobs the cap is meant to block.

File: docsgpt/parser/remote/github_loader.py (fetch_repo_files, _list_candidate_files)

👟 Reproduction steps

  1. Ingest a GitHub repository whose git/trees/<branch>?recursive=1 response is truncated (or mock that response, as below).
  2. The repo contains a committed node_modules/ or dist/ folder and a text file larger than GITHUB_INGEST_MAX_FILE_BYTES (default 1 MB).
  3. The loader logs "Tree for ... is truncated; falling back to the directory walk".
  4. Observe /contents/ requests for node_modules/... and dist/, and the oversized file being fetched and ingested.

I reproduced this by running the real GitHubLoader against mocked GitHub API responses (patched requests.get): a truncated tree, plus a small repo with node_modules/, dist/ and a 5 MB data/huge-dump.json.

👍 Expected behavior

The fallback walk should behave like the tree path:

  • directories matching should_skip_path are pruned before they are requested (no API calls for node_modules/, dist/, etc.)
  • each file's size from the /contents/ listing is passed to select_files, so GITHUB_INGEST_MAX_FILE_BYTES skips oversized files

👎 Actual Behavior with Screenshots

  • 4 of the 12 API requests went into node_modules/ and dist/, which should have been skipped
  • data/huge-dump.json (5 MB) was ingested despite the 1,048,576-byte cap
Image

💻 Operating system

Windows

What browsers are you seeing the problem on?

No response

🤖 What development environment are you experiencing this bug on?

Local dev server

🔒 Did you set the correct environment variables in the right path? List the environment variable names (not values please!)

None required to reproduce. Defaults used: GITHUB_INGEST_MAX_FILE_BYTES (1048576), GITHUB_ACCESS_TOKEN unset. The bug is independent of configuration.

📃 Provide any additional context for the Bug.

Proposed fix:

  • In fetch_repo_files, skip a dir entry when should_skip_path(item["path"] + "/x") is true (or add a directory check), so pruned folders are never requested.
  • Return (path, size) pairs from the walk and pass them straight to select_files instead of (p, 0).
  • Add regression tests in tests/parser/remote/test_github_loader.py for both (fallback makes no request into a skipped directory; an oversized file found via the walk is not selected).

The normal (non-truncated) tree path is not affected; it already applies both checks.

📖 Relevant log output

WARNING Tree for owner/repo is truncated; falling back to the directory walk

=== GitHub API requests made ===
  GET /
  GET /git/trees/main?recursive=1
  GET /contents/
  GET /contents/docs
  GET /contents/node_modules   <-- should have been skipped
  GET /contents/node_modules/lodash   <-- should have been skipped
  GET /contents/node_modules/react   <-- should have been skipped
  GET /contents/dist   <-- should have been skipped
  GET /contents/data
  GET /contents/README.md
  GET /contents/docs/guide.md
  GET /contents/data/huge-dump.json

=== Ingested documents (3) ===
  README.md
  docs/guide.md
  data/huge-dump.json   <-- 5 MB, over the 1048576-byte cap

Requests spent inside SKIP_DIRECTORIES: 4
Oversized file ingested: True

👀 Have you spent some time to check if this bug has been raised before?

  • [x] I checked and didn't find similar issue

🔗 Are you willing to submit PR?

Yes, I am willing to submit a PR!

🧑‍⚖️ Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

Avi112005 avatar Oct 11 '26 20:10 Avi112005

Hi! I'd like to work on this. Could you please assign it to me? I've reproduced it and plan to fix both the skipped-directory walk and the missing size cap, with regression tests.

Avi112005 avatar Oct 11 '26 20:10 Avi112005

@Avi112005, you're assigned.

  • Open a PR or post a progress update within 14 days; otherwise the issue may be made available to others.
  • Read CONTRIBUTING.md before submitting.
  • Include regression tests for directory pruning and the file size cap, plus a screenshot or short recording showing the fix.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 11 '26 20:10 arc53-machine