From a020e2bb31fecad18c76b610f32bc57bfecdf4d8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 12 Sep 2026 19:09:55 +0200 Subject: [PATCH] fix: a greeting does not name the thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01TqXevQJhxFrM7jJg82cgZN --- backend/app/routers/ai_mode.py | 7 +++++-- backend/tests/test_ai_mode.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/app/routers/ai_mode.py b/backend/app/routers/ai_mode.py index f32d905..708b7a9 100644 --- a/backend/app/routers/ai_mode.py +++ b/backend/app/routers/ai_mode.py @@ -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() diff --git a/backend/tests/test_ai_mode.py b/backend/tests/test_ai_mode.py index e489458..5671b22 100644 --- a/backend/tests/test_ai_mode.py +++ b/backend/tests/test_ai_mode.py @@ -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?')