feat: implement global and per-task download rate limiting#361
Open
SuperCoolPencil wants to merge 10 commits intomainfrom
Open
feat: implement global and per-task download rate limiting#361SuperCoolPencil wants to merge 10 commits intomainfrom
SuperCoolPencil wants to merge 10 commits intomainfrom
Conversation
Binary Size Analysis
|
…x/time/rate and improve error handling in downloader and worker loops
…rst size changes in WaitN
…ntext error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greptile Summary
This PR adds global and per-task download rate limiting backed by
golang.org/x/time/rate, wired through a newRateLimiterinterface onProgressStateand aGlobalRateLimitersingleton. The integration into both the single and concurrent download engines is clean, and context-cancellation errors fromWaitNare now properly propagated.The main concern is that
persistSettings()triggers bothReloadSettings()andApplySettings(), causing every rate-limit field in active downloads to be updated twice; the update logic should be consolidated into one path.Confidence Score: 5/5
Safe to merge — only P2 style and test-coverage findings remain; no new blocking defects introduced.
All P0/P1 concerns from prior review rounds are resolved: WaitN errors are now propagated, duplicate downloader branches were collapsed, and the custom token bucket was replaced with golang.org/x/time/rate. The two new findings are P2 only: duplicate rate-update calls on settings save (idempotent, no incorrect behaviour) and missing combined-limiter test coverage.
internal/core/local_service.go and internal/processing/manager.go — redundant rate-update logic that should be consolidated.
Important Files Changed
Sequence Diagram
sequenceDiagram participant TUI as TUI (view_settings) participant LS as LocalDownloadService participant MGR as LifecycleManager participant GRL as GlobalRateLimiter participant Pool as WorkerPool TUI->>TUI: persistSettings() TUI->>LS: ReloadSettings() LS->>GRL: SetRate(globalRate * 1024) [update #1] LS->>Pool: GetAll() → SetRate(perTaskRate) on each [update #1] LS-->>TUI: ok TUI->>MGR: ApplySettings(settings) MGR->>GRL: SetRate(globalRate * 1024) [update #2 – duplicate] MGR->>MGR: getEngineHooks().UpdateActiveRates(perTaskRate) MGR->>Pool: GetAll() → SetRate(perTaskRate) on each [update #2 – duplicate] MGR-->>TUI: ok note over GRL,Pool: Both limiters updated twice per saveComments Outside Diff (1)
internal/processing/manager.go, line 81-111 (link)NewLifecycleManagerloads settings from disk (line 84-88) but never callsApplySettingsorutils.GlobalRateLimiter.SetRate. The singleton is initialized toNewTokenBucket(0)inutils/ratelimit.goand is only updated when the user explicitly saves settings through the TUI (ApplySettings→SaveSettings). Anyglobal_rate_limitconfigured in the settings file will be silently ignored on every restart until the user opens and re-saves the settings screen.Fix: add one line after settings are loaded in
NewLifecycleManager:Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (5): Last reviewed commit: "feat: implement global and per-task down..." | Re-trigger Greptile
Context used: