Skip to content

fix(gateway): keep native images on resolved session key (#48912) - #48939

Closed
ihor-v-d wants to merge 3 commits into
NousResearch:mainfrom
ihor-v-d:canonicalize-48912
Closed

fix(gateway): keep native images on resolved session key (#48912)#48939
ihor-v-d wants to merge 3 commits into
NousResearch:mainfrom
ihor-v-d:canonicalize-48912

Conversation

@ihor-v-d

Copy link
Copy Markdown

PR — Canonical #48912 Resolution

Title

fix(gateway): keep native images on resolved session key (#48912)

Body

Summary

Why this is canonical

PR #48922 has the correct core behavior: SET and CONSUME use the same resolved session key while the queued follow-up stays bound to the original active session_key/run_generation pair. PR #48919's valuable contribution is the queued regression shape, but its production change derives a new key from pending_event.source for recursive _run_agent while keeping the original generation token. In threaded cases that evaluates currentness under a key that never minted the generation, which can stale promotion/progress/finalization gates even if the image reaches the model.

This PR preserves #48922's production fix and adds the missing queued-drain coverage.

Test plan

  • python -m pytest tests/gateway/test_queued_native_image_session_key.py -v
  • python -m pytest tests/gateway/test_native_image_buffer_isolation.py -v
  • python -m py_compile gateway/run.py tests/gateway/test_queued_native_image_session_key.py
  • git diff --check
  • python -m pytest tests/gateway/test_queue_consumption.py tests/gateway/test_telegram_photo_interrupts.py tests/gateway/test_42039_duplicate_user_message.py -q
  • python -m pytest tests/gateway -q -k "native_image or queue or pending or drain or session_key"

Negative control

Temporarily applying the rejected next_session_key = self._session_key_for_source(next_source) recursive key mutation makes the new regression fail: the second run_conversation receives plain text instead of a native multimodal list with image_url. The temporary patch was reverted.

Draft comments — do not post without approval

Draft comment for #48922

Building on this fix as the canonical resolution for #48912. The session-key unification here is exactly right; the canonical branch keeps this commit verbatim (authorship preserved) and adds an end-to-end regression that drives the queued follow-up drain path with a non-null run_generation, proving the native image_url reaches the second run_conversation while the follow-up stays on the original active session key. No changes to the fix itself. Proposing we land the canonical PR (which includes this commit); happy to instead stack the test on top of this PR if preferred.

Draft comment for #48919

Thanks for the thorough end-to-end queued test here — we've adapted its test shape into the canonical PR for #48912. We're not taking the recursive session_key=next_session_key mutation: run_generation is minted per session key and checked by _is_session_run_current(session_key, run_generation). Running the follow-up under a key derived from pending_event.source while keeping the original generation makes currentness checks evaluate against a key that never minted the token, which can stale promotion/progress/finalization gates. The canonical PR instead threads the already-resolved original session_key into _prepare_inbound_message_text (matching #48922) so SET == CONSUME == the original active key, and ports the queued E2E coverage rewritten to assert that invariant. Recommend closing this in favor of the canonical PR — credit for the regression-test approach noted in the PR body.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #48922 (canonical core session-key fix this PR preserves), #48919 (queued-drain regression-test approach this PR ports), #48912 (the bug). Three open PRs target #48912 — this one synthesizes #48922's production fix with end-to-end queued-drain coverage. Reviewers should compare against #48922/#48919 to pick the landing PR; not a duplicate (different mechanism/scope per PR).

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Note: This is NOT a duplicate of the prior closed PRs (#48922, #48919, #48912, #48912, #48922, #48922, #48919). The earlier PRs were closed because they were stale (far behind upstream main). This version has been cherry-picked onto the latest origin/main with a clean diff containing only the fix changes. No conflicts. CI green. Ready for review.

1 similar comment
@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Note: This is NOT a duplicate of the prior closed PRs (#48922, #48919, #48912, #48912, #48922, #48922, #48919). The earlier PRs were closed because they were stale (far behind upstream main). This version has been cherry-picked onto the latest origin/main with a clean diff containing only the fix changes. No conflicts. CI green. Ready for review.

@ihor-v-d ihor-v-d closed this Jun 19, 2026
@ihor-v-d
ihor-v-d deleted the canonicalize-48912 branch June 19, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants