Skip to content

fix(studio): reconcile externally updated saved assistant messages - #11500

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
Souravrajvi0:feat/saved-history-reconcile-3f5c
Oct 2, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
Souravrajvi0:feat/saved-history-reconcile-3f5c

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11496

Problem

When an external client updates an existing assistant message via PUT /api/chat/threads/{threadId}/messages, Studio could fetch the newer history on wake (visibilitychange, pageshow, online) but only ran generation recovery for messages with metadata.generationRunId. Ordinary saved assistant turns stayed stale in the open runtime.

Solution

  • On the same wake path, reconcile persisted assistant bodies into the loaded thread using recoveredContentToImport (no write-back to storage).
  • Skip reconciliation while a message is running, being edited, or owned by an active generation recovery/live stream.
  • Drop stale reads when the user switches threads or a newer reconciliation starts.
  • Also listen for window focus while the document is visible.

Tests

  • studio/frontend/tests/saved-history-reconciliation.test.ts (6 cases)

Before / after

Seeded thread: user "Hi" plus an ordinary assistant reply "Old checkpoint" (no generationRunId). The thread is opened in Studio, then the same assistant record is updated through PUT /api/chat/threads/{id}/messages (pruneMissing: false), then the page is woken.

Wake via visibilitychange + focus + pageshow after saving "New saved checkpoint". Left is the merge base, right is this PR:

wake

A second save of "Newest via focus", woken by a lone window focus event:

focus

In both cases the server held the new text on both sides; only the open view differed.

Captured with the PR at 1bc02fc2b against merge base c0a60448e. The same pair reproduces in Firefox and WebKit.

When another client updates an assistant message through the history API,
wake triggers now merge the persisted body into the open thread without
overwriting active generations, in-progress streams, or edits in flight.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
@danielhanchen
danielhanchen merged commit 5ebf52b into unslothai:main Oct 2, 2026
4 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unsloth Bug] Open chat does not reconcile externally updated saved assistant messages

2 participants