fix: a greeting does not name the thread

The first message named the conversation, so a rail of them read "hi", "hello",
"hi". The name now waits for the first turn that is actually a question —
usually the very next one — and the thread stays "New chat" until then.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TqXevQJhxFrM7jJg82cgZN
This commit is contained in:
Daniel 2026-09-12 19:09:55 +02:00
parent c099dd16fb
commit a020e2bb31
2 changed files with 20 additions and 2 deletions

View file

@ -212,8 +212,11 @@ async def ask(conversation_id: int, data: AskIn, db: Session = Depends(get_db),
answer = ConversationMessage(conversation_id=conversation.id, role="assistant",
content=reply, citations=citations)
db.add(answer)
# The first question names the thread; "New chat" ages badly in a rail of them.
if conversation.title == "New chat":
# The first *question* names the thread; "New chat" ages badly in a rail of
# them, and a rail of threads called "hi" ages worse. A greeting is not what
# the conversation turned out to be about, so the name waits for the turn
# that is — which is usually the very next one.
if conversation.title == "New chat" and mode != "chat":
conversation.title = question[:80] + ("" if len(question) > 80 else "")
conversation.updated_at = datetime.utcnow()
db.commit()

View file

@ -191,6 +191,21 @@ class AiModeRouteTests(_AiModeBase):
_, second = self.ask('And the workup?', conversation_id)
self.assertEqual(second.json()['title'], 'What causes febrile seizures?')
def test_a_greeting_does_not_name_the_thread(self):
"""A rail of threads called "hi" is worse than one called New chat.
The name waits for the turn the conversation turns out to be about,
which is usually the very next one.
"""
with self.reply_with("Hello! What would you like to work on?"):
conversation_id, first = self.ask('hi')
self.assertEqual(first.json()['title'], 'New chat')
self.assertEqual(first.json()['source_count'], 0)
with self.reply_with("Fever, usually."):
_, second = self.ask('What causes febrile seizures?', conversation_id)
self.assertEqual(second.json()['title'], 'What causes febrile seizures?')
def test_both_turns_are_stored_so_a_thread_can_be_reopened(self):
with self.reply_with("Because of fever [[article:7]]."):
conversation_id, _ = self.ask('why do febrile seizures happen?')