Skip to content

Studio: keep a generated chat title in the conversation's language - #16413

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
debojyoti-dev:fix/title-language-16411
Nov 3, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
debojyoti-dev:fix/title-language-16411

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #16411. A chat title from Regenerate title (and from the automatic model title) does not reliably stay in the conversation's language. Two things in studio/frontend/src/features/chat/utils/chat-title.ts push it out of it:

  1. Both TITLE_SYSTEM_PROMPT and TITLE_REFRESH_SYSTEM_PROMPT say "ASCII only", which tells a model that follows the prompt closely to answer in English.
  2. normalizeTitle replaces every non-ASCII character with a space (/[^\x20-\x7E]+/g). So even a model that answers in French gets mangled, and a CJK title is emptied and replaced by the heuristic.

Changes

  • Both prompts drop "ASCII only" and add "Write the title in the same language as the conversation."
  • normalizeTitle keeps letters, combining marks and digits of any script (\p{L}\p{M}\p{N}), plus U+200C (ZWNJ, part of Persian spelling). Emoji and other symbols are still removed, and quotes, punctuation and the role-label echo check behave as before.
  • The 60-unit cap now uses the existing cutToUnits, so it can't split a surrogate pair.
  • If removing emoji leaves only invisible combining marks or joiners, cleanup returns no title so the existing fallback still runs.
  • Tests: the prompt assertions are updated, and the normalizeTitle table now covers French, Spanish, Japanese, Russian, Persian, emoji, and the 60-unit cut on non-ASCII text. The old "Café \u2014 Résumé Matrix" -> "Caf R sum Matrix" expectation is now "Café Résumé Matrix".

Testing

On Windows 11 with Node:

  • node --experimental-strip-types --test on chat-title-clip, chat-title-refresh and the other suites that import chat-title (custom-reasoning, pasted-text-attachment, saved-branch-head, sidebar-opened-chats, sidebar-row-pages-races, sidebar-server-paging): 146/146 pass. Before the source change, the 3 updated tests fail.
  • eslint on the changed files and tsc -p tsconfig.app.json --noEmit: clean.
  • Real model check: I ran unsloth/Qwen3.5-0.8B (transformers, CPU, greedy, 24 new tokens, thinking off) on French, Japanese and Spanish excerpts with the old and new refresh prompts, then passed each answer through normalizeTitle from main and from this branch:
Chat Old prompt + main cleanup New prompt + this branch
French Oui la boisson v g tale Oui la boisson végétale remplacera le
Japanese null (falls back to the heuristic) 東京夜桜スポット
Spanish Qu ndices para consultas por fecha Qué índices para consultas por fecha

This small model already mirrors the chat language, so the table mainly shows the cleanup fix. The prompt change is for models like Qwen3.5-9B from the issue, which follow "ASCII only" and answer in English. That model doesn't fit on this PC's 4 GB GPU, so I couldn't run it, and I couldn't test through a running Studio with llama-server either.

Final-head validation: 147 related frontend tests passed on Linux; the 45 targeted title tests passed with zero skips on Linux, macOS and Windows. Chromium, Firefox and WebKit each passed 1,038 cleanup cases per side. The emoji-only regression test fails on the submitted patch and passes with the fallback fix.

Before and after

French Studio UI, using Regenerate title on the same saved conversation in two isolated installs: merge base 66f1bedef0 and head b2bfd63d7. Both received the same controlled streaming response, Café Résumé Matrix. Before cleanup saved and displayed Caf R sum Matrix; after cleanup saved and displayed Café Résumé Matrix. The screenshot proves request construction, cleanup, persistence and display; it does not measure whether every model follows the language instruction.

Regenerated French title before and after Unicode cleanup

Both title prompts told the model "ASCII only", and normalizeTitle then
replaced every non-ASCII character with a space. A French title came
back as "Oui la boisson v g tale", a Spanish one as "Qu ndices", and a
Japanese one was emptied and dropped for the heuristic.

The prompts now ask for the title in the same language as the
conversation, and the cleanup keeps letters, marks and digits of any
script (plus ZWNJ for Persian) while still dropping emoji and symbols.
The 60-unit cut no longer splits a surrogate pair.

Fixes unslothai#16411
danielhanchen added a commit that referenced this pull request Nov 1, 2026
…16428)

## Summary

`Source lint`'s "No new risky loader call sites" step fails on every PR
based on current main. #16413 shows it, a frontend-only PR:

```
1 risky loader call site(s) not in the baseline:

  unsloth/models/float8_training.py:29  [dynamic-import] spec_from_file_location
```

#16387 (`0bfae01738`, "Add unsloth.precision") added `_load_precision()`
to `unsloth/models/float8_training.py`. It imports `unsloth.precision`.
When the file is loaded on its own, as the gloo test workers do by path
without the `unsloth` package, it falls back to
`spec_from_file_location` on `unsloth/precision/__init__.py` in the
sibling directory. The path is built from `__file__` and a constant, not
from any input, so it is safe. It just was not recorded.

## Change

`python scripts/lint_risky_loaders.py --update`, as the step asks, then
the new entry's `REVIEW ME` replaced with why it is safe. The diff adds
that one entry and changes nothing else in the baseline.

## Testing

- `python scripts/lint_risky_loaders.py`: exit 1 on main with the
finding above; here, `ok: 116 risky loader call site(s), all recorded`.
- `tests/security/test_lint_risky_loaders.py`: 46 passed.
danielhanchen added a commit that referenced this pull request Nov 1, 2026
…, not at collection (#16430)

## Summary

`(Python 3.13, g-r)` fails on several unrelated PRs (#16413, #16414,
#16415):

```
test_hub_source_env_reset_between_tests.py::test_the_next_test_starts_on_the_source_it_inherited
E   AssertionError: assert 'huggingface' == None
E    +  where 'huggingface' = get('UNSLOTH_STUDIO_HUB_SOURCE')
```

The test reads `_INHERITED = os.environ.get(SOURCE_ENV)` at module
import, during collection. Collection goes on after that. Any module
collected later that imports the app (for example
`tests/test_liveness_reports_*.py` with a module-level `from main import
...`) runs `apply_hub_settings()`, and that always writes
`UNSLOTH_STUDIO_HUB_SOURCE`. The conftest fixture
`_restore_hub_settings_env` then correctly restores the value each test
started with (`huggingface`), but the test compares it against the stale
collection-time value (`None`). The fixture is right. The test's
baseline is taken too early, and whether it fails depends on which files
share the shard. #16236 made it compare against the inherited source,
which made it sensitive to this.

## Change

The first test records the source env and the "other" source at the
moment it starts. That is exactly what the fixture saves and restores.
The second test compares against those, and fails with a clear message
if it runs without the first one. Nothing else changes.

## Testing

- **Repro of the CI failure:** run this file plus a later-collected
stand-in module that sets `UNSLOTH_STUDIO_HUB_SOURCE=huggingface` at
import, the way the app import does.
  - main: fails with the same `assert 'huggingface' == None`;
  - this branch: 3 passed.
- This file alone: 2 passed. With `UNSLOTH_STUDIO_HUB_SOURCE=modelscope`
in the environment (the case #16236 was for): 2 passed.
- Sabotage: with the conftest restore loop disabled, the second test
fails again. The test still catches a missing restore.
danielhanchen added a commit that referenced this pull request Nov 1, 2026
… their copy (#16431)

## Summary

`Chat UI Tests (extra)` fails on PRs based on current main (#16418,
#16421, #16413) in the chat width driver:

```
[chat-width] FAIL in step "measure the 'Standard' preset across 7 viewports" after 30.7s: TimeoutError: Locator.click: Timeout 30000ms exceeded.
  - waiting for get_by_role("option", name="Standard", exact=True)
```

#16408 (`8da4ba2f1c`, customizable new-chat greeting) renamed the chat
width option label from "Standard" to "Default"
(`settings.appearance.custom.chatWidth.standard`) in every locale. The
product change is intended. `tests/studio/playwright_chat_width.py`
clicked the option by its English text, so it waited for an option that
no longer exists.

## Change

- **`playwright_chat_width.py`:** the driver picks each preset by its
position in the open listbox, not by its copy. The component lists the
values as `["standard", "wide", "full"]`. The driver's own names for the
presets (`CHAT_WIDTH_PRESETS`) are unchanged, so the measurements and
messages read the same. I did not switch it to the `_en_catalog` reader,
because `test_en_catalog.py` pins every catalog-reading driver to the
composer workflow, and this one runs in `studio-ui-smoke.yml`.
- **New `tests/studio/test_chat_width_driver_presets.py`:** checks that
`appearance-custom-controls.tsx` still maps over `["standard", "wide",
"full"]` in that order, and that the driver has one preset per option. A
reorder or a new option then fails here instead of measuring the wrong
preset.

## Testing

- The new test, `test_en_catalog.py` and
`test_playwright_suites_run_in_ci.py`: 54 passed.
- Sabotage: with the component's order swapped to `["wide", "standard",
"full"]`, the new test fails.
- The driver itself needs a live Studio. It runs in this PR's own `Chat
UI Tests (extra)` job, and I will only merge once that is green.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen danielhanchen self-assigned this Nov 3, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 3, 2026
@danielhanchen

danielhanchen commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

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

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 ae010b31ea (this PR's b2bfd63d7)

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

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

Reviewed commit: ae010b31ea

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror ae010b31ea (this PR's b2bfd63d7).

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

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 3, 2026
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.

Regenerate title language is model-dependent — prompt carries no language instruction

2 participants