Skip to content

Conversation

@JasoonS
Copy link
Collaborator

@JasoonS JasoonS commented Sep 25, 2025

  • Introduced a new example for streaming height updates in examples/height_stream.
  • Updated hypersync-client to support streaming from the /height/stream SSE endpoint.
  • Modified dependencies in Cargo.toml to include necessary libraries for the new functionality.

Summary by CodeRabbit

  • New Features

    • Real-time height streaming in the client via server-sent events with support for multiple payload formats and resilient error handling.
  • Examples

    • Added two runnable examples demonstrating live height subscription and reconnect behavior.
  • Chores

    • Enabled HTTP client streaming support and added the new examples to the workspace.

…eaming capabilities

* Introduced a new example for streaming height updates in `examples/height_stream`.
* Updated `hypersync-client` to support streaming from the `/height/stream` SSE endpoint.
* Modified dependencies in `Cargo.toml` to include necessary libraries for the new functionality.
@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Walkthrough

Adds two example workspace members and a new SSE-based height streaming API to hypersync-client (Client::stream_height). Updates reqwest features for streaming and includes an example binary that consumes and prints streamed heights.

Changes

Cohort / File(s) Summary
Workspace update
Cargo.toml
Adds examples/height_stream and examples/height_stream_reconnect to [workspace] members; formatting/alignment adjusted.
New example crate config
examples/height_stream/Cargo.toml
New crate metadata and dependencies: path ../../hypersync-client, tokio (features: full), env_logger, anyhow.
Example: height stream binary
examples/height_stream/src/main.rs
Adds a Tokio binary that constructs a Client, calls stream_height, iterates received heights, prints them, and exits on stream error.
Client dependency feature
hypersync-client/Cargo.toml
Enables reqwest's "stream" feature in addition to "json" and "rustls-tls".
Client SSE streaming feature
hypersync-client/src/lib.rs
Adds pub async fn stream_height(self: Arc<Self>) -> Result<mpsc::Receiver<Result<u64>>> which connects to /height/sse, requests text/event-stream, optionally uses bearer auth, parses SSE events (plain numeric or JSON {"height": N}), spawns a background task to forward parsed heights over an mpsc channel, and handles stream/parse errors.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App as Example Binary
  participant Client as hypersync_client::Client
  participant Req as reqwest
  participant Server as Hypersync HTTP(S)
  participant Chan as mpsc::channel

  App->>Client: stream_height()
  activate Client
  Client->>Req: GET /height/sse\nAccept: text/event-stream\n(Bearer if configured)
  Req->>Server: HTTP request
  Server-->>Req: 200 OK + SSE stream
  Client->>Chan: spawn task to read SSE and send heights
  deactivate Client

  loop For each SSE event
    Req-->>Client: next SSE event
    Client->>Client: normalize & parse event data (number or JSON {height})
    alt valid height
      Client-->>Chan: Ok(u64)
    else non-height / parse error
      Client-->>Client: ignore or log error
    end
  end

  loop Consumer
    App-->>Chan: recv()
    alt Ok(height)
      App->>App: print height
    else Err(e)
      App->>App: log error and break
    end
  end
Loading
sequenceDiagram
  autonumber
  actor User
  participant Main as examples/height_stream::main
  participant Client as Arc<Client>
  participant Chan as mpsc::Receiver<Result<u64>>

  User->>Main: run binary
  Main->>Main: init env_logger, tokio
  Main->>Client: construct with URL
  Main->>Client: stream_height()
  Client-->>Main: mpsc Receiver
  Main->>Chan: loop recv()
  alt height
    Chan-->>Main: Ok(u64)
    Main->>Main: println!(height)
  else error
    Chan-->>Main: Err(e)
    Main->>Main: log and exit loop
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to SSE parsing edge cases and UTF-8 handling in hypersync-client/src/lib.rs.
  • Verify reqwest feature change and any build implications in hypersync-client/Cargo.toml.
  • Review example for correct URL/config usage and graceful shutdown behavior.

Poem

A hop, a stream, a moonlit trail,
I sniff the SSE and wag my tail.
Heights arrive, I count each beat,
I print, I hum, I nibble a treat.
If errors come, I thump — then try to heal. 🐇✨

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 "feat: add height stream example and enhance hypersync-client with streaming capabilities" directly and comprehensively describes the main changes in the changeset. The title accurately captures both primary objectives: the addition of a new height stream example (implemented across examples/height_stream/Cargo.toml and examples/height_stream/src/main.rs) and the enhancement of the hypersync-client library with streaming support (via the new stream_height method in hypersync-client/src/lib.rs). The title is concise, specific, and follows conventional commit format without unnecessary noise, making it clear to teammates reviewing the repository history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch height-sse

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52197ee and b3f7024.

📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • examples/height_stream/src/main.rs (1 hunks)
  • hypersync-client/src/lib.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • examples/height_stream/src/main.rs
  • hypersync-client/src/lib.rs
  • Cargo.toml
⏰ 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). (2)
  • GitHub Check: test_release
  • GitHub Check: test_dev

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: 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 a1ec5d3 and 52197ee.

📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • examples/height_stream/Cargo.toml (1 hunks)
  • examples/height_stream/src/main.rs (1 hunks)
  • hypersync-client/Cargo.toml (1 hunks)
  • hypersync-client/src/lib.rs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/height_stream/src/main.rs (1)
hypersync-client/src/lib.rs (1)
  • new (71-93)
⏰ 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). (2)
  • GitHub Check: test_release
  • GitHub Check: test_dev
🔇 Additional comments (4)
hypersync-client/Cargo.toml (1)

57-57: Enabling reqwest streaming support looks good.

Adding the stream feature is necessary for accessing bytes_stream() and similar SSE helpers, so this change is spot on.

Cargo.toml (1)

4-15: Thanks for registering the new example in the workspace.

Including examples/height_stream here keeps the workspace consistent and ensures the example builds with the rest of the project.

examples/height_stream/Cargo.toml (1)

1-10: Example crate manifest looks solid.

The dependencies line up with the runtime you’re using, and the path link back to hypersync-client keeps everything in sync.

examples/height_stream/src/main.rs (1)

6-30: Nice, concise example.

This is a clear illustration of the new API, and the error handling is straightforward.

Comment on lines 555 to 564
///
/// Returns a channel receiver that yields `u64` heights. The sender task runs in the background
/// and closes the channel if the connection drops or an error occurs. Messages that cannot be
/// parsed are ignored.
pub async fn stream_height(self: Arc<Self>) -> Result<mpsc::Receiver<Result<u64>>> {
let mut url = self.url.clone();
let mut segments = url.path_segments_mut().ok().context("get path segments")?;
segments.push("height");
segments.push("sse");
std::mem::drop(segments);
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

Fix the /height/stream endpoint path.

The doc comment (and PR objective) call out /height/stream, but the code currently appends "sse", so the client will receive a 404. Please point the request at the documented path instead.

-        segments.push("height");
-        segments.push("sse");
+        segments.push("height");
+        segments.push("stream");
🤖 Prompt for AI Agents
In hypersync-client/src/lib.rs around lines 555 to 564 the path segments
appended for the height streaming endpoint use "sse" causing requests to hit the
wrong URL; change the appended segment from "sse" to "stream" so the client
targets "/height/stream" as documented (update the segments.push call
accordingly and keep the rest of the function unchanged).

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.

2 participants