Skip to content

fix(chat): import branch threads parents-before-children on refresh - #13113

Merged
mahiatlinux merged 4 commits into
unslothai:mainfrom
CelesteHeartsong:fix/chat-branch-import-order-on-refresh
Oct 9, 2026
Merged

mahiatlinux merged 4 commits into
unslothai:mainfrom
CelesteHeartsong:fix/chat-branch-import-order-on-refresh

Conversation

@CelesteHeartsong

@CelesteHeartsong CelesteHeartsong commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

@mahiatlinux mahiatlinux self-assigned this Oct 9, 2026
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.
@CelesteHeartsong
CelesteHeartsong force-pushed the fix/chat-branch-import-order-on-refresh branch from b485584 to 18a02c4 Compare October 9, 2026 02:34
@CelesteHeartsong

Copy link
Copy Markdown
Contributor Author

Rebased onto main to resolve a conflict with #13109, which touched the same load() block. The changes compose: messages now use the orderParentsFirst reorder (the actual fix, #13109 still maps in createdAt order and would throw), and headId uses #13109's savedBranchHead, which I verified always resolves to a leaf so import() won't drop descendants. Test updated to exercise resolveSavedBranchHead. 11110 pass / 0 fail.

@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 bc3c978 into unslothai:main Oct 9, 2026
@CelesteHeartsong
CelesteHeartsong deleted the fix/chat-branch-import-order-on-refresh branch October 9, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants