Repository navigation
Studio: reopen a chat on the branch it was left on - #13109
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Reached Codex review convergence at oobabooga#351. |
Review-fix completeReviewed and converged through mirror PR #189. No functional correctness defect was confirmed. The required PR-scoped comment cleanup landed here as Verification:
UI result: BEFORE reopened the two-message retry branch at Mirror Codex convergence: no major issues on Local browser/platform scope was Chromium on Linux; the source PR's CI supplies the wider browser and OS matrix. |
mahiatlinux
left a comment
There was a problem hiding this comment.
LGTM! Ready to merge, all manually checked.
A branched thread lost its forks on refresh: an edited user message is written after its reply, so the reply's createdAt predates its user parent, and assistant-ui's import() throws on a child that precedes its parent. The write path already ordered rows parents-first; the read path never did, so the import aborted. Reorder the read path's rows with the shared orderParentsFirst (message-order.ts). headId comes from the saved-branch head (unslothai#13109), which always resolves to a leaf, so import won't drop the head's descendants. Adds regression tests through a real MessageRepository.import(); save-temporary-chat injects the shared helper. Full frontend suite: 11110 pass / 0 fail; typecheck clean.
…13113) * fix(chat): import branch threads parents-before-children on refresh A branched thread lost its forks on refresh: an edited user message is written after its reply, so the reply's createdAt predates its user parent, and assistant-ui's import() throws on a child that precedes its parent. The write path already ordered rows parents-first; the read path never did, so the import aborted. Reorder the read path's rows with the shared orderParentsFirst (message-order.ts). headId comes from the saved-branch head (#13109), which always resolves to a leaf, so import won't drop the head's descendants. Adds regression tests through a real MessageRepository.import(); save-temporary-chat injects the shared helper. Full frontend suite: 11110 pass / 0 fail; typecheck clean. * Trim comments in PR scope * Avoid recursive chat parent traversal * Keep fallback chat branch after reordering --------- Co-authored-by: CelesteHeartsong <[email protected]> Co-authored-by: mahiatlinux <[email protected]>
…uting merges (#13173) * Fix the two Backend CI test failures on main after the branch-restore and Omni routing merges test_new_chat_context_recount: #13109 made the history restore estimate the selected branch (estimateContextUsage(branch)) instead of every stored row. The product change is right; the harness that replays the sliced restore did not bind the loader's new `branch` local, so every history-hydration case threw "branch is not defined", and the binding guard's self-check still pinned `msgs`. Bind `branch` with the real orderBySelectedBranch and resolveSavedBranchHead from message-order.ts, the way the loader computes it without a saved head, and make the guard's self-check require only the destructured remoteId plus one plain local, not a specific input of the block. test_omni_text_only_load: #13087's _route tests call FastModel.from_pretrained, which repoints transformers' LOSS_MAPPING at Unsloth's Triton loss for the whole process before the route is captured, and never undo it. Any Omni forward with labels later in that xdist worker then ran Triton on the CPU runner ("0 active drivers"), so 0 to 4 of these tests failed depending on scheduling. Stub patch_loss_functions in _route, which routing does not need, and have the Omni tests use transformers' own causal-LM loss on a CPU host so another leaker cannot break them; on a GPU host they keep Unsloth's loss. * Restore the whole loss mapping after each Omni test, and sort the harness messages like the loader The Omni fixture now snapshots LOSS_MAPPING, installs transformers' own loss for the test body on CPU, and puts the full snapshot back afterwards, so a load inside the test (_capture_fast_base_kwargs) cannot leave the Triton loss behind for the next test in the worker. The recount harness sorts the stored messages by createdAt, role and id before taking msgs.at(-1) as the fallback head, as runtime-provider.tsx does, so an unsorted fixture cannot price a branch the loader would not select.

A Reddit user reports that after closing and reopening Studio, a chat shows only the first prompt and its reply, and that reinstalling did not help. On main this happens to any chat where an early reply was retried (or a message edited) and the original branch was then picked again in the branch picker. Reopening the chat shows the retried branch instead of the one that was left open. The later turns are still stored, and the branch picker on the first reply brings them back. A commenter asked whether the reporter had retried or edited a message, and that question is still unanswered, so it is not confirmed that this is the path the reporter hit.
Root cause
parent_id, but nothing records which branch was on screen.runtime-provider.tsximports the rows without aheadId. assistant-ui'sMessageRepository.importthen usesheadId ?? messages.at(-1), and the loader sorts rows bycreatedAt, so the head is the newest row.Fix
New
utils/branch-head.tsstores the head of the branch on screen per thread in localStorage, underunsloth_chat_branch_head:<thread id>, the same way composer drafts are stored.useBranchHeadRecorderwritesthread.messages.at(-1)whenever it changes: a sent message, a retry, an edit or a branch switch. Temporary chats are skipped until they are saved.The history loader passes the saved head as
headId.resolveSavedBranchHeadinmessage-order.tsfollows it down to its newest leaf, for two reasons:MessageRepository.resetHeaddrops every descendant of the head it is given, so a head that is not a leaf would remove those turns from the view.A saved head whose row no longer exists falls back to the newest row.
The context-usage restore, the token estimate, the recount fallback, the compare-exit restore and the fine-tune export of chats that are not on screen all use the same saved head.
Behavior that stays as on main:
count_chat_messages_for_threadswithout seeing the browser's selection.Testing
Live A/B in Studio, with main at 63988fd and this branch's first commit serving the same backend, using gemma-3-1b-it Q4_K_M. A Playwright script in Chromium sent three prompts, retried the first reply, clicked Previous to return to the original branch (1/2), and stopped there. The backend was then restarted, and the chat was opened in a new browser with the same storage.
studio.dbheld all seven rows in both arms.Neighbouring cases on the same build, each reopened afterwards:
The second commit, which moves the recorder into its own hook and clears the key only after a successful delete, was tested with unit tests only.
reopened-chat-branch.test.tscovers head resolution: the saved branch, no saved head, a deleted head, turns added under the head, a retried child, and legacy rows without parents.saved-branch-head.test.tsruns the recorder hook anddeleteChatItems. Its cases for a temporary chat saved after a branch switch and for a rejected delete each fail without the matching fix.finetune-export-branches.test.tsexports a closed chat on the branch it was left on. It fails with main'sprompt-storage-dialog.tsx.npm run typecheckpassed,eslintreports nothing new on the changed files, andnpm teston Node 24.16 passed 11080 of 11080.Not tested: