fix(gateway): match the profile-namespaced session key in the clarify bypass lookup - #82980
Conversation
… bypass lookup Fixes NousResearch#82975. The adapter-level clarify reply bypass in gateway/platforms/base.py's handle_message() built its session_key via build_session_key(...) without a profile= argument, defaulting to the legacy agent:main namespace. The runner registers pending clarifies under SessionStore._generate_session_key()'s key, which DOES include profile=self._resolve_profile_for_key(source). Under a named-profile multiplex these diverge, so the bypass lookup at clarify_gateway.get_pending_for_session(session_key, ...) misses -- the user's answer to a pending clarify() gets routed to the adapter's busy-session queue instead of resolving it. The turn then hangs until the clarify's 3600s timeout, with no inbound message: log line and no "Gateway intercepted clarify text response" log line, matching the reported Telegram symptom exactly. Verified the divergence directly: _resolve_profile_for_key() returns None when multiplex_profiles is off (default) -- byte-identical to the prior implicit profile=None, so this only changes behavior for multiplexed deployments, matching the issue's exact reported scope. Fixed by using the same self._session_store._resolve_profile_for_key() the runner's key generator calls, guarded with getattr() + a None fallback since _session_store is set via a setter and can be unset for adapters that never call set_session_store() -- preserving prior behavior for any such adapter rather than introducing a new crash. Added a regression test alongside the existing bypass coverage: with a mocked session_store configured for profile multiplexing, a clarify registered under the profile-namespaced key must still be found and resolved (not routed to the busy queue). Verified as a genuine regression by reverting the fix and confirming the new test fails with the exact reported symptom (the message handler never gets awaited -- the clarify lookup misses). 21/21 pass across the five directly related clarify test files; 16/16 across the broader multiplex/clarify-progress test files (no regression).
|
Thanks — I reviewed this against an independent named-profile Telegram reproduction, and the profile-qualified active-session lookup is the right fix for the One adjacent path remains: Telegram I will prepare a small, separately tested follow-up against current |
Fixes #82975.
Root cause
The adapter-level clarify reply bypass in
gateway/platforms/base.py'shandle_message()built itssession_keyviabuild_session_key(...)without aprofile=argument, defaulting to the legacyagent:mainnamespace. The runner registers pending clarifies underSessionStore._generate_session_key()'s key, which DOES includeprofile=self._resolve_profile_for_key(source). Under a named-profile multiplex these diverge, so the bypass lookup misses -- the user's answer to a pendingclarify()gets routed to the adapter's busy-session queue instead of resolving it, and the turn hangs until the 3600s timeout. Matches the reported Telegram symptom exactly (noinbound message:log line, no clarify-intercept log line).Verified the divergence directly by reading both key-construction sites.
_resolve_profile_for_key()returnsNonewhenmultiplex_profilesis off (default) -- byte-identical to the prior implicitprofile=None, so this only changes behavior for multiplexed deployments, matching the issue's exact reported scope.Fix
Uses the same
self._session_store._resolve_profile_for_key()the runner's key generator calls, guarded withgetattr()+ aNonefallback since_session_storeis set via a setter and can be unset for some adapters.Verification
Added a regression test alongside the existing bypass coverage. Verified as a genuine regression by reverting the fix and confirming the new test fails with the exact reported symptom.
21/21 pass across the five directly related clarify test files; 16/16 across broader multiplex/clarify-progress tests (no regression).