Repository navigation
Name forks after the chat they came from, and close their inherited history - #11607
Conversation
…istory Forks were named "fork · Original". Name them "Original (1)", "Original (2)" and so on instead, so a fork sorts and reads next to its source. The number is chosen inside the fork transaction rather than in the route. BEGIN IMMEDIATE is already held there, so the scan for the lowest free number and the insert that takes it cannot interleave: two tabs forking the same chat at once get different numbers. Forking a fork numbers from the same base, so a fork of "Notes (1)" is "Notes (2)" rather than "Notes (1) (1)". A freed number is reused, and archived chats keep theirs so unarchiving cannot collide. Also close the copied history with a "Continued from chat" divider, so the messages above it read as the source chat's and anything below as this one's. The boundary has to be stored. It is not derivable afterwards: copied messages keep the source's timestamps and take fresh ids, so neither a timestamp comparison nor forked_from_message_id identifies the fork's own last inherited row. New column fork_boundary_message_id, following forked_from_* beside it. Forks taken before it are null and show no divider. Message rows render from a propless slot and cannot be handed the thread record, so the boundary reaches them through a small store published on load.
This comment has been minimized.
This comment has been minimized.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5931e6d73f
ℹ️ 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".
The Studio backup importer remaps forkedFromThreadId and forkedFromMessageId onto the new ids it mints, but the new forkBoundaryMessageId went through untouched, so a restored fork lost its "Continued from chat" divider even though the message it points at was restored. It points into the thread's own messages, so it remaps through the same messageIds table as the rest.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9ccbc310a
ℹ️ 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".
Clicking "Continued from chat" now opens the chat the fork came from, using the same navigation the fork action itself uses. The store carries the source thread id alongside the boundary. A source that has been deleted cannot be opened, so the divider keeps its words and drops the button rather than offering a dead link. A button rather than an anchor: this is in-app navigation, not a URL.
It rendered edge to edge: as a sibling of the message roots rather than a child, it never picked up the width constraint each of them applies to itself. Give it the same mx-auto and --thread-content-max-width.
A chat called "Budget (2026)" or "Release (2)" had its suffix read as a generated fork number, so its first fork was "Budget (1)". That drops the year, and in the "Release (2)" case the fork even sorts above its source. Strip the suffix only when the source is itself a fork, which the row already records. An ordinary chat keeps its whole name as the base, so "Budget (2026)" forks to "Budget (2026) (1)". A fork of that fork still numbers from the same base rather than nesting again.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1973ae0862
ℹ️ 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".
Two problems with taking the base from the route's earlier read. The title could be stale: another tab renaming the source between get_chat_thread and the write lock left the fork numbered under the old name. fork_chat_thread no longer takes a title at all; it reads the one on the row it already holds, so the read and the insert are atomic. And forked_from_thread_id alone does not say a "(n)" is ours, since it survives a manual rename. A fork renamed to "Report (2026)" had the year stripped. Strip only when the family the number names is really there: the chat it was forked from, or another fork of it. A renamed fork joins no family and keeps its whole name. The case left over is a fork whose source is gone and which has no siblings; its "(n)" cannot be told from the user's, so it nests.
Two ways the divider outlived the thing it points at. Deleting the inherited message it sits under left the boundary column on a pruned row, so the equality never matched again and the divider went for good even though earlier inherited messages remained. The prune now walks the stored chain, as it already does for protected messages, and moves the boundary up to the ancestor that survived, or clears it when nothing inherited is left. And the backlink was hidden on the local tombstone set, which is this tab's own: a source deleted on another device, or one whose tombstone expired, still rendered a link into nothing. Deleted roots are the likely case, since storage keeps that id for fork lineage. Existence is now settled when the link is clicked, which is the only place it can be, and a missing source says so instead of navigating.
|
@codex review |
…r after a delete The suffix rule guessed whether a "(n)" was generated by checking the title family around it, so deleting or renaming the source erased the only proof and the next fork became "Notes (1) (1)". The base is now written on the fork and cleared on rename, so nothing about the source can take it away. The prune already reseats the divider's anchor, but the delete path never reads the thread again, so the store kept naming the deleted message and the divider stayed gone until the chat was reopened.
|
@codex review |
…tial saves The anchor was the last copied message, which an imported chat can end on a system message, rendered as no row at all. The divider rides its row, so it never appeared. It now takes the last copied message that paints one, and none when nothing inherited is visible. A whole-record save that left the field out also cleared the stored anchor, since Pydantic supplies None for an absent optional. The backend owns this column and moves it itself, so an absent one keeps what is stored.
|
@codex review |
…link on the backend The prune reseated the divider to the nearest surviving ancestor, which can be a system message. Those render as no row, so the divider disappeared with visible inherited history still above it. The reseat now walks past anything that paints nothing, and clears the boundary when none is left. The backlink's existence check went through getStoredChatThread, which answers with this browser's legacy row when the backend has none. That is precisely the case a chat deleted on another device produces, so the check could never see it. It now asks the backend, and keeps "could not reach it" apart from "gone".
|
@codex review |
…d writer carries Preserving the anchor only when the field was absent still let a non-null stale one through: a client that read it before another tab's delete would write the deleted id back over the reseat. It is set on the insert that makes the fork and moved only by the prune, so on conflict the stored value now always wins. The same client carries the old base through a rename, so the title has to decide on its own. A new title clears the base whatever the record still holds.
|
@codex review |
Renaming a pair patches every thread in it after checking the pair's own title, so a thread can be sent the name it already has. Clearing there cost its next fork a number. The patch now compares the stored title against the incoming one, the same rule the upsert already uses.
|
@codex review |
The fork button is offered inside compare panes, where the source thread carries a pairId. The backlink always navigated with `thread`, which opens a single-chat view, so it showed one model's side rather than the comparison. The existence check now hands back the record it already read instead of a boolean, so the pairId is there to navigate with. Null still means gone; undefined still means the backend could not say, and falls through to the single-chat view rather than claiming a deletion.
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
…base survive a save Editing an inherited message starts a sibling branch that keeps the originals, so the fork's anchor leaves the selected branch while earlier inherited messages stay on it, and the divider vanished. Which message closes the history is a fact about the branch, not about one message, so the store now holds every inherited id and one subscriber resolves the anchor against the branch. Rows still compare against a single published id, so the delete render budget is unchanged. Switching back to the original branch restores the old anchor, which a stored id could not do. The base a whole-record writer carries could also restore one that a rename it never saw had cleared, when the titles happened to match again. It is server-managed on an existing row like the anchor beside it, so the payload no longer contributes at all.
|
@codex review |
The two are read in parallel, so a delete landing between them leaves the thread naming a row the list no longer carries. That resolved to no inherited messages at all, which cleared the divider until the chat was reopened, even though the backend had already reseated it. An anchor the list cannot place now costs one re-read, which puts the thread no earlier than the messages: a reseated anchor places, and one that still does not leaves the divider alone for the next load to settle. A failed message read no longer publishes an empty list either.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
… next one, and re-measure the startup budget (unslothai#11676) prompt-storage-dialog and refresh-context-usage were loaded with import() at five sites while the startup set already imports both statically, so nothing was deferred. Rolldown reported both as INEFFECTIVE_DYNAMIC_IMPORT and a build warning is all it ever was. Importing them statically drops 2.2 KB raw from the eager set, and the build now throws on that log instead of printing it. That is not enough on its own: main measures 5,601.9 KB raw against the 5,595.7 KB ceiling. The eager set gained one 303-byte chunk since the last raise and otherwise grew inside chunks already eager, mostly unslothai#11607 and unslothai#11648, so the budget is re-measured with the margin unslothai#11013 chose.
…ts bytes (unslothai#11678) unslothai#11607 added fork_boundary_message_id and fork_title_base to chat_threads, and like every column before them they are added with ALTER TABLE when a current build opens studio.db. The legacy upgrade simulation compared studio.db byte for byte after the owner's reads, so the first additive migration since unslothai#10588 froze the fixture failed it: "Owner read changed studio.db", on every PR whose backend rest shard ran after unslothai#11607 merged. Nothing the old build wrote changed. The probe now reads every legacy table through its legacy columns before and after, the way it already treats auth.db, and keeps the byte comparison for every other file and for the import step.
…istory (unslothai#11607) * Name forks after the chat they came from, and close their inherited history Forks were named "fork · Original". Name them "Original (1)", "Original (2)" and so on instead, so a fork sorts and reads next to its source. The number is chosen inside the fork transaction rather than in the route. BEGIN IMMEDIATE is already held there, so the scan for the lowest free number and the insert that takes it cannot interleave: two tabs forking the same chat at once get different numbers. Forking a fork numbers from the same base, so a fork of "Notes (1)" is "Notes (2)" rather than "Notes (1) (1)". A freed number is reused, and archived chats keep theirs so unarchiving cannot collide. Also close the copied history with a "Continued from chat" divider, so the messages above it read as the source chat's and anything below as this one's. The boundary has to be stored. It is not derivable afterwards: copied messages keep the source's timestamps and take fresh ids, so neither a timestamp comparison nor forked_from_message_id identifies the fork's own last inherited row. New column fork_boundary_message_id, following forked_from_* beside it. Forks taken before it are null and show no divider. Message rows render from a propless slot and cannot be handed the thread record, so the boundary reaches them through a small store published on load. * Carry the fork boundary through a backup restore The Studio backup importer remaps forkedFromThreadId and forkedFromMessageId onto the new ids it mints, but the new forkBoundaryMessageId went through untouched, so a restored fork lost its "Continued from chat" divider even though the message it points at was restored. It points into the thread's own messages, so it remaps through the same messageIds table as the rest. * Link the continuation divider back to the source chat Clicking "Continued from chat" now opens the chat the fork came from, using the same navigation the fork action itself uses. The store carries the source thread id alongside the boundary. A source that has been deleted cannot be opened, so the divider keeps its words and drops the button rather than offering a dead link. A button rather than an anchor: this is in-app navigation, not a URL. * Keep the continuation divider inside the chat column It rendered edge to edge: as a sibling of the message roots rather than a child, it never picked up the width constraint each of them applies to itself. Give it the same mx-auto and --thread-content-max-width. * Only strip a fork number the fork itself put there A chat called "Budget (2026)" or "Release (2)" had its suffix read as a generated fork number, so its first fork was "Budget (1)". That drops the year, and in the "Release (2)" case the fork even sorts above its source. Strip the suffix only when the source is itself a fork, which the row already records. An ordinary chat keeps its whole name as the base, so "Budget (2026)" forks to "Budget (2026) (1)". A fork of that fork still numbers from the same base rather than nesting again. * Name a fork from the row the transaction read Two problems with taking the base from the route's earlier read. The title could be stale: another tab renaming the source between get_chat_thread and the write lock left the fork numbered under the old name. fork_chat_thread no longer takes a title at all; it reads the one on the row it already holds, so the read and the insert are atomic. And forked_from_thread_id alone does not say a "(n)" is ours, since it survives a manual rename. A fork renamed to "Report (2026)" had the year stripped. Strip only when the family the number names is really there: the chat it was forked from, or another fork of it. A renamed fork joins no family and keeps its whole name. The case left over is a fork whose source is gone and which has no siblings; its "(n)" cannot be told from the user's, so it nests. * Keep the divider and its link honest after a delete Two ways the divider outlived the thing it points at. Deleting the inherited message it sits under left the boundary column on a pruned row, so the equality never matched again and the divider went for good even though earlier inherited messages remained. The prune now walks the stored chain, as it already does for protected messages, and moves the boundary up to the ancestor that survived, or clears it when nothing inherited is left. And the backlink was hidden on the local tombstone set, which is this tab's own: a source deleted on another device, or one whose tombstone expired, still rendered a link into nothing. Deleted roots are the likely case, since storage keeps that id for fork lineage. Existence is now settled when the link is clicked, which is the only place it can be, and a missing source says so instead of navigating. * Give a fork's generated name a durable base, and republish the divider after a delete The suffix rule guessed whether a "(n)" was generated by checking the title family around it, so deleting or renaming the source erased the only proof and the next fork became "Notes (1) (1)". The base is now written on the fork and cleared on rename, so nothing about the source can take it away. The prune already reseats the divider's anchor, but the delete path never reads the thread again, so the store kept naming the deleted message and the divider stayed gone until the chat was reopened. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Anchor the fork divider to a row that mounts, and keep it through partial saves The anchor was the last copied message, which an imported chat can end on a system message, rendered as no row at all. The divider rides its row, so it never appeared. It now takes the last copied message that paints one, and none when nothing inherited is visible. A whole-record save that left the field out also cleared the stored anchor, since Pydantic supplies None for an absent optional. The backend owns this column and moves it itself, so an absent one keeps what is stored. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep the divider on a visible row when reseating, and settle the backlink on the backend The prune reseated the divider to the nearest surviving ancestor, which can be a system message. Those render as no row, so the divider disappeared with visible inherited history still above it. The reseat now walks past anything that paints nothing, and clears the boundary when none is left. The backlink's existence check went through getStoredChatThread, which answers with this browser's legacy row when the backend has none. That is precisely the case a chat deleted on another device produces, so the check could never see it. It now asks the backend, and keeps "could not reach it" apart from "gone". * Let the stored anchor and a new title win over whatever a whole-record writer carries Preserving the anchor only when the field was absent still let a non-null stale one through: a client that read it before another tab's delete would write the deleted id back over the reseat. It is set on the insert that makes the fork and moved only by the prune, so on conflict the stored value now always wins. The same client carries the old base through a rename, so the title has to decide on its own. A new title clears the base whatever the record still holds. * Clear the fork base only when the title actually changes Renaming a pair patches every thread in it after checking the pair's own title, so a thread can be sent the name it already has. Clearing there cost its next fork a number. The patch now compares the stored title against the incoming one, the same rule the upsert already uses. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Reopen a paired source as the comparison it was forked from The fork button is offered inside compare panes, where the source thread carries a pairId. The backlink always navigated with `thread`, which opens a single-chat view, so it showed one model's side rather than the comparison. The existence check now hands back the record it already read instead of a boolean, so the pairId is there to navigate with. Null still means gone; undefined still means the backend could not say, and falls through to the single-chat view rather than claiming a deletion. * Follow the branch on screen for the divider, and let only the stored base survive a save Editing an inherited message starts a sibling branch that keeps the originals, so the fork's anchor leaves the selected branch while earlier inherited messages stay on it, and the divider vanished. Which message closes the history is a fact about the branch, not about one message, so the store now holds every inherited id and one subscriber resolves the anchor against the branch. Rows still compare against a single published id, so the delete render budget is unchanged. Switching back to the original branch restores the old anchor, which a stored id could not do. The base a whole-record writer carries could also restore one that a rename it never saw had cleared, when the titles happened to match again. It is server-managed on an existing row like the anchor beside it, so the payload no longer contributes at all. * Do not blank the divider when the thread and the message list disagree The two are read in parallel, so a delete landing between them leaves the thread naming a row the list no longer carries. That resolved to no inherited messages at all, which cleared the divider until the chat was reopened, even though the backend had already reseated it. An anchor the list cannot place now costs one re-read, which puts the thread no earlier than the messages: a reseated anchor places, and one that still does not leaves the divider alone for the next load to settle. A failed message read no longer publishes an empty list either. --------- Co-authored-by: Unsloth <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
… next one, and re-measure the startup budget (unslothai#11676) prompt-storage-dialog and refresh-context-usage were loaded with import() at five sites while the startup set already imports both statically, so nothing was deferred. Rolldown reported both as INEFFECTIVE_DYNAMIC_IMPORT and a build warning is all it ever was. Importing them statically drops 2.2 KB raw from the eager set, and the build now throws on that log instead of printing it. That is not enough on its own: main measures 5,601.9 KB raw against the 5,595.7 KB ceiling. The eager set gained one 303-byte chunk since the last raise and otherwise grew inside chunks already eager, mostly unslothai#11607 and unslothai#11648, so the budget is re-measured with the margin unslothai#11013 chose.
…ts bytes (unslothai#11678) unslothai#11607 added fork_boundary_message_id and fork_title_base to chat_threads, and like every column before them they are added with ALTER TABLE when a current build opens studio.db. The legacy upgrade simulation compared studio.db byte for byte after the owner's reads, so the first additive migration since unslothai#10588 froze the fixture failed it: "Owner read changed studio.db", on every PR whose backend rest shard ran after unslothai#11607 merged. Nothing the old build wrote changed. The probe now reads every legacy table through its legacy columns before and after, the way it already treats auth.db, and keeps the byte comparison for every other file and for the import step.
Follows #11564, which added forking from the row menu.
Naming
Forks were named
fork · Original. They are nowOriginal (1),Original (2)and so on, so a fork sorts and reads next to its source instead of collecting under "f".The number is chosen inside the fork transaction, not in the route.
BEGIN IMMEDIATEis already held there, so the scan for the lowest free number and the insert that takes it cannot interleave. Two tabs forking the same chat at once get different numbers.Three details worth knowing:
Notes (1)isNotes (2), notNotes (1) (1).Notes (2)and the next fork reuses it.Notes extra (1), does not consume a number.Continued from chat
The copied history now ends with a divider, so the messages above it read as the source chat's and anything below as this one's.
The boundary has to be stored. It is not derivable after the fact: copied messages keep the source's timestamps and take fresh ids, so neither a timestamp comparison nor
forked_from_message_ididentifies the fork's own last inherited row. This addsfork_boundary_message_id, following theforked_from_*columns beside it. Forks taken before the column exists are null and show no divider.Message rows render from a propless slot and cannot be handed the thread record, so the boundary reaches them through a small store published when the thread loads.
The divider sits at the same muted colour and size as the "Worked for" header, so it reads as structure rather than as content.
Testing
Backend, 129 passing, including a route-level test against real storage rather than a monkeypatched
fork_chat_thread:(1),(2),(3)Frontend, 8484 passing, typecheck clean. New
tests/fork-boundary.test.tscovers the store and the wiring inthread.tsx.Three existing tests changed, each keeping its guarantee:
thread-delete-render-budget.test.tsassertedcase "edit": return <EditComposer />. The switch now assigns tobodyso the divider can follow it, and the test gained an assertion that the body renders before the rule.chat-history-storage, so the new import needed a stub entry in each.I also corrected fixture titles in the route tests that still read
"fork · Original". Those pass either way because they monkeypatchfork_chat_thread, but they would have misled the next reader.Note
The divider was verified by measuring the rendered markup against the app's live CSS. Driving a real fork through the UI needs a signed-in Studio, so the end-to-end coverage is the route-level test rather than a click-through.