Skip to content

fix: rate-limit retry loop and docstring coverage#559

Merged
biodrone merged 1 commit into
stagingfrom
fix/rate-limit-retry-and-docstrings
Apr 14, 2026
Merged

fix: rate-limit retry loop and docstring coverage#559
biodrone merged 1 commit into
stagingfrom
fix/rate-limit-retry-and-docstrings

Conversation

@biodrone

@biodrone biodrone commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #555
Closes #554

Test plan

  • go build ./... passes
  • go test ./... passes
  • Verify rate-limit retry behaviour with a live stream (or by mocking getStream to return "rate limited")

Summary by CodeRabbit

  • Documentation

    • Enhanced internal code documentation across multiple modules for improved maintainability, including configuration, file operations, and streaming components
  • Bug Fixes

    • Improved retry logic for rate-limited live streams with intelligent exponential backoff scheduling instead of fixed delays, ensuring better handling of temporary service limits

…ings

Replace the deeply nested else-if chain for rate-limit retries in the
live stream tick loop with a clean retry loop with backoff. The old
structure also silently swallowed non-rate-limit errors on the first
attempt.

Add doc comments to all functions and types missing them across
streamdl.go, download_stream.go, grpc_client.go, config.go,
config_reader.go, and move_file.go.

Closes #555
Closes #554
@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR improves docstring coverage across multiple Go source files and fixes a control flow bug in the rate-limit retry logic for live streams. Documentation comments are added to exported types and functions in config, download, gRPC client, and file move modules. The rate-limit retry logic in streamdl.go is refactored from nested conditionals to an explicit loop-based approach with exponential backoff.

Changes

Cohort / File(s) Summary
Documentation Updates
config.go, config_reader.go, download_stream.go, grpc_client.go, move_file.go
Added or improved GoDoc comments for exported types and functions, increasing docstring coverage for config parsing, download logic, gRPC client calls, and file operations.
Retry Logic Refactor
streamdl.go
Replaced nested conditional retry logic with an explicit loop using exponential backoff schedule (0s, 30s, 60s) to fix unreachable "Rate Limited Thrice" branch and improve error handling semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The docs were scattered, branches blocked,
A bunny fixed the logic locked,
With backoff loops and comments clear,
The code shines bright, revision dear! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the two main changes: fixing the rate-limit retry logic and adding docstring coverage across the codebase.
Description check ✅ Passed The description follows the template structure, links both issues (#555 and #554), details the changes made, and includes a test plan with passing build and test results.
Linked Issues check ✅ Passed The pull request fulfills both linked issue requirements: it replaces the nested else-if chain with an explicit retry loop [#555] and adds doc comments to all targeted functions across the Go codebase [#554].
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issues: rate-limit retry refactoring in streamdl.go and documentation additions to config.go, config_reader.go, download_stream.go, grpc_client.go, and move_file.go.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rate-limit-retry-and-docstrings

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

@biodrone biodrone self-assigned this Apr 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
streamdl.go (1)

201-204: Avoid string-matching errors for retry control.

Lines 133 and 201 rely on exact message text ("rate limited"), which is brittle. Prefer a shared sentinel error and errors.Is so retry behavior stays stable if message wording changes.

♻️ Proposed hardening (cross-file)
--- a/grpc_client.go
+++ b/grpc_client.go
@@
+var ErrRateLimited = errors.New("rate limited")
@@
-			case codes.ResourceExhausted:
-				return nil, errors.New("rate limited")
+			case codes.ResourceExhausted:
+				return nil, ErrRateLimited
@@
-			case codes.ResourceExhausted:
-				return "", errors.New("rate limited")
+			case codes.ResourceExhausted:
+				return "", ErrRateLimited
--- a/streamdl.go
+++ b/streamdl.go
@@
 import (
+	"errors"
 	"flag"
@@
-					if err.Error() == "rate limited" {
+					if errors.Is(err, ErrRateLimited) {
 						log.Errorf("Rate limited checking VODs for %s, skipping", streamer.User)
 						// ...
 					} else {
@@
-							if err.Error() != "rate limited" {
+							if !errors.Is(err, ErrRateLimited) {
 								log.Warnf("GetStream failed for user=%s: %v", streamer.User, err)
 								break
 							}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@streamdl.go` around lines 201 - 204, Replace the brittle string comparison of
err.Error() == "rate limited" with a package-level sentinel error (e.g., var
ErrRateLimited = errors.New("rate limited")) and use errors.Is to check it;
update the failing branch in the code around GetStream (and the similar check
around line 133) to use if !errors.Is(err, ErrRateLimited) { ... } and ensure
wherever the rate-limited condition is created or returned it wraps or returns
ErrRateLimited (using fmt.Errorf("%w", ErrRateLimited) or returning
ErrRateLimited directly) so the errors.Is check reliably detects the sentinel.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@streamdl.go`:
- Around line 201-204: Replace the brittle string comparison of err.Error() ==
"rate limited" with a package-level sentinel error (e.g., var ErrRateLimited =
errors.New("rate limited")) and use errors.Is to check it; update the failing
branch in the code around GetStream (and the similar check around line 133) to
use if !errors.Is(err, ErrRateLimited) { ... } and ensure wherever the
rate-limited condition is created or returned it wraps or returns ErrRateLimited
(using fmt.Errorf("%w", ErrRateLimited) or returning ErrRateLimited directly) so
the errors.Is check reliably detects the sentinel.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 64c73079-3288-4a4a-99ea-099fd022df7a

📥 Commits

Reviewing files that changed from the base of the PR and between 17a7856 and 31ef9b0.

📒 Files selected for processing (6)
  • config.go
  • config_reader.go
  • download_stream.go
  • grpc_client.go
  • move_file.go
  • streamdl.go

@biodrone biodrone merged commit a8567a1 into staging Apr 14, 2026
8 checks passed
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.

1 participant