Skip to content

fix(concurrent): avoid extra initial remainder request - #581

Merged
SuperCoolPencil merged 3 commits into
SurgeDM:mainfrom
snowyukitty:fix/signed-range-request-overfetch
Aug 7, 2026
Merged

SuperCoolPencil merged 3 commits into
SurgeDM:mainfrom
snowyukitty:fix/signed-range-request-overfetch

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cap new parallel downloads at one initial range per actual worker
  • fold division/alignment remainder into the final primary range
  • leave saved resume tasks and sequential chunking unchanged

Why

The aligned chunk size can leave a small (N+1)th remainder task after N primary ranges. Request-sensitive signed URLs can reject that extra HTTP range request even though the primary ranges are valid.

Testing

  • go test ./internal/strategy/concurrent -run '^(TestInitialRangesStayWithinWorkerRequestBudget|TestTaskRangeAssignment)$' -count=1
  • go test ./internal/strategy/concurrent -count=1
  • go vet ./...
  • go test ./internal/lint/... -count=1
  • go build ./...
  • all Go packages except cmd and internal/probe (the two reproduced Windows baseline failures)

go test ./... -count=1 -timeout 90s passed every other package. On this Windows host, cmd still fails its dummy batch-editor test and internal/probe still reports a DNS resolver goroutine; both failures reproduce on the audited base. The race detector was unavailable because the host has no CGO toolchain, WSL, or running Docker daemon.

Coordination

This patch touches internal/strategy/concurrent/downloader.go alongside open #550 and #580. Both current merge trees are clean, and the concurrent package passes on each combined tree.

Addresses the initial partitioning case in #579. Runtime hedging, permanent HTTP retry handling, and connection prewarming remain out of scope.

Assistance disclosure: This contribution was developed with AI assistance (OpenAI Codex).

Summary by CodeRabbit

  • Performance

    • Improved parallel download task allocation to respect the configured worker limit.
    • Reduced unnecessary task creation while preserving complete file coverage.
    • Improved handling of uneven file sizes, small downloads, and single-worker transfers.
  • Bug Fixes

    • Corrected byte-range assignment for concurrent and signed-range downloads.
    • Ensured remainder data is included in the final download task without creating extra requests.
    • Ensured downloads fully cover the requested file without invalid or empty ranges.

@coderabbitai

coderabbitai Bot commented Aug 4, 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af7a1145-4b7a-4ac7-89eb-f9584a578b61

📥 Commits

Reviewing files that changed from the base of the PR and between ab47fb9 and 6a97922.

📒 Files selected for processing (1)
  • internal/strategy/concurrent/signed_range_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/strategy/concurrent/signed_range_test.go

📝 Walkthrough

Walkthrough

Concurrent downloads now limit initial tasks to the configured connection count. The final retained task absorbs the remaining file range. Sequential mode preserves all chunks. Tests cover task sizing, setup wiring, and signed range requests.

Changes

Concurrent task budgeting

Layer / File(s) Summary
Initial task creation
internal/strategy/concurrent/chunk_test.go, internal/strategy/concurrent/downloader.go
createInitialTasks limits tasks to the worker count and assigns the remainder to the final task. Tests cover uneven, small, single-worker, minimum-size, and matrix cases.
Downloader task setup
internal/strategy/concurrent/downloader.go, internal/strategy/concurrent/downloader_helpers_test.go
Task setup receives the connection count. Parallel downloads use capped tasks, while sequential downloads retain all chunks.
Initial range request validation
internal/strategy/concurrent/signed_range_test.go
Tests validate byte ranges and confirm that initial requests stay within the configured worker budget.

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

Sequence Diagram(s)

sequenceDiagram
  participant Downloader
  participant setupTasks
  participant createInitialTasks
  participant HTTPServer
  Downloader->>setupTasks: provide connection count
  setupTasks->>createInitialTasks: create parallel initial tasks
  createInitialTasks-->>Downloader: return worker-limited tasks
  Downloader->>HTTPServer: send signed byte-range requests
  HTTPServer-->>Downloader: return partial-content responses
Loading
🚥 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 concisely describes the main fix: preventing an extra initial remainder request in concurrent downloads.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

🧹 Nitpick comments (1)
internal/strategy/concurrent/signed_range_test.go (1)

35-43: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the exact request ranges.

The handler accepts every in-bounds range. A partition with an overlap or a gap can still return 206 and pass this test. Compare each parsed range with the expected three ranges, including the final fileSize-1 boundary.

🤖 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 `@internal/strategy/concurrent/signed_range_test.go` around lines 35 - 43,
Update the test handler around parseTestByteRange to validate each request’s
parsed start and end against the expected three partition ranges, rejecting
overlaps and gaps instead of accepting any in-bounds range. Ensure the expected
ranges include the final fileSize-1 endpoint before returning a successful
partial response.
🤖 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.

Nitpick comments:
In `@internal/strategy/concurrent/signed_range_test.go`:
- Around line 35-43: Update the test handler around parseTestByteRange to
validate each request’s parsed start and end against the expected three
partition ranges, rejecting overlaps and gaps instead of accepting any in-bounds
range. Ensure the expected ranges include the final fileSize-1 endpoint before
returning a successful partial response.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e7985d6-8f9e-4340-8902-c7830cc495bf

📥 Commits

Reviewing files that changed from the base of the PR and between 11c4fcb and f0f89ee.

📒 Files selected for processing (4)
  • internal/strategy/concurrent/chunk_test.go
  • internal/strategy/concurrent/downloader.go
  • internal/strategy/concurrent/downloader_helpers_test.go
  • internal/strategy/concurrent/signed_range_test.go

@SuperCoolPencil
SuperCoolPencil force-pushed the fix/signed-range-request-overfetch branch from 15213f3 to ab47fb9 Compare August 7, 2026 08:23
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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: 1

🤖 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 `@internal/strategy/concurrent/signed_range_test.go`:
- Around line 29-43: Update the test handler around downloadTask to record every
validated (start, end) range, then after downloadTask completes compare the
recorded pairs against the corresponding tasks entries. Add assertions for exact
range coverage, including that the final range ends at fileSize-1, while
retaining the existing request-count validation.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c658b17b-cfe2-4d1d-9330-8f2934f58632

📥 Commits

Reviewing files that changed from the base of the PR and between b99f5ec and ab47fb9.

📒 Files selected for processing (4)
  • internal/strategy/concurrent/chunk_test.go
  • internal/strategy/concurrent/downloader.go
  • internal/strategy/concurrent/downloader_helpers_test.go
  • internal/strategy/concurrent/signed_range_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/strategy/concurrent/downloader.go
  • internal/strategy/concurrent/downloader_helpers_test.go

Comment thread internal/strategy/concurrent/signed_range_test.go
@SuperCoolPencil
SuperCoolPencil merged commit 449597b into SurgeDM:main Aug 7, 2026
9 checks passed
@SuperCoolPencil

SuperCoolPencil commented Aug 7, 2026

Copy link
Copy Markdown
Member

Thanks so much @snowyukitty 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants