Skip to content

feat: stream handler added - #24

Merged
bobrykov merged 2 commits into
masterfrom
feat/stream-handler
May 11, 2026
Merged

feat: stream handler added#24
bobrykov merged 2 commits into
masterfrom
feat/stream-handler

Conversation

@bobrykov

Copy link
Copy Markdown
Contributor

added basic skeleton for stream handler with configs

@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d8679cf-312f-4eea-8af4-572bdbb31f49

📥 Commits

Reviewing files that changed from the base of the PR and between 77262a6 and 356d5e5.

📒 Files selected for processing (1)
  • src/stream/handler.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/stream/handler.rs

📝 Walkthrough

Walkthrough

Adds a new handler sub-module under src/stream providing timeout and retry configuration types with validation, StreamOutcome/StreamHandlerError enums, a StreamProgress payload, a StreamHandler wrapper with constructors/accessors, and comprehensive unit tests.

Changes

Streaming Handler Module

Layer / File(s) Summary
Module Export & Documentation
src/stream.rs
Exposes the new handler sub-module and adds parent-file documentation referencing stream handling with retry, timeout, and fallback control.
Module Documentation
src/stream/handler.rs
Module-level documentation describing the streaming resilience architecture and lifecycle phases.
Timeout Configuration
src/stream/handler.rs
StreamTimeoutConfig defines initial/per-event/total timeouts, max consecutive timeouts, progress interval, fallback flag, Default, and validate().
Retry Configuration
src/stream/handler.rs
StreamRetryConfig holds exponential backoff params (base_delay_ms, max_delay_ms, jitter_factor, max_retries), base_delay(attempt) capped by max_delay_ms, Default, and validate().
Outcome Types
src/stream/handler.rs
StreamOutcome enum models termination reasons and implements Display formatting for contextual fields.
Handler Error Types
src/stream/handler.rs
StreamHandlerError enum represents handler failures and implements Display and std::error::Error.
Progress Payload & Handler Wrapper
src/stream/handler.rs
StreamProgress (elapsed, events_processed); StreamHandler wrapper with new, with_config, accessors, Debug, and Default.
Tests
src/stream/handler.rs (tests)
Unit tests for defaults, custom configs, exponential backoff and capping, validation paths (including jitter edge cases), and Display formatting.

Possibly related PRs

  • feat: add llm stream handling #11: Populated the same src/stream module with streaming event types and StreamAccumulator; this PR extends the module with handler configuration and error semantics.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat: stream handler added' directly and clearly describes the main change: introducing a new stream handler module with configuration and utility types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 50.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 feat/stream-handler

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/stream/handler.rs (1)

189-195: ⚡ Quick win

Add config validation before accepting custom handler settings.

jitter_factor is documented as 0.0..=1.0, but with_config accepts any f64 (including NaN/out-of-range). Similarly, zero durations/delays can slip in. A lightweight validate() on configs (called from with_config) will prevent invalid runtime states as execution logic is added.

Also applies to: 572-577

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/stream/handler.rs` around lines 189 - 195, Add a lightweight validate()
method on the handler config struct(s) that checks jitter_factor is finite and
within 0.0..=1.0, that any Duration/timeout/delay fields are non-zero and
finite, and returns a Result/Err with a clear message on invalid values; call
this validate() from with_config (and the other with_config-like constructor
referenced around the other struct) before accepting the settings so with_config
rejects NaN/out-of-range jitter_factor and zero/invalid durations. Ensure the
validation references the exact fields (jitter_factor and the duration/delay
fields) and propagate the error instead of silently accepting the bad config.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/stream/handler.rs`:
- Around line 1-28: The module-level rustdoc overstates behavior (saying
StreamHandler performs retry/timeout/fallback/cancellation) while the file
currently only exposes config/data types and constructors; update the docs to
accurately reflect the current implementation by changing claims about runtime
behavior to say the file defines the StreamHandler type, its configuration
structs, and constructors (and note which behaviors are planned or implemented
elsewhere), or alternatively implement the missing behavior in the referenced
functions (init_with_retry, process_events, fallback_non_streaming) to match the
doc; ensure references to ApiClient::stream_messages, ApiClient::create_message,
and CancelSignal are consistent with what is implemented and apply the same doc
corrections to the later summary section currently duplicated around the end of
the file.

---

Nitpick comments:
In `@src/stream/handler.rs`:
- Around line 189-195: Add a lightweight validate() method on the handler config
struct(s) that checks jitter_factor is finite and within 0.0..=1.0, that any
Duration/timeout/delay fields are non-zero and finite, and returns a Result/Err
with a clear message on invalid values; call this validate() from with_config
(and the other with_config-like constructor referenced around the other struct)
before accepting the settings so with_config rejects NaN/out-of-range
jitter_factor and zero/invalid durations. Ensure the validation references the
exact fields (jitter_factor and the duration/delay fields) and propagate the
error instead of silently accepting the bad config.
🪄 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 Plus

Run ID: 1badbb3e-3b73-4d78-97d5-d44823a0f1f4

📥 Commits

Reviewing files that changed from the base of the PR and between a8c24db and bf8a373.

📒 Files selected for processing (2)
  • src/stream.rs
  • src/stream/handler.rs

Comment thread src/stream/handler.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/stream/handler.rs (1)

665-670: ⚡ Quick win

Constructor currently permits invalid configs to enter StreamHandler.

with_config stores inputs directly, so validation is opt-in and easy to skip. Adding a fallible constructor (try_with_config) would enforce invariants at the API boundary.

Suggested API addition
 impl StreamHandler {
+    pub fn try_with_config(
+        timeout: StreamTimeoutConfig,
+        retry: StreamRetryConfig,
+    ) -> Result<Self, String> {
+        timeout.validate()?;
+        retry.validate()?;
+        Ok(Self {
+            timeout_config: timeout,
+            retry_config: retry,
+        })
+    }
+
     #[must_use]
     pub fn with_config(timeout: StreamTimeoutConfig, retry: StreamRetryConfig) -> Self {
         Self {
             timeout_config: timeout,
             retry_config: retry,
         }
     }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/stream/handler.rs` around lines 665 - 670, Add a fallible constructor
try_with_config on StreamHandler that enforces config invariants rather than
storing inputs blindly: implement StreamHandler::try_with_config(timeout:
StreamTimeoutConfig, retry: StreamRetryConfig) -> Result<Self,
StreamConfigError> which validates both timeout and retry (call existing
validate methods if present, or add validate() on
StreamTimeoutConfig/StreamRetryConfig) and returns Err with a descriptive
StreamConfigError if any check fails; on success return the StreamHandler with
timeout_config and retry_config set. Ensure the new StreamConfigError type (or
use an existing error enum) carries which config failed and why so callers can
handle validation failures at the API boundary.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/stream/handler.rs`:
- Around line 169-188: StreamTimeoutConfig::validate currently misses a guard
for max_consecutive_timeouts allowing 0; add a check in the validate() method to
return Err when self.max_consecutive_timeouts.is_zero() (or == 0) with a clear
message like "max_consecutive_timeouts must be non-zero" and place it alongside
the other zero-value guards (e.g., after the progress_interval check or
logically near the other timeout field checks) so the config enforces at least
one consecutive timeout.

---

Nitpick comments:
In `@src/stream/handler.rs`:
- Around line 665-670: Add a fallible constructor try_with_config on
StreamHandler that enforces config invariants rather than storing inputs
blindly: implement StreamHandler::try_with_config(timeout: StreamTimeoutConfig,
retry: StreamRetryConfig) -> Result<Self, StreamConfigError> which validates
both timeout and retry (call existing validate methods if present, or add
validate() on StreamTimeoutConfig/StreamRetryConfig) and returns Err with a
descriptive StreamConfigError if any check fails; on success return the
StreamHandler with timeout_config and retry_config set. Ensure the new
StreamConfigError type (or use an existing error enum) carries which config
failed and why so callers can handle validation failures at the API boundary.
🪄 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 Plus

Run ID: e71783b7-af64-4d06-a341-3dfb0d2e290f

📥 Commits

Reviewing files that changed from the base of the PR and between bf8a373 and 77262a6.

📒 Files selected for processing (1)
  • src/stream/handler.rs

Comment thread src/stream/handler.rs
@bobrykov
bobrykov force-pushed the feat/stream-handler branch from 77262a6 to 356d5e5 Compare May 11, 2026 19:38
@bobrykov
bobrykov merged commit 638749d into master May 11, 2026
6 checks passed
@bobrykov
bobrykov deleted the feat/stream-handler branch July 1, 2026 06:34
bobrykov added a commit that referenced this pull request Aug 18, 2026
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