Skip to content

Studio: keep the composer draft across chats, pages and tabs - #13722

Merged
shimmyshimmer merged 6 commits into
mainfrom
studio-chat-draft-persist
Oct 14, 2026
Merged

shimmyshimmer merged 6 commits into
mainfrom
studio-chat-draft-persist

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

What changed

Text typed into the chat composer now follows you. Switch to another chat, start a new chat, open Settings or another page, reload, or open Studio in a second tab, and the composer shows whatever you typed last. Before, each chat had its own draft and New chat cleared it, so going to another chat looked like your text had disappeared.

  • composer-draft.ts: one shared draft slot (chat-draft:latest, plus chat-draft-pastes:latest for long pastes) instead of one per chat.
  • thread.tsx: the restore runs on every chat switch, keyed on the chat on screen, and it now covers unsaved new chats too (before, those had no draft at all). Sending a message still clears the draft, and the existing sent-text guard still stops a late save from bringing sent text back.
  • Every clearNewChatDraft() call is gone (sidebar, Library, Projects, Hub, shared run-config links, desktop New chat), so starting a new chat no longer wipes what you were typing.
  • Deleting a chat removes that chat's leftover draft from the old per-chat scheme and never touches the shared one. Switching accounts still clears it, since the key keeps the chat-draft prefix that account-transition.ts wipes.

Verification

  • npm run typecheck, npm test (12121 pass), npm run build. Biome on the changed files: no new diagnostics compared with main, apart from one useExhaustiveDependencies note on the intentional draftScope dependency.
  • Live isolated Studio driven with Playwright: typed in chat A, then checked the composer in chat B (via the sidebar), after going to Settings and back, in a new chat, after editing in the new chat and opening chat B in a second tab, and after a reload. Every step showed the latest text.

Not tested here

  • Sending clears the draft: not run live, since this host has no loaded model. The send-clear code is unchanged, and the sent-text guard tests pass.
  • Desktop (Tauri) app: it serves the same frontend, but I did not run it here.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-10-14T14:43:29.079338Z 545d394 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: 3cca62217e

ℹ️ 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 on lines +7 to +11
const DRAFT_KEY = "chat-draft:latest";
const PASTE_DRAFT_KEY = "chat-draft-pastes:latest";
// Drafts used to be kept per chat under these prefixes; only deleting a chat still touches them.
const LEGACY_DRAFT_PREFIX = "chat-draft:";
const LEGACY_PASTE_DRAFT_PREFIX = "chat-draft-pastes:";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Migrate existing per-thread drafts before switching keys

When a user upgrades with an unsent draft stored by the previous release as chat-draft:<threadId> or chat-draft-pastes:<threadId>, the composer now reads only the new :latest keys, while the legacy prefixes are used solely for deletion. Consequently, reopening that chat makes its draft appear lost. When the shared slot is absent, migrate or fall back to the active chat's legacy text and paste slots before adopting the new key.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2aa352: opening a chat adopts its old per-chat text and paste slots into the shared draft when nothing newer is stored, then drops them (adoptLegacyDraft, tested in composer-paste-draft.test.ts).

Comment on lines 3941 to +3942
composer.setText(draft);
}, [draftKey, aui]);
}, [draftScope, draftKey, aui]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Subscribe to shared-draft updates from other tabs

When two Studio tabs are already open, typing in one updates localStorage but the other tab never reruns this restore because neither draftScope nor the other dependencies change on a storage event or tab focus. The second tab therefore keeps stale text instead of showing the latest draft and can overwrite the newer shared value on its next edit. Add synchronization for changes to the shared draft keys, such as a filtered storage subscription.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2aa352: the composer listens for storage events on the shared key and applies them, and skips saving text that arrived from another tab so it cannot overwrite a newer write there.

Comment on lines +3914 to +3917
const draftScope = referenceThreadId;
const draftKey = composerDraftKey();
// unsent pasted File objects need a separate slot because they exist only in memory
const pasteDraftKey = draftThreadId
? composerPasteDraftKey(draftThreadId)
: null;
const lastDraftKeyRef = useRef(draftKey);
// save only after this key's paste restore finishes to avoid premature clearing
const restoredPasteKeyRef = useRef<string | null>(null);
const pasteDraftKey = composerPasteDraftKey();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep temporary-chat drafts out of persistent storage

When the user starts a temporary chat and types before sending, referenceThreadId is null but this now unconditionally selects the shared persistent key, so the autosave writes the temporary prompt—and pasted-text attachments—to localStorage. Leaving the temporary chat then restores that content into an ordinary chat or after a reload, contradicting the UI promise that a temporary chat is not saved and disappears when left. Gate draft persistence and restoration on the runtime's incognito state, keeping temporary drafts in memory only.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2aa352: a temporary chat is its own draft scope that neither reads, writes nor clears the shared draft, in the chat composer and in Compare.

Comment on lines +3912 to +3915
// One draft shared by every chat, mirrored to localStorage and restored
// whenever the chat on screen changes, so the last thing typed follows the user.
const draftScope = referenceThreadId;
const draftKey = composerDraftKey();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include the comparison composer in shared draft persistence

When the user enters Compare, the visible input is SharedComposer, which still initializes its own text to empty in features/chat/shared-composer.tsx:644 and never reads or writes these draft helpers; this persistence effect belongs only to the hidden normal Composer. As a result, the shared draft does not appear in comparison mode, and anything typed in the comparison composer disappears on exit or reload. Wire SharedComposer into the same shared draft store or move persistence into an abstraction used by both composers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2aa352: SharedComposer starts from the shared draft and saves to it with the same 300 ms debounce, so text carries into and out of Compare.

…y chats unsaved, share the draft with Compare
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 14, 2026

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

ℹ️ 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 on lines +651 to +654
const [text, setText] = useState(() =>
useChatRuntimeStore.getState().incognito
? ""
: (readComposerDraft(composerDraftKey()) ?? ""),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Synchronize Compare with the mounted single composer

When entering or leaving Compare, this one-time initializer and the localStorage-only debounce do not synchronize with the normal composer that chat-page.tsx:3417-3430,4925-5002 deliberately keeps mounted and hidden. Same-document localStorage writes do not emit a storage event, so text entered in Compare is absent after exit and the hidden composer's next edit can overwrite it; similarly, entering Compare within the normal composer's debounce can initialize stale text and later overwrite the newer write. Fresh evidence beyond the earlier fix claim is that the final tree still has two concurrently mounted composer states with no same-tab synchronization between them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ac5600: both composers publish their text on a shared in-page channel (composer-draft.ts publishDraft/subscribeDraft, which also relays other tabs' storage events) and apply each other's, so Compare opens with the latest text and the hidden chat composer picks up what was typed in Compare. Compare also flushes its pending save when it unmounts.

Comment on lines +3991 to +3995
draftScope === INCOGNITO_DRAFT_SCOPE ||
composer.getState().attachments.length > 0
) {
restoredPasteScopeRef.current = draftScope;
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove temporary paste attachments before adopting the shared scope

When an empty scratch chat is toggled into temporary mode, pasted-text attachments already in the composer survive because this branch merely marks the incognito scope as restored; toggling back in place then takes the attachments.length > 0 branch, marks those temporary attachments as belonging to the normal scope, and the following save effect writes them to chat-draft-pastes:latest. The same leak occurs for a long paste created while temporary and then toggled back. Fresh evidence beyond the earlier temporary-chat fix claim is this explicit adoption of existing attachments without clearing or distinguishing their incognito origin, which persists temporary content despite the UI promise.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ac5600: crossing into or out of the temporary scope removes the pasted-text attachments on screen before any restore or adoption, so a temporary paste is never saved and the saved ones are not shown in a temporary chat.

Comment on lines +3960 to +3962
const onStorage = (event: StorageEvent) => {
if (event.key !== draftKey) return;
const composer = aui.composer();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Synchronize pasted attachments across tabs

When a long paste is added or removed in another open Studio tab, its update is written to chat-draft-pastes:latest, but this listener accepts only the text draftKey. Because draftScope and the local attachment signature also remain unchanged, the paste restore effect never reruns, so the second tab keeps stale attachments; after a send removes the shared paste, changing attachments in the stale tab can even write the sent paste back. Listen for pasteDraftKey changes and reconcile the in-memory pasted-text attachments as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one: pasted attachments are restored on the next chat switch or reload, and keeping megabyte pastes live across open tabs means re-adding File attachments on every remote change. Text, which is what people type, syncs live.

Comment on lines +84 to +85
if (text !== null) storage.setItem(DRAFT_KEY, text);
if (pastes !== null) storage.setItem(PASTE_DRAFT_KEY, pastes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Roll back partial legacy-draft migrations

When a legacy draft contains small text plus a large pasted attachment and localStorage has room for the text but not the paste, the first setItem succeeds and the second throws. The catch leaves the legacy entries for retry, but on the next opening DRAFT_KEY is already populated, so the copy block is skipped and both legacy entries are removed, permanently discarding the paste. Migrate the slots independently or roll back any successful shared write before treating the migration as failed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ac5600: adoption is all or nothing; if the paste slot fails to write, the shared text written just before it is removed, so the next try still copies both (tested).

…stes on toggle, roll back partial draft adoption
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 14, 2026

@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: 2ac5600bff

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


if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
window.addEventListener("storage", (event) => {
if (event.key === DRAFT_KEY) publishDraft(event.newValue ?? "", OTHER_TAB);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve newer local edits from delayed storage events

With two tabs editing inside the 300 ms debounce window, this unconditionally applies an older storage event over a newer local edit. For example, if tab A types at t=0 and tab B types at t=100 ms, A's write arrives around t=300, replaces B's text, and the resulting render cancels B's pending t=400 write, permanently losing B's later input. Fresh evidence beyond the earlier synchronization fix is that storage events carry no revision or timestamp, so the subscriber cannot distinguish this delayed older value from a newer draft; version writes or retain a dirty local value until its revision is committed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: this needs keystrokes in two tabs inside the same 300 ms window, which one person typing does not produce. Sequential edits in different tabs sync as intended.

// would leave the previous thread's text on screen under this one.
// would undo the clear. Clear rather than return early, which would leave
// the previous thread's text on screen under this one.
if (sentTextGuardBlocksDraft(justSentRef.current, draft, draftKey)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bypass the sent-text guard for adopted legacy drafts

When a user sends text in one chat and then opens another chat whose pre-upgrade legacy draft contains identical text, adoptLegacyDraft successfully moves that second draft into the shared slot, but the guard still owns the same global draftKey and classifies the migrated text as a raced copy of the sent message. This branch then deletes the newly adopted draft. Fresh evidence beyond the earlier migration fix is the collision between distinct per-thread legacy drafts and the new single shared guard key; an adopted draft needs its original scope preserved or must bypass this sent-write suppression.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: it needs a pre-upgrade draft in another chat that is character-for-character the message just sent, opened before any other keystroke. That migration-only coincidence costs the duplicate of a message that was already sent.

Comment on lines +653 to +655
const [text, setText] = useState(() =>
useChatRuntimeStore.getState().incognito ? "" : latestDraft(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore the saved draft when Compare exits temporary mode

When Compare is opened from a temporary chat, ChatPage resets incognito only after the Compare view mounts, so this initializer deliberately starts with "". On the subsequent incognito=false render there is no effect that reloads latestDraft(); instead the save effect publishes that empty value, which also clears the hidden normal composer and then removes the previously preserved persistent draft. Fresh evidence beyond the earlier temporary/Compare fixes is this true-to-false transition during Compare mounting; restore the shared value when leaving the temporary scope rather than treating the initial empty state as a new edit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 884183a: Compare's save effect treats a temporary-to-normal switch as a restore, loading latestDraft() instead of publishing the empty temporary text. The mount-before-reset window comes from the incognito reset effect in chat-page.tsx; a URL switch into Compare from a temporary chat kept the draft before and after.

Comment on lines +3944 to +3946
const draft = adoptLegacyDraft(draftScope)
? (readComposerDraft(draftKey) ?? "")
: latestDraft();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prefer the in-memory draft before adopting a legacy slot

When the user types a new shared draft and switches chats within the 300 ms debounce, publishDraft has updated the in-memory latest value but DRAFT_KEY is still absent from localStorage. If the destination chat has a pre-upgrade draft, adoptLegacyDraft therefore treats the shared slot as empty, copies the older legacy value, and this branch restores it instead of the newer in-memory text; the source timer is canceled by the scope switch, so the newer input is permanently lost. Fresh evidence beyond the earlier migration fix is the unsaved in-memory shared slot, which must take precedence when deciding whether adoption is allowed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 884183a: adoptLegacyDraft returns early when this session holds unsaved text, leaving the old slot for a later open (tested).

Comment on lines +4026 to +4029
void Promise.all(
stored.map((text) => composer.addAttachment(createPastedTextFile(text))),
).finally(() => {
restoredPasteKeyRef.current = pasteDraftKey;
restoredPasteScopeRef.current = draftScope;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ignore paste restores that finish after the scope changes

If restoring a saved paste is still awaiting addAttachment when the user toggles into a temporary chat, this finally callback later writes the captured persistent draftScope into restoredPasteScopeRef even though the active scope has changed. A subsequent toggle back can then skip restoration as supposedly complete and let the paste-save effect overwrite the persistent slot from an empty composer; depending on attachment timing, the late attachment can also appear in the temporary chat. Fresh evidence beyond the earlier paste-boundary fix is this uncancelled asynchronous completion; verify that the active scope still matches before attaching or marking restoration complete.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 884183a: the restore claims its scope only if that scope is still current when the attachments finish; otherwise the next run handles the new scope, removing any late pastes when it is the temporary one.

… when Compare leaves a temporary chat, ignore late paste restores
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 14, 2026

@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: 884183aebc

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

// Changing attachments re-runs this effect, which is how the retry happens.
if (composer.getState().attachments.length > 0) return;
const stored = pasteDraftKey ? readPasteDraft(pasteDraftKey) : [];
if (restoredPasteScopeRef.current === draftScope) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recheck the scope before accepting late paste attachments

When a persisted paste's addAttachment is still pending and the user toggles into a temporary chat, the transition pass can mark the incognito scope restored before the attachment lands. Fresh evidence beyond the earlier fix claim is this early return: when the late attachment changes composerAttachmentSignature, the effect exits here before the cross-scope removal below, leaving persisted content visible in the temporary chat. Check for and remove cross-scope pastes before treating the current scope as fully restored, or cancel the in-flight restore.

Useful? React with 👍 / 👎.

@shimmyshimmer shimmyshimmer Oct 14, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: this needs the temporary toggle to land inside the few milliseconds addAttachment takes for an in-memory text file. If it does, the restored paste shows in the temporary chat, but it is the user's own saved draft and nothing is written to storage while temporary, so no content leaks out of the temporary chat.

Comment on lines +4013 to +4017
draftScope === INCOGNITO_DRAFT_SCOPE ||
composer.getState().attachments.length > 0
) {
restoredPasteScopeRef.current = draftScope;
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore saved pastes before accepting unrelated attachments

When the composer receives a non-paste attachment before the shared paste restore completes—for example, a Library chat handoff starts adding an image from the earlier effect at thread.tsx:3205-3223—this branch treats the nonempty attachment list as proof that the saved pasted-text attachments are already present. It marks the scope restored, and the following save effect extracts no pasted text from the image and removes chat-draft-pastes:latest, permanently losing the saved paste. Verify that the existing attachments actually contain the stored pastes, or defer marking the scope restored until those pastes have been added.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 545d394: the restore now compares the saved pastes with the pasted-text attachments actually on screen and adds only the missing ones, so an image added first no longer counts as a restore. A one-pass guard keeps its own additions from re-adding. Checked live: a saved paste plus an image pasted right after a reload leaves one paste in storage and on screen.

Comment on lines +676 to +679
const timer = setTimeout(() => {
writeComposerDraft(composerDraftKey(), text);
unsavedDraftRef.current = null;
}, 300);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear the persisted draft synchronously after Compare sends

When Compare accepts a send, clearSubmittedDraft() sets text to empty, but this effect waits 300 ms before removing the persisted value. If the user reloads or closes the app during that window, React's unmount cleanup is not guaranteed to run and the next session restores the already-sent prompt—or an even older persisted value if the sent edit itself was still debounced. The normal composer clears storage synchronously on send; Compare should do the same rather than routing the send clear through the ordinary typing debounce.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 545d394: an emptied Compare composer (a send, or clearing it) writes the empty draft at once instead of through the 300 ms debounce.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 545d394024

ℹ️ 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 pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 9, 2026
Typing an unfinished prompt in one chat currently carries it into other
chats and New chat. Keep drafts separate by default, and expose the
existing shared-draft behavior under **Settings → Chat → Chat defaults →
Share drafts across chats** (off by default).

This follows up on the intentional behavior change in unslothai#13722 and
preserves unslothai#15782's cross-window isolation. Opting in shares a draft
across chats and Compare within the same tab; it does not restore live
synchronization between windows. Opening as a draft for agreement on the
default behavior.

- Saved chats, fresh New chat navigation, and Compare pairs have
separate draft scopes, including long pasted text.
- Flush pending text on navigation without removing the typing debounce;
clear sent drafts and discard paste restores that finish after switching
chats.
- Preserve the stored shared draft and per-chat copies when changing the
preference. Include translations in every locale.

Validation:
- 74 focused draft, composer-preference, and send-guard tests pass,
including upstream tab-isolation coverage.
- `npm run typecheck` and `npm run i18n:check:strict` pass.
- Local React lifecycle probe passes quick navigation, New chat, sends,
late paste restores, Compare isolation, preference toggles, and
temporary-chat isolation.
- Playwright/Chromium drove the repository's real SettingsDialog
preview: navigated to Chat, verified the toggle defaults off, enabled
it, and verified persistence after reload.

The native Unsloth Desktop shell and model-backed sends were not
exercised.


<!-- ui-evidence:start -->
### Before / after: composer drafts

Two isolated Studio installs, no model loaded. Two saved chats are
seeded; the draft "unfinished question typed in chat A" is typed in chat
A, then the sidebar opens chat B, then New chat. Draft pairs: merge base
`6c486bd0c` vs head `a55e89f10`.

Chat B after leaving chat A: before, chat A's draft follows into chat B;
after, chat B starts empty.
![Chat B composer, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16548/pr16548_pair_00-dcb864fb1efa.png)

New chat after leaving chat A: before, the draft follows into New chat;
after, New chat starts empty. Returning to chat A afterwards shows its
own draft again. Unsent New chat text is kept in one New chat slot, so
stored drafts are only `chat-draft:__new__` and one per saved chat.
![New chat composer, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16548/pr16548_pair_01-17887437c23d.png)

Settings > Chat > Chat defaults gains "Share drafts across chats", off
by default (merge base `6c486bd0c` vs head `fe81dbae8`, current main
layout). With it switched on, the same chat A, New chat, chat B, chat A
sequence shows the same composer text at every step on both builds.
![Settings Chat defaults, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16548/settings_chat_defaults_fe81-a8938bac3b9e.png)
<!-- ui-evidence:end -->

---------

Co-authored-by: Daniel Han <[email protected]>
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.

1 participant