🐛 Bug Report: GitHub loader's truncated-tree fallback ignores the skip list and the file size cap
📜 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:
- 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 byselect_files. - It returns paths only, and the caller passes
select_files([(p, 0) for p in paths]), so every file has size 0 andGITHUB_INGEST_MAX_FILE_BYTESis never applied, even though the/contents/listing includes each file'ssize.
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
- Ingest a GitHub repository whose
git/trees/<branch>?recursive=1response is truncated (or mock that response, as below). - The repo contains a committed
node_modules/ordist/folder and a text file larger thanGITHUB_INGEST_MAX_FILE_BYTES(default 1 MB). - The loader logs "Tree for ... is truncated; falling back to the directory walk".
- Observe
/contents/requests fornode_modules/...anddist/, 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_pathare pruned before they are requested (no API calls fornode_modules/,dist/, etc.) - each file's
sizefrom the/contents/listing is passed toselect_files, soGITHUB_INGEST_MAX_FILE_BYTESskips oversized files
👎 Actual Behavior with Screenshots
- 4 of the 12 API requests went into
node_modules/anddist/, which should have been skipped data/huge-dump.json(5 MB) was ingested despite the 1,048,576-byte cap
💻 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 adirentry whenshould_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 toselect_filesinstead of(p, 0). - Add regression tests in
tests/parser/remote/test_github_loader.pyfor 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
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, 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.mdbefore 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.