Skip to content

Conversation

@JasoonS
Copy link
Collaborator

@JasoonS JasoonS commented Oct 27, 2025

Summary by CodeRabbit

  • New Features

    • User-Agent customization: set a custom User-Agent per client or use the default identifier; helps label and track requests for monitoring and debugging.
    • HTTP client now sends the configured User-Agent with requests by default.
  • Chores

    • Package version bumped to mark the release containing the User-Agent enhancement.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

Adds an optional user_agent field to ClientConfig with a chainable setter, uses that value (or a default "hscr/") when building the internal reqwest::Client, and bumps the crate version in Cargo.toml.

Changes

Cohort / File(s) Summary
User agent configuration
hypersync-client/src/config.rs
Adds user_agent: Option<String> to ClientConfig with serde annotations; adds with_user_agent(mut self, user_agent: impl Into<String>) -> Self setter and a crate-private user_agent() accessor.
HTTP client initialization
hypersync-client/src/lib.rs
Computes user_agent from config or composes default hscr/<version> and passes it into reqwest::Client::builder().user_agent(...) when creating Client in Client::new.
Package metadata
hypersync-client/Cargo.toml
Bumps package version from 0.20.0-rc.1 to 0.20.0-user-agent-1.

Sequence Diagram(s)

sequenceDiagram
  participant Config as ClientConfig
  participant ClientInit as Client::new
  participant Reqwest as reqwest::Client::builder

  Note over Config,ClientInit: Read configuration
  Config->>ClientInit: user_agent() -> Option<String>
  alt user_agent present
    ClientInit->>Reqwest: .user_agent(configured UA)
  else no user_agent
    ClientInit->>ClientInit: compose "hscr/<version>"
    ClientInit->>Reqwest: .user_agent(default UA)
  end
  Reqwest-->>ClientInit: built reqwest client
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review serde annotations and visibility of the user_agent() accessor in config.rs.
  • Verify default UA composition uses the correct crate version and is passed to reqwest builder.
  • Confirm Cargo.toml version bump is intentional.

Poem

🐰 I hopped into config with a curious tug,
A tiny header string, snug as a rug.
Chain me or skip—I'll greet each request,
With "hscr" or your name, I’ll do my best. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "User agent" directly summarizes the primary objective of the changeset. The modifications across the three files are cohesively focused on implementing user agent functionality: adding a private user_agent field and setter method to ClientConfig, computing and configuring the user agent in the HTTP client initialization, and versioning the package to reflect this feature. The title is concise, clear, and specific enough that a teammate reviewing the commit history would immediately understand that this pull request introduces user agent support to the hypersync client. The title avoids vague terminology and file listings, meeting the criteria for clarity and relevance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch user-agent

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
hypersync-client/src/lib.rs (1)

79-84: Consider propagating the build error instead of unwrapping.

With the new custom user agent feature, invalid user agent strings (containing characters not allowed in HTTP headers) could now cause a panic at line 84. Since Client::new already returns Result<Self>, consider propagating the error for more graceful handling.

Apply this diff to handle the error:

         let http_client = reqwest::Client::builder()
             .no_gzip()
             .timeout(Duration::from_millis(timeout.get()))
             .user_agent(user_agent)
             .build()
-            .unwrap();
+            .context("build http client")?;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f91c16a and 6d63e6a.

📒 Files selected for processing (2)
  • hypersync-client/src/config.rs (1 hunks)
  • hypersync-client/src/lib.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
