feat: Implement concurrent file summarization with ThreadPoolExecutor#23
Conversation
- Replace sequential file summarization with concurrent execution using ThreadPoolExecutor - Limit max workers to 10 to avoid overwhelming API providers - Use thread-safe locks for collecting summaries and errors - Preserve existing error handling and progress bar integration - Significantly reduces processing time for repositories with many files
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesConcurrent Summarization Pipeline
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
repo2readme/cli/main.py (1)
163-164: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNit: unused loop variable.
futureis not used inside theas_completedloop; rename to_(also silences Ruff B007).♻️ Suggested tweak
- for future in as_completed(futures): + for _ in as_completed(futures): progress.update(task, advance=1)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@repo2readme/cli/main.py` around lines 163 - 164, The as_completed loop in main.py uses an unused loop variable named future, which triggers Ruff B007. Update the loop in the code path that updates progress for the futures collection so the unused variable is replaced with a throwaway name like underscore, while keeping the progress.update(task, advance=1) behavior unchanged.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@repo2readme/cli/main.py`:
- Around line 135-164: The `errors` list in `process_document` is being
populated but never surfaced, and `summarize_file` failures are already returned
in `summaries` as error objects. Update `main` to collect and report both kinds
of failures after the ThreadPoolExecutor finishes: read from `errors` and also
scan `summaries` for entries containing an error, then print or include them in
the workflow state instead of silently swallowing them. Use the existing
`process_document`, `summarize_file`, `summaries`, and `errors` symbols to wire
the reporting into the post-processing path.
- Around line 158-160: Handle the empty-document case in the worker setup before
entering the ThreadPoolExecutor block: max_workers derived from min(10,
total_documents) can become 0 when no documents are found, which causes a
ValueError. Update the logic in the main processing flow to either return early
when total_documents is 0 or ensure the worker count is clamped to at least 1
before creating the executor.
- Line 142: The language detection call in the metadata handling flow is using
file_type, which is often just an extension and can cause detect_lang to fall
back to unknown. Update the call site in the main processing logic to pass
meta["file_path"] into detect_lang, or adjust detect_lang to handle extension
strings explicitly, so the existing language detection behavior works for normal
inputs.
---
Nitpick comments:
In `@repo2readme/cli/main.py`:
- Around line 163-164: The as_completed loop in main.py uses an unused loop
variable named future, which triggers Ruff B007. Update the loop in the code
path that updates progress for the futures collection so the unused variable is
replaced with a throwaway name like underscore, while keeping the
progress.update(task, advance=1) behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
- Skip ThreadPoolExecutor when there are no documents to summarize - Prevents ValueError when max_workers would be 0
|
Hi! Could you please remove the ECSoC26 label and add it again? The sentinel did not assign the level, so it won't be considered for ECSoC26 marking. Re-adding the ECSoC26 label should fix it. Thank you! |
|
I tried but this is not working |
|
Thank you for trying! |
Summary
Fixes #17
Implements concurrent file summarization using
ThreadPoolExecutorto reduce processing time for repositories containing many files. File summaries are now generated in parallel while preserving existing functionality, error handling, and progress reporting.Changes
main.pyConcurrent File Summarization
ThreadPoolExecutor.ThreadPoolExecutoras_completedthreadingThread Safety
summaries_lockerrors_lockError Handling
Progress Reporting
rich.progressprogress bar.Implementation
Previous Behavior
Files were summarized sequentially:
Each API request completed before the next file began processing.
New Behavior
Files are processed concurrently using a thread pool:
Multiple network-bound LLM requests can now execute simultaneously while safely collecting results.
Benefits
Testing
Verified by:
python -m py_compilesuccessfully.Performance
For repositories containing approximately 100 files:
Expected improvement: 5–10× faster execution, depending on LLM response times and provider rate limits.
Summary by CodeRabbit