openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(observability,database): silence expected provider/channel errors and add SQLite busy timeout for WhatsApp store

Open YellowSnnowmann opened this issue 6 months ago • 1 comments

Summary

  • Demoted expected custom_openai upstream 400 errors (upstream_error / “Bad request to upstream provider”) from Sentry error events to structured info logs.
  • Extended suppression across all OpenAI-compatible provider paths (responses_api, chat_completions, native_chat, streaming_chat, stream_chat) to reduce duplicate llm_provider noise.
  • Updated expected-error classification so wrapped agent/runtime variants of upstream 400 failures are also treated as provider user-state.
  • Switched channel supervision error handling to report_error_or_expected(...) so transient network disconnects can be classified/silenced instead of always triggering alerts.
  • Added SQLite busy_timeout support for WhatsApp data store connections to reduce database is locked failures under concurrent ingestion/read activity.
  • Added regression tests for expected-error classification and supervision transport-wrapped network failures.

Problem

  • Sentry was receiving high-volume, low-actionability noise from:

    • transient channel/network disconnects,
    • deterministic custom_openai upstream 400 provider/user-state failures,
    • duplicate reporting through both provider and higher-level wrappers.
  • WhatsApp ingestion/read concurrency could trigger immediate SQLITE_BUSY (database is locked) failures because SQLite connections did not wait before failing.

Solution

  • Added targeted classification for exact custom_openai upstream 400 error envelopes and routed them to info-level observability instead of Sentry error capture.
  • Applied the classifier consistently across all OpenAI-compatible provider request paths to avoid duplicate provider noise regardless of request mode.
  • Expanded expected_error_kind matching so wrapped higher-level runtime/agent variants still classify as ProviderUserState.
  • Updated supervision loop reporting to use report_error_or_expected(...) with channel tagging, preserving actionable signal while suppressing expected transient transport failures.
  • Configured rusqlite busy_timeout (15s) in the WhatsApp data store to align with other SQLite store patterns and reduce lock-related ingestion flakiness.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage ≥ 80% — changed lines (Vitest + cargo-llvm-cov merged via diff-cover) meet the gate enforced by .github/workflows/coverage.yml. Run pnpm test:coverage and pnpm test:rust locally; PRs below 80% on changed lines will not merge.
  • Coverage matrix updated — added/removed/renamed feature rows in docs/TEST-COVERAGE-MATRIX.md reflect this change (or N/A: behaviour-only change)
  • All affected feature IDs from the matrix are listed in the PR description under ## Related
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md)
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Runtime/platform impact:

    • Rust core behavior changes for observability and SQLite store handling.
    • Affects desktop flows using:
      • channel supervision,
      • provider inference,
      • WhatsApp data store operations.
  • Performance impact:

    • Reduced noisy Sentry reporting.
    • SQLite operations may wait up to timeout instead of failing immediately under contention.
  • Security/compatibility impact:

    • No new external dependencies.
    • No API contract changes.
    • Fully backward-compatible behavior with improved resilience and cleaner telemetry.

Related

Summary by CodeRabbit

  • Improvements

    • Enhanced error classification to better distinguish user-related upstream failures from system errors.
    • Improved supervised channel error reporting for more reliable restart handling and clearer transport-related classification.
    • Added specialized handling and logging for a known upstream “bad request” pattern to avoid noisy alerts.
    • Configured DB connections to wait on locks to reduce immediate contention failures.
  • Tests

    • Added tests validating new error classifications and supervision message formatting.

Review Change Stack

YellowSnnowmann avatar May 18 '26 12:05 YellowSnnowmann

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: bd34c804-4010-4f6c-b1f8-1d4e10dcf5b1

📥 Commits

Reviewing files that changed from the base of the PR and between 980184b604677ef37a38a339c9ddd6488738570f and 5954fbe233bc43536d4b950db6bb7f6beefca1b6.

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

📝 Walkthrough

Walkthrough

Adds detection and classification for a custom_openai upstream 400 error shape across provider request paths and observability, suppresses Sentry for that known user-state error, switches supervised listener error reporting to the centralized reporter with metadata, and configures a 15s SQLite busy timeout.

Changes

Custom OpenAI Upstream Error Handling and Infrastructure

Layer / File(s) Summary
Detection and Logging Helpers
src/openhuman/inference/provider/ops.rs
New is_custom_openai_upstream_bad_request_http_400 predicate and log_custom_openai_upstream_bad_request_http_400 info-level event to tag this known non-2xx/provider_user_state case.
API Error Handling and Sentry Suppression
src/openhuman/inference/provider/ops.rs
api_error computes the custom-openai flag and routes matching 400 responses to the new logging helper instead of default Sentry reporting.
Observability Classification Extension
src/core/observability.rs
is_provider_user_state_message now recognizes the custom_openai API error (400 envelope with inner bad request to upstream provider + upstream_error substrings; unit tests added for raw and wrapped payloads and regression negatives.
Supervised Error Reporting Integration
src/openhuman/channels/runtime/supervision.rs
Replace direct tracing error in spawn_supervised_listener with report_error_or_expected, formatting the error and adding channel metadata; test asserts NetworkUnreachable classification for a Discord gateway failure string.
Provider Request Path Integration
src/openhuman/inference/provider/compatible.rs
Five paths (chat_via_responses, stream_native_chat, chat_with_system, chat, stream_chat_with_system) add else if branches to call the custom-openai logging helper for the identified 400 shape before generic failure reporting.
SQLite Connection Timeout Configuration
src/openhuman/whatsapp_data/store.rs
Introduce SQLITE_BUSY_TIMEOUT (15s) and set busy_timeout on DB connections in open_conn to wait on contention.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • tinyhumansai/openhuman#2077: The WhatsApp DB busy_timeout change directly addresses SQLITE_BUSY lock contention described in that issue.

Possibly related PRs

Suggested reviewers

  • graycyrus
  • senamakel

Poem

🐰 A tiny rabbit hops by the log,
Finds a 400 wrapped in a fog.
"It's user-state," the rabbit declares,
Sentry stays quiet — fewer stares.
Timeouts wait patiently, debugging at ease.

🚥 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 captures the main changes: demoting expected provider/channel errors from Sentry noise and adding SQLite busy timeout for WhatsApp store, which align with the core objectives across multiple modified files.
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[bot] avatar May 18 '26 12:05 coderabbitai[bot]