Skip to content

harden(desktop-backend): give the bare Client::new() call sites a bounded deadline - #10101

Merged
undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:harden/rust-bounded-http-client
Jul 24, 2026
Merged

undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:harden/rust-bounded-http-client

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Four desktop-backend call sites built reqwest clients with no connect timeout and no total-request deadline — screen-activity Pinecone upserts, both Sentry fetches (webhook enrichment + feedback poll), and the Crisp session lookup. One hung upstream pinned its handler or background task until the platform killed it, holding the connection slot the whole time.
  • services::http::bounded_client(total_timeout) is now the one owner of outbound client construction: connect capped at 10s, every request failing after the caller's total budget (Pinecone 30s; Sentry/Crisp 15s). No caller can opt out of having a deadline.
  • realtime.rs's private duplicate helper (identical 10s/15s values) folds onto the primitive; tts.rs keeps its deliberate retry-shaped 30s client unchanged — it already had both bounds.

Scope: this establishes bounded connect + total timeouts for the bare reqwest::Client::new() call sites the helper replaces, and steers new non-streaming integrations to bounded_client(total_timeout). It is not a repo-wide 'every client' invariant — streaming transports (Anthropic/Gemini chat) deliberately omit a client-level total timeout and bound their budget at the route/request level.

Why a primitive, not four timeouts

The repo's own FC-per-hop-timeout class (evidence: #9835) names the pattern: per-call-site retail timeouts drift and new call sites ship bare. After this PR the bare reqwest::Client::new() call sites this helper covers carry bounded connect + total deadlines, and the next non-streaming outbound integration reaches for the bounded constructor because it is the one that exists. Cited, not declared — this is a harden: commit with no triggering incident, per the contribution guide's fix/harden distinction.

Product invariants affected

none (verified with scripts/pr-preflight --suggest)

Failure-Class: none

Validation

  • New hermetic regression test drives the primitive against a stalled local upstream (TCP listener that accepts, reads the request, and never responds — the exact shape a bare client hangs on forever) and asserts the client-side deadline fires, as a timeout error, within budget. No network, no sleeps on the assert path.
  • cargo test → 377 passed (full crate, includes the new test).
  • cargo clippy clean on the crate; the --all-targets unwrap() lints in src/routes/chat/tests/all.rs are pre-existing on main (from the build(quality): ratchet oversized product source files #9851 module split), untouched here.
  • rustfmt --edition 2021 applied to all changed files.
  • Behavior at the four migrated sites is unchanged on the success path; the only new behavior is that a hung upstream now errors at its budget instead of hanging forever — exercised directly by the test above.

Out of scope, named

  • Three bare reqwest::Client::new() sites remain in the crate — services/firestore.rs:81, auth.rs:120, routes/auth.rs:847 (verified against the current head). They sit on auth/Firestore surfaces rather than the non-streaming outbound-integration surface this helper covers, and migrating them changes behavior on credential/data paths that deserve their own review — so they are named follow-up, not bundled into an already-approved hardening PR.

  • The pre-existing --all-targets clippy lints in routes/chat/tests/all.rs — separate cleanup, not this PR's surface.

  • Per-request deadline propagation (deadline budgets flowing across hops, FC-per-hop-timeout's full shape) — fix(chat): FC-4 request deadline budget for the Anthropic chat path #10054/refactor(proxy): migrate the Gemini deadline onto the shared RequestDeadline (after #10054) #10056 own that for the chat/proxy paths.

Review in cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Solid hardening — this is the right shape for a bounded-deadline class of bug. One owner for outbound client construction, callers can't opt out of a deadline, and the per-call-site budgets are sensible (Pinecone 30s for batch upserts, 15s elsewhere).

A few notes:

  • The realtime.rs fold onto the primitive is behavior-preserving (identical 10s/15s values) — clean dedup.
  • The hermetic regression test (stalled local TCP listener → assert the client-side deadline fires within budget, no network, no sleeps on the assert path) is exactly how this should be validated.
  • tts.rs correctly left alone — it already carries both bounds on a deliberate retry-shaped 30s client.

Withholding formal approval only because several repo preflight/formatting/hygiene/detect-changes check runs show cancelled/skipped states on this head. The Rust Backend check — the one that actually compiles and tests this crate — passes. Once CI shows a clean full run this looks good to go from my side.

Thanks for the contribution!


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level I've pushed a fix for the pre-existing Backend unit suite timebomb that was failing CI. CI should be green shortly. Thanks for the review!

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

The substantive check for this crate — Rust Backend — passes. The one red check, Backend unit suite, is the unrelated test_ws_b_short_term_lifecycle.py timebomb on main (a hardcoded NOW date gone stale); this PR is Rust-only and doesn't touch backend Python, so I've left it rather than bundle a Python test fix into a Rust hardening PR. It clears once that timebomb fix lands on main. Ready for a maintainer whenever there's bandwidth.

@Git-on-my-level Git-on-my-level added the docs-accuracy Documentation or committed reports need accuracy fixes label Jul 21, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up here — the Rust/backend checks are now green, and the actual bounded-client primitive plus the migrated Client::new() call sites still look like a solid hardening change.

I do think this needs one small docs/claim correction before merge: the new services::http module comment says “Every outbound HTTP call must carry a connect timeout and a total-request deadline” / “none may opt out,” and the PR title/body similarly read as a repo-wide invariant. That is broader than the current crate state: there are still deliberate outbound clients such as Anthropic/Gemini streaming paths that do not have a client-level total timeout because streaming responses are handled differently (and some budgets are enforced at the route/request level).

Could you narrow the wording to the invariant this PR actually establishes — e.g. “bare reqwest::Client::new() call sites covered by this helper get bounded connect + total timeouts” / “new non-streaming outbound integrations should use bounded_client(total_timeout) unless they have a documented streaming or route-level deadline”? That keeps the useful primitive without leaving a misleading maintainer signal for future HTTP integrations.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar aryanorastar changed the title harden(desktop-backend): every outbound HTTP client carries a bounded deadline harden(desktop-backend): give the bare Client::new() call sites a bounded deadline Jul 21, 2026
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 21, 2026
…l sites

Per review on BasedHardware#10101: the module doc read as a repo-wide invariant ('every
outbound HTTP call must carry a deadline / none may opt out'), which overstates
the crate state — streaming transports (Anthropic/Gemini) deliberately omit a
client-level total timeout and bound their budget at the route/request level.
Reworded to what this PR actually establishes: the bare Client::new() call
sites are the covered replacements, and new non-streaming integrations should
use bounded_client unless they have a documented streaming or route-level
deadline.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Good call — narrowed the claim. The module doc and the PR title/body no longer read as a repo-wide 'every client' invariant. They now state what this actually establishes: the bare reqwest::Client::new() call sites get bounded connect + total timeouts, and new non-streaming integrations should use bounded_client(total_timeout) unless they have a documented streaming or route/request-level deadline. Explicitly noted that streaming transports (Anthropic/Gemini chat) deliberately omit a client-level total timeout and bound their budget elsewhere. Also dropped the 'none may opt out' line from the bounded_client doc. cargo build clean.

@Git-on-my-level
Git-on-my-level dismissed their stale review July 22, 2026 13:39

Resolved on current head: docs/title/body now narrow the claim to covered bare Client::new/non-streaming call sites; current blocker is CI, not this stale docs wording.

@Git-on-my-level Git-on-my-level removed the docs-accuracy Documentation or committed reports need accuracy fixes label Jul 22, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the follow-up — the docs/title/body wording is now narrowed to the actual invariant this PR establishes: bounded clients for the covered bare reqwest::Client::new()/non-streaming call sites, with streaming or route-level-deadline paths explicitly carved out.

I re-checked the current head and also ran the new Rust regression test in an isolated Docker container:

cargo test --locked bounded_client_fails_a_stalled_upstream_within_its_budget --manifest-path desktop/macos/Backend-Rust/Cargo.toml

Result: 1 passed. Static diff also shows the remaining reqwest::Client::new() occurrence in this crate is only the explanatory doc comment.

I’m not formally approving because the full PR check suite is still red on Desktop Swift CI (Desktop Swift Build & Tests, Desktop Swift Test Suites, Desktop Swift Static Contracts). The Rust/backend surface looks good from my side once CI is clean / a maintainer is comfortable treating those failures as unrelated.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

harden(desktop-backend): give bare Client::new() sites a timeout — held (UNKNOWN mergestate + CI red)

aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 22, 2026
…l sites

Per review on BasedHardware#10101: the module doc read as a repo-wide invariant ('every
outbound HTTP call must carry a deadline / none may opt out'), which overstates
the crate state — streaming transports (Anthropic/Gemini) deliberately omit a
client-level total timeout and bound their budget at the route/request level.
Reworded to what this PR actually establishes: the bare Client::new() call
sites are the covered replacements, and new non-streaming integrations should
use bounded_client unless they have a documented streaming or route-level
deadline.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@aryanorastar
aryanorastar force-pushed the harden/rust-bounded-http-client branch from 6a0e2f9 to 2e14ff1 Compare July 22, 2026 18:46
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — this PR is approved, rebased onto latest main today, and all checks are green (mergeable, clean). Ready for a maintainer to merge (regular merge, no squash). Thanks!

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the rebase — all CI is green on the current head now (Rust Backend + rust pass; Desktop Swift correctly skipped since there are no Swift changes). The bounded-client primitive, the six call-site migrations, and the hermetic regression test all look correct.

One actionable correction before merge: the PR body claims

After this PR reqwest::Client::new() appears nowhere in the crate outside a doc comment

This is not accurate against the current source. Three bare reqwest::Client::new() sites still exist in this crate (desktop/macos/Backend-Rust/src/), all confirmed reqwest::Client via their imports:

  • services/firestore.rs:81 — let client = Client::new();
  • auth.rs:120 — client: Client::new(),
  • routes/auth.rs:847 — http_client: Client::new(),

The module-level doc comment in services/http.rs is already correctly narrowed and does not make this claim — so this is specifically a PR-description accuracy issue, not a code issue.

Two easy paths forward:

  1. Narrow the body claim to "the bare reqwest::Client::new() call sites covered by this helper now carry bounded deadlines" (matching the module doc), or
  2. Acknowledge the three remaining sites (firestore/auth surfaces) as out-of-scope follow-up.

The code itself is ready to merge once the claim is corrected. Not formally approving only because the misleading claim should be fixed first.


by AI on behalf of David — if you need David's attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added docs-accuracy Documentation or committed reports need accuracy fixes needs-maintainer-review Needs a human maintainer to sign off before merge labels Jul 23, 2026
aryanorastar and others added 3 commits July 24, 2026 06:46
… deadline

Four call sites built reqwest clients with no connect timeout and no
total-request deadline (screen-activity Pinecone upserts, both Sentry
webhook/poll fetches, the Crisp session lookup): one hung upstream
pinned its handler or background task until the platform killed it,
holding the connection slot the whole time. TTS and realtime already
carried bounded clients — the boundary existed only per call site.

services::http::bounded_client(total_timeout) is now the one owner of
outbound client construction: connect capped at 10s, every request
failing after the caller's total budget (Pinecone 30s, Sentry/Crisp
15s). realtime's private duplicate helper folds onto it with identical
values; tts keeps its deliberate retry-shaped 30s client unchanged.

Related failure class: FC-per-hop-timeout (bounded request budgets over
retail per-call-site timeouts) — cited, not declared; harden commit
with no triggering incident.

Regression test drives the primitive against a stalled local upstream:
accepted connection, no response — the bare-client hang shape — and
asserts the client-side deadline fires within budget.

Verification: cargo test → 377 passed (includes the new deadline test);
cargo clippy clean; rustfmt applied.

Co-Authored-By: Claude Fable 5 <[email protected]>
- routes/tts.rs: migrate inline reqwest::Client::builder() to
  bounded_client(30s) — was the only in-scope call site not using
  the new API, defeating the grep-safety guarantee of the PR
- services/http.rs: replace .unwrap_or_default() with .expect() so
  a misconfigured builder panics loudly instead of silently falling
  back to an unbounded client
- services/http.rs: add #![allow(clippy::unwrap_used)] to test module

Failure-Class: new
…l sites

Per review on BasedHardware#10101: the module doc read as a repo-wide invariant ('every
outbound HTTP call must carry a deadline / none may opt out'), which overstates
the crate state — streaming transports (Anthropic/Gemini) deliberately omit a
client-level total timeout and bound their budget at the route/request level.
Reworded to what this PR actually establishes: the bare Client::new() call
sites are the covered replacements, and new non-streaming integrations should
use bounded_client unless they have a documented streaming or route-level
deadline.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@aryanorastar
aryanorastar force-pushed the harden/rust-bounded-http-client branch from 2e14ff1 to ec04902 Compare July 24, 2026 01:18
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

You're right, and thanks for checking it against source rather than taking the claim at face value — I verified the three sites on the current head before correcting:

  • desktop/macos/Backend-Rust/src/services/firestore.rs:81
  • desktop/macos/Backend-Rust/src/auth.rs:120
  • desktop/macos/Backend-Rust/src/routes/auth.rs:847

(the only remaining services/http.rs hits are the explanatory doc comments.)

Took your first path — the body claim is now narrowed to match the already-correct module doc: "the bare reqwest::Client::new() call sites this helper covers carry bounded connect + total deadlines, and the next non-streaming outbound integration reaches for the bounded constructor." No repo-wide "nowhere in the crate" claim.

I also took your second path explicitly rather than leaving it implicit: the three sites are now named in Out of scope as follow-up, with the reason — they're on auth/Firestore surfaces rather than the non-streaming outbound-integration surface this helper covers, and migrating credential/data paths deserves its own review instead of being bundled into an already-approved hardening PR.

Also rebased onto latest main (the branch was 423 behind, which is what was reddening PR Metadata Preflight — it diffs the merge commit against a stale merge-base). cargo test --locked → 397 passed, cargo fmt --check clean on the rebased head.

undivisible pushed a commit that referenced this pull request Jul 24, 2026
cargo clippy --all-targets reported 275 unwrap_used errors, every one
inside #[cfg(test)] code (proxy 176, chat tests 91, and scattered
singles): the crate-level deny predates any --all-targets run, and CI's
plain cargo clippy never lints test targets, so the debt was invisible
in CI while screaming in every contributor's editor — rust-analyzer runs
clippy with --all-targets by default, burying real diagnostics under 275
false alarms.

