Skip to content

Preserve images across conversation turns - #1313

Open
bmehta001 wants to merge 1 commit into
mainfrom
fix/multiturn-image-context
Open

bmehta001 wants to merge 1 commit into
mainfrom
fix/multiturn-image-context

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Summary

  • Retain ordered image and audio snapshots in the chat transcript and rebuild multimodal prompts from the complete conversation.
  • Restore media during cold Responses replay, privately snapshotting local image files without changing public input_items.
  • Preserve the existing restriction on combining media with declared tools or historical tool activity.

Validation

  • Windows and Linux/WSL: 304 focused native tests plus 9 text-session regression tests on each platform; no skips.
  • Windows and Linux/WSL: five real Qwen3.5-9B CPU vision scenarios each, across separate runs, covering image order, warm/cold replay, cancellation/undo, streaming and deleted local files; no skips.
  • Linux: 304 focused tests and a real-model cancellation/undo scenario under ASan/UBSan with leak detection and no LSan suppressions; no skips. The packaged ONNX Runtime dependencies are prebuilt rather than sanitizer-instrumented.
  • lintrunner -r HEAD and git diff --check.
  • The full repository test suite was not run.

Limitations

  • Retained media has no size limit, so memory use grows with conversation history.
  • Multi-image behavior depends on the model and its chat template; Qwen3.5-9B was exercised here.

Existing sanitizer note

The comments for the OgaCreateStringArrayFromStrings and OrtxTensorResultGetAt entries in lsan.supp appear stale for the exercised ONNX Runtime GenAI 0.19.0/Qwen path: the wrapper owns the string array and the Qwen processor owns the returned tensors. The real-model sanitizer check above ran without these or any other LSan suppressions. The existing suppression file is unchanged.

Retain ordered image and audio snapshots so warm sessions and rebuilt response chains preserve multimodal context on later turns.

Files:
- sdk_v2/cpp/src/inferencing/generative/chat/
- sdk_v2/cpp/src/inferencing/generative/openresponses/
- sdk_v2/cpp/src/inferencing/session/request.{cc,h}
- sdk_v2/cpp/src/service/responses_handler.cc
- sdk_v2/cpp/test/internal_api/ and sdk_v2/cpp/test/sdk_api/
- sdk_v2/INFERENCING.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ff6cebe1-eff5-44bd-a00b-71c047fed86c
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
foundry-local Ready Ready Preview Nov 10, 2026 5:55am UTC

Request Review

Copilot AI balanced review requested due to automatic review settings November 10, 2026 05:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the multi-turn image history and replay changes.

No open issues 🎉

What changed in this PR

This PR enables multi-turn image conversations in the native SDK by retaining media in chat history and restoring it during Responses replay, including after local image files are deleted.

Changes:

  • Preserve ordered image and audio snapshots and rebuild multimodal prompts from the complete conversation.
  • Store private local-image snapshots for cold replay without changing public input_items, while retaining media/tool restrictions.
  • Add coverage for image ordering, warm/cold replay, cancellation, undo, streaming, and deleted files; document updated limitations.
File Description
sdk_v2/​INFERENCING.md Documents multi-turn images and remaining limitations.
sdk_v2/​cpp/​test/​sdk_api/​responses_vision_test.cc Tests multi-turn vision, replay, streaming, cancellation, and undo.
sdk_v2/​cpp/​test/​internal_api/​web_service_test.cc Updates expected media-policy errors.
sdk_v2/​cpp/​test/​internal_api/​response_lifecycle_test.cc Tests private snapshots through response-store lifecycle changes.
sdk_v2/​cpp/​test/​internal_api/​chat/​onnx_chat_generator_vision_test.cc Tests historical image markers, names, reasoning, and role validation.
sdk_v2/​cpp/​test/​internal_api/​chat/​media_input_test.cc Tests media continuation policy and ordered replay snapshots.
sdk_v2/​cpp/​test/​internal_api/​chat/​chat_transcript_test.cc Tests ordered media retention and snapshot ownership.
sdk_v2/​cpp/​src/​service/​responses_handler.cc Publishes private replay snapshots for both response modes.
sdk_v2/​cpp/​src/​inferencing/​session/​request.h Clarifies local-file snapshot semantics.
sdk_v2/​cpp/​src/​inferencing/​session/​request.cc Recursively snapshots message parts and resolves image bytes.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_store.h Adds private replay data to stored responses.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_store.cc Preserves private snapshots in storage and replay hops.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_converter.h Declares the private image-snapshot helper.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_converter.cc Restores typed media and snapshots local images for replay.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_chain.h Adds a private input override to replay hops.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​prepared_chat_prompt.cc Passes reasoning-history support into media rendering.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​onnx_chat_generator.h Updates the multimodal transformation interface.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​onnx_chat_generator.cc Renders historical media while preserving names and optional reasoning.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​media_input.h Declares transcript media collection and revised validation helpers.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​media_input.cc Collects retained media and rejects incompatible tool activity.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_transcript.h Defines ordered media entries with shared snapshot ownership.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_transcript.cc Retains media during ingestion and recognizes media-bearing input.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_session.h Documents media retention during undo.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_session.cc Builds full-history media prompts and invalidates incompatible cached generators.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
Preview — 188c3e9a Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants