Skip to content

Studio: stop the chat composer draft mirroring into other open tabs - #15795

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
debojyoti-dev:fix/composer-draft-tabs-15782
Oct 30, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
debojyoti-dev:fix/composer-draft-tabs-15782

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15782

What was wrong

The composer draft lives in one localStorage slot (chat-draft:latest), and composer-draft.ts had a storage listener that published every write from another tab straight into this tab's composers. So with two tabs open on different chats, typing, pasting or deleting text in one tab rewrote the "Ask anything" box in the other, and sending in one tab cleared the other's text.

What changed

  • composer-draft.ts: removed the cross-tab storage listener. Each open tab now keeps its own draft in memory. The saved slot is read once per tab (latestDraft() seeds from it on first use), so a reload or a newly opened tab still starts from the last draft, and adopting an old per-chat draft refreshes that seed.
  • The draft still follows the user across chats, pages and the Compare composer inside the same tab, as before.
  • Comments in thread.tsx and shared-composer.tsx no longer mention other tabs.
  • tests/composer-paste-draft.test.ts: new tests for a reload/new tab starting from the saved draft, another tab's save and send (with the storage events the browser fires) not reaching this tab, and a tab keeping its own text after another tab saves. The "another tab" test fails on the old code and passes with the fix.

Testing

On Windows 11, Node 22:

  • node --experimental-strip-types --test tests/composer-paste-draft.test.ts: 16 passed.
  • npm run typecheck: clean. eslint on the changed files: clean.
  • Full frontend suite (node --test --test-timeout=120000 "tests/**/*.test.ts"): 14361 passed, 4 failed. Three of them (a quit with no window on screen raises no overlay, both sides agree on the event names, macOS termination checks unsaved transcripts before allowing exit) fail the same way on a clean copy of main. The fourth, codex-learned-capabilities-survive-sync.test.ts, timed out under the full run's load and passes when run on its own.
  • I couldn't run the full Studio backend on this machine, so I didn't click through two live browser tabs; the storage events are simulated in the tests.

Long pastes too

A paste over the attach threshold becomes a file chip, and those were still read back from the shared chat-draft-pastes:latest slot on every chat switch, so a long paste in one tab appeared in another tab as soon as that tab opened a different chat. latestPasteDraft() now keeps each tab's pastes in memory once it has saved any, the same way latestDraft() does for text, and the paste restore in thread.tsx reads it. A new tab or a reload still starts from the saved pastes, and an adopted pre-upgrade paste still reaches the restore. Two tests cover this; the first fails on the old read path.

Before / after, two live tabs on different chats

Merge base f1dedb6 vs head 68ec78e, each built with install.sh --local into its own Studio home, driven with Playwright. Tab B types its own text, then tab A types; tab B's box is read back.

Browser tab B after tab A typed, before after same tab, draft follows to another chat
Chromium typed only in tab A tab B's own unsent text n/a
Firefox typed only in tab A tab B's own unsent text kept on both
WebKit typed only in tab A tab B's own unsent text kept on both

Clearing tab A's box also cleared tab B before, and leaves it alone after. Long paste in tab A, then tab B switches chat: tab B shows 1 paste chip before, 0 after.

Firefox, typed text (tab B on the left of each half):

Firefox two tabs before and after

Chromium, long paste followed by a chat switch in the other tab:

Long paste two tabs before and after

…ixes unslothai#15782)

Typing, pasting or sending in one tab rewrote the composer in every other open tab, even on a different chat, because a storage listener pushed each saved draft into all tabs. Each tab now keeps its own text; the saved draft still seeds a reload or a newly opened tab, and the draft still follows the user across chats, pages and Compare within a tab.
danielhanchen added a commit that referenced this pull request Oct 28, 2026
## Summary

`Frontend unit tests` fails on main (seen as the Windows leg on #15795;
reproduces locally on `795da3b42a`) with three tests that read
`studio/src-tauri/src/main.rs` and still describe the quit as it was
before #15723:

```
not ok - a quit with no window on screen raises no overlay
    (expects fn quit_raises_the_overlay)
not ok - both sides agree on the event names
    (expects const APP_CLOSING_EVENT / APP_CLOSING_CANCELLED_EVENT in main.rs)
not ok - macOS termination checks unsaved transcripts before allowing exit
    (expects begin_or_attach_termination(quit_requires_confirmation(app)))
```

#15723 changed the quit on purpose: the cover step now hides the main
window on every platform instead of emitting the Windows-only
`app-closing` overlay events, a window that was not on screen is left
hidden, and the macOS terminate path holds on while a window is on
screen (`quit_requires_confirmation(app) ||
main_window_on_screen(app)`). Its description notes the frontend overlay
(`closing-signal.ts`, `ClosingScreen`) is no longer triggered and leaves
removing it to a follow-up. The product is right; these three tests were
not updated with it.

## Change

`studio/frontend/tests/desktop-closing-overlay.test.ts`: the two tests
pinned to the removed Rust emitters are replaced by the contract that
replaced them:

- **a quit with no window on screen leaves it hidden**:
`hide_main_window_for_quit` hides only when `main_window_on_screen(app)`
says the window is visible, read via `window.is_visible()`;
- **the quit hides the window after the confirmations and before the
reap**: in `quit_sequence`, `if !confirm()` comes before `hide()`, which
comes before `reap()`; and `main.rs` does not emit `app-closing`, so if
the overlay is ever wired back the test says to put it back under test
(or remove it).

The store-level overlay tests in the same file still pass and still
cover `closing-signal.ts` until the follow-up removes it.

`studio/frontend/tests/audio-transcript-lifecycle.test.ts`: the macOS
check now matches
`begin_or_attach_termination(quit_requires_confirmation(app)...`, so the
terminate path may hold on for more reasons but never fewer; the `||
renderer.unsaved_transcript` and `confirm_quit_with_unsaved_transcript`
checks are unchanged.

## Testing

- Whole frontend suite (`node --experimental-strip-types --test
"tests/**/*.test.ts"`): 3 failing on main (the three above), 0 with this
change.
- Sabotage on `main.rs`, one at a time:
- reaping before hiding fails "the quit hides the window after the
confirmations and before the reap";
- hiding without asking whether the window is on screen (`let hide =
true;`) fails "a quit with no window on screen leaves it hidden";
- dropping `|| renderer.unsaved_transcript` from
`quit_requires_confirmation` fails the macOS transcript test.
danielhanchen added a commit that referenced this pull request Oct 28, 2026
…dapter check (#15803)

## Summary

`Repo tests (CPU, studio)` fails against unsloth-zoo `main` (seen on
#15795; 4 failed, 9862 passed) since unslothai/unsloth-zoo#2190 landed:

```
tests/python/test_fused_linear_trl_routes.py::test_adapter_bounds_its_logits_buffer_by_chunk_size[*]
E   assert (None is None and 258048 == ((64 * 1000) * 4))
```

unslothai/unsloth-zoo#2190 pads the fused linear forward statistics
buffer's row stride to a multiple of 16 (`_FWD_PAD = 16`), so Triton
keeps its divisibility-by-16 specialisation and the no-grad and
trainable-head statistics agree bitwise for vocab sizes not divisible by
16. With the test's `V = 1000` the one uncapped `[N, V]` buffer is now
`64 x 1008 x 4 = 258048` bytes instead of `256000`. The zoo change is
intentional; the test pinned the unpadded size.

## Change

The "TRL's default tile is bigger, so no row cap" check still requires
`max_rows_per_chunk is None` and a single `[N, V]` buffer, but sizes `V`
with the zoo's own pad: `getattr(fused_linear, "_FWD_PAD", 1)`, rounded
up. Against a zoo without #2190 the pad is 1 and the check is exactly
the old one.

## Testing

`tests/python/test_fused_linear_trl_routes.py` with `unsloth_zoo` on the
path:

- zoo `main` (`cd630187`): 4 failed on main, 37 passed with this change.
- zoo just before #2190 (`cd630187~1`): 37 passed with this change, so
the zoo floor is unaffected.
- Sabotage: making the zoo's `_padded` round to 64 while `_FWD_PAD`
stays 16 (a buffer wider than the zoo says it pads) fails all four cases
again.
danielhanchen added a commit that referenced this pull request Oct 28, 2026
…rowth (#15822)

## Summary

`Frontend build + bundle sanity` fails on main (seen on #15806, #15799,
#15798, #15795; reproduces locally on `556b28bb40`):

```
eager startup JS: 5837.8 KB raw, 1806.0 KB transfer, 85 chunks
over the startup budget: transfer 1806.0 KB > 1795.7 KB, raw 5837.8 KB > 5819.8 KB
```

Building every frontend commit since the last budget base (`8222149ee`)
and measuring the eager set the same way
`scripts/check-bundle-budget.ts` does:

| commit | raw B | transfer B |
|---|---|---|
| `ed9857c0c3` (#15718) | 5,942,150 | 1,836,750 |
| `39b8a6ce13` (#15678, Trick or treat row) | 5,972,134 | 1,847,702 |
| `556b28bb40` (main) | 5,977,895 | 1,849,311 |

Every other step in the range moves by 0.0 to 0.5 KB. #15678 added
29,984 B raw / 10,952 B transfer in one step and merged without
re-measuring. #15485 then raised the budget by its own 1,953 B, but
measured against `8222149ee`, a base from before #15678, so main has
been over ever since.

## Change

`BUDGET` in `studio/frontend/scripts/check-bundle-budget.ts` is raised
by #15678's measured growth (+29,984 B raw, +10,952 B transfer), with
the measurement recorded next to the earlier raises. Main is then within
budget with 0.5 KB transfer / 11.3 KB raw to spare, so the next
unmeasured growth still fails here.

I tried the gate's first suggestion before raising it. Loading the Trick
or treat dialog on first open (`React.lazy` in `app-sidebar.tsx`) saves
only 10.4 KB raw / 3.0 KB transfer, and it raises the startup set from
85 to 90 chunks: the case the script warns about, where a dynamic import
splits shared modules into extra startup chunks. The rest of #15678's
weight is its Halloween color themes in
`features/settings/lib/color-themes.ts`, which the theme store reads at
startup to apply the saved theme. So that is not a laziness fix, and I
left it out.

## Testing

- `npm run build && npm run bundle:check`: over on main, `within budget
(0.5 KB transfer, 11.3 KB raw to spare)` with this change.
- `tests/bundle-budget-cli.test.ts`,
`tests/bundle-budget-closure.test.ts`: 43 passed.
- Measurements on Node 24.22.1, one machine and build, as the earlier
entries.
@danielhanchen danielhanchen self-assigned this Oct 29, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #15795, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#600.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror e1584fa75 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: e1584fa750

No triage reaction was recorded on the mirror

Round 2: reviewed mirror 312a87379 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 312a873799

No triage reaction was recorded on the mirror

Round 3: reviewed mirror 36519b3da (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 36519b3dad

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 36519b3da (no equivalent commit found on this PR).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit c99ccea into unslothai:main Oct 30, 2026
43 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.

[Bug] Text CRUD in "Ask anything" (chat) input textarea [textarea name="input"] duplicates across open tabs even when tabs have different chats open

2 participants