fix(gateway): resolve queued follow-up session key before native-image buffering

The cherry-picked #48919 fix resolved next_session_key AFTER
_prepare_inbound_message_text had already buffered native image paths
under the stale key. Reorder so the write key and the consume key are
the same resolved key.
This commit is contained in:
teknium1 2026-07-03 02:42:34 -07:00 committed by Teknium
parent bb24ac6f20
commit 741bd9ba42

View file

@ -19072,16 +19072,11 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
session_key or "?",
)
return result
next_message = await self._prepare_inbound_message_text(
event=pending_event,
source=next_source,
history=updated_history,
session_key=session_key,
)
if next_message is None:
return result
next_message_id = self._reply_anchor_for_event(pending_event)
next_channel_prompt = getattr(pending_event, "channel_prompt", None)
# Resolve the follow-up's session key BEFORE preparing the
# inbound text: _prepare_inbound_message_text buffers native
# image paths under the key it is given, and the recursive
# _run_agent below consumes them under next_session_key.
# The write and consume keys must match or the images drop.
try:
next_session_key = self._session_key_for_source(next_source)
except Exception:
@ -19090,6 +19085,16 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
session_key or "?",
exc_info=True,
)
next_message = await self._prepare_inbound_message_text(
event=pending_event,
source=next_source,
history=updated_history,
session_key=next_session_key,
)
if next_message is None:
return result
next_message_id = self._reply_anchor_for_event(pending_event)
next_channel_prompt = getattr(pending_event, "channel_prompt", None)
# Restart typing indicator so the user sees activity while
# the follow-up turn runs. The outer _process_message_background