Skip to content

Studio: keep replaced replies out of ShareGPT exports - #10941

Merged
mahiatlinux merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-sharegpt-export-siblings
Sep 15, 2026
Merged

mahiatlinux merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-sharegpt-export-siblings

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Exporting a chat as ShareGPT included replies you had regenerated and prompts you had edited, with nothing to mark them. Training on that file teaches the model the replies you rejected. The Training JSONL export already left them out.

ShareGPT export now includes only the version of the chat you see, like Training JSONL. Markdown and CSV exports still include every version.

Tested in the real Studio UI with Qwen3-0.6B. After regenerating a reply and after editing a prompt, the ShareGPT export on main held the old turns and on this branch held only the current chat. New tests cover both cases and 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-14T20:59:53.791629Z bd516c9 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea8a41ef0c

ℹ️ 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".

return (
format !== "jsonl-raw" &&
format !== "jsonl-messages" &&
format !== "sharegpt"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Export the branch selected in the live thread

When a user uses the branch picker to return to an earlier reply and then exports ShareGPT, this setting does not export the branch currently on screen. loadConversationMessages rereads storage, while orderBySelectedBranch chooses sorted.at(-1) as the head (message-order.ts:58); branch-picker navigation does not update message timestamps or persist a selected head. Consequently both single and bulk ShareGPT exports silently contain the newest-created branch instead of the displayed one, potentially training on the reply the user navigated away from. Pass the live selected branch/head into the exporter or persist branch selection rather than inferring it from creation time.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct catch, fixed in 229e08a. The branch picker only moves the head in memory, so the exporter now takes the displayed head from the open thread and walks the parent chain from there, falling back to the newest branch when the thread is not open or that head is not saved yet. Training JSONL and Message JSONL had the same gap on main and use the same path, so they are covered too. The new tests in sharegpt-export-branches.test.ts fail on ea8a41e and pass on 229e08a.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 229e08a1c3

ℹ️ 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".

Comment on lines +59 to +60
let currentId: string | null =
headId != null && byId.has(headId) ? headId : (sorted.at(-1)?.id ?? null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid exporting a fallback branch while the live head is pending

When ShareGPT is exported immediately after regenerating or editing a turn, the new branch's history append can still be pending: exports remain enabled during runs (thread.tsx:6057-6059), and listStoredChatMessages does not wait for that append (chat-history-storage.ts:718-747). In that window the live head is absent from byId, so this fallback selects the newest stored leaf—often the rejected reply—and silently puts it back into the training export. Wait for pending history writes or use the nearest persisted ancestor of the live branch instead of falling back to an unrelated leaf.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct catch, fixed in 86fc432. A regenerated reply is saved only when its run finishes, so the exporter now walks back to the newest saved turn of the branch on screen instead of falling back to the newest leaf. While an edited first prompt is still unsaved it exports nothing from the old branch. A closed thread still follows the newest branch. The two new cases in sharegpt-export-branches.test.ts fail on 229e08a and pass on 86fc432.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86fc4325f1

ℹ️ 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".

if (!hasParentIds) return raw;
return orderByParentChain(raw, { includeSiblings }) as typeof raw;
// Newest saved turn of the branch on screen: a reply still generating is not stored yet, and falling back to the newest leaf would export the reply it replaces.
const liveBranch = liveThreadBranch(threadId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture the selected branch before awaiting storage

When an export is started from a branch-picked thread and the user switches chats before listStoredChatMessages finishes, this lookup runs against the newly displayed thread and returns null for the exported ID. Since that storage read includes backend requests, the race can be long enough to hit in normal use; headId then becomes undefined, so ShareGPT and Training/Message JSONL silently fall back to the newest stored leaf and can export the rejected reply. Capture the live branch before the asynchronous storage read so the export remains tied to the branch selected when it was initiated.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct catch, fixed in bd516c9. The live branch is now read before the storage request, so switching chats while the export loads no longer points the lookup at another thread. The new case in sharegpt-export-branches.test.ts switches the chat during the read; it fails on 86fc432 and passes on bd516c9.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: bd516c952a

ℹ️ 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".

@NilayYadav

NilayYadav commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions UI evidence

Pinned head: bd516c9. Codex raised three items on the export path (two P1, one P2); all three were genuine and are fixed, and the Codex review of bd516c9 found no further issues.

  1. Branch picker ignored (229e08a, P1). The picker moves the head only in memory, so export rebuilt the chat from storage and followed the newest reply. Regenerate, go back to reply 1/2, export: the file held reply 2/2. Training JSONL and Message JSONL had the same gap on main. Export now reads the branch on screen from the open thread.
  2. Unsaved turn fell back to another branch (86fc432, P1). A regenerated reply is saved only when its run finishes, so exporting mid-run fell back to the newest saved leaf, which is the reply being replaced. Export now stops at the newest saved turn of the branch on screen, and exports nothing from the old branch while an edited first prompt is still unsaved.
  3. Chat switched during the export (bd516c9, P2). The live branch was read after the storage request, so switching chats meanwhile pointed the lookup at another thread. It is now read before the request.

Real Studio flow, same harness on every leg (fresh upstream main 8760d44, Chromium 1280x900, no model). A prompt with two sibling replies is seeded through the chat-history API, the branch picker is clicked back to 1/2, and ShareGPT JSONL and Training JSONL are downloaded from Export chat. The legs differ only in the PR's files.

leg run on screen ShareGPT gpt turns Training assistant turns result
main 34892804222 reply 1/2 regenerated, first regenerated FAIL
PR head ea8a41e 34892807620 reply 1/2 regenerated regenerated FAIL
first fix 229e08a 34892986640 reply 1/2 first first PASS
head bd516c9 34895900292 reply 1/2 first first PASS

Controls held on every leg: 3 stored rows, picker 2/2 → 1/2, first reply on screen. The same legs were also run in isolated Modal containers with identical facts.

What Export chat actually downloaded. The Studio screen is the same on every leg (reply 1/2, "Apples", is picked); this PR changes only the downloaded files:

main: ShareGPT holds both replies unmarked; Training holds the reply navigated away from

ShareGPT JSONL: {"conversations":[{"from":"human","value":"Name one fruit."},{"from":"gpt","value":"REGENERATED REPLY: Bananas. The branch picker moved away from this one."},{"from":"gpt","value":"FIRST REPLY: Apples. This is the reply picked with the branch picker."}]}
Training JSONL: {"messages":[{"role":"user","content":"Name one fruit."},{"role":"assistant","content":"REGENERATED REPLY: Bananas. The branch picker moved away from this one."}]}

PR head ea8a41e: both files hold only the reply navigated away from

ShareGPT JSONL: {"conversations":[{"from":"human","value":"Name one fruit."},{"from":"gpt","value":"REGENERATED REPLY: Bananas. The branch picker moved away from this one."}]}
Training JSONL: {"messages":[{"role":"user","content":"Name one fruit."},{"role":"assistant","content":"REGENERATED REPLY: Bananas. The branch picker moved away from this one."}]}

Fixed head bd516c9: both files hold only the reply on screen

ShareGPT JSONL: {"conversations":[{"from":"human","value":"Name one fruit."},{"from":"gpt","value":"FIRST REPLY: Apples. This is the reply picked with the branch picker."}]}
Training JSONL: {"messages":[{"role":"user","content":"Name one fruit."},{"role":"assistant","content":"FIRST REPLY: Apples. This is the reply picked with the branch picker."}]}
Screenshots (chat identical on every leg; the dark box lists the downloaded files)

PR 10941 before/after

Tests. Each new case in sharegpt-export-branches.test.ts fails on the commit before its fix and passes on bd516c9. Typecheck is clean. The full frontend suite (7,472 tests) has no new failures; the two that remain (workflow timeout budget, "the Python client agrees") fail without this PR too.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits ndjson.ts where exportFormatIncludesSiblings still returns true for sharegpt, so regenerated and edited turns end up in the exported training file. Will get this reviewed.

@mahiatlinux mahiatlinux self-assigned this Sep 15, 2026
@mahiatlinux
mahiatlinux self-requested a review September 15, 2026 04:30
@mahiatlinux

Copy link
Copy Markdown
Contributor

Before

On merge base 03af220ac, selecting reply 1/2 still exports both replies in ShareGPT and reply 2/2 in Training JSONL. Six regression cases fail for the expected branch-selection defects; the CSV control passes.

After

Head bd516c952 exports only the selected reply. The browser scenario also passes on merge b2782c590.

Real Studio runs used Ling-3.0-tiny-Q6_K through a local llama.cpp CUDA server on an RTX 5060 Ti:

ShareGPT download Base turns Head turns
Regeneration request held in flight 2 1
Regeneration complete 3 2
First reply selected again 3 2
Edited prompt and completed reply 5 2

Verdict

Confirmed issue, fixed by the existing head. No additional defects found.

Regression checks

99 focused tests plus five additional edge cases pass on head and merge. Coverage includes legacy conversations, empty live branches, inactive threads, disposed views, multi-turn branch selection, unsaved replies and switching chats during export. CSV retains every branch in real downloads; Markdown export tests pass. Base, head and merge builds pass. Head typecheck and focused ESLint pass.

Compatibility

Linux x86_64, Node 26.8.2, Python 3.14.4, Playwright 1.62.0, NVIDIA driver 595.91.07. Browser downloads verified on base and head in Chromium 151.0.7922.34, Firefox 153.0, Google Chrome 153.0.8010.36 and Microsoft Edge 153.0.4234.32, at 1280×900.

UI evidence

Captured and inspected five before/after pairs. The chat looks the same; the footer annotations show the actual downloaded contents.

Branch-picker export comparison

GPU regeneration and prompt-edit comparison

Full report, browser screenshots, downloaded files, commands and test logs.

Fixes

No repair commits needed. Reviewed head: bd516c952a4dc74f19238effc1e0c8c7c29fb61b.

@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, all manually checked.

@mahiatlinux
mahiatlinux merged commit 74e732e into unslothai:main Sep 15, 2026
38 of 42 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