Skip to content

fix(gateway): preserve local profile integrations after update - #50933

Open
vlsdpro wants to merge 1 commit into
NousResearch:mainfrom
vlsdpro:fix/preserve-profile-gateway-integrations
Open

fix(gateway): preserve local profile integrations after update#50933
vlsdpro wants to merge 1 commit into
NousResearch:mainfrom
vlsdpro:fix/preserve-profile-gateway-integrations

Conversation

@vlsdpro

@vlsdpro vlsdpro commented Jun 22, 2026

Copy link
Copy Markdown

Summary

  • Seed approximate prompt/total token counters before the provider call so the context meter still updates when a provider response omits usage metadata.
  • Restore gateway session context around auto-TTS synthesis after the agent handler returns, preserving Telegram/profile-aware voice routing in the background TTS thread.
  • Add a profile-local Telegram med: callback bridge for medical reminder scripts under $HERMES_HOME/scripts/medical-reminders/.
  • Add regression coverage for HTML MEDIA: extraction, auto-TTS session context, and usage-less provider token fallback.

Test Plan

  • python -m py_compile agent/conversation_loop.py gateway/platforms/base.py plugins/platforms/telegram/adapter.py tests/gateway/test_platform_base.py tests/gateway/test_tts_media_routing.py tests/run_agent/test_context_token_tracking.py
  • python -m pytest tests/gateway/test_tts_media_routing.py::test_auto_tts_restores_telegram_session_context_after_agent_handler tests/run_agent/test_context_token_tracking.py::test_context_counter_falls_back_to_request_estimate_when_provider_omits_usage tests/gateway/test_platform_base.py::TestExtractMedia::test_media_tag_supports_html_artifact -q -o 'addopts='
  • python -m pytest tests/gateway/test_tts_media_routing.py tests/run_agent/test_context_token_tracking.py tests/gateway/test_platform_base.py::TestExtractMedia -q -o 'addopts='
  • git diff --check origin/main..HEAD
  • static added-line secret scan: matches 0

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter tool/tts Text-to-speech and transcription P3 Low — cosmetic, nice to have labels Jun 22, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying the post-handler auto-TTS context gap; current main still calls TTS after await self._message_handler(event) in gateway/platforms/base.py:4882-4995, while tools/tts_tool.py:2200-2202 reads the session platform.

Problems

  • The new med: callback dispatches a local subprocess without a callback authorization check. Existing script-backed Gmail callbacks authorize first at plugins/platforms/telegram/adapter.py:5712-5721; the proposed med: route does not.
  • The token fallback would overwrite the post-compression -1 sentinel that current preflight explicitly preserves in agent/turn_context.py:401-405. The TUI intentionally leaves provider-less current occupancy unknown at tui_gateway/server.py:3219-3243, rather than presenting an estimate as real usage.
  • HTML MEDIA support is already present: .html/.htm are in gateway/platforms/base.py:1455-1472, and extract_media() consumes that shared extension set at gateway/platforms/base.py:3641-3658.

Suggested changes

  • Split out and rework the auto-TTS context restoration with complete routing identity and targeted tests.
  • Remove the named medical-reminder script bridge, or make it a generic authorized extension.
  • Drop the redundant HTML and token-fallback portions.

Automated hermes-sweeper review.

return

# --- Medical reminder callbacks (med:event_id:item_id) ---
if data.startswith("med:"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dispatch reaches a subprocess-backed handler without checking _is_callback_user_authorized(). The existing gt: script callback authorizes the caller before executing anything; apply the same guard before accepting med: actions.

api_messages, tools=agent.tools or None
)
try:
agent.context_compressor.last_prompt_tokens = approx_request_tokens

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not unconditionally overwrite compressor state with an estimate here. Current preflight preserves the -1 post-compression sentinel (agent/turn_context.py:401-405), and the TUI deliberately treats absent real occupancy as unknown; this assignment defeats both contracts.

@teknium1 teknium1 added 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 sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit area/install-update Installer, updater, packaging, wheels, doctor area/profiles Multi-profile isolation, HERMES_HOME scoping labels Jul 15, 2026

@GottZ GottZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Summary

Two PRs are associated with this complex, but their diffs address distinct causes rather than competing implementations: #36930 adds early local-model prompt compaction and cache diagnostics, while #50933 combines auto-TTS session-context restoration with unrelated token-accounting, HTML-media, and profile-specific Telegram callback changes.

Related pull requests

  • #36930 [closed] related — (+330/-14) — closed as superseded by #69335: the diff adds a local-endpoint/model-specific prefill guard, but misses the fully assembled pre-API path and introduces an environment override that conflicts with the config-only contract. Despite the earlier MAINTAINER-BOT keep_open verdict, the later contributor decision records that #69335 implemented the core absolute-token trigger and covered the missing pre-API path; only a per-model absolute threshold and usage.cache diagnostics remain suitable for fresh, separate follow-ups.
  • #50933 related — (+177/-2) — keep open with a narrowed salvage path: consistent with the keep_open review on #50933, the auto-TTS change restores the session platform around background synthesis and directly addresses the documented post-handler context gap. The remaining diff should not be retained in its current form: the med: callback lacks the repository's existing authorization check, the token fallback overwrites the preserved post-compression -1 sentinel, and HTML MEDIA: handling is already provided by the shared extension path.

Duplicates

#36930 and #50933 are not duplicates; they modify agent/conversation_loop.py and token-tracking tests for different purposes, while their primary reported causes and viable residual changes do not overlap.

Suggested consolidation

Keep #36930 closed as superseded by #69335, preserving its two residual ideas only as separate follow-ups. For #50933, author action: split out and rework the auto-TTS session-context restoration as the salvageable change; drop the already-implemented HTML test and token fallback, and move the profile-specific med: callback to a separate proposal with an explicit authorization check. No PR in this complex should be treated as a duplicate of the other.

Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 32 kB of PR diffs, 2 kB of issue/PR text, 3 kB of discussion (2 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

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

Labels

area/install-update Installer, updater, packaging, wheels, doctor area/profiles Multi-profile isolation, HERMES_HOME scoping comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants