Skip to content

Fix/lint and ci#44

Merged
EggerMarc merged 5 commits into
mainfrom
fix/lint-and-ci
Jun 2, 2026
Merged

Fix/lint and ci#44
EggerMarc merged 5 commits into
mainfrom
fix/lint-and-ci

Conversation

@EggerMarc

@EggerMarc EggerMarc commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Examples & Documentation

    • Simplified human-in-the-loop approval prompts to accept a single confirmation input.
    • Updated Google Maps example coordinates.
    • Added macOS Metal-backend run instructions for the MistralRS voice example.
  • Code Quality

    • Various internal refactors and formatting improvements for consistency.
    • Added Clippy lint suppressions to reduce noisy warnings across providers and adapters.

@coderabbitai

coderabbitai Bot commented Jun 1, 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf8a6bbe-7792-4cf0-bb2a-8d5d431ee334

📥 Commits

Reviewing files that changed from the base of the PR and between 68bdf00 and bca5ff7.

📒 Files selected for processing (6)
  • examples/claude/hitl.rs
  • examples/openai/hitl.rs
  • examples/router/keyword.rs
  • examples/router/stream.rs
  • providers/router/src/router.rs
  • providers/router/src/stream_router.rs
✅ Files skipped from review due to trivial changes (1)
  • examples/router/keyword.rs

📝 Walkthrough

Walkthrough

Mechanical cleanup across the codebase: derive Default where possible, standardize CallId fallbacks, add documented Clippy allow attributes, simplify router/stream guard patterns, tighten streaming parsing conditions, reflow formatting, and simplify example prompts. No public API changes.

Changes

Code Cleanup and Refactoring

Layer / File(s) Summary
Default trait derivation and usage simplification
core/src/types/provider_meta.rs, providers/completions/src/api/stream.rs, core/src/types/messages/parts.rs, core/src/types/messages/tool.rs, core/src/types/metadata/usage.rs
ProviderMeta and StreamState now derive Default. Tool::new and PartEnum::from_function_response use unwrap_or_default() instead of CallId::new(). Tests removed redundant ..Default::default() usage.
Clippy lint suppressions with documentation
core/src/chat/stream/handle.rs, providers/claude/src/api/types/error.rs, providers/completions/src/api/types/error.rs, providers/completions/src/api/types/response.rs, providers/gemini/src/api/types/error.rs, providers/gemini/src/api/types/request.rs, providers/mistralrs/src/lib.rs, providers/responses/src/api/types/error.rs
Added #[allow(...)] attributes with explanatory comments: large_enum_variant, result_large_err, wrong_self_convention, and too_many_arguments in the noted modules.
Router circuit-breaker and error handling simplification
providers/router/src/router.rs, providers/router/src/stream_router.rs
Refactored provider iteration guards and resolve_order error mapping to use map_err(ChatFailure::from_err)?, short-circuit non-retryable failures, and condensed the last-resort longest_open() fallback into single chained conditions.
Streaming event parsing and delta handling refactoring
core/src/chat/mod.rs, providers/claude/src/api/stream.rs, providers/mistralrs/src/api/stream.rs
Use Option::replace for pause transitions in tool approval. Claude stream parsing and MistralRS delta/final-message checks consolidated into combined conditionals.
Formatting, struct construction, and minor simplifications
core/src/chat/stream/input.rs, core/src/chat/stream/mod.rs, providers/gemini/src/api/types/request.rs, providers/mistralrs/src/api/types/request.rs, providers/mistralrs/src/api/types/response.rs, providers/openai/src/api/embedding.rs, providers/openai/src/client.rs, providers/responses/src/lib.rs, src/lib.rs
Reflowed struct literals and calls for readability; GeminiPart construction moved to struct literals with ..Default::default(); minor single-line formatting tweaks for headers, returns, and re-exports.
Example code refactoring and documentation updates
examples/claude/hitl.rs, examples/gemini/google_maps.rs, examples/mistralrs/voice.rs, examples/openai/hitl.rs, examples/router/*
HITL prompts simplified to single prompt + match; Google Maps coordinates tweaked; MistralRS voice example docs include macOS Metal run snippet; router example sort logic switched to sort_by_key(Reverse(...)).
CI: ALSA dev deps
.github/workflows/rust.yml
Install libasound2-dev and pkg-config in check and build jobs before lint/build steps.

Sequence Diagram(s)

sequenceDiagram
  participant Router
  participant CircuitBreaker
  participant Provider
  Router->>CircuitBreaker: resolve_order(request)
  Router->>Provider: call provider (if available)
  Provider-->>Router: response or error
  Router->>CircuitBreaker: record_success()/record_failure()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A cleanup hop, so neat and clean,
Defaults derived, no dupes between,
Clippy notes penned with gentle care,
Guards chained tight, parsers trimmed and spare,
Examples trimmed — the code can preen!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix/lint and ci' is vague and uses generic terms that don't convey meaningful information about the specific changes in this multi-faceted changeset. Consider a more descriptive title that highlights the primary change, such as 'Refactor error handling, clippy suppressions, and CI setup' or 'Add ALSA dependencies and refactor for clippy compliance'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.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 fix/lint-and-ci

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.

@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: 6

🧹 Nitpick comments (1)
providers/mistralrs/src/lib.rs (1)

23-26: 💤 Low value

Consider function-level suppression for consistency with other providers.

While the crate-level #![allow(clippy::result_large_err)] avoids repetition, other providers (Claude, Completions, Gemini, Responses) use function-level #[allow(clippy::result_large_err)] on their error handlers. Crate-level attributes can hide future lint violations in new code that might not need the suppression.

If multiple functions truly need this suppression, the crate-level approach is reasonable. Otherwise, consider using function-level attributes for consistency and to limit the scope of the suppression.

🤖 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 `@providers/mistralrs/src/lib.rs` around lines 23 - 26, The crate currently
uses a crate-level suppression `#![allow(clippy::result_large_err)]`; change
this to function-level suppressions to match other providers by removing the
crate-level attribute and adding `#[allow(clippy::result_large_err)]` only to
the specific error-handling/conversion functions (e.g., the conversion functions
that return `ChatFailure`/`ChatError` and any other functions producing large
Err types) so the lint scope is limited and consistent with
Claude/Completions/Gemini/Responses.
🤖 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 `@core/src/types/provider_meta.rs`:
- Around line 6-8: The ProviderMeta struct currently exposes data as
HashMap<String, Box<dyn Any + Send + Sync>> which violates the repo contract;
change the data field to use JSON values (HashMap<String, serde_json::Value>) in
the ProviderMeta definition, remove the Box<dyn Any + ...> usage, import
serde_json::Value, and update any constructors, getters, setters, impls, and
(de)serialization code that reference ProviderMeta::data to accept and return
HashMap<String, Value> so provider metadata is represented as JSON values across
the codebase.

In `@examples/claude/hitl.rs`:
- Around line 103-110: The match on prompt(...) uses raw input that may include
CR or case differences; capture the prompt result into a variable, call
.trim().to_lowercase() on it, and then match that normalized string so inputs
like "y\r" or "Y" map to "y" and produce Decision::Approve (reference the
prompt(...) call and the Decision::Approve / Decision::Reject arms).

In `@examples/openai/hitl.rs`:
- Around line 103-110: The match on the raw prompt result can misclassify inputs
like "y\r" on Windows; normalize the string from prompt() before matching by
trimming whitespace and converting to lowercase (e.g., call trim() and
to_lowercase() on the prompt() result) and then match against normalized values
so Decision::Approve and Decision::Reject branches (Decision::Approve,
Decision::Reject(...)) behave correctly across platforms.

In `@providers/gemini/src/api/types/request.rs`:
- Around line 190-213: The current PartEnum::Tool branch calls tool.to_tuple()
and unconditionally serializes a GeminiFunctionCall into assistant_parts, which
can leak unresolved Tool states; change this to use tool.try_to_tuple() (or
explicitly check ToolStatus and early-return/skip for Pending/Approved/Running)
and only build GeminiPart/GeminiFunctionCall and function_parts when
try_to_tuple() yields Some((fc, maybe_fr)) (i.e., the tool is in a resolved
state like Completed/Rejected/Failed); update code paths that reference
assistant_parts, function_parts, GeminiPart, and GeminiFunctionCall to only run
when the tool is resolved.

In `@providers/router/src/router.rs`:
- Around line 57-61: The loop over providers currently records every provider
error into last_failure and continues, which violates the contract; change the
error handling inside the loop that calls provider.complete() (and the
surrounding block that checks self.circuit_breaker and order iteration) so that:
for each provider call, if it succeeds return immediately; if it fails and the
returned ChatError::is_retryable() is true, set last_failure to that error and
continue to the next provider; if it fails and is_retryable() is false
(non-retryable errors such as Provider, InvalidResponse, MaxStepsExceeded,
Callback, Other), return that error immediately without updating last_failure;
ensure this logic replaces the current unconditional last_failure assignment in
the loop (affecting the blocks around where last_failure is set and where
iteration advances).

In `@providers/router/src/stream_router.rs`:
- Around line 46-50: Both complete and stream currently stash every provider
failure and continue, causing non-retryable (fatal) provider errors to be
retried or masked; update the failure handling in the retry/fallback loops
inside complete and stream so that when an attempt returns an error you check
error.is_retryable() (or equivalent) and if it returns false you immediately
return that error instead of pushing it into the failures list and continuing;
remove/stash only retryable errors and ensure the same change is applied to all
fallback loops handling provider responses (the loops around order iteration and
circuit_breaker checks) so non-retryable errors short-circuit the method.

---

Nitpick comments:
In `@providers/mistralrs/src/lib.rs`:
- Around line 23-26: The crate currently uses a crate-level suppression
`#![allow(clippy::result_large_err)]`; change this to function-level
suppressions to match other providers by removing the crate-level attribute and
adding `#[allow(clippy::result_large_err)]` only to the specific
error-handling/conversion functions (e.g., the conversion functions that return
`ChatFailure`/`ChatError` and any other functions producing large Err types) so
the lint scope is limited and consistent with
Claude/Completions/Gemini/Responses.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: f73c26bc-8057-4ebe-98eb-d78789f45d11

📥 Commits

Reviewing files that changed from the base of the PR and between 11e8822 and d110020.

📒 Files selected for processing (30)
  • core/src/chat/mod.rs
  • core/src/chat/stream/handle.rs
  • core/src/chat/stream/input.rs
  • core/src/chat/stream/mod.rs
  • core/src/types/messages/parts.rs
  • core/src/types/messages/tool.rs
  • core/src/types/metadata/usage.rs
  • core/src/types/provider_meta.rs
  • examples/claude/hitl.rs
  • examples/gemini/google_maps.rs
  • examples/mistralrs/voice.rs
  • examples/openai/hitl.rs
  • providers/claude/src/api/stream.rs
  • providers/claude/src/api/types/error.rs
  • providers/completions/src/api/stream.rs
  • providers/completions/src/api/types/error.rs
  • providers/completions/src/api/types/response.rs
  • providers/gemini/src/api/types/error.rs
  • providers/gemini/src/api/types/request.rs
  • providers/mistralrs/src/api/stream.rs
  • providers/mistralrs/src/api/types/request.rs
  • providers/mistralrs/src/api/types/response.rs
  • providers/mistralrs/src/lib.rs
  • providers/openai/src/api/embedding.rs
  • providers/openai/src/client.rs
  • providers/responses/src/api/types/error.rs
  • providers/responses/src/lib.rs
  • providers/router/src/router.rs
  • providers/router/src/stream_router.rs
  • src/lib.rs
💤 Files with no reviewable changes (1)
  • core/src/types/metadata/usage.rs

Comment thread core/src/types/provider_meta.rs
Comment thread examples/claude/hitl.rs Outdated
Comment thread examples/openai/hitl.rs Outdated
Comment thread providers/gemini/src/api/types/request.rs
Comment thread providers/router/src/router.rs
Comment thread providers/router/src/stream_router.rs
@EggerMarc
EggerMarc merged commit 633b37a into main Jun 2, 2026
4 checks passed
@EggerMarc
EggerMarc deleted the fix/lint-and-ci branch June 2, 2026 10:56
@coderabbitai coderabbitai Bot mentioned this pull request Jun 2, 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