Skip to content

The agent that grows with you

refactor(gateway): carry the /retry callback through carry_callback

Tekniumbccbf5e755c6
diff --git a/gateway/session_ingress_context.py b/gateway/session_ingress_context.py
index 66b034f38b9..aef3ebf7842 100644
--- a/gateway/session_ingress_context.py
+++ b/gateway/session_ingress_context.py
@@ -69,30 +69,15 @@ def native_callback(runner, event, transport_home, profile=None):
def carry_callback(event, rewritten):
- """A gateway-side rewrite of a callback's event (``pre_gateway_dispatch``) keeps the callback's
- provenance: it changes the text only, never the source the callback authenticated (#139045)."""
+ """Gateway code that rebuilds a callback's event (a ``pre_gateway_dispatch`` rewrite, the
+ ``/retry`` re-send) keeps the callback's provenance, but only on the source object the callback
+ authenticated: a new event with a swapped source carries nothing (#139045, #139040)."""
for bound_var in (_callback, _relay_callback):
bound = bound_var.get()
if bound is not None and bound[1] is event and rewritten.source is event.source:
bound_var.set((bound[0], rewritten, *bound[2:]))
-@contextmanager
-def redispatched_native(runner, event):
- """Re-enter the ambient native callback for an event a handler re-sends itself.
-
- A slash handler's re-dispatched turn (``/retry``) is not a new inbound event: admission
- matches provenance by event identity, so a freshly built event carries none and native
- admission refuses it as ``invalid_params`` under session authority.
- """
- context = _callback.get()
- if context is None or context[0] is not runner:
- yield
- return
- with native_callback(runner, event, context[2], context[3]):
- yield
-
-
def _binding(runner, source, profile):
registries = [(None, runner.adapters), *getattr(runner, '_profile_adapters', {}).items()]
from gateway.config import Platform
diff --git a/gateway/slash_commands_session.py b/gateway/slash_commands_session.py
index 06d50f414a8..6156bd33d13 100644
--- a/gateway/slash_commands_session.py
+++ b/gateway/slash_commands_session.py
@@ -429,15 +429,14 @@ class GatewaySessionCommandsMixin:
return t("gateway.retry.failed_unchanged")
session_entry.last_prompt_tokens = 0 # transcript was truncated
self._record_model_friction("retry", source, session_entry.session_id)
- # The re-sent turn is the SAME inbound event's turn, not a new one: re-enter its native
- # callback so admission resolves the same provenance (session authority refuses a fresh
- # event under multiplex_profiles / a stamped transport home).
- from gateway.session_ingress_context import redispatched_native
+ # The re-sent turn is the /retry event's own turn, built on its authenticated source: carry
+ # that event's native callback to it, or admission refuses it under multiplex (#139040).
+ from gateway.session_ingress_context import carry_callback
turn = MessageEvent(
text=last_user_msg, message_type=MessageType.TEXT, source=source,
raw_message=event.raw_message, channel_prompt=event.channel_prompt)
- with redispatched_native(self, turn):
- return await self._handle_message(turn)
+ carry_callback(event, turn)
+ return await self._handle_message(turn)
def _record_model_friction(self, signal: str, source, session_id: str, turns: int = 1) -> None:
"""Slash dispatch does not install the routed profile's scope, so a multiplexed runner