Skip to content

Studio: keep earlier messages in chats with images - #10944

Merged
mahiatlinux merged 2 commits into
unslothai:mainfrom
NilayYadav:fix-vision-history-with-image
Sep 15, 2026
Merged

mahiatlinux merged 2 commits into
unslothai:mainfrom
NilayYadav:fix-vision-history-with-image

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

On image models that run through transformers, once a chat had a picture, every later reply only saw the newest message and the picture. Earlier questions and the model's own answers were dropped, so follow up questions got answers with no memory of the chat. On Mac, MLX already kept the full chat.

Studio now sends the whole chat, with the picture attached to the message that sent it.

Tested with Qwen2.5-VL-3B. Asked for a code word given at the start, main answered "7" and this branch answered "PELICAN-42". Asked to quote its last answer, main made one up and this branch quoted it. The model still reads the picture on later turns, and chats without pictures are unchanged. New tests fail on main, with no other new failures.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T03:26:10.789725Z fab6233 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review, GitHub Actions A/B, and real GPU UI evidence

Pinned head: fab6233c44da23f6785f5b96035fbf1ef0c46732 (merge base 03af220ac0). No blocking findings. main has not touched the three changed files since the merge base.

GitHub Actions A/B (same workflow, same deps; the only difference is inference.py and chat_template_helpers.py):

  • Fix reverted to main: expected-failing run: exactly the 4 new tests fail at their assertions, 41 pass. The rendered thread is [user(image, "LATER")] with EARLIER gone, roles collapse to ['system', 'user'], an image-only turn sends only Describe this image., and a continuation loses the replayed turns.
  • PR head: passing run: test_vision_client_tools.py 45 passed, 0 failed.

Fresh-main staging (this PR merged onto main at 8760d44, staging PR): 14 of 15 workflows passed, including Backend CI, Unsloth UI/API/GGUF on Linux, Windows and Mac, Wheel, Lint and the Kaggle T4 GPU job. Core fails only in its three Core zoo jobs, on the same unsloth_zoo tests that fail on current main (gemma4 spatial localization on HF 4.57.6, and the flashinfer opt-out guard).

Real Studio, transformers vision path (NVIDIA L4, unsloth/Qwen2-VL-2B-Instruct-bnb-4bit, Chromium). One install at the merge base; BEFORE ran on that exact tree, AFTER on the exact PR head, with separate Studio homes. Turn 1 gives the code word PELICAN-42, turn 2 attaches an image reading CAT, turn 3 asks for the code word. The frontend sent the same 5-message thread on both sides.

Before After
Turn 3 answer in the chat UI CAT PELICAN-42
Same thread over /v1/chat/completions, temperature 0 CAT PELICAN-42
Prompt tokens for that request 307 363
Control: same question in a text-only thread PELICAN-42 (100 tokens) PELICAN-42 (100 tokens)
Control: later turn asks what the image said CAT CAT

PR 10944 before/after

Conclusion: before, once a chat had an image, the model only saw the newest question and the image. After, the whole chat reaches the model and it still reads the image. The three Core zoo reds on this PR fail the same 8 tests on current main, so they are unrelated.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits the collapse at studio/backend/core/inference/inference.py where an ordinary image turn is rebuilt from only the newest user text, dropping earlier questions and answers. Will get this reviewed.

@mahiatlinux mahiatlinux self-assigned this Sep 15, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor

The image-history fix works on the tested head. Before this PR, recalling a code word from before an image turn returns CAT; after this PR it returns the correct PELICAN-42. Both revisions still read CAT from the image and DOG from a replacement image. No additional defect found within the tested scope.

Tested merge base 03af220ac0023ab846727397b3a1de9efa0aec42 against unmodified head fab6233c44da23f6785f5b96035fbf1ef0c46732, using two independent Studio installs and identical recall request payloads. No PR source changes were needed.

Verification

  • Head: 1,038 backend tests passed, plus the separately rerun tokenizer-profile test after supplying its missing public fixture: 1,039 passing checks. Base fails the four intended regressions.
  • Reverting only the inference change breaks four regression tests. Reverting only the helper change breaks image-only fallback.
  • 4,800 generated history cases per revision pass retention, image ownership, immutability, and idempotence checks, with concurrent calls and histories up to 5,000 messages also checked.
  • 31 relevant frontend tests pass on each revision. Both fresh installs complete TypeScript checking and frontend builds. Ruff and diff whitespace checks pass.
  • Real GPU/API checks cover text-only, historical/single/image-only inputs, continuation, replacement images, tools-none, concurrent requests, and recovery after closing a stream. Head continues PELICAN- with 42; base generates 1.
  • Chrome, Firefox, Edge, and Chromium each complete the live UI conversation, reload, reopen the saved chat, and read the retained image. No page errors. All four labelled screenshot pairs were visually checked.
Commands and environment

Both revisions were installed with bash install.sh --local --python <isolated-python>. Backend checks, from studio/backend:

python -m pytest tests/test_vision_client_tools.py tests/test_chat_template_continuation.py tests/test_control_markup_neutralize_7066.py tests/test_sf_client_tools_passthrough.py tests/test_mlx_vlm_prompt_cache.py tests/test_truncated_answer_continuation.py tests/test_length_truncated_reasoning_continuation.py tests/test_runtime_context_length.py tests/test_context_overflow_truncation.py -q -p no:cacheprovider --timeout=40

Frontend checks, from studio/frontend:

node --experimental-strip-types --test tests/vision-toggle-gating.test.ts tests/vision-toggle-config.test.ts tests/uncaptioned-image-empty-text-block.test.ts tests/chat-history-revision.test.ts

GPU and browser scenarios used local API/Playwright harnesses, not additions to this PR.

Linux x86_64, Python 3.13.14, RTX 5060 Ti 16 GB, NVIDIA driver 595.91.07, PyTorch 2.11.0+cu130, Transformers 5.5.0, PEFT 0.18.1, bitsandbytes 0.50.2. Unsloth Zoo pinned to 97ee45c073c237be9ec5985419729e1f82415159. Model: unsloth/Qwen2-VL-2B-Instruct-bnb-4bit, revision 7a5816478cef9812cefab3303bb998c269e46965.

Earlier CPU checks also passed the focused 87-test suite on head with Transformers 4.57.6 and 5.5.0, and on recorded merge bc7d6c16f7d8eb8200ffb70d7d764d84013bcf0f with 4.57.6. Those processor probes used stubbed generation; the fresh GPU runs above used real model generation.

Browser versions: Chrome 153.0.8010.36, Firefox 153.0, Edge 153.0.4234.32, Chromium 151.0.7922.34. Viewport 1440×1100, en-US, light theme, reduced motion. Captured UI requests use temperature 0 and max_tokens 4096; direct API probes use temperature 0 and max_tokens 64.

UI evidence

Chrome:

Chrome: base answers CAT; head recalls PELICAN-42

Firefox, Edge, and Chromium comparisons

Firefox:

Firefox before and after

Edge:

Edge before and after

Chromium:

Chromium before and after

Published screenshot files. Full local logs and original captures are retained; they are not included in the public media branch.

Limits

After 25 filler exchanges, the 2B model answers OK instead of the code word, both with and without an image. Head retains the longer prompt (676 tokens versus base's collapsed 115), but this is not a successful semantic-recall check. The same failure on the text-only control points to a model limitation, not this image-history change.

Native macOS/Safari, Windows browsers, Apple MLX execution, other accelerators/model families, exhaustive dependency combinations, training, and long-duration performance were not tested locally. Screenshot token rates are observations, not controlled benchmarks. This review does not claim universal correctness.

@mahiatlinux
mahiatlinux self-requested a review September 15, 2026 03:18

@mahiatlinux mahiatlinux 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.

LGTM! Ready to merge.

Reviewed head fab6233. The real GPU and four-browser A/B checks confirm the image-history fix; no additional defect found within the tested scope. UI evidence, verification results, and remaining limits.

@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: fab6233c44

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mahiatlinux
mahiatlinux merged commit 63a147a into unslothai:main Sep 15, 2026
44 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants