fix(integrations): strip inference path from backend URL (#2075)
Summary
- Strip inference-style paths (
/openai/v1/chat/completions) fromBACKEND_URLenv / compile-time fallback before it becomes any integration call's prefix. - Recover scheme-less inputs (
api.tinyhumans.ai/...) innormalize_backend_api_base_urlso a misbaked env still normalizes. - Re-sanitize
backend_urlinsideIntegrationClient::newandwarn!on first fix-up — defense-in-depth + runtime detector.
Problem
Sentry OPENHUMAN-TAURI-H6 (103 events) and OPENHUMAN-TAURI-HN (50 events) — 153 affected users could never load or manage Composio integrations:
GET https://api.tinyhumans.ai/openai/v1/chat/completions/agent-integrations/composio/connections → 404
GET https://openrouter.ai/api/v1/chat/completions/agent-integrations/composio/connections → 404
effective_backend_api_url's override branch already normalized via normalize_backend_api_base_url, but the env / compile-time branch returned the raw value, so a misconfigured BACKEND_URL=https://api.tinyhumans.ai/openai/v1/chat/completions (the cited prod misbake) flowed straight into every integration request as the prefix. list_connections, delete_connection, and every other IntegrationClient operation 404'd.
Solution
Three-layer fix:
src/api/config.rs—effective_backend_api_url: routeapi_base_from_env()throughnormalize_backend_api_base_urlbefore returning, closing the env-fallback bypass.normalize_backend_api_base_url: promoted topub(crate); on parse failure (scheme-less input) retries withhttps://prefix so the path can still be stripped. Empty input round-trips unchanged so callers' "no backend" sentinel is not overwritten.src/openhuman/integrations/client.rs—IntegrationClient::new: re-runsnormalize_backend_api_base_urlon the constructor argument andwarn!s once when input had to be fixed. Holds the local invariant ("backend_urlhas no inference path") even if a future caller forgets the resolver, and emits the diagnostic the issue asked for.
The Sentry HN case (openrouter.ai/...) is additionally caught by the pre-existing looks_like_local_ai_endpoint heuristic (path-end match works on any host); the new sanitize layer guarantees correct behavior even if the heuristic is bypassed.
Submission Checklist
- [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
- [x] Diff coverage ≥ 80% — every new branch in the three touched functions has a dedicated unit test (8 new tests cover env-bake, scheme-less, idempotent-clean, empty-input, sanitize variants, and
IntegrationClient::newinvariant). - [x] Coverage matrix updated —
N/A: behaviour-only change(bug fix, no new/removed/renamed feature row). - [x] All affected feature IDs from the matrix are listed in the PR description under
## Related—N/A: behaviour-only change. - [x] No new external network dependencies introduced (mock backend used per Testing Strategy).
- [x] Manual smoke checklist updated if this touches release-cut surfaces —
N/A: bug fix in URL normalization, no release-cut surface touched. - [x] Linked issue closed via
Closes #NNNin the## Relatedsection.
Impact
- Runtime / platform: Rust core only. Affects every desktop platform that ships the core. No frontend / Tauri shell changes.
- Performance: O(1) URL parse on
IntegrationClient::new(once per construction). Negligible. - Security: none — strictly defensive URL hygiene.
- Migration / compatibility: backward-compatible. Clean URLs round-trip unchanged; misconfigured URLs are silently fixed up with a
warn!so the regression is observable.
Related
- Closes: #2075
- Follow-up PR(s)/TODOs: none
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: N/A
- Commit SHA: N/A
Validation Run
- [x]
pnpm --filter openhuman-app format:check— N/A: no app/ changes - [x]
pnpm typecheck— N/A: no app/ changes - [x] Focused tests: N/A
- [x] Rust fmt/check (if changed): N/A
- [x] Tauri fmt/check (if changed): N/A
Validation Blocked
command:N/Aerror:N/Aimpact:N/A
Behavior Changes
- Intended behavior change: N/A
- User-visible effect: N/A
Parity Contract
- Legacy behavior preserved: N/A
- Guard/fallback/dispatch parity checks: N/A
Duplicate / Superseded PR Handling
- Duplicate PR(s): N/A
- Canonical PR: N/A
- Resolution (closed/superseded/updated): N/A
Summary by CodeRabbit
- Bug Fixes
- Backend URL handling now robustly normalizes and sanitizes misconfigured values (including schemeless or malformed overrides), strips any inference/path fragments, and ensures client-backed URLs use the clean root. Emits a redacted warning when an input URL is altered.
- Tests
- Added tests covering sanitization, idempotency, empty-input behavior, and client-side enforcement.
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: 0c99c397-5bc6-45d2-abe8-4fd935433b0d
📥 Commits
Reviewing files that changed from the base of the PR and between 3621415bc3a19c0d4ae5e7870ee667adab8252d0 and 88cddb22186135d7d762c0ba8c957b18a6997988.
📒 Files selected for processing (2)
src/api/config.rssrc/openhuman/integrations/client.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- src/openhuman/integrations/client.rs
- src/api/config.rs
📝 Walkthrough
Walkthrough
Config-level normalization now strips inference-style paths from env-derived backend URLs and is exposed crate-wide; integration client construction also sanitizes backend URLs to ensure stored bases are host-rooted. Tests added for both normalization and client sanitization behaviors.
Changes
Backend URL Sanitization for Integration Clients
| Layer / File(s) | Summary |
|---|---|
Backend URL normalization in config module src/api/config.rs |
effective_backend_api_url now returns normalize_backend_api_base_url(&env_url) for env fallbacks. normalize_backend_api_base_url was made pub(crate) and now handles schemeless/malformed inputs by attempting parse with and without https://, then strips path/query/fragment to a host-root string. redact_url_for_log visibility widened. Tests verify env-path stripping, schemeless normalization, idempotency, and clean-root pass-through. |
Integration client backend URL sanitization src/openhuman/integrations/client.rs, src/openhuman/integrations/client_tests.rs |
Adds sanitize_backend_url (trim, remove trailing slashes, normalize via config cleaner, log redacted warning when changed) and applies it in IntegrationClient::new. Tests assert sanitizer strips inference paths, is idempotent on clean roots, preserves empty input, and that IntegrationClient::new stores the cleaned backend URL. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- tinyhumansai/openhuman#1764: Addresses related backend URL cleaning in
normalize_backend_api_base_url/effective_backend_api_url.
Poem
🐰 I nudged a URL, trimmed and neat,
Stripped the path where/completionsmeet.
A warning whispered, userinfo redacted,
Client stores a root that's clean and acted.
Now requests stroll home, no 404 bleat.
🚥 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 concisely describes the main change: fixing a bug where inference paths are stripped from backend URLs in integrations. |
| Linked Issues check | ✅ Passed | The PR comprehensively addresses all coding objectives from #2075: normalizes backend URLs to prevent inference paths [effective_backend_api_url, normalize_backend_api_base_url], adds sanitization in IntegrationClient::new, includes runtime detection/logging, and provides 8 unit tests covering varied backend_url shapes. |
| Out of Scope Changes check | ✅ Passed | All changes are directly scoped to fixing #2075: three files modified for URL normalization logic and tests, no extraneous features or unrelated modifications present. |
| 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.
Comment @coderabbitai help to get the list of available commands and usage tips.