Skip to content

[Bug]: Provider/LLM switch leaves stale encrypted_content causing 400 errors on Telegram sessions #34205

Closed as not planned

Description

@kublaishive

Bug Description

When switching providers mid-session (e.g. openai-codex → xai-oauth / grok-4.3), the active Telegram session retains encrypted_content reasoning blobs from the previous provider. xAI cannot decrypt OpenAI blobs, so every subsequent request fails with HTTP 400 before the model ever sees the message.

Would be happy to test a fix.

Steps to Reproduce

1. Start a Telegram session with an OpenAI-based provider.
2. Switch the active model to an xAI provider via hermes model or config.
3. Send any message through the Telegram gateway.
4. Gateway returns 400; the session is now poisoned.

Expected Behavior

Hermes should automatically handle provider changes by either:
- Clearing or stripping provider-specific encrypted_content / reasoning blobs on provider switch, or
- Isolating sessions by provider (so a switch naturally starts fresh context for the new provider), or
- Detecting the mismatch and forcing a new session for that chat.

Actual Behavior

When anything gets written in Telegram to bot, this error appears twice in a row -

⚠️ The model provider failed after retries. I kept raw provider details out of chat; check gateway logs for diagnostics.

Session continues to carry the incompatible encrypted blobs. Manual workaround: set "suspended": true on the session key in sessions.json and restart the gateway.

- Affects gateway sessions (especially Telegram DMs).
- The issue only surfaces on future request after the provider change.
- Related files: gateway/run.py, session store (hermes_state.py), and how encrypted_content is persisted per message.

Affected Component

Other, Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Debug Report

Report       https://paste.rs/07AHe
  agent.log    https://paste.rs/VdKj4
  gateway.log  https://paste.rs/AGRvT

Operating System

Ubuntu 24.04

Python Version

Python 3.11.5

Hermes Version

Hermes Agent v0.15.0 (2026.5.28)

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    P3Low — cosmetic, nice to have
    comp/gatewayGateway runner, session dispatch, delivery
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    on May 29, 2026
  2. alt-glitch commented on May 29, 2026

    @alt-glitch

    Duplicate of #32617 — same root cause: cross-provider encrypted_content replay after model switch causes 400. Open PR #31629 (foreign-issuer stamp+drop) would fix. Workaround: suspend session and restart gateway.

  3. teknium1 commented on Jul 13, 2026

    @teknium1
    Collaborator

    This is fixed on current main. Automated hermes-sweeper review verified the duplicate report’s referenced fix was salvaged and merged.

    • 9c69204d8 stamps Responses reasoning items with their issuer and drops foreign-issuer encrypted_content before replay (agent/codex_responses_adapter.py:405). This preserves same-endpoint continuity while preventing OpenAI Codex ↔ xAI session poisoning.
    • The transport supplies the active issuer to that filter (agent/transports/codex.py:148). Regression coverage exercises the xAI-to-Codex switch in tests/run_agent/test_codex_xai_oauth_recovery.py:1033.
    • Legacy unstamped sessions are also protected: an invalid_encrypted_content response is classified, replay state is stripped, and the request retries once (agent/conversation_loop.py:2901; merged via 91d05b982d0bc08a735a2c0b1fedccd93b7fc9cd).
    • The member comment linked PR fix(codex_responses_adapter): drop foreign-issuer reasoning on replay #31629; its implementation is present on main through merged salvage PR fix(codex): drop foreign-issuer reasoning on replay #33156.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointcomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adapterprovider/xaixAI (Grok)sweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions