Skip to content

Add rate limit information and proactive rate limit sleep support#57

Open
JonoPrest wants to merge 2 commits intomainfrom
claude/upgrade-hypersync-rate-limiting-IHWT1
Open

Add rate limit information and proactive rate limit sleep support#57
JonoPrest wants to merge 2 commits intomainfrom
claude/upgrade-hypersync-rate-limiting-IHWT1

Conversation

@JonoPrest
Copy link
Collaborator

@JonoPrest JonoPrest commented Mar 20, 2026

Summary

This PR adds comprehensive rate limit handling to the HyperSync client, including new APIs to query rate limit information and a configuration option for proactive rate limit management.

Key Changes

  • New RateLimitInfo struct: Exposes rate limit details from server response headers including limit, remaining quota, reset time, cost per request, retry-after header, and suggested wait time
  • New QueryResponseWithRateLimit struct: Wraps query responses with associated rate limit information
  • New get_with_rate_limit() method: Allows queries to retrieve both response data and rate limit info in a single call
  • New rate_limit_info() method: Returns the most recently observed rate limit information from any prior request
  • New wait_for_rate_limit() method: Async utility to wait until the current rate limit window resets
  • New proactive_rate_limit_sleep config option: Enables proactive sleeping when rate limit is exhausted instead of sending requests that would be rejected with 429 status (defaults to true)
  • Updated TypeScript definitions: Added corresponding type definitions for all new structures and methods

Implementation Details

  • RateLimitInfo is converted from the underlying hypersync_client::RateLimitInfo type with proper casting of numeric values to i64
  • The is_rate_limited field is computed via the is_rate_limited() method on the underlying type
  • The suggested_wait_secs field is computed via the suggested_wait_secs() method on the underlying type
  • All new methods are properly exposed via the #[napi] macro for Node.js interoperability
  • Updated hypersync-client dependency to version 1.1.0 to support the new rate limit functionality

https://claude.ai/code/session_012mwJv9YsuFKTvrgftATDB7

Summary by CodeRabbit

Release Notes

New Features

  • Added rate-limit aware query method that returns results with current rate limit information
  • Added methods to retrieve rate limit status and wait for rate limit window reset
  • Added configuration option for proactive rate limiting to prevent rate-limited requests

- Upgrade hypersync-client dependency from 1.0.1 to 1.1.0
- Add RateLimitInfo type with limit, remaining, resetSecs, cost,
  retryAfterSecs, isRateLimited, and suggestedWaitSecs fields
- Add QueryResponseWithRateLimit type for combined response + rate limit data
- Add getWithRateLimit() method to HypersyncClient for queries with rate limit info
- Add rateLimitInfo() method to get last observed rate limit state
- Add waitForRateLimit() method to wait until rate limit window resets
- Add proactiveRateLimitSleep config option to ClientConfig (default: true)
- Bump package version from 1.1.0 to 1.2.0
- Update TypeScript type definitions (index.d.ts)

https://claude.ai/code/session_012mwJv9YsuFKTvrgftATDB7
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a21649db-e2c0-4f95-a6da-03be7bf781d9

📥 Commits

Reviewing files that changed from the base of the PR and between dcdab8f and 699e217.

📒 Files selected for processing (5)
  • Cargo.toml
  • index.d.ts
  • package.json
  • src/config.rs
  • src/lib.rs

📝 Walkthrough

Walkthrough

This PR extends the Hypersync client Rust binding with rate-limit aware APIs, adding methods to query with rate-limit information, retrieve the latest rate-limit state, and wait for rate-limit windows to reset. A configuration option for proactive rate-limit sleeping is introduced. The upstream hypersync-client dependency is updated to version 1.1.1 to support these capabilities.

Changes

Cohort / File(s) Summary
Dependency Updates
Cargo.toml, package.json
Updated hypersync-client dependency from 1.0.1 to 1.1.1 and bumped package version from 1.1.0 to 1.2.0.
TypeScript Type Definitions
index.d.ts
Added three new rate-limit methods to HypersyncClient (getWithRateLimit, rateLimitInfo, waitForRateLimit), new proactiveRateLimitSleep config option, and two new exported interfaces (RateLimitInfo, QueryResponseWithRateLimit).
Rust Configuration
src/config.rs
Extended ClientConfig struct with optional proactive_rate_limit_sleep field and mapped it to the upstream hypersync_client::ClientConfig during conversion.
Rust Implementation
src/lib.rs
Added RateLimitInfo and QueryResponseWithRateLimit structs with NAPI object decorations; implemented three new async/sync methods on HypersyncClient to expose rate-limit aware query and state-inspection capabilities; added From conversion for RateLimitInfo.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 With fuzzy ears and rate-limit care,
We fetch with wisdom, swift and rare,
getWithRateLimit hops along,
No 429 tears with this new song,
Proactive sleeping, gentle and wise! 💤✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add rate limit information and proactive rate limit sleep support' accurately and concisely describes the main changes in the pull request, which introduces rate-limit handling features and a proactive sleep configuration option.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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 claude/upgrade-hypersync-rate-limiting-IHWT1

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 and usage tips.

@JonoPrest JonoPrest requested review from DZakh and JasoonS March 20, 2026 15:46
Comment on lines +20 to +36
#[napi(object)]
pub struct RateLimitInfo {
/// Total request quota for the current window.
pub limit: Option<i64>,
/// Remaining budget in the current window.
pub remaining: Option<i64>,
/// Seconds until the rate limit window resets.
pub reset_secs: Option<i64>,
/// Budget consumed per request.
pub cost: Option<i64>,
/// Seconds to wait before retrying (from retry-after header).
pub retry_after_secs: Option<i64>,
/// Whether the rate limit quota has been exhausted.
pub is_rate_limited: bool,
/// Suggested number of seconds to wait before making another request.
pub suggested_wait_secs: Option<i64>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I need to remind myself and look at the rust client, but the rust client knows the timestamp of its last request also after we spoke? Just want to understand that, otherwise this is looking good!

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.

3 participants