fix(gateway): isolate pending native image paths by session#18202
Merged
Conversation
Minor follow-up to the native-image-buffer isolation fix. The write site in _prepare_inbound_message_text was calling build_session_key directly, while every other call site in gateway/run.py uses the _session_key_for_source helper — which consults session_store._generate_session_key first and falls back to build_session_key. Keeping the write key and consume key on the same helper prevents key drift if the session store ever overrides the default keying behavior.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #17002 (@Yukipukii1) onto current main with a small follow-up nit.
Summary
Fixes a cross-session state leak in the gateway's native-image routing path. Between
_prepare_inbound_message_text(writes pending paths) and the consume site insiderun_conversationthere are many awaits; two sessions interleaving on the sameGatewayRunnercould overwrite or drop each other's pending native-image attachments.Changes
_pending_native_image_pathsattribute with a per-session_keydict_pending_native_image_paths_by_session._consume_pending_native_image_paths(session_key)helper — pops only the current session's buffer.session_key; the write site now uses_session_key_for_sourceto match every other session-keyed call site ingateway/run.py(follow-up commit on top of the contributor's commit — was callingbuild_session_keydirectly).tests/gateway/test_native_image_buffer_isolation.py: interleaved sessions with native images, and a native-image session not being cleared by a parallel plain-text session.Validation
Closes #17002. Contributor @Yukipukii1 credited via cherry-picked commit (rebase-merge preserves authorship).