Skip to content

Studio: fork a chat from its row menu - #11564

Merged
mahiatlinux merged 19 commits into
mainfrom
studio-fork-chat-from-row
Sep 22, 2026
Merged

mahiatlinux merged 19 commits into
mainfrom
studio-fork-chat-from-row

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

What this changes

Forking was reachable only from a message inside the open thread, so copying a chat meant opening it first and finding the message to fork from. A chat row's menu now carries Fork.

The menu was one run of items with a single rule before Archive. It now reads as three groups:

  • Rename, Pin, Mark as unread, Fork: what acts on the row itself.
  • Open chat folder, Project, Export: what reaches outside it.
  • Archive, Delete.

The fork itself

forkChatRow sits in components/chat-row-menu.ts, beside the rest of what a chat row's menu is made of, so the Projects page rows can take the same item later.

It forks from the chat's last message and settles the chat's thread-scoped settings first. The fork copies settings_json inside its own transaction, so a pill toggled moments ago and still inside the debounce would not be in the copy, and the fork would open on the modes the chat had before rather than the ones it has now. This is the same guard the thread's own Fork uses.

The copy opens straight away, the same as forking from a message, and the container snapshot warning is carried into the toast when there is one.

Fork is disabled on a comparison row. A comparison is two threads and has no single tip to fork from.

Tests

npm run test passes 8466. sidebar-row-actions.test.ts gains coverage for the placement under Mark as unread, the rule that follows it, the comparison guard, the settings settle before the copy, and opening the fork once it is made. Lint is unchanged from the baseline on every file touched.

Forking was reachable only from a message inside the open thread. Add
Fork to the chat row menu, under Mark as unread, and group the menu so
what acts on the row is set off from what reaches outside it.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-22T18:09:27.901972Z 1b20ded 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: 3c57cab52d

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

Fork stayed enabled on a streaming row, where the last stored message is
the prompt or a half-written reply, so the copy ended mid-answer. It now
takes the row's isGenerating, the way the message-level Fork takes
thread.isRunning.

Reopening the menu and picking Fork again before the first request landed
posted a second, each with its own thread id. The in-flight store moves
out of thread.tsx so the row menu and the thread share one flag.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Both findings were right, and both are fixed in 39fc80d.

Fork on a generating row. The item checked only whether the row was a comparison, so Fork stayed live while a reply was streaming. forkChatRow takes the last message that is actually stored, which mid-stream is the user prompt or a half-written answer, and the copy would end there. It now takes the row's own isGenerating, which was already computed a few lines up, the same way the message-level Fork takes thread.isRunning.

Duplicate forks. There was no in-flight guard, so reopening the menu and picking Fork again before the first request landed posted a second, each with its own thread id, and the two navigations raced. Rather than give the row menu a second flag of its own, useForkInFlight moves out of thread.tsx into features/chat/utils/fork-in-flight.ts and both surfaces read the one store. Two flags would not have helped here: the chord, the message button and the row menu are three callers of the same action, and only a shared flag covers a fork started on one surface and then on another. The read is synchronous through getState(), and the flag also disables the menu item while a fork is in flight.

Running the full suite caught a third thing worth mentioning: keyboard-shortcuts.test.ts asserted the store was declared inside thread.tsx. Its point was that the flag must not be any one caller's own state, which moving it to a shared module keeps, so the assertion now points at the new home and additionally checks the declaration is gone from thread.tsx.

npm run test passes 8467, typecheck is clean, and lint is unchanged from the baseline on every file touched, thread.tsx included.

@codex review

pre-commit-ci Bot and others added 2 commits September 22, 2026 17:28
…11561)

* Studio: drag sidebar rows in the desktop app, and drop the drag hint

Sidebar rows were wired to the HTML5 drag API, which the desktop
webview never forwards to the page, so no row could be dragged there.
Rebuild the gesture on pointer events, and take out the label that
followed the cursor.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep the edge scroll going, and let one pointer own the drag

Edge scrolling ran off pointermove alone, so a pointer resting on the
edge took one step and stalled, and the cue stayed on the row that had
slid away. A frame loop drives it now and re-aims as the list moves.

The window handlers also answered every pointer, so a finger could drive
and drop a drag the mouse started, which is what touch is kept out of.
Each one now answers only the pointer that pressed the row.

---------

Co-authored-by: Unsloth <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

@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: 39fc80d4db

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

danielhanchen and others added 2 commits September 22, 2026 10:32
…no git (#11565)

Qwen-Image-2.1 refuses to load with "needs diffusers >= 0.41.0 ... this
environment has diffusers 0.40.0" on installs that did nothing wrong.

The pinned main build is a git+https requirement, and install_python_stack
skips that step non-fatally when _has_working_git() is false. The desktop
bundle ships no git, and on macOS `git` is frequently a bare xcrun shim that
exits non-zero, so the skip fires for a large share of desktop installs and
the only visible sign is one note during a long dependency pass.

Reproduced end to end with the shipped bundles, git shimmed to exit 1:
installing 0.1.811 leaves diffusers 0.40.0, and updating to 0.1.812 leaves it
at 0.40.0 as well, so reinstalling the app does not repair it. With a working
git both land on 0.41.0.dev0 at the pinned commit.

Nothing in that step actually needs git: the same commit is a zip over plain
https. _github_archive_url derives it from the requirement, so there is still
one commit written down in one place, and the git clone stays the default
because it records a ref. The derivation is deliberately narrow (github.com,
full 40 character commit, no subdirectory) because an archive records no ref
of its own, so only a SHA in the URL identifies the tree afterwards.

_direct_reference_is_installed has to read that back or the fallback works
exactly once. Measured: the archive install reads as absent to a vcs_info-only
check, _diffusers_main_supersedes_release then says the release pin was not
superseded, and the next pass reinstalls 0.40.0 straight over it.

The refusal message also pointed at `pip install -r diffusers-main.txt`, which
resolves the same git URL and fails identically for the most likely cause. It
now names git as the thing to check and quotes the zip, read out of the pin
file so it cannot drift from the commit that is installed.

Verified on a real git-less install: the dependency pass logs "diffusers main
(no git, from archive)", diffusers ends at 0.41.0.dev0 with direct_url.json
recording the pinned commit's archive, _diffusers_main_resident() is True
against it, and a second forced pass leaves it in place.
The disabled state reads runningByThreadId, which is this tab's memory:
empty after a reload and blind to a second tab. A chat generating in
either case passed it and forked to the prompt, or to a reply still
being written.

The click now checks the backend snapshot chat-api calls authoritative,
and an unreachable backend falls back to the local map rather than
blocking every fork. A chat that is still generating is reported as a
refusal, not a failure.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Right again, and fixed in e853e2a. I checked the claim before acting and chat-api.ts says it outright on getActiveGenerations:

Authoritative where runningByThreadId is not: that map is per-tab, empty after a reload and blind to a second tab, and /load 409s on these.

So the previous fix only closed the same-tab case. A chat generating in a second tab, or one whose tab was reloaded mid-generation, still reached forkChatRow and forked to the prompt or to a reply still being written.

The click now reads the backend snapshot and refuses if the thread is in thread_ids. It follows the pattern confirm-stop-running-chats.ts already uses for the same map: wrapped in a try, so an unreachable backend or an older build falls back to the local map rather than blocking every fork. The check runs before the settings settle and before the message read, so nothing is set up for a copy that will not happen.

It stays at the click rather than in the disabled state on purpose. Disabling off backend state would mean polling every row, and only the click can afford a round trip.

One thing I added beyond the finding: a chat that is still generating is a refusal, not a failure, so it no longer surfaces as "Failed to fork". The error carries unslothForkRefused, the same way loadModel tags a user cancellation, and the caller shows it as an info toast.

npm run test passes 8468, typecheck and build are clean, lint unchanged from baseline.

@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: e853e2aa0e

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

oobabooga and others added 4 commits September 22, 2026 10:40
A client snapshot cannot close this: another tab can start a generation
between the check and the POST, and the route forked regardless. It now
refuses with a 409, which is the only guard inside the request that
forks.

The client check moves after the message read so it covers the read that
chose the tip, and a 409 is reported as a refusal rather than a failure.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Right, and I was wrong to try to close this from the client. Fixed in 145fda0.

The route now refuses with a 409 when the thread it is asked to fork has a generation in flight, read from state/active_generations. That module's own docstring makes the case better than I can:

A frontend guard alone would miss a second tab or a REST call.

Two things came out of implementing it.

The client check stays, but it moved to after the message read rather than before it. The fork is anchored to whichever message id the read picked, so what matters is whether the tip was settled at that moment, not at the moment of the POST. Asked before the read, a prompt appended in between was invisible to it. Asked after, it covers the read that chose the tip.

A 409 from the route is now reported as a refusal rather than a failure, matching the client-side refusal path.

I also checked the case that would have made a blanket route refusal wrong, forking at an earlier message while a later turn streams, and it does not apply: the message-level Fork already disables itself on thread.isRunning, so refusing a generating thread matches what the UI has always allowed.

Backend: two tests in test_chat_history_routes.py, one for the 409 and one checking a different chat generating is not a reason to refuse this one. test_chat_history_routes.py, test_active_generations.py and test_chat_history_storage.py pass, 193 total. Frontend: npm run test passes 8468, typecheck and build clean.

@codex review

* Keep weight_decay when embedding_learning_rate is set

Setting embedding_learning_rate routes optimizer creation through
_create_unsloth_optimizer, which read the decay from optimizer_kwargs.
transformers keeps the decay on the param groups and only puts it in
optimizer_kwargs for schedule-free and stable_adamw, so the .get(..., 0.0)
default always won: the run trained with no weight decay at all, silently, with
the value the user set still on the config. _create_q_galore_optimizer in the
same file already reads self.args.weight_decay.

Read it from the config, and split the groups on
Trainer.get_decay_parameter_names so restoring the decay does not start
decaying biases and norm weights, which the path this replaces excludes.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Drop the empty param groups the four-way split creates

The decay fix is right, but splitting non_embeddings and embeddings each into
a decay and a no-decay group emits four groups where there used to be two, and
on a LoRA run two of them are always empty: nothing trains a bias or a norm, so
both no-decay groups come back with no params.

An empty group is not free. AdafactorSchedule.get_lr reads group["params"][0]
with no emptiness guard, so optim="adafactor" now raises IndexError. And
torch's load_state_dict rejects a checkpoint whose group count differs from the
optimizer's, so every run checkpointed before this stopped being resumable,
even at weight_decay=0.

Dropping the empty groups fixes both and costs nothing: the categories are
logical, they do not have to each be a group. _create_q_galore_optimizer in
this same file already guards its groups the same way. A LoRA run is back to
the two groups it always had, in the same order and the same sizes, so old
checkpoints load again.

test_create_optimizer_model_arg asserted on param_groups[1] being empty, which
was only ever incidental; it now asserts what it meant.

* Tighten the comments on the decay fix

Twelve comment lines to five. The two facts that are not visible from the
code stay: transformers only puts weight_decay in optimizer_kwargs for
schedule-free and stable_adamw, and an empty group breaks both
AdafactorSchedule and resume.

* Migrate a pre-split optimizer checkpoint instead of refusing it

Splitting the decay out gives a model with trainable biases or norms more
param groups than the two it was checkpointed with, and torch requires the
counts and per-group sizes to match, so resume_from_checkpoint raised
instead of continuing. Fixing only the optimizer moves the failure one line
later into the scheduler, which overwrites base_lrs wholesale, so both are
handled.

The remap is exact rather than inferred: torch keys saved state by a
parameter's position in the flat concatenation of its groups, and the old
layout (non-embeddings then embeddings, each in named_parameters order) is
reproducible from the model, so old position maps to parameter maps to new
position one to one. Anything that is not exactly that old shape is refused
and torch raises as before, because pairing a parameter with another
parameter's moments would corrupt a run in silence where today it stops.

A resumed run now also gets the decay it was configured with rather than the
0.0 the old checkpoint recorded.

The two resume tests fail without this and pass with it; the third asserts
the refusal and is a guard against a future over-eager migration rather than
a regression test for this commit.

* Key the migration on the group shape, and remap the plateau floors

Two gaps in the previous commit, both reproduced.

The migration was gated on the group COUNT differing, which misses the case
where it does not. A model with no trainable embedding has a legacy layout of
[all non-embeddings, empty embeddings] and a new one of [decayed,
non-decayed]: two groups either way, different sizes, and torch rejects it on
the size check instead. Gated on the shape now, so the count coinciding no
longer hides it.

reduce_lr_on_plateau also carries a per-group min_lrs. Expanding base_lrs and
_last_lr but not that one let a two-element list replace a correctly sized
one, and the next reduction raised once it walked the optimizer's groups.

Both new tests fail without these and pass with them.

* Offer every legacy checkpoint to the migration, and remap the scheduler by role

Two more gaps, both silent rather than loud, both reproduced.

A LoRA resume needs no reshaping because the old and new layouts coincide, so
the migration was skipped and torch loaded the group hyperparameters from the
checkpoint, including the weight_decay=0.0 this change exists to correct. The
decay was silently off again for the most common shape there is. Every
recognisably legacy checkpoint is offered to the migration now, not only the
ones whose shape moved.

The scheduler remap keyed on list length, and two entries can mean two things:
with no trainable embedding both current groups are non-embeddings, so a saved
[ordinary, embedding] pair is the same length yet handed the second group the
embedding rate. Remapped by role instead, which is the identity whenever the
roles already line up.

Both new tests fail without these and pass with them.

* Hook the scheduler on a subclass, not on the instance

My own regression, and a worse one than the bug it sat next to. A scheduler's
state_dict is its __dict__ minus the optimizer, so assigning the wrapper to
the instance put an unpicklable closure into it: torch.save raised
PicklingError on the FIRST checkpoint of any run with embedding_learning_rate
set, whether or not anything was ever resumed.

Overridden on a per-instance subclass instead, so it lives on the class and
never reaches the state dict. isinstance and the class name are unchanged.
The optimizer hook was never affected, since Optimizer.state_dict builds its
result explicitly rather than from __dict__, and the test now saves both.

Fails without this with PicklingError, passes with it.

* Find the roles through the accelerate wrapper, and keep per-group optimizer state

Two more, both reproduced, both silent.

accelerator.prepare swaps self.optimizer for an AcceleratedOptimizer before
create_scheduler runs, and that wrapper defines no __getattr__, so asking it
for the recorded roles returned None and the scheduler hook quietly installed
nothing on the ordinary training path. The lookup unwraps now. The test pins
the absence of __getattr__ on the real class, so it stops passing if accelerate
ever changes that.

The migration also rebuilt each group from the freshly constructed one and
restored only lr, which resets anything an optimizer keeps per group.
Schedule-free holds its own progress there (k, weight_sum, lr_max), so the
saved per-parameter state would have come back beside reset group state. The
saved group is the base now, and only what deliberately changed, the params
and the corrected weight_decay, is overridden.

Both new tests fail without these and pass with them.

* Remap the scheduler only when the optimizer says the checkpoint was legacy

Length cannot tell a legacy [ordinary, embedding] pair from a current pair
that is two non-embedding groups, which is what you get when
embedding_learning_rate is set and no embedding is trainable. Remapping the
latter copied the first group's value over the second, so distinct per-group
min_lr floors written by this very code came back collapsed.

transformers loads the optimizer before the scheduler, so the optimizer hook
now records whether what it just saw was the old layout, and the scheduler
remaps only then. The scheduler tests follow that same order, which is what
the trainer actually does.

Fails without this with min_lrs collapsing to the first floor.

* Tighten the comments the review rounds accumulated

Post-convergence pass. Six rounds of fixes left overlapping explanations, one
of them sitting above a guard that had since moved. Comments and docstrings
only, AST verified, 224 comment lines to 205 in this file.

Every surviving line is a fact the code does not state: why the saved group is
the base, why the hook is on a subclass, why the scheduler remap is gated on
the optimizer, and why the lookup unwraps.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: danielhanchen <[email protected]>

@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: 145fda02a2

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

shimmyshimmer and others added 2 commits September 22, 2026 10:57
Escape cancels while the button is still down, and the release comes
later. The guard was armed at the keypress and torn down on the next
tick, so releasing over the source row opened the chat the drag had just
been cancelled out of.

The gesture keeps its listeners through escape now. The release is what
detaches, swallows the click and, being escaped, drops nothing.

Co-authored-by: Unsloth <[email protected]>
A client cannot choose it safely. Checking activity before the read lets
another tab append a prompt in between; checking after misses a
generation that finishes in between, leaving the same dangling prompt as
the tip. Either order has a round trip in the middle of it.

The route resolves the tip itself now, straight after its own generation
check, so messageId is optional and the row menu sends none. The message
level Fork still names its own message.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Right, and it is the window I talked myself out of last round. Fixed in 1b20ded, but not by reordering again.

The two findings so far point in opposite directions, and that is the useful part. Checking activity before the read lets another tab append a prompt in between, which is what the earlier comment caught. Checking after misses a generation that finishes in between, which is what this one catches. Both are true, because either order has a network round trip sitting in the middle of a read and a check that need to agree.

So the client no longer picks the tip. messageId is optional on the fork request, and the row menu sends none. The route resolves the tip itself with list_chat_messages(thread_id)[-1], immediately after its own active-generations check, in one synchronous request with nothing in between. The message-level Fork is unchanged and still names the message it is on.

This also took code out rather than adding more: forkChatRow no longer reads messages, no longer calls getActiveGenerations, and is down to settle, post, map a 409 to a refusal.

Backend tests cover the tip being resolved to the last message, the 404 when a thread has none, and that the generation check runs first, the last one by making list_chat_messages raise if it is reached while a generation is registered. 275 passing across the chat-history, storage, active-generations and account-settings suites. Frontend: npm run test passes 8468, typecheck and lint clean.

Two of my own tests pinned the client-side tip selection and had to be rewritten rather than loosened, since the behaviour genuinely moved.

@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: 1b20ded99b

ℹ️ 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 thread studio/backend/routes/chat_history.py Resolved
@mahiatlinux

Copy link
Copy Markdown
Contributor

Promoted the accepted staging head ff92f04dd1c9b25c41a372253bee970148ec0d12 unchanged to this PR. Validation used merge base be072ee2ff0334c95d300cd5c522fd9df3b1023f; GitHub reports the source PR is conflict-free against current main. Final staging review.

The remaining generation-admission finding is fixed: fork_chat_thread checks durable runs inside its write transaction before selecting or copying the tip. The regression covers a committed queued run before supervisor registration. Active Deep Research runs also refuse forks until they settle.

The final changes preserve assistant replies with tied timestamps, legacy flat/mixed history, and the branch currently visible in an open chat. Closed chats still resolve their tip on the server. Existing explicit branches, settings, project membership, metadata detachment, comparison-row restrictions, shared duplicate-request protection, and sandbox warnings remain supported.

The small refactor extracts the identical success notification into showForkCreatedToast. Both callers retain the same success/warning text and severity, error handling, settings settlement, request guards, and navigation.

Executed validation on the accepted head:

  • 180 focused backend tests across chat history routes, history storage, and durable generation runs passed.
  • All 9 Deep Research status cases passed.
  • 164 sidebar, keyboard shortcut, and thread-settings invariant tests passed.
  • Regression checks failed before the fixes for generation admission, tied timestamps, legacy ancestry, and visible branch selection.
  • Direct notification checks, Ruff, and diff checks passed. Frontend lint had no added diagnostics against the upstream baseline.

Browser appearance was not verified; no screenshot evidence is claimed. The full upstream CI matrix was not rerun locally or used as a reason to repeat the completed review.

@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 2036ee0 into main Sep 22, 2026
48 of 50 checks passed
@mahiatlinux
mahiatlinux deleted the studio-fork-chat-from-row branch September 22, 2026 20:21
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Correct finding, and I verified every step of it: create_run inserts the empty assistant placeholder and the chat_generation_runs row in one BEGIN IMMEDIATE transaction, supervisor.start registers the thread in active_generations only afterwards through _ensure_reservation, and a fork landing between the two would have taken the placeholder as the tip.

No change needed though. It is already closed on main, by the version of this PR that merged, and closed better than the route-level check I had started on. fork_chat_thread now does the refusal and the tip selection inside its own transaction:

admission and copying share the write lock, including the gap before supervisor registration.

That works because chat_generation_runs_db._connect() wraps the same get_connection() on the same database file, so the two BEGIN IMMEDIATE transactions are serialised by SQLite's write lock rather than merely ordered. It also covers active research runs, which a route-level check against active_generations would have missed entirely.

Tests for it are on main as well: test_fork_refuses_durable_run_before_supervisor_registration and test_fork_resolves_tip_after_concurrent_generation_completes, both passing here along with the rest of the chat-history route and storage suites.

I had a route-level version of this ready and threw it away rather than send a redundant PR.

shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
Add the row-menu fork action with shared request protection. Serialize forks with durable chat and research runs, preserve legacy history and the selected branch, and share fork success notifications.
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.

5 participants