Skip to content

fix: route embedding emitters through expected-error reporting#2216

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
oxoxDev:fix/sentry-ollama-embed-emitter
May 20, 2026
Merged

fix: route embedding emitters through expected-error reporting#2216
senamakel merged 3 commits into
tinyhumansai:mainfrom
oxoxDev:fix/sentry-ollama-embed-emitter

Conversation

@oxoxDev
Copy link
Copy Markdown
Contributor

@oxoxDev oxoxDev commented May 19, 2026

Summary

  • Routed embedding error emission through report_error_or_expected at the three direct-emit sites called out in kickoff.
  • Added focused classifier-state tests for Ollama/OpenAI embedding wire-shapes to lock current expected vs unexpected behavior.
  • Kept scope strictly in embeddings modules; no src/core/observability.rs changes.

Problem

  • ollama.rs and openai.rs were using report_error(...) directly, bypassing expected-error classification and creating avoidable Sentry noise.
  • We needed the Sentry-only routing swap while avoiding ongoing merge traffic in observability.rs lanes.

Solution

  • Swapped report_error(message.as_str(), ...) to report_error_or_expected(&message, ...) at:
    • src/openhuman/embeddings/ollama.rs (transport and non-2xx paths)
    • src/openhuman/embeddings/openai.rs (non-2xx path)
  • Added test coverage in embeddings tests to capture current classifier state for MA/KM/GP/GX-style wire strings and a guard for genuine parse/OpenAI key errors remaining unexpected.
  • Left classifier-arm additions to follow-up lanes touching observability.rs.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • N/A: Diff coverage ≥ 80% is enforced by CI for this branch/repo workflow
  • N/A: No coverage-matrix feature-row add/remove/rename in this change
  • N/A: No affected feature IDs were added/removed for matrix mapping in this lane
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • N/A: No release-cut manual-smoke surface touched
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Runtime impact is limited to embedding error reporting behavior (classifier-routed vs direct emit).
  • No migration, schema, or compatibility changes.
  • MA/KM/GX classifier-arm follow-up remains in the observability lanes; this PR intentionally avoids those file conflicts.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: fix/sentry-ollama-embed-emitter
  • Commit SHA: 1a22b1ddc61d3bb6fdf7727ab5c4e567ab225ec5

Validation Run

  • N/A: pnpm --filter openhuman-app format:check (Rust-only lane)
  • N/A: pnpm typecheck (Rust-only lane)
  • Focused tests: CARGO_TARGET_DIR=target_codex cargo test --lib openhuman::embeddings::ollama::tests:: -- --test-threads=1; CARGO_TARGET_DIR=target_codex cargo test --lib openhuman::embeddings::openai::tests::openai_embedding_api_error_stays_unexpected -- --exact
  • Rust fmt/check (if changed): cargo fmt; CARGO_TARGET_DIR=target_codex cargo check
  • N/A: Tauri fmt/check (if changed)

Validation Blocked

  • command: CARGO_TARGET_DIR=target_codex cargo clippy --all-targets -- -D warnings
  • error: Fails on pre-existing repository-wide warnings/lints outside this PR scope
  • impact: No local all-target clippy clean signal for this lane; relied on focused tests + CI

Behavior Changes

  • Intended behavior change: Embedding provider errors now flow through expected-error classifier routing.
  • User-visible effect: Fewer noisy Sentry captures for expected embedding conditions; runtime behavior unchanged.

Parity Contract

  • Legacy behavior preserved: Embedding request/response/error handling semantics preserved.
  • Guard/fallback/dispatch parity checks: Only observability reporting API changed at emit sites.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: This PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • Bug Fixes

    • Improved error tracking and classification for embedding API failures to better distinguish between expected and unexpected errors.
  • Tests

    • Added test coverage to verify error classification behavior for embedding services.

Review Change Stack

@oxoxDev oxoxDev requested a review from a team May 19, 2026 13:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 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: 9e7a414a-3e20-49f7-8fe9-d965d6faf86e

📥 Commits

Reviewing files that changed from the base of the PR and between 3aa2984 and 1a22b1d.

📒 Files selected for processing (4)
  • src/openhuman/embeddings/ollama.rs
  • src/openhuman/embeddings/ollama_tests.rs
  • src/openhuman/embeddings/openai.rs
  • src/openhuman/embeddings/openai_tests.rs

📝 Walkthrough

Walkthrough

Both Ollama and OpenAI embedding providers' error reporting paths are updated to use report_error_or_expected instead of report_error, enabling classification of expected vs. unexpected errors. Unit tests validate that various error message patterns are classified correctly, ensuring expected errors skip incident reporting while authentic issues remain visible.

Changes

Embedding Error Reporting Classification

Layer / File(s) Summary
Ollama embedding error reporting refactor
src/openhuman/embeddings/ollama.rs
Transport-failure (.send().await) and non-2xx HTTP response error paths switch from report_error to report_error_or_expected, preserving error messages and observability context.
Ollama error classification test suite
src/openhuman/embeddings/ollama_tests.rs
New #[test] functions validate expected_error_kind classifications for MA/KM/GX/GP "wire shape" messages (remaining unclassified or routing through classification) and Ollama parse errors (unclassified).
OpenAI embedding error reporting refactor
src/openhuman/embeddings/openai.rs
Non-2xx embedding response error path switches from report_error(message.as_str(), ...) to report_error_or_expected(&message, ...) with metadata and bail behavior unchanged.
OpenAI error classification test
src/openhuman/embeddings/openai_tests.rs
New test openai_embedding_api_error_stays_unexpected verifies OpenAI 401 authentication errors return None (unexpected), ensuring API credential failures reach Sentry unfiltered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • tinyhumansai/openhuman#1795: Introduces the foundational ExpectedErrorKind classification logic and report_error_or_expected function that this PR applies to embedding error paths.
  • tinyhumansai/openhuman#1798: Extends error classification to other transient leak paths (channels/composio) using the same report_error_or_expected observability mechanism.
  • tinyhumansai/openhuman#1719: Expands the expected_error_kind classifier to treat session-expired 401 errors as expected, complementing the embedding error filtering introduced here.

Suggested labels

working

Suggested reviewers

  • senamakel
  • graycyrus

🐰 Embedding errors now wear a sorting hat,
Expected ones skip the Sentry chat,
Ollama and OpenAI aligned,
Error classification by design!

🚥 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 clearly and accurately summarizes the main change: replacing direct error reporting calls with expected-error routing in embedding modules.
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.


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

@coderabbitai coderabbitai Bot added the working A PR that is being worked on by the team. label May 19, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 19, 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.

Walkthrough

Clean, well-scoped fix that routes three embedding error-emission sites through the expected-error classifier (report_error_or_expected) instead of the unconditional report_error. This reduces Sentry noise for known Ollama/OpenAI error wire shapes while ensuring genuine parse/API-key errors still propagate. Six classifier-state tests lock the current behavior so follow-up classifier batches (post #2063 + #2188) can safely flip the expected values.

Change Summary

File Change type Description
src/openhuman/embeddings/ollama.rs Modified Swap report_errorreport_error_or_expected at transport-error and non-2xx paths
src/openhuman/embeddings/ollama_tests.rs Modified 5 new classifier-state tests (MA, KM, GP, GX wire shapes + parse-error sentinel)
src/openhuman/embeddings/openai.rs Modified Swap report_errorreport_error_or_expected at non-2xx path
src/openhuman/embeddings/openai_tests.rs Modified 1 new classifier-state test (401 API key error sentinel)

Per-file Analysis

ollama.rs — Mechanical swap at two call sites. The message.as_str()&message change is correct (&String derefs to &str, both impl Display, and the generic signature <E: Display + ?Sized> is identical between old and new functions). Tag slices unchanged. LGTM.

openai.rs — Same mechanical swap, same correctness reasoning. LGTM.

ollama_tests.rs — Five well-commented tests that call expected_error_kind directly (synchronous, no network). Good use of assertion messages to explain the "why" behind each expected value. One minor note below on gp_wire_shape_classifies.

openai_tests.rs — Clean sentinel test ensuring 401 errors remain unexpected. LGTM.

Overall this is a solid, focused PR. No critical or major issues — just one minor suggestion on test precision.

assert_eq!(
crate::core::observability::expected_error_kind(msg),
None,
"KM — matcher arm pending follow-up classifier batch"
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.

[minor] is_some() doesn't pin the specific ExpectedErrorKind variant. If a future broader matcher catches this message but classifies it as a different kind, this test would pass silently.

Consider matching the exact variant for consistency with the other tests' precision:

assert_eq!(
    crate::core::observability::expected_error_kind(msg),
    Some(ExpectedErrorKind::LocalAiCapabilityUnavailable),
    "GP — LocalAiCapabilityUnavailable matcher must catch this; closed by this PR"
);

Not blocking — the other five tests all use assert_eq! with an exact expected value, so this would also bring stylistic consistency.

senamakel added 2 commits May 19, 2026 20:05
# Conflicts:
#	src/openhuman/embeddings/openai.rs
…ariant

Matches the exact ExpectedErrorKind variant in gp_wire_shape_classifies
instead of `is_some()`, for stylistic consistency with the other
classifier tests and to avoid passing if a future broader matcher
catches the message under a different variant.

Addresses @graycyrus review comment on ollama_tests.rs:355.
@senamakel senamakel merged commit 1fe8afb into tinyhumansai:main May 20, 2026
26 checks passed
mtkik pushed a commit to mtkik/openhuman-meet that referenced this pull request May 21, 2026
CodeGhost21 pushed a commit to CodeGhost21/openhuman that referenced this pull request May 22, 2026
AusAgentSmith pushed a commit to AusAgentSmith/openhuman that referenced this pull request May 23, 2026
…umansai#2216)

Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

working A PR that is being worked on by the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants