Skip to content

Studio: keep each imported tool call's own result when a chat file reuses call ids - #11596

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:studio-import-tool-result-per-call
Sep 23, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:studio-import-tool-result-per-call

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When an imported chat has more than one turn using the same tool call id, like tool_call_0, every earlier tool card shows the last result. That wrong result is also sent to the model if you continue the chat. This happens with providers that do not send their own ids.

Each result now goes to the matching call in the closest turn before it, and two calls with the same id in one turn get their results in order.

@NilayYadav

NilayYadav commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions UI evidence

Pinned review: d43cec95faf1d963755822523e6a0b3c697e0abb. No blocking code findings. Codex reviewed the same commit on a clone of this PR (NilayYadav/unsloth-staging#153) and found no major issues.

I reproduced the real Studio flow in Chromium at 1366×1000, on fresh upstream main (2036ee0b) with this PR merged. The test goes through Settings → Data → Import chats with a chat file where two turns both use tool_call_0 (get_weather for Paris, then Tokyo). Both branches run the same probe and differ only in studio/frontend/src/features/chat/utils/chat-import.ts:

  • Fix reverted, expected-failing run: the tool card results are ["Tokyo: 27°C, clear sky", "Tokyo: 27°C, clear sky"]. The Paris card shows Tokyo's result, and the probe fails on that assertion.
  • PR head, passing run: the results are ["Paris: 18°C, light rain", "Tokyo: 27°C, clear sky"]. Each card keeps its own result, and the probe passes.

PR 11596 before/after

Unit A/B: with the base chat-import.ts, the two new tests fail on this exact bug (['RESULT_B','RESULT_B'] and ['TOKYO','TOKYO']). On the head, all 66 import tests pass and npm run typecheck is clean.

CI: the 35 red upstream checks are all CANCELLED, not failures. The full CI on the same commit is running on the fork PR above.

Conclusion: I reproduced the wrong-result bug and verified the fix. I found no new blocker.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that main maps tool results by id across the whole imported chat in chat-import.ts, so reused ids like tool_call_0 give every earlier card the last result. Thanks for the tests covering both the cross-turn and same-turn cases; will get this reviewed.

@Lyxot Lyxot self-assigned this Sep 23, 2026
@Lyxot

Lyxot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Pushed 3f07007: the reuse test now starts with an interrupted turn whose tool_call_0 call got no result, so it checks that a result lands on the call in its own turn rather than the oldest unanswered one. Test-only; no production change.

@Lyxot

Lyxot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Codex review and CI on the same head 3f07007921 ran on staging PR Lyxot#74 (base = this PR's merge base):

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Each imported tool result now goes to its own turn's call when ids repeat; Codex and CI are clean on 3f07007.

@Lyxot
Lyxot merged commit dcbb66e into unslothai:main Sep 23, 2026
47 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…uses call ids (unslothai#11596)

* Studio: keep each imported tool call's own result when a chat file reuses call ids

* test(studio): cover imported tool results skipping an earlier unanswered turn

---------

Co-authored-by: Lyxot <[email protected]>
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