Repository navigation
fix(agent): stop synchronized sessions from misidentifying the active host - #102192
fangliquanflq wants to merge 2 commits into
Conversation
|
I reviewed this PR against the same reproduction and agree that it addresses the root cause more directly: synchronized session prompt snapshots need a live machine identity, and cross-host/legacy local snapshots must be rebuilt. I closed my overlapping PR #102201 in favor of this one. It focused on making The hostname anchoring and restoration invalidation here are the important fix. If maintainers want additional operator-facing diagnostics later, the status changes from #102201 could be considered as a separate follow-up; I would not block this PR on them. Thanks for the thorough reproduction and regression coverage. |
lorencato23
left a comment
There was a problem hiding this comment.
A few follow-up hardening points to consider before merge:
-
Add a regression test for
socket.gethostname()returning an empty string or raisingOSError. The current comparison is intentionally conservative, but the behavior should be explicit: a local stored prompt must not silently be treated as verified when the live hostname cannot be read. -
Hostname is a useful human-readable signal but not a globally unique gateway identity. Two cloned VMs or machines can share a hostname, and two gateway instances can run on the same host. Please consider documenting that this is host anchoring, not an authentication boundary, and track a follow-up for a stable opaque per-install/runtime identity if stronger guarantees are needed.
-
It may be worth adding a same-hostname/different-profile or same-hostname/different-gateway test to make the remaining limitation visible and prevent future overclaiming of the guarantee.
These are hardening/follow-up items, not blockers for the PC-versus-Atlas case this PR fixes.
What does this PR do?
Hermes can restore a persisted system prompt copied from another machine and confidently report the wrong active host. This change places the live machine hostname in the local-runtime prompt and rejects copied or legacy local prompt snapshots when their hostname is missing or no longer matches.
Symptom
A Telegram session served by Atlas can claim it is running on a synchronized personal PC because the prompt exposes only the operating system, home, cwd, and synchronized profile state, not the live machine identity.
Impact
Users in synchronized multi-host setups can receive incorrect host attribution and direct debugging or operational instructions at the wrong machine.
Bug Cause
Trigger:
agent/prompt_builder.py:build_environment_hintsandagent/conversation_loop.py:_stored_prompt_matches_runtimeCausal chain:
Why it is wrong: Profile and filesystem identity are not proof of which process currently serves the session.
Working sibling / contrast: Remote terminal backends intentionally describe the tool execution sandbox instead of the Hermes process host and continue to suppress local host information.
Ruled out: Platform routing is not the missing signal. The prompt already persists
Platform: telegram; it does not identify whether that gateway process is on Atlas or the personal PC.Fix
Add the live
socket.gethostname()value to local environment hints. During stored-prompt restoration, compare that anchored hostname with the current process host, reject cross-host snapshots, and rebuild legacy local snapshots once so they gain the new identity field. Keep the existing project-context anchoring so user prose cannot spoof the comparison.Related Issue
Closes #102170
Type of Change
Changes Made
agent/prompt_builder.py- expose the live local machine hostname in the stable environment block.agent/conversation_loop.py- invalidate persisted local prompts when the machine identity is absent or stale.tests/agent/test_prompt_builder.py- verify local hostname emission.tests/run_agent/test_compression_persistence.py- cover copied-host, matching-host, and legacy prompt restoration.How to Test
scripts/run_tests.sh tests/run_agent/test_compression_persistence.py -k 'machine_hostname or legacy_local_prompt' scripts/run_tests.sh tests/agent/test_prompt_builder.py -k identifies_live_machineChecklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
cli-config.yaml.exampleis N/A because no config keys changedCONTRIBUTING.mdandAGENTS.mdare N/A because no architecture or workflow changedsocket.gethostname()