You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Studio: preserve refusal messages in imported chats - #16599
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
Use main at 81dc73ac43b3bb487820752a4e749f6cf2c3f05f.
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"}
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
81dc73ac43b3bb487820752a4e749f6cf2c3f05f.{"role":"user","content":"A question"} {"role":"assistant","content":null,"refusal":"I cannot help with that request."} {"role":"user","content":"Another question"}refusalcontent part or imported inside a training-stylemessagesrecord.Fix
Read refusal text from either representation in OpenAI's message types. Use the top-level
refusalonly 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: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.