Skip to content

fix(inference): suppress spurious Sentry events for Ollama tool-schema rejection 400s#2812

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
staimoorulhassan:fix/ollama-tools-400-sentry
May 29, 2026
Merged

fix(inference): suppress spurious Sentry events for Ollama tool-schema rejection 400s#2812
senamakel merged 3 commits into
tinyhumansai:mainfrom
staimoorulhassan:fix/ollama-tools-400-sentry

Conversation

@staimoorulhassan
Copy link
Copy Markdown
Contributor

@staimoorulhassan staimoorulhassan commented May 28, 2026

Summary

Closes #2787.

Every Ollama model that doesn't support tool-calling generates a Sentry event on each agent turn that tries to use tools. The chat() retry loop already handles these 400s by re-issuing without tools — the bug was that stream_native_chat fired the Sentry event before the retry loop could handle it silently.

Root cause: In stream_native_chat, the non-2xx handler checked is_provider_config_rejection_http but not is_native_tool_schema_unsupported. Tool-schema-rejection 400s therefore fell through to should_report_provider_http_failure → Sentry before the caller's retry loop could suppress them.

Changes:

  • compatible.rsstream_native_chat: Insert is_native_tool_schema_unsupported check between the config-rejection guard and the Sentry gate. When matched, log at info! and return the error string (the retry loop in chat() catches it and re-issues without tools).
  • compatible_tests.rs: Two new unit tests covering the Sentry-suppression path for the Ollama "does not support tools" wire body.

Test plan

  • cargo test -p openhuman -- inference::provider::compatible_tests passes
  • Connecting an Ollama model that doesn't support tools no longer floods Sentry with TAURI-RUST-4K7 events
  • Models that do support tools are unaffected

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for OpenAI-compatible tool schema issues (HTTP 400/422 errors). The system now detects these specific failures and automatically retries requests without tools, with enhanced logging to track these scenarios.

Review Change Stack

…ols' streaming 400

The `stream_native_chat` error handler fired a Sentry event for every Ollama
model that returns HTTP 400 "does not support tools", even though the retry
loop in `chat()` already handles this case correctly by re-issuing the request
without tool definitions.

Root cause: the streaming error path checked `is_budget_exhausted_http_400`,
`is_custom_openai_upstream_bad_request_http_400`, `is_provider_access_policy_denied_http_403`,
and `is_provider_config_rejection_http` — but not `is_native_tool_schema_unsupported`,
which already existed and matched the exact Ollama wire shape. The check was
only present in the non-streaming `chat()` path (line 1871), so each streaming
attempt produced a TAURI-RUST-4K7 Sentry event before the retry succeeded.

Fix: add an `is_native_tool_schema_unsupported` check between the config-rejection
and `should_report_provider_http_failure` arms in `stream_native_chat`'s non-2xx
handler. Matched events are demoted to `log::info!` — the caller's retry loop
handles the actual recovery.

Tests: two new unit tests:
- `is_native_tool_schema_unsupported_matches_ollama_does_not_support_tools` — pin
  detection of all known phrases, non-matching statuses, and unrelated 400 bodies
- `err_supports_no_tools_retry_matches_streaming_error_format` — verify the retry
  predicate correctly parses the anyhow string produced by stream_native_chat

Closes tinyhumansai#2787
@staimoorulhassan staimoorulhassan requested a review from a team May 28, 2026 04:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 394c0ed0-47ff-4f56-87a6-d4a801b46d85

📥 Commits

Reviewing files that changed from the base of the PR and between b574d95 and 1140c8a.

📒 Files selected for processing (1)
  • src/openhuman/inference/provider/compatible.rs
💤 Files with no reviewable changes (1)
  • src/openhuman/inference/provider/compatible.rs

📝 Walkthrough

Walkthrough

This change adds targeted error handling in stream_native_chat to detect when OpenAI-compatible providers (e.g., Ollama) reject tool definitions with HTTP 400/422 responses. The new branch logs a retry intent and prevents generic provider failure reporting.

Changes

Tool Schema Unsupport Detection and Retry

Layer / File(s) Summary
Error detection and logging in stream_native_chat
src/openhuman/inference/provider/compatible.rs
A new else-if branch detects HTTP 400/422 responses with "tools not supported" error text using is_native_tool_schema_unsupported, logs an informational message indicating the caller will retry without tools, and skips generic provider failure reporting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2346: Both PRs update stream_native_chat's non-success HTTP error handling by adding new else-if branches to classify and skip generic failure reporting (this PR: tool-schema-unsupported; retrieved: provider-config-rejection).
  • tinyhumansai/openhuman#2689: The new error detection branch is positioned alongside the existing provider-config-rejection logic that the retrieved PR updates, so both affect tool-support error classification.
  • tinyhumansai/openhuman#2813: Both PRs handle "tools not supported" HTTP failures in the compatible provider to enable retry without tools and reduce Sentry noise.

Suggested labels

sentry-traced-bug

Suggested reviewers

  • M3gA-Mind
  • oxoxDev

