Skip to content

test(agent): harden hostname anchoring against gethostname failures - #102436

Open
beplee wants to merge 4 commits into
NousResearch:mainfrom
beplee:fix/gateway-live-runtime-identity-hardened
Open

beplee wants to merge 4 commits into
NousResearch:mainfrom
beplee:fix/gateway-live-runtime-identity-hardened

Conversation

@beplee

@beplee beplee commented Sep 3, 2026

Copy link
Copy Markdown

What does this PR do?

Addresses @lorencato23 review hardening points on PR #102192 (stop synchronized sessions from misidentifying the active host).

Changes

  1. **Fail closed when raises ** — the previous code silently skipped the hostname check when failed, which meant a local stored prompt could be treated as verified when it shouldn't be. Now we reject the stored prompt.

  2. Fail closed when returns empty string — same conservative behavior: reject the stored prompt rather than silently treating it as verified.

  3. Regression tests for failure modes — added tests in both and covering:

    • raising
    • returning empty string
    • Legacy local prompt without hostname (already existed, now also tested with failure)
  4. Document hostname as host anchoring, not authentication — added comments explaining that hostname is a useful human-readable signal but not a globally unique gateway identity (two cloned VMs can share a hostname).

  5. Same-hostname/different-profile test — makes the remaining limitation visible and prevents future overclaiming of the guarantee.

Type of Change

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

How to Test

scripts/run_tests.sh tests/run_agent/test_compression_persistence.py -k 'machine_hostname or legacy_local_prompt or gethostname or same_hostname'
scripts/run_tests.sh tests/agent/test_prompt_builder.py -k 'identifies_live_machine or omits_hostname'

Related

fangliquanflq and others added 4 commits September 3, 2026 21:11
Addresses @lorencato23 review on PR NousResearch#102192:
- Fail closed when socket.gethostname() raises OSError or returns empty
- Add regression tests for gethostname failure modes
- Document hostname as host anchoring, not authentication boundary
- Add same-hostname/different-profile test to make limitation visible
@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 area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Sep 3, 2026
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

PR #102436 — harden hostname anchoring against gethostname failures

Verdict: Looks good. Thoughtful host-anchoring for DB-synced prompts with honest scoping (anchoring, not auth — stated in the comment) and fail-closed behavior on unreadable hostnames.

What the change does

  • agent/prompt_builder.py:96-101 — local-backend prompts gain a Machine hostname: line (omitted when empty/raising).
  • agent/conversation_loop.py:20-64 — _stored_prompt_matches_runtime rejects cross-machine reuse (hostname mismatch), one-time-rejects legacy hostname-less prompts to upgrade them, fails closed on OSError/empty; read window widened to idx-3..idx+4 since host fields now precede the anchor.
  • contributors/emails/bepleecanton@gmail.com — salvage attribution for fix(agent): stop synchronized sessions from misidentifying the active host #102192.
  • Tests: hostname emit/omit matrix, cross-machine stale, legacy rebuild, fail-closed cases, same-host-different-profile still valid.

Non-blocking

  1. conversation_loop.py:63 — casefold() comparison is right for Windows (ATLAS vs atlas), but hostnames that legitimately differ in case cosmetics across dual-boot/synced profiles would force a rebuild per switch. Cheap (one rebuild) — noting only.
  2. Hostname is a weak anchor (cloned VMs, DHCP defaults like localhost, containers sharing a hostname): two different machines with the same hostname and cwd will still share a prompt. The code comment acknowledges this and tracks a stable-identity follow-up — agree with that framing; just making sure the follow-up is actually filed/tracked somewhere.
  3. conversation_loop.py:31 — widening the scan to 3 lines before the anchor slightly enlarges the spoof surface (a Host:-looking line in user-controlled prompt text just above the anchor could satisfy the read). First-occurrence anchoring on Hermes' own block mitigates it; and stored prompts are local-DB content, not remote input. Acceptable — noting the tradeoff of the window change.

Tests: The same-host/different-profile test pins the anchoring-vs-auth boundary explicitly. Good.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants