From 08f0f2ab18aa102d3300afd6f42df7bdea25c5ea Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sun, 27 Sep 2026 00:43:05 +0530 Subject: [PATCH] refactor(gateway): route first-contact note through first_contact_turn_note _hmwa_first_contact_notes re-implemented the branch logic of agent.onboarding.first_contact_turn_note (profile_build mode check, is_seen, mark_seen, plain-intro fallback) that the TUI already uses, so the gateway and TUI paths could drift apart. #123987 deduplicated only the note literal. Call the shared helper instead; it already falls back to PLAIN_INTRO_NOTE on error, so the local try/except goes away. The has_any_sessions() gate stays. Suggested in review of #123987 by jonpol01. --- gateway/run_turn.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/gateway/run_turn.py b/gateway/run_turn.py index 015d37cda2..b0efe8d0a6 100644 --- a/gateway/run_turn.py +++ b/gateway/run_turn.py @@ -1424,24 +1424,15 @@ class GatewayTurnMixin: if history: return if not await self.async_session_store.has_any_sessions(): - from agent.onboarding import PLAIN_INTRO_NOTE - _intro_note = PLAIN_INTRO_NOTE - # onboarding.profile_build == "ask" (default) and not yet offered: swap the plain intro for - # a consent-gated profile-build directive. Fires at most once. - try: - from agent.onboarding import ( - PROFILE_BUILD_FLAG, is_seen, mark_seen, profile_build_directive, - profile_build_mode, - ) - _onb_cfg = _load_gateway_config() - if profile_build_mode(_onb_cfg) == "ask" and not is_seen(_onb_cfg, PROFILE_BUILD_FLAG): - turn_sidecar_notes.append(profile_build_directive().strip()) - mark_seen(_hermes_home / "config.yaml", PROFILE_BUILD_FLAG) - else: - turn_sidecar_notes.append(_intro_note) - except Exception as _pb_err: - logger.debug("Profile-build onboarding directive failed, using plain intro: %s", _pb_err) - turn_sidecar_notes.append(_intro_note) + # Same branch logic as the TUI (profile-build offer once when "ask", else plain intro); + # first_contact_turn_note already falls back to the plain intro on error. + from agent.onboarding import first_contact_turn_note + note = first_contact_turn_note( + _load_gateway_config(), _hermes_home / "config.yaml", + session_history_empty=True, install_has_prior_sessions=False, + ) + if note: + turn_sidecar_notes.append(note) # One-time prompt if no home channel is set (webhooks deliver to configured targets instead). if not source.platform or source.platform in (Platform.LOCAL, Platform.WEBHOOK):