hypersync-client/src/lib.rs (1)
hypersync-client/src/config.rs (1)
  • user_agent (37-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint
  • GitHub Check: test_release
  • GitHub Check: test_dev
🔇 Additional comments (3)
hypersync-client/src/config.rs (2)

24-27: LGTM! Good encapsulation and serde configuration.

The private field with skip_serializing_if is appropriate for optional configuration. The crate-private accessor provides controlled access while keeping the field encapsulated.


29-40: LGTM! Idiomatic builder pattern and accessor.

The implementation follows Rust best practices:

  • Builder-style setter with impl Into<String> for flexibility
  • Crate-private accessor returns borrowed &str to avoid allocations
  • Clear documentation about intended use for language bindings
hypersync-client/src/lib.rs (1)

73-77: LGTM! Clear default user agent with helpful comment.

The fallback logic is well-implemented with a sensible default format that includes the library version. The comment explaining the "hscr" abbreviation is helpful.

/// Custom user agent string for HTTP requests.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[doc(hidden)]
pub user_agent: Option<String>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hidden from documentation, making it "somewhat hidden"

I tried making it not public, but that wasn't really possible due to the structure of how you create the client.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But it'll allow me to override it for the typescript/python and hyperindex. Will still test that out.

I should make an rc release.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really understand...

Do you want to be able to set this externally? Like from the nodejs client for eg?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if it's not part of public cfg, rather add it as a parameter on the Client. So for eg, have an internal function like "new_internal" which takes the cfg and the user agent.

Then make "new" call this fn with the defaulted user agent. And have another fn called "new_with_agent" which passes in a custom agent.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06586aa and e718098.

📒 Files selected for processing (1)
  • hypersync-client/Cargo.toml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Publish to crates.io
  • GitHub Check: lint
  • GitHub Check: test_release
  • GitHub Check: test_dev

[package]
name = "hypersync-client"
version = "0.20.0-rc.1"
version = "0.20.0-user-agent-1"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

❓ Verification inconclusive

Non-standard version format—use semantic versioning.

The version 0.20.0-user-agent-1 does not follow semantic versioning conventions. Pre-release identifiers should use formats like 0.20.0-rc.2 or 0.20.0-alpha.1, not feature names with underscores.

Clarify the intended versioning strategy:

  • If releasing this version as stable: use 0.20.0
  • If keeping as pre-release: use 0.20.0-rc.2 or similar
  • If this is temporary (e.g., for a feature branch): document the strategy clearly

Standard semantic versioning ensures compatibility with package managers and tooling.


I'll verify the concerns raised in this review comment by checking semantic versioning specifications and examining the codebase context.

Now let me examine the codebase to understand the context and versioning strategy:

Based on my web search verification, I can now provide a comprehensive assessment.

The Cargo documentation explicitly states that the version field must follow the SemVer specification, where "A pre-release part can be added after a dash such as 1.0.0-alpha. The pre-release part may be separated with periods to distinguish separate components."

The version format 0.20.0-user-agent-1 is problematic because:

  1. Violates SemVer conventions: Standard pre-release format uses patterns like "1.0.0-alpha.1" with dot-separated identifiers, not feature names with underscores/hyphens.

  2. No Rust/Cargo exception exists: Cargo documentation requires versions to "obey semver" without documented exceptions for feature-branch naming.

  3. Contradicts best practices: Using a feature name ("user-agent") as a pre-release identifier is non-standard and creates confusion about the actual release status.

Corrective action needed: Change to one of:

  • 0.20.0 (if releasing as stable)
  • 0.20.0-rc.2 or 0.20.0-rc.3 (if continuing pre-release)
  • 0.20.0-alpha.1 or 0.20.0-beta.1 (if in early pre-release)

Version format must follow semantic versioning conventions.

The version 0.20.0-user-agent-1 does not comply with standard SemVer pre-release formats. Pre-release parts should follow patterns like "1.0.0-alpha" or use dot-separated components like "1.0.0-alpha.1".

Update to a standard format:

  • Stable release: 0.20.0
  • Pre-release: 0.20.0-rc.2 or 0.20.0-alpha.1
🤖 Prompt for AI Agents
In hypersync-client/Cargo.toml around line 3, the version value
"0.20.0-user-agent-1" is not SemVer-compliant; replace it with a standard SemVer
identifier depending on intent — e.g., set to "0.20.0" for a stable release, or
use a proper pre-release token like "0.20.0-rc.2", "0.20.0-alpha.1", or
"0.20.0-beta.1" (use dot-separated numeric qualifiers for iterations if needed),
then save Cargo.toml.

@JasoonS JasoonS requested a review from JonoPrest October 29, 2025 15:16
@JasoonS
Copy link
Collaborator Author

JasoonS commented Oct 29, 2025

Will sort out merge conflicts still when I bump the version at the end 👍

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

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

Can you rebase onto main and add it as an rc.3 rather than your own side release?

Also have a slight opinion on keeping user agent out of the Config struct if its not really meant to be public.

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