Skip to content

fix(agent): reuse HTTP connections for Future model refreshes - #562

Merged
huichen merged 1 commit into
mainfrom
claude/http-connection-reuse
Sep 12, 2026
Merged

huichen merged 1 commit into
mainfrom
claude/http-connection-reuse

Conversation

@huichen

@huichen huichen commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Reuse a process-lifetime reqwest::blocking::Client for Future model-catalog refreshes instead of constructing and dropping a connection pool on every /api/v1/models request.
  • Lazily initialize the client inside the existing dedicated fetch thread so calls made from a Tokio runtime remain safe. Keep API keys, base URLs and the 10-second timeout per-request; refresh backoff and single-flight behavior are unchanged.
  • Add a real HTTP/1.1 regression test that accepts exactly one TCP socket for two fetch calls, verifies a rotated Authorization header, and invokes fetching from a Tokio test runtime.

Scope

This fixes the confirmed connection-pool lifetime issue in model-catalog refreshes. It does not claim to eliminate all new connections or speed up model generation. LLM clients already retain their HTTP clients; their SSE terminal/cancellation behavior is deliberately unchanged so completion does not wait for HTTP EOF.

Draft / do not merge: requested for review only.

Validation

Rust 1.97.0, Windows, isolated HOME/USERPROFILE:

  • cargo fmt -p future-agent --check — passed.
  • cargo clippy -p future-agent --all-targets -- -D warnings — passed.
  • cargo test -p future-agent fetch_future_models_reuses_connection_with_current_credentials — passed. The same regression test failed against the original per-request Client implementation (server observed EOF before the second request).
  • cargo test -p future-agent and cargo test -p future-agent --quiet --no-fail-fast — run; not green on this Windows host. Patched unit suite: 1704 passed, 35 failed, 1 ignored. cli_smoke: 15 passed, 2 failed. All other integration test targets passed.
  • Baseline comparison: temporarily restored the original production implementation and ran cargo test -p future-agent --quiet --no-fail-fast -- --skip fetch_future_models_reuses_connection_with_current_credentials. Baseline: 1703 passed, the same 35 unit failures, 1 ignored, and the same 2 cli_smoke failures. Restored the fix and reran checks afterward.

The pre-existing failures concern Windows/POSIX path assumptions, redirected-home assumptions, Unix shell commands, SQLite file locking, and profile smoke tests. In the changed module, the sole existing failure is cache_path_falls_back_to_tmp_without_home (/home/x\\.future/... vs /home/x/.future/...). These unrelated issues are not changed in this PR.

@huichen
huichen marked this pull request as ready for review September 12, 2026 03:32
@huichen
huichen merged commit a3ca4e3 into main Sep 12, 2026
12 checks passed
@huichen
huichen deleted the claude/http-connection-reuse branch September 12, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant