From 782046469524e8cf01f6bb1f859db42004dc58e8 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 20:54:44 +0530 Subject: [PATCH] fix(gateway): internal-only sessions still pin the session-context prompt The internal-event branch returned an unpinned render when no pin existed yet, so sessions that only ever see internal turns (kanban/API-server wakes, startup resumes) re-rendered the session-context prompt every turn and lost the verbatim-reuse immunity base gave them. Reuse an existing pin when present; otherwise fall through to render-and-pin as before. Applies teknium1's inline review suggestion on #122048. --- gateway/run_agent_cache.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gateway/run_agent_cache.py b/gateway/run_agent_cache.py index 8462ff251c..f18efeadf4 100644 --- a/gateway/run_agent_cache.py +++ b/gateway/run_agent_cache.py @@ -629,11 +629,11 @@ class GatewayAgentCacheMixin: source rebuilt from the persisted origin, without chat_name/user_name/message_id. Rendering from it re-keyed the pin, and the next human turn re-keyed it back (A→B→A), rewriting already-sent system bytes each time. An internal event is never a real metadata change, so - it reuses the existing pin verbatim and never re-pins.""" + it reuses an existing pin verbatim; with no pin yet it renders and pins as usual.""" _pin_state = self._peek_session_state(session_key) if session_key else None _eph_pin = _pin_state.conversation.ephemeral_pin if _pin_state else None - if internal: - return _eph_pin[1] if _eph_pin is not None else build_session_context_prompt(context, redact_pii=redact_pii) + if internal and _eph_pin is not None: + return _eph_pin[1] _eph_key = self._ephemeral_change_key(context, redact_pii) if _eph_pin is not None and _eph_pin[0] == _eph_key: return _eph_pin[1]