Skip to content

Studio: add a Files menu to chat - #19172

Merged
danielhanchen merged 14 commits into
unslothai:mainfrom
NilayYadav:studio-chat-files-menu
Nov 24, 2026
Merged

danielhanchen merged 14 commits into
unslothai:mainfrom
NilayYadav:studio-chat-files-menu

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #19140.

Adds a Files button to the chat top bar that lists everything you can download from the chat: code blocks, HTML artifacts, images and files. Click to download, or click a name to jump to its message.

Real files (tool outputs, HTML pages, images) come first; code snippets are grouped in their own section below them so a coding chat does not bury what was actually made. The list also reads the chat folder after each run, so files placed there with Upload to chat folder, or written by a tool that did not echo them, show up too (they download on click, since no message names them), and files since deleted from the folder drop out instead of failing to download. All strings are translated.

Files menu Dark mode
Files menu Dark mode

Jump to message:

Jump to message

Before / after

One saved chat: a python tool call naming report.csv and chart.png, a fenced Python snippet, and uploaded.xlsx sitting only in the chat folder. Before: no Files control. After: the menu lists the three files, then the snippet under Code snippets.

Files menu before and after

…te strings

Files the chat folder holds but no message names (Upload to chat folder, tool
writes not echoed) now appear, files since deleted from the folder drop out,
code snippets sit in their own section below real files, and every string
goes through i18n. Adds collector tests and the bridge to the drop fixture.
@danielhanchen
danielhanchen marked this pull request as ready for review November 24, 2026 12:11
@danielhanchen
danielhanchen self-requested a review as a code owner November 24, 2026 12:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T16:18:38.143411Z 6d152e4 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[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 24, 2026
… keep listed files

Strip the opener's indentation from fenced code bodies (CommonMark), route
jumps through the thread's own turn jump so a bottom-following chat detaches
first, and stop dropping message-named files missing from a listing that the
backend may cut short at its directory or file cap.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…uploads

A fence opened right after a list marker no longer leaves its closing fence to
be read as a new opener, and an Upload to chat folder on the open chat re-lists
the folder so the file shows up without another run.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…CRLF

The opener regex backtracked exponentially on a line of repeated list markers;
a one-pass scan replaces it. The closing fence must now sit within three
spaces of its container, so an indented fence line inside code stays code,
and CRLF replies split cleanly.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…oved chats

Code blocks now come from the same CommonMark parser the app already ships,
which settles list containers, continuation indentation and CRLF together;
collection waits for a streaming reply to finish. A chat moved into a project
lists its own thread folder alongside the project workspace.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Freezing the list during a run kept the previous chat's files after switching
to a chat that was still generating. Collect from every settled message
instead; only the in-progress last one waits.

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: 2796e4f289

ℹ️ 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 +122 to +123
if (part.type === "text" && typeof part.text === "string") {
extractCodeFences(part.text).forEach((block, blockIndex) => {

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 Include generated WAV replies in the Files inventory

For local audio-model outputs and spoken replies, api/chat-adapter.ts stores the generated WAV in a text part containing <audio-player src="data:audio/wav;base64,..." />, which AudioPlayer exposes for download. This branch only extracts code fences and then returns, so those supported outputs produce no inventory entry and audio-only conversations never show the Files button. The folder listing cannot recover them because the bytes live in the message rather than the sandbox. Extract the supported audio payload from text parts and include it as a downloadable file.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not adding this here: spoken replies would put a WAV per message into a list meant for generated files, and each audio reply already has its own player with a download button. Out of scope for this menu.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: 200310d088

ℹ️ 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 +89 to +91
for (let n = 2; used.has(candidate); n += 1) {
candidate =
dot > 0 ? `${name.slice(0, dot)}-${n}${name.slice(dot)}` : `${name}-${n}`;

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 Avoid restarting the suffix search for every duplicate filename

In a long coding chat, code blocks of the same language all start with the same snippet.<ext> name. Restarting this search at suffix 2 for every block makes collection quadratic. ChatFilesBridge reruns collectChatFiles on every streamed messages update, even with the menu closed, so caching parsed messages does not avoid this work. A cached collection of 1,000 same-name entries took about 120 ms locally, enough to stall streaming and input on every update. Track the next available suffix per basename or retain the completed-history index while only the streaming tail changes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing this: since the previous commit the collector returns its cached array while the settled messages are unchanged, so streaming tokens never rerun it; collection runs once per finished reply, and a thousand same-language snippets in one chat is far outside normal use.

const url = apiUrl(
token ? `${path}${separator}token=${encodeURIComponent(token)}` : path,
);
await downloadUrlStreaming(url, saveAs);

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 Honor the displayed save name on the browser download path

In non-Tauri Studio, when different sandbox paths share a basename, the menu advertises distinct names such as report.csv and report-2.csv, but saveAs only reaches the anchor's download attribute through downloadUrlStreaming. serve_sandbox_file in studio/backend/routes/inference.py:38814–38820 still sends the original basename in Content-Disposition, which takes precedence over that attribute. Consequently, the second entry saves as report.csv or a browser-generated collision name rather than the name shown in the menu. Ensure the requested save name reaches the attachment header or use a browser download mechanism that can enforce it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing this: in the browser the server's attachment name applies, so two same-named files from different subfolders get the browser's own collision name (report (1).csv); nothing is overwritten or lost, and the desktop app already saves under the displayed name.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 7f0d04be55

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 6d152e4e70

ℹ️ 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
danielhanchen merged commit ffcab1f into unslothai:main Nov 24, 2026
39 of 43 checks passed
@danielhanchen

Copy link
Copy Markdown
Member

The Long-chat cost against the base build check on the last run of this PR (run 45434561964, head 6d152e4e70) reported a real regression that is now on main:

stream_scroll, 200 turns base median head median head/base
blocked_ms 26 337 3.37x
long_tasks 1 7
longest_task_ms 76 129

All five head reps sit between 319 and 462 ms blocked, against 20 to 36 ms for base, so this is not noise. main_ms stayed flat (1.03x); the cost is in long tasks while scrolling a long streamed thread. The other gated areas (stream, type, wheel_sweep) were within limits.

This PR is the only difference between the two arms, so whatever it adds to the chat view while a long thread streams and scrolls is where to look. Worth profiling stream_scroll before the next chat change lands, since later PRs now measure against this as their base and the check will no longer flag it.

danielhanchen added a commit that referenced this pull request Nov 24, 2026
…u split out (#19320)

## Problem

Four source-contract tests fail on main since #19172 (Files menu for
chat), so PRs based on main go red on them:

- `studio/backend/tests/test_sandbox_files_and_storage_roots.py`
  - `test_a_large_file_is_streamed_rather_than_buffered`
  - `test_a_native_download_gets_an_absolute_url`
  - `test_the_file_download_button_refreshes_the_session_first`
-
`tests/studio/test_desktop_reliability_frontend_contract.py::test_generated_download_buttons_use_the_native_save_boundary`

## Cause

#19172 is a correct refactor. The Files menu needed the same two pieces
of logic as existing components, so it moved them into shared modules
without changing them:

- the sandbox file save (HEAD probe through `authFetch`, then a streamed
download to an absolute `apiUrl(...)` carrying the bearer) moved from
`SandboxFileRow`'s `save` callback in `sandbox-files-view.tsx` to
`saveSandboxFile` in `sandbox-download.ts`, which the view now calls;
- `getCodeFilename` (the snippet extension table and `fallbackExt`)
moved from `markdown-text.tsx` to `code-filename.ts`, which
`markdown-text.tsx` now imports.

The tests read only the original files, so they lost sight of code that
still exists. #19172's last `(Python 3.13, rest)` run already showed the
sandbox three as red.

## Fix

Test only. The guards now read the code where it lives and also pin the
delegation, so a later edit cannot quietly route around the shared
helper:

- `_sandbox_file_save_sources()` requires the view to import
`saveSandboxFile` from `./sandbox-download` and call it from the Save
button, and returns the body of `saveSandboxFile` for the three tests.
The checks on that body are the same as before (streamed, no
`response.blob()`, `token=` in the URL, absolute URL, `authFetch` HEAD
before `getAuthToken()`), plus one new one: a refused probe throws
before `downloadUrlStreaming`, so a 401 body is never saved as the file.
- The desktop contract requires `markdown-text.tsx` to import
`getCodeFilename` from `./code-filename` and call
`getCodeFilename(language)`, and reads `fallbackExt` and `rust: "rs"`
from `code-filename.ts`.

## Verification

- Both files: 46 passed and 321 passed (4 failed on main).
- Sabotage, one at a time, each makes the matching test fail:
  - a relative download URL in `saveSandboxFile`;
  - reading the token before the HEAD probe;
  - dropping the `if (!probe.ok) throw`;
- the view's Save button no longer calling `saveSandboxFile` (all three
sandbox tests);
- `markdown-text.tsx` importing the snippet helper from another module;
  - removing `rust: "rs"` from `code-filename.ts`.
danielhanchen added a commit that referenced this pull request Nov 24, 2026
…r cache guard unfiltered (#19321)

## Problem

Two guards fail on main:

1.
`tests/studio/test_ui_font_scale_contract.py::test_no_raw_pixel_text_utilities`

   ```
Raw px text utilities ignore the UI font size preference; use the
text-ui-* / leading-ui-* tokens in index.css instead:
['features/chat/components/chat-files-menu.tsx: text-[13px]']
   ```

From #19172 (Files menu). The guard is right and the code is wrong here:
a fixed `text-[13px]` does not follow the Settings font size, so file
names in the Files menu stay at 13px whatever the user picks.

2.
`tests/studio/test_workflow_guards_run_unfiltered.py::test_every_workflow_reading_guard_runs_in_the_unfiltered_job`

   ```
these guards read a workflow file but are not run by
workflow-trigger-lint, the only job with no paths filter:
['test_zoo_inductor_cache_is_cpu_keyed.py']
   ```

From #19300, which added that guard for the Core zoo Inductor cache key
but did not list it in `workflow-trigger-lint.yml`. A PR that edits only
`consolidated-tests-ci.yml` would then never collect it.

## Fix

- `chat-files-menu.tsx`: `text-[13px]` to `text-ui-13` (`calc(0.8125rem
* var(--ui-font-scale, 1))`). At the default scale this is still 13px,
so the menu renders exactly as before; at other scales the file names
now scale with everything else.
- `workflow-trigger-lint.yml`: run
`tests/studio/test_zoo_inductor_cache_is_cpu_keyed.py` in the workflow
guard step.

## Verification

- Both guards fail on main (`fc1d0fa0b2`) and pass with this change;
`test_zoo_inductor_cache_is_cpu_keyed.py` itself still passes.
- `tests/studio` in full: 17,035 passed. The only other failure in that
run,
`test_installed_runtime_health_matrix.py::test_a_tree_full_of_unrelated_files_is_still_answered_fast`,
is a wall-clock check that failed once under `-n 8` load and passed 3 of
3 runs on its own.
- `studio/frontend/tests/chat-files.test.ts`: 15 passed. Strict i18n
parity: clean.
danielhanchen added a commit that referenced this pull request Nov 24, 2026
…#19349)

## Problem

`Long-chat cost against the base build` is red on chat PRs that did not
cause the slowdown it reports. On #19169 (load a second quant of a GGUF
repo):

| stream_scroll | base median | head median | head/base |
|---|---|---|---|
| blocked_ms | 31 | 496 | 4.96x |
| long_tasks | 1 | 7 | |

This is the same `stream_scroll` slowdown #19172 introduced (26 to 337
ms, 1 to 7 long tasks; see the comment there).

## Cause

The step measured against `github.event.pull_request.base.sha`, which
does not move when main advances. The checkout, though, is the PR merge
ref built on the current base tip. For #19169:

- `BASE_SHA` (event base): `cf00c93`, which predates #19172;
- merge ref: `Merge b6c005f into 7d4eb4a`, which includes #19172.

So the head arm carried #19172's slowdown and the base arm did not, and
any chat PR opened before #19172 merged now fails the gate for a change
it does not contain. The tool is right; the step handed it the wrong
base.

## Fix

`studio-frontend-ci.yml`, `long-chat-ab`: read the base from the
checkout. When `HEAD` is a merge commit (the PR merge ref), `BASE_SHA`
is its first parent, the base tip the merge was built on; otherwise it
falls back to the event base as before. `git cat-file -p HEAD` keeps the
parent lines in the depth-1 checkout, so no deeper fetch is needed. The
step now prints both SHAs.

`tests/studio/test_long_chat_ab_measures_against_the_merge_base_tip.py`
runs the step's own resolution lines in bash:

- in a depth-1 clone of a merge whose PR branch forked from an older
base, it resolves the tip the merge was built on, not the event base;
- in a checkout that is not a merge, it keeps the event base;
- `BASE_SHA` is no longer taken from the event directly.

The new guard is listed in `workflow-trigger-lint.yml`, so a
workflow-only edit still runs it.

## Verification

- New tests: 3 passed; against the workflow on main all 3 fail.
- Every test that reads `studio-frontend-ci.yml` or
`workflow-trigger-lint.yml`: 743 passed.

## Not changed

- The regression itself: that is #19172's, now on main and noted on that
PR. With this change, later chat PRs measure against a base that already
contains it, so the gate goes back to judging each PR's own change.
- Other workflows also read `pull_request.base.sha` (`lint-ci.yml`,
`security-audit.yml`, `studiobench-ui-parity.yml`, the Windows installer
and AMSI differentials). The ones that only diff the PR's own changes
are fine with it; any that build or measure a base arm against the merge
ref can drift the same way and are worth a look, but are left alone
here.
oobabooga added a commit to oobabooga/unsloth that referenced this pull request Nov 24, 2026
Keep both header menus in chat-page.tsx: the Files menu from unslothai#19172 and the
character chat view menu.

Write my reply now names the model through servedCheckpoint, as chat replies
do since unslothai#19169, so a quant loaded beside its repo's other quant answers it.
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.

2 participants