Skip to content

fix(gateway): match the profile-namespaced session key in the clarify bypass lookup - #82980

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
ygd58:fix/gateway-clarify-bypass-profile-namespace
Aug 15, 2026
Merged

fix(gateway): match the profile-namespaced session key in the clarify bypass lookup#82980
teknium1 merged 1 commit into
NousResearch:mainfrom
ygd58:fix/gateway-clarify-bypass-profile-namespace

Conversation

@ygd58

@ygd58 ygd58 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #82975.

Root cause

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 misses -- the user's answer to a pending clarify() 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 (no inbound message: log line, no clarify-intercept log line).

Verified the divergence directly by reading both key-construction sites. _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.

Fix

Uses 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 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).

… 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).
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter area/profiles Multi-profile isolation, HERMES_HOME scoping P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 10, 2026
@fmercurio

Copy link
Copy Markdown

Thanks — I reviewed this against an independent named-profile Telegram reproduction, and the profile-qualified active-session lookup is the right fix for the clarify bypass in #82975.

One adjacent path remains: Telegram _photo_batch_key() currently builds its burst/album key without the routed profile, so named-profile photos can still be buffered in the legacy namespace before handle_message() runs. There is also a separate ordering case where an uncaptioned image reaches the busy queue just before an open-ended clarify is registered.

I will prepare a small, separately tested follow-up against current main, linked to #82975 and explicitly excluding this PR's base-key change so it is not a competing implementation. The follow-up will use generic fixtures and exact-event identity checks to avoid consuming a later replacement message or duplicating a prompt. If you prefer a different split, please say so here; I do not have push access to this branch.

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

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

4 participants