Skip to content

feat(updates): Parallel File Downloads — v1.6.0 (Issue #128) + audit fixes - #4169

Merged
makr-code merged 5 commits into
developfrom
copilot/add-parallel-file-downloads
Mar 13, 2026
Merged

makr-code merged 5 commits into
developfrom
copilot/add-parallel-file-downloads

Conversation

Copilot AI commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Implements ParallelDownloader for the updates domain, delivering all four v1.6.0 ACs. A subsequent audit pass fixed a thread-safety bug, a stale docstring, an unused include, and documentation inconsistencies.

Description

New: ParallelDownloader (include/updates/parallel_downloader.h + src/updates/parallel_downloader.cpp)

AC Mechanism
Configurable concurrency setConcurrency(n) → worker thread pool; default = hardware_concurrency()
Bandwidth throttling setBandwidthLimit(bps) → token-bucket, CAS-atomic refill+consume
Priority queue DownloadTask::priority → std::priority_queue max-heap; highest first
Resume per file enable_resume=true → reads existing file size, passes resume_offset to FetchFn
ParallelDownloader dl;
dl.setConcurrency(4);
dl.setBandwidthLimit(100ULL * 1024 * 1024);   // 100 MB/s

for (const auto& file : manifest.files) {
    tasks.push_back({
        .url           = file.download_url,
        .dest          = config.download_directory + "/" + file.path,
        .expected_hash = file.sha256_hash,
        .priority      = file.type == "executable" ? 10 : 1
    });
}
auto results = dl.downloadAll(tasks);   // blocks; results in input order

Additional: SHA-256 integrity verification (corrupt files auto-removed), exponential back-off retry, injectable FetchFn for full testability without network, per-file progress callback, DownloadBatchStats.

Audit fixes (same PR)

  • Thread-safety bug: refillTokens() and consumeBandwidth() used non-atomic load-compute-store sequences on the shared token_bucket_ — multiple concurrent workers could race, causing uint64_t underflow (wraparound to ~18 EB). Fixed with compare_exchange_weak/strong.
  • Stale docstring: header claimed "every 100 ms"; code uses an adaptive ≥10 ms threshold. Clarified.
  • Unused include: removed #include <future>.
  • Wrong test count: docs claimed 25 tests; actual count is 29. Corrected throughout; module total updated 185 → 189.
  • Duplicate ROADMAP entries: two conflicting "Build system audit" bullets merged; source file count corrected 14 → 15.

Infrastructure

  • parallel_downloader.cpp registered in cmake/CMakeLists.txt + cmake/ModularBuild.cmake
  • ParallelFileDownloadsFocusedTests CTest target in tests/CMakeLists.txt
  • CI: .github/workflows/parallel-file-downloads-ci.yml

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated — 29 focused tests in tests/test_parallel_file_downloads.cpp covering all 4 ACs, hash verification, retry exhaustion, partial-failure isolation, and progress callbacks; all network-free via injected FetchFn
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Parallel File Downloads</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'Parallel File Downloads' for the updates domain. It is sourced from the consolidated roadmap under 🟠 High Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.6.0.

Primary detail section: Parallel File Downloads

Goal

Deliver the scoped changes for Parallel File Downloads in src/updates/ and complete the linked detail section in a release-ready state for v1.6.0.

Detailed Scope

Parallel File Downloads

Priority: High
Target Version: v1.6.0

Download multiple files concurrently to reduce update time.

Features:

  • Configurable concurrency level
  • Bandwidth throttling
  • Priority queue for critical files
  • Resume support per file

Implementation:

ParallelDownloader downloader;
downloader.setConcurrency(4);           // 4 parallel downloads
downloader.setBandwidthLimit(100_MB);   // 100 MB/s total

// Download manifest files
std::vector<DownloadTask> tasks;
for (const auto& file : manifest.files) {
    tasks.push_back({
        .url = file.download_url,
        .dest = config.download_directory + "/" + file.path,
        .expected_hash = file.sha256_hash,
        .priority = file.type == "executable" ? 10 : 1
    });
}

auto results = downloader.downloadAll(tasks);

Expected Improvement: 3-5x faster downloads (network bound)


Acceptance Criteria

  • Configurable concurrency level
  • Bandwidth throttling
  • Priority queue for critical files
  • Resume support per file

Relationships

References

  • src/ROADMAP.md
  • src/updates/FUTURE_ENHANCEMENTS.md#parallel-file-downloads
  • Source key: roadmap:128:updates:v1.6.0:parallel-file-downloads

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 13, 2026 08:46
- Add ParallelDownloader class (include/updates/parallel_downloader.h +
  src/updates/parallel_downloader.cpp) with:
  * Configurable concurrency (setConcurrency / worker thread pool)
  * Bandwidth throttling (setBandwidthLimit / token-bucket)
  * Priority queue for critical files (DownloadTask::priority / max-heap)
  * Per-file resume support (enable_resume / HTTP Range)
  * Hash verification (SHA-256 via OpenSSL EVP)
  * Retry with exponential back-off (DownloadTask::max_retries)
  * Injected FetchFn for full testability
  * Progress callback (thread-safe, per-file status)
- Add 25 focused tests in tests/test_parallel_file_downloads.cpp covering
  all 4 acceptance criteria
- Register parallel_downloader.cpp in cmake/CMakeLists.txt and
  cmake/ModularBuild.cmake
- Add ParallelFileDownloadsFocusedTests CTest target in tests/CMakeLists.txt
- Add .github/workflows/parallel-file-downloads-ci.yml CI workflow
- Update src/updates/FUTURE_ENHANCEMENTS.md (mark as Implemented)
- Update src/updates/ROADMAP.md (Phase 5 + production checklist)

Co-authored-by: makr-code <[email protected]>
- Clarify number of standalone test targets (9 not 8)
- Make test count exact (185 not 185+)
- Move parallel-downloads bullet to correct position in Completed list

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] Implement parallel file downloads for updates feat(updates): Parallel File Downloads — v1.6.0 (Issue #128) Mar 13, 2026
Copilot AI requested a review from makr-code March 13, 2026 08:51
@makr-code
makr-code marked this pull request as ready for review March 13, 2026 09:03
@github-actions github-actions Bot added the type:test Test-only change label Mar 13, 2026
- Fix TOCTOU race in token-bucket (refillTokens + consumeBandwidth now use
  compare_exchange_weak/strong for atomic read-modify-write)
- Remove unused #include <future>
- Fix header docstring to accurately describe adaptive 10ms refill interval
- Correct test count 25→29 in ROADMAP.md, FUTURE_ENHANCEMENTS.md
- Deduplicate ROADMAP.md Completed entries; correct source file count 14→15
- Update Current Status line to mention parallel downloads"

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title feat(updates): Parallel File Downloads — v1.6.0 (Issue #128) feat(updates): Parallel File Downloads — v1.6.0 (Issue #128) + audit fixes Mar 13, 2026
@makr-code
makr-code merged commit b976696 into develop Mar 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:test Test-only change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parallel File Downloads

2 participants