Skip to content

fix(model_metadata): localhost->127.0.0.1 at both outbound probe sites (#61528 salvage) - #77615

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/61528-localhost-ipv4
Aug 3, 2026
Merged

fix(model_metadata): localhost->127.0.0.1 at both outbound probe sites (#61528 salvage)#77615
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/61528-localhost-ipv4

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Salvage of #61528 by @pierrenode — mechanism re-derived onto main's current fetch sites with authorship preserved (original conflicts; 5,436 commits behind).

Context — what this changes for users

On dual-stack machines, httpx/requests resolve 'localhost' IPv6-first; when the local server (LM Studio, llama.cpp, ollama) listens on IPv4 only, every metadata probe pays an IPv6 connection timeout first. Measured on this Mac (dead port): localhost 32.9ms vs 127.0.0.1 0.1ms per connect — and on Windows the stall is ~2s per probe.

Applied at BOTH of main's current outbound URL builders in fetch_endpoint_model_metadata (the generic /models loop AND the llama.cpp /v1/props follow-up — whole bug class), reusing the existing _localhost_to_ipv4 helper that main already has for detect_local_server_type. Cache keys keep the un-rewritten URL so localhost and 127.0.0.1 share entries.

Verification

10 tests green (2 new sibling-site guards); mutation: rewrite disabled -> exactly the 2 new tests fail; restore green; ruff clean.

Closes #61528.

…probe sites

fetch_endpoint_model_metadata's generic (non-LM-Studio) /models fetch and
its llama.cpp /v1/props context-length follow-up built request URLs
straight from the unrewritten candidate, unlike every other local-probe
site. Both retained the multi-second dual-stack IPv6 connect penalty
that _localhost_to_ipv4() exists to skip (measured on macOS: localhost
32.9ms vs 127.0.0.1 0.1ms on a dead port; ~2s on Windows). normalized
stays the cache key so caching behavior is unchanged; only the outbound
request target is rewritten.

Re-derived from PR NousResearch#61528 onto current main (original no longer applied
cleanly).
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 3, 2026 11:40
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint platform/windows Native Windows-specific behavior or breakage labels Aug 3, 2026
@Ruanjq98

Ruanjq98 commented Aug 3, 2026

Copy link
Copy Markdown

Code Review: #77615

Verdict: Approve

read_file hint: helpful UX improvement.

LGTM - Reviewed diff. Changes are sound.

CI slice 3/7 failures: run_conversation tests pass MagicMock base_urls
through the metadata probe path; re.sub raised TypeError where the old
code let non-strings flow through. Preserve that contract.
@kshitijk4poor
kshitijk4poor merged commit 733e7d2 into NousResearch:main Aug 3, 2026
38 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/61528-localhost-ipv4 branch August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have platform/windows Native Windows-specific behavior or breakage type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants