Repository navigation
Studio chat autosave: skip the full-thread echo the client discards - #18918
Conversation
The autosave after every turn PUTs the whole thread and throws the echoed rows away. An opt-in echoMessages=false query flag lets that caller skip the server re-read and serialisation; deletes and every other caller keep the echo, and an older backend that ignores the flag still works.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…VFP4 nested kernel, Kaggle input via env) (#19027) ## Summary Four tests are red on `main` and fail on every PR whose staging run includes them (seen on #18918, #18925 and #19000). Each was reproduced on `main` before fixing. In all four the code under test is right and the test is not. | Failing test (shard) | Introduced by | Cause | Fix | |---|---|---|---| | `test_diffusion_ddp_effective_precision.py::test_real_gloo_two_ranks[fp8,*]` (`(Python 3.13, diffusion)`) | #18967 | The verdicts are right (`SAME`, `REFUSED ...`), but gloo prints `[Gloo] Rank N is connected to 1 peer ranks ...` on the child's stdout first, and the test required the output to start with the verdict. | Read the verdict from the child's last line. | | `test_diffusion_base_precision.py::test_resolve_auto_uses_klein_variant_size` and `test_auto_sizes_flux2_klein_9b_off_its_own_weights[*]` (`(Python 3.13, diffusion)`): `'nf4' == 'fp8'` | #18967 | Near the 8-bit band (20 GB free against the 18.2 GB dense 9B), Auto's fp8 pick also checks host RAM through `_auto_swap_host_ram_ok`, because that load holds the bf16 base on the host. The tests fake the GPU but read the runner's real RAM, so a 16 GB CI runner gets `nf4` (correctly) and a large dev box gets `fp8`. | An autouse fixture pins host RAM high, like the file's existing `_not_rocm` pin, since these cases simulate GPU tiers. New `test_klein_9b_near_the_8bit_band_falls_back_to_nf4_on_a_small_host` pins the small-host fallback explicitly. | | `tests/test_nvfp4_qat_backward_skip.py::test_cpu_forward_kernel_is_restored_on_exit` (`Repo tests (CPU, rest)`): `there's already a kernel registered from python overriding nvfp4_qat_linear_v2's behavior for CPU` | #18864 | The test enters `_cpu_forward_kernel(op)` inside the module-scoped `op` fixture, which has already registered that kernel. torch 2.10 refuses a second Python registration for the same op, key and namespace, so the test fails on every run. | The `op` fixture is per test, and the restore test takes the bare op (new `raw_op` fixture), so it checks a real register-then-restore from a clean state. | | `tests/kaggle/test_fire_and_forget.py::test_every_gate_budget_covers_the_reaper_window` (`Repo tests (CPU, rest-2)`): `the collector's default age ceiling is not readable from the workflow` | #18969 | #18969 correctly moved the dispatch input out of the script into `MAX_AGE_HOURS: ${{ inputs.max_age_hours \|\| '3' }}`, and the test's regex only knew the inline form. | Read the default from either form, and when it is an env var, assert that variable is what reaches `--max-age-hours`. | Only tests change. ## Testing - The four files: all red on `main`. With this change, 98 passed / 6 skipped (the two diffusion files) and 125 passed (the NVFP4 and Kaggle files); `tests/kaggle/` as a whole: 1081 passed. - Sabotage, each guard still catches what it is for: - **gloo:** making `check_effective_precision` a no-op fails the `REFUSED` case. - **klein:** removing the host RAM gate from `_resolve_base_precision` fails the new small-host test. Forcing a 16 GB runner over the whole file fails the same 5 cases CI did, plus the new one. - **NVFP4:** keeping the test library alive instead of destroying it fails the restore test. - **Kaggle:** a workflow default of `9` fails (it no longer matches `collect.DEFAULT_MAX_AGE_HOURS`), and so does not passing `$MAX_AGE_HOURS` to `--max-age-hours` (`MAX_AGE_HOURS never reaches --max-age-hours`).
After every chat turn the autosave PUTs the whole exported thread to
/api/chat/threads/{id}/messages. The route writes the rows, thensync_chat_messagesre-reads the entire thread, the route builds aChatMessageper row and serialises all of it back. The autosave caller (syncExportedRepositoryToBackendfromruntime-provider.tsx) never looks at that echo; only the delete path reads it, to republish the fork boundary. On a 150-turn chat that is a ~720 KB response per turn, and with ten inline images it is ~20 MB re-read, serialised, sent and parsed per turn for nothing.Change
PUT /api/chat/threads/{id}/messagestakes an opt-inechoMessagesquery flag (camelCase alias, likeallowGenerationEditon the single-message route). Defaulttruekeeps today's response. WithechoMessages=falsethe route passesreturn_rows=Falsetosync_chat_messages, which skips the trailinglist_chat_messagesre-read, and answers{"messages": []}. The write transaction, stored rows, status codes, error paths and theX-Unsloth-Chat-Revisionheader are unchanged.sync_chat_messages(..., return_rows=True)uses the same signature and docstring as Studio: skip no-op writes and the discarded re-read when importing external sessions #18862, so the two branches merge without conflict whichever lands first.syncChatMessages/syncStoredChatMessagestakeecho?: boolean.syncExportedRepositoryToBackendsendsecho: falseonly on the non-pruning autosave; any call withpruneMissingordeletedMessageIdsalways keeps the echo, sopublishForkBoundarystill receives the stored rows. Withecho: falsethe call resolves to the records it sent, so the result is the same whether the backend honours the flag or is an older one that ignores it and echoes as before.Results
Real
routes/chat_history.pythrough FastAPITestClienton a tempstudio.db, 150 turns (300 rows, ~717 KB payload), each timed PUT is an autosave that resends the thread with the last reply edited. 9 timed PUTs per process after a warm-up, 3 processes per arm, medians per process (shared host, so expect a few ms of jitter):echoMessages=falseechoMessages=falseThe text-only PUT drops from about 26 to 37 ms down to about 22 ms, and the image-heavy one from about 240 to 275 ms down to about 135 to 150 ms. Both changes are outside the A/A spread. The default response matches base byte for byte. A base backend sent
echoMessages=falseignores it and echoes the full body as before (735,399 and 20,735,899 bytes). On the client,JSON.parseof the echoed body in Node's V8 takes 0.85 ms for the text-only thread and about 19 ms for the image one; with the flag that parse is now a 15-byte body. Real HTTP transfer of the 20 MB echo over a socket is not part of the numbers above and is also saved.Tests
studio/backend/tests/test_chat_sync_no_echo.py: stored rows identical with and without the flag across insert, append and edit; the response is{"messages": []}and the revision header is still well formed; the default andechoMessages=truestill echo; prune still deletes under the flag; the 404 and 400 paths are unchanged;sync_chat_messages(return_rows=False)skips the re-read and returnsNone. On base, 3 of its 5 tests fail (the flag is ignored there); all pass on head.studio/frontend/tests/thread-sync-no-echo.test.ts:echo: falseadds?echoMessages=falseand resolves to the sent records; an echoing older backend is still accepted; the default call and any prune or delete call send no flag and return the server rows; a failed sync still throws; the autosave sendsecho: falsewhiledeleteThreadMessagekeeps the echo.npm teston base and head, plusnpm run typecheckon head.