Skip to content

Studio: stop a reopened chat from saving every replayed event, and let Stop reach it - #12464

Merged
mahiatlinux merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-chat-recovery-save-loop
Oct 1, 2026
Merged

mahiatlinux merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-chat-recovery-save-loop

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Refs #12435

Studio keeps generating a reply on the server after its tab is closed or reloaded. When the chat is opened again, the new tab catches up by replaying the run's stored events. This replay had two bugs, both reported in #12435:

  1. It flooded the server with saves. The tab saved the whole message once per replayed event, thousands of times per reply. Once the run had ended, each of those saves was refused with 409 server-managed generation messages cannot be edited, which is the loop in the report's log.
  2. Stop did nothing. The Stop button only cancels a run that the same tab started, so a reply being replayed kept generating.

Fix

  • While catching up, the tab no longer renders or saves each replayed event. It shows the reply once it has caught up.
  • After that, the reply still updates live, but it is saved at most once every 8 seconds and once at the end. Nothing is lost: the events stay on the server, so a skipped save only makes the next replay longer.
  • Stop now cancels a replayed run on the server. A run the tab started itself is unaffected.
  • If the replay stalls, the partial reply is saved with the correct position, so a later replay does not repeat text.

The changes are in scheduleGenerationRecovery (runtime-provider.tsx), with a new stopRecoveredRun handle used by the composer's Stop.

Tests

Live A/B against main on Linux with Chromium, using unsloth/Qwen3-0.6B-GGUF Q4_K_M on CPU. Each run sent a long prompt, closed the tab 1.5 s later, and then reopened the chat. Replies were 2,400 to 3,700 events long.

Reopened chat Main This PR
Run already finished 3,555 saves, final reply saved after 24.2 s 1 save, after about 1 s
Run still going, watched to the end 3,506 saves, 304 refused with 409 9 saves, none refused
Run still going, Stop pressed after 6 s Nothing happened; run finished; 1,920 saves refused with 409 Run cancelled after 8.9 s, 2 saves

Pressing Stop 1 s after reopening also did nothing on main and worked with this PR. In all 13 replayed replies, the saved text matched the run's stored events.

  • A new test runs the real recovery code on a finished 400-event run and checks it is saved and shown only once, complete. It fails on main. Other new tests cover the save pacing and the Stop handle.
  • Frontend tests: 9,691 of 9,700 passed; the 9 failures also fail on main. Typechecks passed, and ESLint found no issues on changed lines.

Not covered

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#324.

@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 c1e5a56 into unslothai:main Oct 1, 2026
42 checks passed
@mahiatlinux

Copy link
Copy Markdown
Contributor

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