Poem

A rabbit hops through error streams,
Finds tools unsupported in Ollama's schemes,
Logs a gentle retry note with care,
Spares the Sentry inbox from the despair! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: suppressing spurious Sentry events for Ollama tool-schema rejection errors, which is the core fix in this PR.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from #2787: detects tool-schema-unsupported 400 errors [#2787], suppresses Sentry reporting [#2787], allows retry without tools [#2787], adds unit tests [#2787], and maintains tool-supporting model behavior [#2787].
Out of Scope Changes check ✅ Passed All changes are directly aligned with fixing the tool-schema rejection issue in compatible.rs and adding corresponding tests in compatible_tests.rs per #2787 requirements.
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.


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 added rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. bug labels May 28, 2026
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
src/openhuman/inference/provider/compatible_tests.rs (1)

1588-1595: ⚡ Quick win

Consider adding a positive test case for 422 UNPROCESSABLE_ENTITY.

The function is_native_tool_schema_unsupported (line 879) accepts both BAD_REQUEST (400) and UNPROCESSABLE_ENTITY (422) status codes. While the current test verifies that a 500 status doesn't match, it doesn't verify that a 422 status does match with a valid tool-rejection body.

✅ Suggested test addition
     // Non-400 status must not match even with the right body.
     assert!(
         !OpenAiCompatibleProvider::is_native_tool_schema_unsupported(
             StatusCode::INTERNAL_SERVER_ERROR,
             r#"{"error":"does not support tools"}"#,
         ),
         "500 with tool-schema body must not match"
     );
+
+    // 422 UNPROCESSABLE_ENTITY should also match.
+    assert!(
+        OpenAiCompatibleProvider::is_native_tool_schema_unsupported(
+            StatusCode::UNPROCESSABLE_ENTITY,
+            r#"{"error":"does not support tools"}"#,
+        ),
+        "422 with tool-schema body must match"
+    );
 
     // Unrelated 400 bodies must not match.
🤖 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/openhuman/inference/provider/compatible_tests.rs` around lines 1588 -
1595, Add a positive test asserting that
OpenAiCompatibleProvider::is_native_tool_schema_unsupported returns true for a
422 UNPROCESSABLE_ENTITY response with the same tool-rejection body; mirror the
existing 400 test in compatible_tests.rs by calling
is_native_tool_schema_unsupported(StatusCode::UNPROCESSABLE_ENTITY,
r#"{"error":"does not support tools"}"#) and assert it is true with an
explanatory message so the function's handling of 422 is covered.
🤖 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.

Nitpick comments:
In `@src/openhuman/inference/provider/compatible_tests.rs`:
- Around line 1588-1595: Add a positive test asserting that
OpenAiCompatibleProvider::is_native_tool_schema_unsupported returns true for a
422 UNPROCESSABLE_ENTITY response with the same tool-rejection body; mirror the
existing 400 test in compatible_tests.rs by calling
is_native_tool_schema_unsupported(StatusCode::UNPROCESSABLE_ENTITY,
r#"{"error":"does not support tools"}"#) and assert it is true with an
explanatory message so the function's handling of 422 is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 864616f5-2e99-4366-93c8-1e00adf70161

📥 Commits

Reviewing files that changed from the base of the PR and between 3f2e2f2 and b574d95.

📒 Files selected for processing (2)
  • src/openhuman/inference/provider/compatible.rs
  • src/openhuman/inference/provider/compatible_tests.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 28, 2026
@oxoxDev oxoxDev self-assigned this May 28, 2026
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

@staimoorulhassan hey! the code looks good to me — the fix is targeted and the tests are solid. one thing before I approve: the "Rust Core Tests (Windows — secrets ACL)" job is failing. that one tends to need org secrets that aren't available on external contributor PRs, so it may not be related to your changes, but CI needs to be 100% green before I can sign off. can you check whether that failure is pre-existing or if there's something you can do to resolve it? once that's green, I'll come back and approve this.

@oxoxDev oxoxDev removed their assignment May 28, 2026
graycyrus
graycyrus previously approved these changes May 28, 2026
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

CI is green now — the prior Windows sccache flake sorted itself out with the retrigger.

Code itself was clean on first read: the is_native_tool_schema_unsupported guard slots in exactly where it belongs (between config-rejection and the Sentry gate), the log::info! demotion is the right severity, and both tests are well-structured — pinning the detection phrases, verifying the non-400 escape hatch, and confirming the retry predicate parses the streaming error format correctly.

Approved.

@coderabbitai coderabbitai Bot added the sentry-traced-bug Bug identified via Sentry triage label May 29, 2026
Copy link
Copy Markdown
Contributor Author

@staimoorulhassan staimoorulhassan left a comment

Choose a reason for hiding this comment

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

PR ready to be merged @graycyrus

@senamakel senamakel merged commit ebe364b into tinyhumansai:main May 29, 2026
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. sentry-traced-bug Bug identified via Sentry triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama models that don't support tools receive tool definitions, causing 400 errors

4 participants