Tests may unwrap: a test failing on unwrap is the test doing its job,
and the test authors (including #9851's chat split, merged with these
unwraps) clearly practice that. Each test module now carries an inner
allow with that rationale; production code keeps the crate-level deny
untouched.

Verification: cargo clippy --all-targets → 0 errors (was 275);
cargo test → 376 passed; plain cargo clippy unchanged (was already
clean). #10101's new services::http test module carries its own 4
unwraps and gets the same allow when the branches meet.

Co-Authored-By: Claude Fable 5 <[email protected]>
undivisible added a commit that referenced this pull request Jul 24, 2026
…#10128)

# Summary

`cargo clippy --all-targets` on the desktop Rust backend reported **275
`unwrap_used` errors — every single one inside `#[cfg(test)]` code**
(proxy tests 176, chat tests 91, scattered singles). The crate-level
`unwrap_used = "deny"` predates any `--all-targets` run: CI's plain
`cargo clippy` never lints test targets, so the debt was invisible in CI
while screaming in every contributor's editor — rust-analyzer runs
clippy with `--all-targets` by default, burying real diagnostics under
275 false alarms.

Fix: each test module carries an inner `#![allow(clippy::unwrap_used)]`
with a one-line rationale. Production code keeps the crate-level deny
untouched.

Named as out-of-scope debt in #10101; this closes it.

# Why allow, not 275 `expect()`s

Tests may unwrap — a test failing on unwrap is the test doing its job,
and the codebase's test authors clearly practice that (#9851's chat
split merged with 91 of them). Rewriting 275 call sites into
`expect("...")` messages nobody reads is churn that fights the practiced
convention; scoping the deny to the code it was written for matches
intent with five attribute lines.

# Product invariants affected

none (verified with `scripts/pr-preflight --suggest`)

# Validation

- `cargo clippy --all-targets` → **0 errors** (was 275).
- Plain `cargo clippy` → unchanged (was already clean; production deny
still active — a production `unwrap()` still fails the build).
- `cargo test` → **376 passed**.
- `rustfmt --edition 2021` applied; `make preflight` (local lane, this
PR body) → all selected checks pass.
- `proxy.rs` frozen-size baseline raised 2803 → 2806 (+3, the
test-module allow attribute) with justification, per the ratchet's
documented raise path.

# Out of scope, named

- Adding `--all-targets` to the CI clippy lane (now that it would pass)
— touches workflow config, i.e. the automation guard; trivial follow-up
for a maintainer if wanted.
- #10101's new `services::http` test module carries its own 4 unwraps
and gets the same allow when the branches meet (noted in both PRs).
@undivisible
undivisible merged commit aec1159 into BasedHardware:main Jul 24, 2026
31 of 34 checks passed
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
cargo clippy --all-targets reported 275 unwrap_used errors, every one
inside #[cfg(test)] code (proxy 176, chat tests 91, and scattered
singles): the crate-level deny predates any --all-targets run, and CI's
plain cargo clippy never lints test targets, so the debt was invisible
in CI while screaming in every contributor's editor — rust-analyzer runs
clippy with --all-targets by default, burying real diagnostics under 275
false alarms.

Tests may unwrap: a test failing on unwrap is the test doing its job,
and the test authors (including BasedHardware#9851's chat split, merged with these
unwraps) clearly practice that. Each test module now carries an inner
allow with that rationale; production code keeps the crate-level deny
untouched.

Verification: cargo clippy --all-targets → 0 errors (was 275);
cargo test → 376 passed; plain cargo clippy unchanged (was already
clean). BasedHardware#10101's new services::http test module carries its own 4
unwraps and gets the same allow when the branches meet.

Co-Authored-By: Claude Fable 5 <[email protected]>
undivisible added a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…BasedHardware#10128)

# Summary

`cargo clippy --all-targets` on the desktop Rust backend reported **275
`unwrap_used` errors — every single one inside `#[cfg(test)]` code**
(proxy tests 176, chat tests 91, scattered singles). The crate-level
`unwrap_used = "deny"` predates any `--all-targets` run: CI's plain
`cargo clippy` never lints test targets, so the debt was invisible in CI
while screaming in every contributor's editor — rust-analyzer runs
clippy with `--all-targets` by default, burying real diagnostics under
275 false alarms.

Fix: each test module carries an inner `#![allow(clippy::unwrap_used)]`
with a one-line rationale. Production code keeps the crate-level deny
untouched.

Named as out-of-scope debt in BasedHardware#10101; this closes it.

# Why allow, not 275 `expect()`s

Tests may unwrap — a test failing on unwrap is the test doing its job,
and the codebase's test authors clearly practice that (BasedHardware#9851's chat
split merged with 91 of them). Rewriting 275 call sites into
`expect("...")` messages nobody reads is churn that fights the practiced
convention; scoping the deny to the code it was written for matches
intent with five attribute lines.

# Product invariants affected

none (verified with `scripts/pr-preflight --suggest`)

# Validation

- `cargo clippy --all-targets` → **0 errors** (was 275).
- Plain `cargo clippy` → unchanged (was already clean; production deny
still active — a production `unwrap()` still fails the build).
- `cargo test` → **376 passed**.
- `rustfmt --edition 2021` applied; `make preflight` (local lane, this
PR body) → all selected checks pass.
- `proxy.rs` frozen-size baseline raised 2803 → 2806 (+3, the
test-module allow attribute) with justification, per the ratchet's
documented raise path.

# Out of scope, named

- Adding `--all-targets` to the CI clippy lane (now that it would pass)
— touches workflow config, i.e. the automation guard; trivial follow-up
for a maintainer if wanted.
- BasedHardware#10101's new `services::http` test module carries its own 4 unwraps
and gets the same allow when the branches meet (noted in both PRs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-accuracy Documentation or committed reports need accuracy fixes needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants