Skip to content

fix(agent): short-circuit local server detection for known public provider hosts - #61428

Open
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-61421
Open

fix(agent): short-circuit local server detection for known public provider hosts#61428
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-61421

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

When using the openai-api provider with the default base URL https://api.openai.com/v1, Hermes sends HTTP GET requests to local-only discovery endpoints (/api/tags, /v1/props, /version) on api.openai.com. These endpoints return 404 Not Found (as expected, since they're not part of the OpenAI API), creating noise in egress logs and monitoring dashboards.

This PR adds a hostname blacklist to detect_local_server_type() to short-circuit detection for known public provider hosts. Local/custom endpoints (localhost, 127.0.0.1, RFC1918 IPs, custom URLs) still probe as expected.

Related Issue

Fixes #61421

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/model_metadata.py: Add hostname check to detect_local_server_type() to short-circuit detection for known public provider hosts (api.openai.com, api.anthropic.com, generativelanguage.googleapis.com)
  • tests/agent/test_model_metadata_local_ctx.py: Add TestDetectLocalServerTypePublicProviderShortCircuit test class with 5 regression tests

How to Test

  1. Configure Hermes with:
    model:
      provider: openai-api
      default: gpt-5.1
      base_url: "https://api.openai.com/v1"
  2. Use Hermes via gateway or CLI to send prompts with images (triggers vision routing)
  3. Before fix: Egress logs show 404s to /api/tags, /v1/props, /version on api.openai.com
  4. After fix: No probing requests to those endpoints; only normal /v1/... API traffic
  5. Run pytest tests/agent/test_model_metadata_local_ctx.py::TestDetectLocalServerTypePublicProviderShortCircuit -v — all 5 tests pass

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/agent/test_model_metadata_local_ctx.py -v and all 39 tests pass
  • I've added tests for my changes (5 new tests in TestDetectLocalServerTypePublicProviderShortCircuit)
  • I've tested on my platform: macOS 15.2

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — hostname parsing uses stdlib urlparse, works on all platforms
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

…vider hosts

- Add hostname blacklist to detect_local_server_type() to avoid probing
  local-only endpoints (/api/tags, /v1/props, /version) on public SaaS APIs
- Prevents noisy 404s in egress logs and monitoring dashboards
- Known hosts: api.openai.com, api.anthropic.com, generativelanguage.googleapis.com
- Local/custom endpoints still probe as expected

Fixes NousResearch#61421
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API labels Jul 9, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the unnecessary discovery traffic. The underlying path remains present on current main: agent/model_metadata.py:704-740 probes the configured URL, and agent/image_routing.py:321-331 can call that detector for an unknown capability.

Problems

  • agent/model_metadata.py:690 parses the hostname directly instead of using the existing base_url_hostname() helper. That misses the trailing-dot normalization contract already covered by tests/test_base_url_hostname.py:37-38: https://api.openai.com./v1 will still be probed.

Suggested changes

  • Use the already imported base_url_hostname(normalized) at agent/model_metadata.py:690 and add a matching no-request regression case.

Automated hermes-sweeper review.

Comment thread agent/model_metadata.py
# This reduces noise in egress logs and monitoring dashboards.
try:
url = normalized if "://" in normalized else f"https://{normalized}"
host = urlparse(url).hostname or ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use the existing base_url_hostname(normalized) helper here. It canonicalizes trailing DNS dots (covered by tests/test_base_url_hostname.py), so https://api.openai.com./v1 is treated as the same OpenAI host and does not retain the probe behavior this change targets.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 11, 2026
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 provider/openai OpenAI / Codex Responses API sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Hermes probes non‑OpenAI endpoints (/api/tags, /v1/props, /version) on api.openai.com, causing noisy 404s

3 participants