Skip to content

feat: Implement concurrent file summarization with ThreadPoolExecutor#23

Merged
agsaru merged 3 commits into
agsaru:mainfrom
mrunmayeekokitkar:Concurrent-File-Summarization
Jul 7, 2026
Merged

feat: Implement concurrent file summarization with ThreadPoolExecutor#23
agsaru merged 3 commits into
agsaru:mainfrom
mrunmayeekokitkar:Concurrent-File-Summarization

Conversation

@mrunmayeekokitkar

@mrunmayeekokitkar mrunmayeekokitkar commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #17

Implements concurrent file summarization using ThreadPoolExecutor to 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.py

Concurrent File Summarization

  • Replaced the sequential file summarization loop with concurrent execution using ThreadPoolExecutor.
  • Added imports for:
    • ThreadPoolExecutor
    • as_completed
    • threading
  • Configured a maximum of 10 concurrent workers to balance throughput while avoiding excessive requests to LLM providers.

Thread Safety

  • Added dedicated locks for shared collections:
    • summaries_lock
    • errors_lock
  • Ensures summaries and errors are safely collected across multiple worker threads.

Error Handling

  • Preserved the existing behavior where failures in one file do not interrupt processing of remaining files.
  • Errors continue to be collected and reported after execution completes.

Progress Reporting

  • Maintained integration with the existing rich.progress progress bar.
  • Progress is updated as each worker completes, providing accurate real-time feedback.

Implementation

Previous Behavior

Files were summarized sequentially:

for doc in documents:
    ...
    summary = summarize_file(...)

Each API request completed before the next file began processing.

New Behavior

Files are processed concurrently using a thread pool:

with ThreadPoolExecutor(max_workers=10) as executor:
    futures = {
        executor.submit(process_document, doc): doc
        for doc in documents
    }

    for future in as_completed(futures):
        progress.update(task, advance=1)

Multiple network-bound LLM requests can now execute simultaneously while safely collecting results.


Benefits

  • Reduced overall processing time for repositories containing many files.
  • Improved utilization of network-bound LLM API requests.
  • Better user experience through shorter execution times.
  • Preserved existing README generation and review workflows.
  • Establishes a scalable foundation for future asynchronous improvements.

Testing

Verified by:

  • Running python -m py_compile successfully.
  • Confirming existing functionality remains unchanged.
  • Verifying thread-safe result collection.
  • Confirming progress reporting updates correctly as tasks complete.
  • Ensuring failures in individual files do not stop the overall summarization process.

Performance

For repositories containing approximately 100 files:

Previous Updated
100 sequential API requests Up to 10 concurrent API requests
Total time proportional to the sum of all request durations Total time approximately proportional to the slowest batch of concurrent requests

Expected improvement: 5–10× faster execution, depending on LLM response times and provider rate limits.

Summary by CodeRabbit

  • New Features
    • Speed up repository summarization by generating multiple file summaries concurrently.
    • Improve user feedback: the “generating summaries” progress indicator updates as each file completes, making long runs feel more responsive.

- 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
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b37293b3-b714-43d6-a448-5392563a97f3

📥 Commits

Reviewing files that changed from the base of the PR and between 249731c and a8517b5.

📒 Files selected for processing (1)
  • repo2readme/cli/main.py

📝 Walkthrough

Walkthrough

repo2readme/cli/main.py now summarizes files concurrently with a bounded ThreadPoolExecutor, using locks to protect shared summary and error collection, and advancing progress as each future completes.

Changes

Concurrent Summarization Pipeline

Layer / File(s) Summary
Concurrent summarization implementation
repo2readme/cli/main.py
Adds ThreadPoolExecutor, as_completed, and threading imports, introduces lock-protected shared result handling in process_document, and replaces the sequential summarization loop with bounded concurrent execution and completion-based progress updates.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: concurrent file summarization with ThreadPoolExecutor.
Linked Issues check ✅ Passed The PR meets the issue goals by parallelizing summarization, limiting workers, protecting shared state, and preserving error handling and progress updates.
Out of Scope Changes check ✅ Passed No clearly unrelated or out-of-scope changes are evident beyond the requested concurrent summarization work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
repo2readme/cli/main.py (1)

163-164: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Nit: unused loop variable. future is not used inside the as_completed loop; 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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7f62d4eb-077e-4c9e-96c5-e76fab551a81

📥 Commits

Reviewing files that changed from the base of the PR and between 2c765ec and 249731c.

📒 Files selected for processing (1)
  • repo2readme/cli/main.py

Comment thread repo2readme/cli/main.py Outdated
Comment thread repo2readme/cli/main.py Outdated
Comment thread repo2readme/cli/main.py Outdated
mrunmayeekokitkar and others added 2 commits July 6, 2026 22:53
- Skip ThreadPoolExecutor when there are no documents to summarize
- Prevents ValueError when max_workers would be 0
@agsaru agsaru merged commit 2f0ed53 into agsaru:main Jul 7, 2026
4 checks passed
@mrunmayeekokitkar

Copy link
Copy Markdown
Contributor Author

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!

@agsaru agsaru added ECSoC26 and removed ECSoC26 labels Jul 8, 2026
@agsaru

agsaru commented Jul 8, 2026

Copy link
Copy Markdown
Owner

I tried but this is not working

@mrunmayeekokitkar

Copy link
Copy Markdown
Contributor Author

Thank you for trying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Implement Concurrent File Summarization

2 participants