Skip to content

The agent that grows with you

test(bot-mode): pin grant-refresh reauthorization on execution-policy drift

Teknium1cf36398135f
diff --git a/tests/gateway/test_api_server_runs.py b/tests/gateway/test_api_server_runs.py
index 8f74f74345a..0f9f573ac4e 100644
--- a/tests/gateway/test_api_server_runs.py
+++ b/tests/gateway/test_api_server_runs.py
@@ -1671,6 +1671,57 @@ class TestHostedRoomRuns:
assert denied.status == 401
assert denied_body["error"]["code"] == "invalid_room_grant"
+ @pytest.mark.asyncio
+ async def test_scoped_grant_refresh_refuses_execution_policy_drift(
+ self, auth_adapter, monkeypatch
+ ):
+ """Renewal must pause for reauthorization when the target's execution
+ policy changed since the grant was issued — never silently mint a
+ grant against the drifted policy (blocker 2, #97681 review)."""
+ from gateway import hosted_rooms
+ from gateway.hosted_room_peer import issue_room_grant, decode_room_grant
+ from gateway.hosted_rooms import local_authority_gateway_id
+
+ stale_digest = "c" * 64
+ drifted = issue_room_grant(
+ auth_adapter._room_grant_secret(),
+ grant_id="grant-drifted",
+ room_id="room-1",
+ home_install_id="install-home",
+ authority_gateway_id="install-home",
+ authority_epoch=1,
+ member_id="member-peer",
+ target_install_id=local_authority_gateway_id(),
+ target_profile="default",
+ execution_policy_digest=stale_digest,
+ issued_at=100,
+ ttl_seconds=300,
+ status_expires_at=1000,
+ )
+ drifted_claims = decode_room_grant(
+ auth_adapter._room_grant_secret(),
+ drifted,
+ permission="status",
+ now=100,
+ )
+ hosted_rooms.reserve_peer_room(
+ hosted_rooms.default_db_path(),
+ claims=drifted_claims,
+ expires_at=1000,
+ now=100,
+ )
+ monkeypatch.setattr("gateway.platforms.api_server.time.time", lambda: 200)
+ app = _create_runs_app(auth_adapter)
+ async with TestClient(TestServer(app)) as cli:
+ refused = await cli.post(
+ "/v1/room-members/grants/refresh",
+ json={"ttl_seconds": 300},
+ headers={"Authorization": f"HermesRoom {drifted}"},
+ )
+ refused_body = await refused.json()
+ assert refused.status == 403
+ assert refused_body["error"]["code"] == "room_reauthorization_required"
+
@pytest.mark.asyncio
async def test_scoped_grant_refresh_fails_after_secret_rotation(
self, auth_adapter, monkeypatch
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index 08600960d11..0e50502a3f0 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -152,6 +152,15 @@ Once a peer is registered, the messaging protocol taught to every Bot Chat (`age
Requirements: the peer machine runs the `api_server` gateway platform with a strong `API_SERVER_KEY`; reachability is your network's business (LAN, Tailscale, VPN). The key is a credential and lives in `~/.hermes/.env` as `HERMES_PEER_<NAME>_KEY`; peer names/URLs live in `config.yaml` under `bot_peers`.
+:::note One-way reachability (NAT)
+Cross-gateway links are direct gateway-to-gateway connections — Desktop is a
+viewer, not a relay. A gateway behind home NAT can dial out to a public peer
+(laptop → VPS works), but the reverse direction has no inbound route
+(VPS → home fails) unless your network provides one. If your Group Chat spans
+a NAT boundary, put the room's authority on the host every participant can
+reach (typically the public VPS), or bridge the network with Tailscale/VPN.
+:::
+
## Bots across machines
When you register several backends in **Settings → Connections** — the local runtime, remote gateways, SSH hosts, Hermes Cloud instances — the roster shows the Bots from **every** connected source, persistently: SSH sources are inventoried without spawning anything on the remote box, and machines that are momentarily unreachable keep their last-known rows instead of vanishing. When the same profile name exists on several sources, handles disambiguate as `@name-device` (for example `@research-homelab`). A Bot's chats, sessions, memory, and routines live on the machine that owns the profile.