Skip to content

Studio: preserve refusal messages in imported chats - #16599

Merged
oobabooga merged 1 commit into
unslothai:mainfrom
DimitriChrysafis:studio-import-refusals
Nov 4, 2026
Merged

oobabooga merged 1 commit into
unslothai:mainfrom
DimitriChrysafis:studio-import-refusals

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

What was broken

Importing an OpenAI chat drops assistant refusal replies. The imported conversation shows two user turns in a row instead of the refusal between them.

Repro

  1. Use main at 81dc73ac43b3bb487820752a4e749f6cf2c3f05f.
  2. Import this message JSONL:
{"role":"user","content":"A question"}
{"role":"assistant","content":null,"refusal":"I cannot help with that request."}
{"role":"user","content":"Another question"}
  1. Only the two user turns appear. The same reply is also dropped when represented as a refusal content part or imported inside a training-style messages record.

Fix

Read refusal text from either representation in OpenAI's message types. Use the top-level refusal only when content produces no parts, so an existing answer is not duplicated.

This is separate from #16435, which fixes saved-connection response collection. Chat-file imports do not pass through that collector.

Test

Tests cover both JSONL layouts and refusal formats, including empty content. They also check message order, parent links, and that an existing text answer takes precedence. The two refusal tests fail before the fix; the precedence test already passes.

From studio/frontend, the final test counts are:

$ node --experimental-strip-types --test --test-reporter=tap tests/message-jsonl-import.test.ts
# tests 18
# pass 18
# fail 0

The full frontend suite reports 14,786 passing tests, zero failures, and one Windows-only skip on macOS. Locale parity, typecheck, build, bundle budget, and all seven repository lint commands also exit successfully.

@oobabooga

Copy link
Copy Markdown
Member

Reached Codex review convergence at oobabooga#457.

@oobabooga

Copy link
Copy Markdown
Member

oaiContentToParts in chat-import.ts only read text and image_url parts, so an assistant message whose only payload was a refusal (a top-level refusal with null or empty content, or a refusal content part) came out empty, and oaiMessagesToRecords dropped it, leaving two user turns in a row. Studio's own OpenAI-format export never writes refusal, so this affected chat files from other tools.

Both forms are the ones in OpenAI's OpenAPI spec: refusal is a field separate from content on ChatCompletionResponseMessage and on the assistant request message, and an assistant content array may be "exactly one of type refusal". In a real refusal content is null, so preferring text over refusal never discards anything, and the refusal is re-exported as assistant content, which the spec also accepts.

The two new tests fail with main's chat-import.ts and pass here, and all 18 tests in message-jsonl-import.test.ts pass on the PR merged with main. A refusal next to a text part or tool_calls keeps both. Mirror CI is clear at b05911500b: 45 checks passed.

@oobabooga
oobabooga merged commit 91be109 into unslothai:main Nov 4, 2026
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