fix: add retry logic, per-chunk progress saving, and gzip support#138
fix: add retry logic, per-chunk progress saving, and gzip support#138
Conversation
Three interrelated fixes to make uploads robust against transient failures: 1. Retry logic with exponential backoff (2s, 4s, 8s...): - Actually uses the existing retry_attempts config (was defined but unused) - Each chunk is retried independently on failure - Failed chunks don't lose progress from successful ones 2. Per-chunk incremental progress saving: - Messages are sorted by date before chunking so older messages go first - After each successful chunk, last_date_uploaded is saved immediately - On the next upload run, only newer messages are re-sent - Previously: progress was only saved after ALL chunks completed 3. Gzip compression via reqwest feature: - Enables automatic Accept-Encoding: gzip for API responses - Response decompression is automatic with the feature enabled Also refactored upload_single_chunk into its own function with a ChunkContext struct to keep the signature clean and make the retry loop readable.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds gzip support to reqwest, registers a new canonical model Changes
Sequence Diagram(s)sequenceDiagram
participant Client as upload_message_stats()
participant Chunker as chunk_iterator
participant Retry as retry_loop
participant Upload as upload_single_chunk()
participant HTTP as HTTP_Server
participant Config as config.last_date_uploaded
Client->>Chunker: sort messages by date and create chunks
loop for each chunk
Chunker->>Retry: start retry attempts (max_retries)
loop while retries_left > 0
Retry->>Upload: upload chunk
Upload->>HTTP: POST chunk
alt success (200)
HTTP-->>Upload: success
Upload-->>Retry: return success
Retry->>Config: save_chunk_progress(last_uploaded_timestamp + 1ms)
Retry->>Chunker: proceed to next chunk
else failure (non-200 / error)
HTTP-->>Upload: error
Upload-->>Retry: return error
Retry->>Retry: wait exponential_backoff
Retry->>Retry: decrement retries_left
end
end
alt all retries exhausted
Retry->>Config: save_chunk_progress(for completed chunks)
Retry-->>Client: return final error
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/upload.rs`:
- Around line 195-199: The code currently sets the checkpoint using
chrono::Utc::now() via config.set_last_date_uploaded(date) which can skip
messages created during the upload; instead set the checkpoint to the timestamp
of the last successfully uploaded message plus 1ms. Modify the final-save logic
in upload.rs to use the tracked last_uploaded_timestamp (or compute it from the
batch of uploaded messages) and call
config.set_last_date_uploaded(last_uploaded_timestamp + 1) before
config.save(true) rather than using Utc::now(); ensure the variable used matches
the existing identifier that records the last uploaded message timestamp.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f1a954a0-d9e1-4831-aed1-7807998f7788
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
Cargo.tomlsrc/models.rssrc/upload.rssrc/upload/tests.rs
The final save after the upload loop was overwriting the correct message-anchored checkpoint (set by save_chunk_progress) with Utc::now(), which could skip messages created during the upload window. save_chunk_progress already persists the checkpoint after every chunk including the last one, so the final save was both redundant and harmful.
Three interrelated fixes to make uploads robust against transient failures:
Retry logic with exponential backoff (2s, 4s, 8s...):
Per-chunk incremental progress saving:
Gzip compression via reqwest feature:
Also refactored upload_single_chunk into its own function with a ChunkContext struct to keep the signature clean and make the retry loop readable.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores