perf(model-metadata): resolve localhost to IPv4 in detect_local_server_type - #37595
Closed
rodboev wants to merge 3 commits into
Closed
perf(model-metadata): resolve localhost to IPv4 in detect_local_server_type#37595rodboev wants to merge 3 commits into
rodboev wants to merge 3 commits into
Conversation
rodboev
force-pushed
the
pr/ipv4-localhost-probe
branch
2 times, most recently
from
June 28, 2026 20:00
bedec7a to
162aeca
Compare
…r_type On Windows, `localhost` resolves to both ::1 (IPv6) and 127.0.0.1 (IPv4). httpx tries IPv6 first, hanging 2 sec per probe when the server binds IPv4 only. detect_local_server_type() is called 3+ times during init, each with a new httpx.Client, compounding to ~14s of dead time. Replace localhost with 127.0.0.1 inside the function before connecting. The function is only called for local endpoints (callers guard with is_local_endpoint()), so IPv6 loopback adds no diagnostic value. Measured: 19.9s → 4.0s on Windows with a local proxy on 127.0.0.1:8317.
rodboev
force-pushed
the
pr/ipv4-localhost-probe
branch
from
July 7, 2026 04:38
300b8d8 to
7d324b0
Compare
kshitijk4poor
added a commit
that referenced
this pull request
Jul 9, 2026
…be sites #37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
Collaborator
|
Thanks @rodboev — your fix landed! The probe-cache cluster has now landed on main via PR #61368 (merge commit f556edc), which salvaged this cluster of PRs onto current main with structured review, live smoke tests, and full test gates. Both of your commits were cherry-picked with Closing since this is now merged with your authorship intact. |
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…be sites NousResearch#37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
justemu
pushed a commit
to justemu/hermes-agent
that referenced
this pull request
Jul 18, 2026
…be sites NousResearch#37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…be sites NousResearch#37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…be sites NousResearch#37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…be sites NousResearch#37595 fixed the Windows dual-stack IPv6 timeout only inside detect_local_server_type. The same 2s-per-probe penalty existed at every other helper that builds a probe URL from base_url. Extract the rewrite into _localhost_to_ipv4() and apply it at: - query_ollama_num_ctx - query_ollama_supports_vision - _query_ollama_api_show (server_url derivation) - _query_local_context_length (server root + LM Studio native URL) Tests cover the helper's URL forms, non-localhost passthrough, and that the ollama probes actually POST to 127.0.0.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows,
localhostresolves to both::1(IPv6) and127.0.0.1(IPv4). Python httpx tries IPv6 first; when the local server only binds IPv4, each connection attempt hangs for the full 2 sec connect timeout before falling back.detect_local_server_type()is called 3+ times during agent init (fromfetch_endpoint_model_metadata,get_ollama_num_ctx, and_query_local_context_length), each creating a freshhttpx.Client, so the IPv6 timeout compounds to ~6-14s of dead time.The fix replaces
localhostwith127.0.0.1insidedetect_local_server_type()before connecting. The function is only called for local endpoints (all callers guard withis_local_endpoint()), so IPv6 loopback adds no diagnostic value and the replacement is safe.Changes
agent/model_metadata.py: resolvelocalhostto127.0.0.1indetect_local_server_type()after_normalize_base_urland/v1stripping, before probe requests (+6 lines)tests/agent/test_model_metadata_local_ctx.py: addTestDetectLocalServerTypeLocalhostIPv4with 3 tests verifying localhost resolution, LAN IP passthrough, and 127.0.0.1 passthrough (+60 lines)Validation
localhost:8317(IPv4-only server, Windows)127.0.0.1:8317192.168.1.100:8080(LAN IP)Test plan
pytest tests/agent/test_model_metadata_local_ctx.py -v --timeout=0— 25 passedhermes -m claude-sonnet-4-6 -z "test"on Windows withlocalhostbase_url — 4.0s vs 19.9s beforeFixes #37594