Skip to content

The agent that grows with you

fix: reload transport role policy after Discord membership awaits

Teknium43ae9e9a2312
diff --git a/plugins/platforms/discord/adapter_authorization.py b/plugins/platforms/discord/adapter_authorization.py
index 0a78f267023..1c776973890 100644
--- a/plugins/platforms/discord/adapter_authorization.py
+++ b/plugins/platforms/discord/adapter_authorization.py
@@ -32,8 +32,13 @@ class DiscordAuthorizationMixin:
member = await asyncio.wait_for(guild.fetch_member(uid), timeout=10)
except (HTTPException, TimeoutError, OSError):
return False
- # Neither a replaced client nor a policy edit may reuse the old lookup.
- if self._client is not client or policy() != (roles, guild_id):
+ # The entry-time ContextVar contains a secret snapshot. Reload the same
+ # transport home after SDK I/O so an intervening .env edit is visible too.
+ from gateway.run import _profile_runtime_scope
+ from hermes_constants import get_hermes_home
+ with _profile_runtime_scope(get_hermes_home()):
+ current_policy = policy()
+ if self._client is not client or current_policy != (roles, guild_id):
return False
return (member.id == uid and member.guild.id == int(guild_id)
and any(role.id in roles for role in member.roles))
diff --git a/tests/gateway/fixtures/native_role_peer.py b/tests/gateway/fixtures/native_role_peer.py
index b6b93eb77bf..3170ae506a1 100644
--- a/tests/gateway/fixtures/native_role_peer.py
+++ b/tests/gateway/fixtures/native_role_peer.py
@@ -109,6 +109,24 @@ async def probe(peer):
await send(event('wrong-guild', scope='999'))
assert len(list_session_admissions(authority.db, session_id=entry.session_id, pending_only=False)) == 1
assert len(peer.requests) == 1
+ if sys.argv[1] == 'multiplex':
+ guild.roles = [SimpleNamespace(id=700)]
+ # Hot policy edits during SDK I/O must not reuse the entry-time secret scope.
+ def revoke_policy():
+ guild.hook = None
+ (transport / '.env').write_text('DISCORD_ALLOWED_ROLES=999\n')
+ guild.hook = revoke_policy
+ from gateway.session_ingress_context import native_callback
+ from hermes_state_runtime import RuntimeStoreError
+ ev = event('policy-revoked-during-fetch')
+ with native_callback(runner, ev, transport, 'transport'):
+ try:
+ await authority.admit_native(ev)
+ except RuntimeStoreError as exc:
+ assert exc.reason == 'permission_denied'
+ else:
+ raise AssertionError('revoked transport role policy was durably accepted')
+ assert len(peer.requests) == 1
if sys.argv[1] == 'positive':
# Independent user/pairing grants survive membership revocation.
calls = guild.calls