Skip to content

fix(ui): name a chat when its first message is taken, and title cloud chats - #5580

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/chat-title-on-send
Oct 23, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/chat-title-on-send

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A chat you leave while it is still answering no longer stays "New Task" forever. It is named after its first question as soon as the server takes the message, whether or not its window is still open. Cloud chats (Fireworks via Lemonade) now get a real written title too. Before this change, every cloud chat was titled with its truncated first question, because the title request ran out of tokens while the model was still reasoning.

Test plan

  • python -m pytest tests/unit/chat/ui/test_chat_title_on_send.py tests/unit/chat/ui/test_chat_helpers.py
  • python -m pytest tests/unit/chat -n 4
  • cd src/gaia/apps/webui && npx tsc --noEmit -p . && npx vitest run
  • Agent UI with fireworks.deepseek-v4p1-flash: send "write a 1200-word essay on the history of tea" in a new chat, click New chat within a few seconds and ask something else. The first chat shows its question as its name at once, then a short written title once its answer finishes.
  • A local-model chat still gets a written title, and a "New Task" draft you never send to is still removed when you leave it.
🔍 Technical details

Root causes

  • F41. The only provisional title was a client-side updateSession in ChatView.tsx's onDone. It runs only if that chat's view is still mounted when the stream ends. The server titler should have covered this, but it never produced anything for a cloud model (see F42).
  • F42. _generate_session_title (src/gaia/ui/_chat_helpers.py, the old max_tokens = 96 if … else 24) sent cloud models max_completion_tokens=24, and no_thinking_kwargs is empty for cloud ids. Fireworks' deepseek-v4p1-flash reasons by default. Measured against the real API, it returned content: null, finish_reason: "length" and reasoning_tokens: 24, so the titler fell back to the first question every time. reasoning_effort: "none" is not a portable fix: glm-5p3-flash and gpt-oss-120b reject it with a 400. Cloud title requests now get 512 tokens. All three models then return a title in 6 to 182 tokens.

Also fixed on the way

  • The titler used session_model, which is the stored or custom model before resolve_session_model. It now uses the model the turn actually ran on, on both the streamed (relayed included) and plain paths. As a result, a local turn is never titled by a cloud model. A local guard model whose stand-in default is a cloud model is also no longer titled in the cloud.
  • _should_retitle now also accepts the provisional question title, so the LLM title can replace it. A rename made while a title is being generated wins.
  • The DB-update failure was logged at debug inside a broad except. It is now a warning for sqlite3.Error. Exceptions escaping a _spawn_background task are now logged instead of vanishing.
  • The client no longer writes a title. When the server first accepts the message it calls getSession once, so the sidebar shows the server's name immediately. The 5 s session poll brings in the LLM title. sessionCleanup.ts is unchanged: a chat that never sent anything is still "New Task" with zero messages.
  • An attachment-only first message is named after the file ([name](url) → name).

Pre-existing, unrelated: tests/unit/chat shows one teardown error in test_sse_confirmation.py. A thread left over from test_sidecar_relay_profiles.py setup tries to spawn a daemon. It reproduces on origin/main without this change.

… chats

A chat left mid-answer stayed "New Task" for good, because only the open
window named it. The server now names the chat after its first question as
soon as it takes the message, unpinned, so the auto-titler can still
replace it.

Cloud chats never got a written title: the title request allowed 24
tokens, and fireworks.deepseek-v4p1-flash reasons by default, so it spent
all of them reasoning and returned no content. Cloud title requests now
get room to reason. The titler also runs on the model the turn actually
ran on (relayed turns included), never sends a local chat to a cloud
model, and logs failures as warnings instead of at debug.
@github-actions github-actions Bot added the tests Test changes label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

A chat now gets its name from the server as soon as the server accepts the first message, so a chat you leave mid-answer no longer stays "New Task". Cloud chats get a real written title, because the title request now leaves room for the model's reasoning. The server-side design is sound: renames you make still win, a local chat is never sent to a cloud model just to name it, and the new tests check the real request shape.

Two things worth fixing before merge:

  • Attach real-world evidence. This change is visible in the Agent UI sidebar, but the PR has no screenshot and no captured API output. The manual test-plan items are all unchecked.
  • A failed title attempt now retries on every later turn. When titling fails, the chat keeps its question-name, and that name stays eligible for replacement. Each later message (at most once per 30 s) makes another title call, which costs real money on a cloud model. Writing the question-name back as the final title, or recording that titling was already tried, would stop that.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review alone. The Agent UI sidebar behaviour and the Fireworks title call were not exercised here.

🔍 Technical details

🟡 Missing real-world evidence for an Agent-UI-visible change
The PR changes what the sidebar shows (ChatView.tsx) and what POST /api/chat/send writes. Please add a before→after screenshot of a "New Task" chat left mid-answer, or at least the route evidence. That means POST /api/chat/send followed by GET /api/sessions/{id} showing the provisional title, title_is_custom: false, then the LLM title.

🟢 Retitle retries every turn after a failed title (src/gaia/ui/_chat_helpers.py:311-339)
_should_retitle(..., provisional=_title_from_question(user_msg)) keeps returning True while the title equals the question-name. If _generate_session_title returns None or falls back to _title_from_question (equal to current_title, so it early-returns at :339), nothing marks the attempt as done. The next turn more than 30 s later re-issues the request (throttle at :849-855). That includes background model leases on local models and billed calls on cloud models. One option is to stop retrying once a title request has run for the session, for example by keeping _AUTO_TITLE_LAST_AT as an "attempted" marker that is not time-limited for the provisional case. Retrying on failure is also defensible, but then it should be a deliberate choice with a cap.

🟢 Client only recognises 'New Task' as unnamed (ChatView.tsx:711)
The server treats "New Chat" and "Untitled" (and an empty title) as placeholders too, so a session created with those names waits for the 5 s poll instead of refreshing at once. Also, session?.title !== 'New Task' is true when session is undefined, which silently skips the refresh. That is harmless, but worth knowing.

🟢 Rename guard is check-then-write (_chat_helpers.py:342-346)
A rename that lands between get_session and update_session is still overwritten. The window is tiny. If it matters, a conditional UPDATE … WHERE title = ? AND title_is_custom = 0, like set_provisional_title, would close it.

Strengths

  • The titler now runs on the resolved turn model (turn_box["model"], and the streaming model_id after resolve_session_model) rather than the stored or custom model. This fixes a real mismatch on both paths, and _title_model_for refusing a cloud stand-in for a local guard model is the right privacy call.
  • set_provisional_title is transactional and only touches placeholder, unpinned titles. The except Exception → (sqlite3.Error, RuntimeError) warning and the _log_background_failure done-callback remove two silent-failure paths, as CLAUDE.md asks.
  • The tests assert the outgoing cloud request's shape (no llama.cpp-only fields, auth header, token budget) and drive a relayed sidecar turn end-to-end. These are boundary checks, not just "was it called".

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Checked live in the Agent UI with Fireworks DeepSeek V4 Flash: a chat left 2 s after sending is titled from its question within 3 s, and the model's title replaces it once the answer finishes.

🔍 Technical details

Sent "Chat C: explain how tides work in about 600 words." then clicked New chat after ~2 s.

  • t+3 s: GET /api/sessions → title "Chat C: explain how tides work in about 600 words" (before: stayed "New Task" forever)
  • t+40 s: title "Tides explanation in 600 words", shown in the sidebar (before: no Fireworks chat ever got a model-written title)
    Live build with this branch merged, relayed sidecar, desktop-style install.

A failed title request left the question-name in place, which kept the
chat eligible, so every later turn more than 30 s apart made another
title call, billed on a cloud model. Each session now gets one title
request per server run. The title is written with a conditional UPDATE,
so a rename that lands mid-request always wins, and the view refreshes
the name for every placeholder title the server recognises, not only
"New Task".
@kovtcharov

Copy link
Copy Markdown
Contributor Author

A failed title no longer retries on every later turn: each chat gets one title request, so a cloud chat is billed for it once. Also took the two smaller suggestions. Live Agent UI evidence (a chat left 2 s after sending, then titled by Fireworks) is in this comment.

🔍 Technical details
  • Retry: _AUTO_TITLE_TRIED records a session once its title request is issued, which replaces the 30 s timestamp throttle (now redundant). It is held in memory, so a server restart allows one more attempt. Failing for good after a single try was a deliberate choice: the question-name is a usable title.
  • Rename race: the write is now ChatDatabase.replace_auto_title, one UPDATE … WHERE title = ? AND title_is_custom = 0, in place of the separate read and write.
  • Client: isPlaceholderTitle (utils/sessionTitle.ts) mirrors the server's PLACEHOLDER_TITLES, so "New Chat", "Untitled" and empty titles refresh right away. A missing session now refreshes too, which costs one GET. ChatView.tsx is 101,471 bytes (LF).
  • Tests: new tests cover a failed title not being re-requested, the conditional write losing to a rename or a pin, and the client refresh for each placeholder. tests/unit/chat -n 4 (2,177) and test_chat_ui_integration.py pass. Webui tsc and the build pass. vitest passes 1,527 of 1,528. The one failure is in ChatView.historyNotice/sessionPanel and only happens under full-suite load: both use a non-placeholder title and pass on their own. util/lint.py --all is clean.
  • Commit: 3563298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants