Skip to content

Studio: keep chat titles whole so a wider sidebar shows more of them - #8078

Merged
shimmyshimmer merged 26 commits into
mainfrom
fix/studio-chat-title-clip
Aug 7, 2026
Merged

shimmyshimmer merged 26 commits into
mainfrom
fix/studio-chat-title-clip

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

Widening the chat sidebar never revealed any more of a chat title. The rows kept their ... no matter how much room they had.

The clip was not in the layout, it was baked into the stored title. When a chat had no model written title we fell back to the first user message cut at 48 characters with a literal ... appended, and that string is what went into the database. No width could bring back characters that were never stored.

The giveaway is that the ... lands at a different x on each row. A CSS clip ends every row at the same pixel, a character count ends them wherever the glyphs happen to fall.

Changes

  • chat-title.ts (new): the fallback title now keeps the whole first line and lets the sidebar row clip it with CSS, so the text grows with the sidebar. The 120 character cap only keeps a pasted wall of text out of the store and matches the rename input's maxLength.
  • repair-legacy-chat-titles.ts (new): titles already stored pre-cut are rewritten from their own first message when the sidebar loads, otherwise existing chats would keep the old clip forever. One batched messages:batch call covers every candidate rather than one request per row.
  • use-chat-sidebar-items.ts: runs the repair after each load and skips threads it already tried.

Notes on the repair

  • A title only qualifies if it is exactly the old 48 character cut of its own first user message, so a chat someone renamed to something ending in ... is left alone.
  • A title patch does not touch updatedAt, so Recents keeps its order while rows are rewritten.
  • It takes whichever threads the caller just loaded, so a project scoped sidebar repairs its own rows instead of waiting for a full listing.

Testing

  • New tests/chat-title-clip.test.ts covers the title itself and the repair plan, including the rename that must not be touched.
  • Full suite 734 passing, typecheck and eslint clean, production build clean.

Chat titles fell back to the first user message cut at 48 characters with
a literal "...", so the clip was baked into the stored title and widening
the sidebar could never reveal more. Store the whole first line and let
the sidebar row clip it with CSS, capped at 120 (the rename maxLength).

Titles already stored pre-cut are rewritten from their first message on
load, in one batched call. A title has to be the exact old cut of its own
message to qualify, so a rename ending in "..." is left alone, and the
patch leaves updatedAt alone so Recents keeps its order.

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

ℹ️ 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 +46 to +48
cleaned.length > LEGACY_FALLBACK_TITLE_MAX &&
cleaned.slice(0, LEGACY_FALLBACK_TITLE_MAX) === kept
);

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 Preserve manually shortened titles during migration

A title manually renamed to the first 48 characters of its own first message followed by ... is indistinguishable from the old fallback under this predicate, so merely loading the sidebar permanently expands that intentional custom title. Checking the message prefix proves the text matches but not that the title was generated by the legacy code; an explicit provenance/version marker or a non-destructive migration path is needed to avoid rewriting user-authored values.

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.

I looked at this one carefully and I do not think it is actionable as written.

A provenance marker cannot be applied retroactively. The titles this migration targets were written by the old code with no marker on them, so any migration of that existing data has to be a heuristic, and the non-destructive option is to not migrate at all, which leaves everyone with permanently clipped titles.

The predicate is already as tight as it can be: the title has to be exactly the first 48 characters of its own first user message plus .... To be a false positive someone has to have hand typed a rename that reproduces their own opening line character for character and then appended three dots. If that somehow happens the result is the title expanding to the full first line, which a rename undoes.

Leaving as is, but the check is covered by a test that asserts a rename ending in ... is not touched.

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.

A collision needs a user to have renamed a chat to exactly the first 48 whitespace-collapsed characters of that same chat's own opening prompt plus a literal dot-dot-dot, at exactly 51 characters. The realistic way that string exists is that it is the legacy fallback this migration targets, and the outcome is the full first line of the same message, not data loss.

Review follow-ups on the title migration.

Cut the fallback title on code points. A UTF-16 cut can halve an emoji,
and the lone surrogate that leaves parses fine but raises
UnicodeEncodeError when the backend binds it into SQLite, so the write
failed for those chats.

Read the titles again right before patching, so a rename that lands while
the messages request is in flight wins over the rewrite.

Keep a thread marked attempted only once it has been read and written. A
failed read or PATCH now clears the mark so a later refresh retries
instead of leaving the row clipped for the session.

Cap each pass at 100 rows and hold writes to 4 in flight, so a long
history drains over a few refreshes rather than putting its whole backlog
on a synchronous SQLite route at once.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The last review round narrowed the rename race to the patch round trip
but could not close it: a read and a write are two requests, so a rename
landing between them was still overwritten.

Add expectedTitle to PATCH /api/chat/threads/{id}. The guard rides in the
UPDATE's WHERE clause, so the check and the write are one statement, and
a stale rewrite gets 409 instead of clobbering the user's title. Other
callers are unaffected: without the field the patch applies as before.

The repair now sends the title it planned from and drops the extra list
call the previous commit added, since correctness comes from the guard
rather than from narrowing the window.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

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

ℹ️ 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 +135 to +137
// Older pre-cut titles cannot grow with the sidebar. Each patch fires
// a history update, which reloads the list.
void repairLegacyChatTitles(threads).catch(() => undefined);

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 Reuse the sidebar's existing message batch

Whenever requireMessages is true, the preceding listStoredChatThreadsWithMessages call has already fetched the messages for every listed thread with batchListChatMessages, but invoking the repair here discards that map and immediately fetches the full histories of up to 100 candidates again. For accounts with large conversations this duplicates SQLite reads, response serialization, and transcript transfer during sidebar startup; return or pass through the message map from the first batch, or integrate repair planning into that load.

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.

Good catch, and it is worse than it looks: listStoredChatThreadsWithMessages was batching every listed threads messages purely to test whether each one had content, then throwing the map away. The repair then refetched up to 100 of those same histories.

It now returns the map alongside the threads and the sidebar passes it down, so on that path the repair makes no message request at all. It still falls back to a batch call when a caller has no map, since the hook can run with requireMessages false. Only one call site, so the shape change was contained.

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.

Performance only, and it was implemented in 4f583d1 then deliberately reverted in c79de38. Reusing a snapshot the caller fetched earlier re-widens the window between the message read and the write, which is the exact hazard the opening-message guard exists to close.

Unsloth and others added 2 commits August 6, 2026 22:33
Three review follow-ups on the migration.

Reuse the messages the sidebar just fetched. listStoredChatThreadsWithMessages
already batched every listed thread's messages and threw the map away, so the
repair was refetching up to 100 of the same histories on startup. It now hands
the map over and the repair only calls out when it has none.

Read Dexie when the backend has nothing for a thread. A legacy chat whose
import has not landed yet reads empty from a successful batch call, so the
catch-based retry never fired and the row sat marked with its title still
clipped.

Schedule the next page instead of relying on a write. Paging drained on the
history update each PATCH fires, so a page that wrote nothing left the rest of
the backlog waiting on an unrelated refresh.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Unsloth and others added 2 commits August 6, 2026 22:57
The paging added last commit had a hole. Failed writes are unmarked so a
later refresh can retry them, but the next page was selected off the same
thread list, so it drew those rows straight back in: with a failing PATCH
the drain re-ran the same page every 500ms and never reached the rest.
The page now hands back the rows it did not take and the next one reads
from those.

Take the earliest user message rather than the first row of the array. A
Dexie read arrives in index order, so a chat whose ids do not sort by
createdAt could be compared against a later turn and skipped. The local
read is also sorted the way the backend lists messages.

Keep a row retryable when nothing was found for it. A read that failed
was landing in the map as an empty array, which the repair then took as
proof the chat had no opening message and wrote the row off for the
session. The map now carries only what was actually read, and rows that
come back with nothing stay eligible for a later refresh.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@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: 1bcd3547ed

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

// A chat still only in Dexie (legacy import pending or failed) reads empty
// from the backend, so look locally before writing it off.
await runWithConcurrency(
threadsMissingMessages(ids, messages),

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 Fall back when the opening user message is missing

For a partially imported legacy chat where the backend contains any later message but the opening user message still exists only in Dexie, threadsMissingMessages treats the nonempty backend array as complete and skips the local read. planLegacyTitleRepairs then either finds no user message or compares against a later turn, while the thread remains in attempted, so its clipped title is never repaired during this SPA session. Select the Dexie fallback when the opening user message is unavailable, or merge local messages for repair candidates rather than checking only whether the array is empty.

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.

Right, and my fallback was the wrong shape for it. Keying off "the array is empty" only catches a chat that is entirely in Dexie. A part-imported one, opening turn local and later turns already on the backend, reads as complete, so the plan had nothing to compare the clipped title against and the row stayed marked.

The trigger is now the outcome rather than the array: any candidate the first plan could not explain gets the local read, and the two sources are merged by id before planning again. That covers the entirely-local case as a subset, so it replaces the old check rather than adding to it. Rows that come back with nothing known at all are still left unmarked for a later refresh.

The test walks the exact shape from your comment: backend holds only a later turn, first plan is empty, the old empty-only check reports nothing to do, threadsWithoutRepairs picks the row out, and after merging the local opening message the rewrite is planned.

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.

The consequence is a cosmetic title staying clipped for this session, retried on the next app load. Nothing is written wrong and nothing is lost. The Dexie fallback this asks for is the deleted-prompt resurrection reported in the two items below it, which is why 8d730f3 removed it.

The local read only fired when a thread came back with no messages at
all, so a part-imported legacy chat, holding its opening turn in Dexie
while later ones are already on the backend, read as complete. The plan
then had no opening message to compare against, found nothing to do, and
left the row marked with its title still clipped.

Any candidate the first plan could not explain now gets the local read,
and the two sources are merged by id before planning again.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Unsloth and others added 2 commits August 6, 2026 23:46
Three review follow-ups.

Queue the passes. Several sidebars can be mounted at once and each was
free to claim its own page and its own four write lanes, so
REPAIR_CONCURRENCY only ever bound a single pass.

Let a local read fail on its own. A rejecting Dexie read came out of the
gather step and threw away the whole page, including repairs already
planned from backend data, and returned before scheduling the rest. It
now leaves that one row unexplained and the page carries on.

Stop trusting a local-only message once the import is done. Deleting a
message prunes the backend and leaves the Dexie copy behind, so merging
unconditionally could put a deleted opening prompt back and expand the
title from it. Local rows are now trusted on the same terms
listStoredChatMessages already merges them on: while the import is
unfinished, or when the backend holds nothing.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Unsloth and others added 2 commits August 7, 2026 00:09
The local read is gone. Its rule trusted Dexie whenever the backend held
nothing for a thread, and that is also what a chat looks like once every
message in it has been deleted: the prune clears the backend and leaves
the Dexie rows, so the repair could rewrite a title out of a prompt the
user removed. That is the second way this has been wrong, and narrowing
the rule again only moves the next case along.

A chat whose messages are not stored yet now reads as unknown, which
already leaves it retryable, so it gets rewritten on a later pass once
its import lands rather than by reading around the backend. The case
genuinely lost is an import that never completes, where the title stays
clipped.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Unsloth and others added 2 commits August 7, 2026 00:31
Two ways deleted content could still reach a title.

The sidebar's map was not backend-only. Its entries for a thread the
batch call returned nothing for come from listStoredChatMessages, whose
zero-backend branch merges the Dexie rows, and a chat whose messages have
all been deleted looks exactly like that. Removing the repair's own Dexie
read last commit closed one door and left this one open.

That map is also fetched at sidebar load, not at write time, so a prompt
deleted after the load could still be expanded into a title much later:
the title guard does not notice, since deleting a message leaves the
title alone.

The repair now makes its own batched call per page, immediately before
planning and writing, and takes nothing from callers. listStoredChatThreadsWithMessages
goes back to its original shape. The window is now one pass rather than
the whole session, though a delete inside that window is still possible.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Unsloth and others added 2 commits August 7, 2026 00:52
expectedTitle is enforced by the backend, so it only guards where the
backend knows the field. The desktop app ships its own frontend and can
meet an older one, which ignores the field and applies the write, and
this API layer already carries fallbacks for exactly that pairing. The
repair was assuming a guard it might not have.

Read the page's titles back immediately before writing and drop any row
that no longer holds the title it was planned from. One call for the
page, taken last. Where the backend does enforce expectedTitle the write
stays atomic; where it does not, this is what respects a rename.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…he cap

A backend from before expectedTitle drops the field and applies the write,
so on that pairing a rename landing between the title read and the PATCH
was still lost. Probing by sending a conditional patch is not available:
on the backend in question that request is itself the harm. The served
OpenAPI schema answers without touching anything, so the migration now
runs only when ChatThreadPatch declares the field, and anything
unreadable counts as unsupported. A failed probe is not cached, so one
hiccup does not park the migration for the session.

The cap also overran the rename input. It kept 120 units and then added
the ellipsis, and counted code points where maxLength counts UTF-16
units, so an emoji title could reach 241 of them and could not be edited
until a character was deleted. The ellipsis now comes out of the same
120-unit budget, still without splitting a pair.
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 7, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0c7a48fe99

ℹ️ 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 added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 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. Delightful!

Reviewed commit: 0f0c261237

ℹ️ 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
shimmyshimmer merged commit 467e564 into main Aug 7, 2026
52 of 56 checks passed
@shimmyshimmer
shimmyshimmer deleted the fix/studio-chat-title-clip branch August 7, 2026 14:09
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Oct 19, 2026
Fixes unslothai#9712

## What was wrong

FastAPI's built-in `/openapi.json` route is `async`, and it builds the
schema inside that route, on the event loop. Studio has about 550
routes, so the first build per backend process takes seconds, and
nothing else is served while it runs: `/api/liveness`, `/api/health`,
chat, everything.

Every session triggers it. Since unslothai#8078 the chat sidebar fetches
`/openapi.json` to check whether the backend supports guarded title
patches before it repairs legacy chat titles.

## How it was found

The stall watchdog from unslothai#9715 is armed in `studio-mac-ui-smoke.yml` and
logs `event loop answering again after Xs` whenever a no-op scheduled
onto the loop takes more than 1s. I went through the server logs from
the 167 runs whose artifacts are still retained (Oct 18-19):

- 126 of 167 runs had at least one loop stall over 1s, 183 stalls in
total, the longest 5.3s.
- 182 of the 183 overlap a slow `/openapi.json`. The one left over is a
single 2.6s probe during `/api/inference/validate`.
- The first `/openapi.json` per backend took 2.26s median, 3.20s p90 and
5.94s max on the macOS runner (622 backends). Later calls hit FastAPI's
cache: 17ms median.

None of those runs had a 10s+ stall or a faulthandler dump, and the logs
from the runs in the original report have expired. So I cannot prove the
10-33s windows in unslothai#9712 were this. The shape does match, though: a
request accepted and then left sitting, nothing served, and recovery on
its own. The same CPU-bound build on a starved 3 vCPU runner that is
also running CPU-only llama-server could plausibly last that long.

## The change

`FastAPI(openapi_url=None)` turns off the built-in route, and
`/openapi.json` is registered on the same path. It builds the schema
with `asyncio.to_thread`, under a lock so that two cold requests build
it once, and later requests read FastAPI's existing cache. The
`root_path` server entry is added the same way FastAPI's route adds it.
`app.openapi_url` stays `/openapi.json`, so `/docs` and `/redoc` are
unchanged, and `app.openapi()` still works for callers in the same
process. The served schema is byte-identical.

The build still holds the GIL while it runs, but the loop now gets a
turn at every switch interval, so requests keep being served during the
build.

## Verification

Repro: an in-process ASGI client polls `/api/liveness` on the backend's
own event loop while the first `/openapi.json` is in flight.

| | first `/openapi.json` | worst liveness delay during it | schema |
|---|---|---|---|
| main | 3.44s | 3490ms (loop blocked) | 1,049,101 bytes |
| this PR | 4.10s | 292ms | 1,049,101 bytes, identical |

This host was heavily loaded (loadavg ~690), so read these as ratios,
not absolute times.

`tests/test_openapi_off_the_event_loop.py` slows the cold build by 3s so
the result does not depend on machine speed:

- main: 2 failed (event loop blocked 7.6s and 7.7s), 1 passed (the
behaviour-parity test)
- this PR: 3 passed

Route, auth and docs suites (`test_middleware`, `test_desktop_auth`,
`test_keyless_api_access*`, `test_lan_access_settings`,
`test_quick_tunnel_streaming_routes`, `test_mcp_forward`,
`test_chat_history_routes`, `test_account_installation_mutations`,
`test_health_answers_within_probe_budget`, `test_stall_watchdog`) pass
when run serially. Under `-n 8` on the loaded host,
`test_desktop_auth::test_health_response_reports_desktop_capability_fields`
fails the same way on main.

End to end on macOS (`Chat UI, API, Update and GGUF inference`, staging
run 39253072492, green): the first `/openapi.json` per backend still
took 1.76-2.82s to build, but none of the 6 backend logs had a single
`consecutive slow probes` line, so the event loop never went more than
1s without answering. On main, 126 of 167 runs had at least one.
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.

2 participants