Skip to content

fix(conversation): fix failed conversation auto-titles#1992

Merged
piorpua merged 2 commits intoiOfficeAI:mainfrom
Ericwong5021:fix/conversation-title-refresh
Mar 31, 2026
Merged

fix(conversation): fix failed conversation auto-titles#1992
piorpua merged 2 commits intoiOfficeAI:mainfrom
Ericwong5021:fix/conversation-title-refresh

Conversation

@Ericwong5021
Copy link
Copy Markdown
Contributor

Summary

  • Stabilizes conversation auto-titling by anchoring the title to the first user prompt
  • Fixes cases where a conversation could stay as New Chat after multiple turns
  • Prevents later turns from overriding the initial topic when the title was still unset

Changes

  • Moves auto-title triggering earlier in the send flow so it no longer depends on a later successful callback
  • Derives the title from the first user message in conversation history
  • Falls back to the current input only when the conversation has no user message yet
  • Adds a small shared auto-title utility for extracting the first-line title
  • Revalidates the active conversation view after title updates
  • Adds targeted regression tests for auto-title derivation, hook behavior, and conversation page refresh

Why

Previously, auto-title updates were timing-sensitive:

  • some conversations stayed as New Chat because the rename path was missed
  • later retry/follow-up turns could become the title if the initial rename never happened

This PR makes the title source deterministic: use the first user prompt.

Tests

  • bun run vitest tests/unit/chat/autoTitle.test.ts tests/unit/chat/useAutoTitle.dom.test.tsx tests/unit/chat/conversationIndex.dom.test.tsx tests/unit/renderer/platformSendBoxes.dom.test.tsx tests/unit/renderer/useGeminiInitialMessage.dom.test.tsx tests/unit/RemoteSendBox.dom.test.tsx

Scope

  • Fixes auto-title behavior for new and actively opened conversations
  • Does not include a bulk backfill for already existing historical conversations with stale default titles

@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 31, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

Code Review:fix(conversation): fix failed conversation auto-titles (#1992)

变更概述

本 PR 重构了会话自动标题功能,将标题来源从当前输入改为对话历史中的第一条用户消息,解决了多轮对话后标题仍为"New Chat"或被后续消息覆盖的问题。改动涉及 useAutoTitle hook、所有平台 SendBox 组件(acp/codex/gemini/nanobot/openclaw/remote)、会话页面 index.tsx,以及新增的 autoTitle.ts 工具函数。


方案评估

结论:✅ 方案合理

方案正确解决了目标问题:将 auto-title 的来源从"当前发送的消息"改为"历史中的第一条用户消息",使标题确定性可复现。将 checkAndUpdateTitle 调用提前到 send IPC 之前,配合 fallbackContent 参数处理首条消息尚未入库的边界情况,设计考虑周全。新增的 syncTitleFromHistory 在会话页面加载时也会尝试补齐标题,覆盖了用户刷新页面的场景。方案与项目现有架构(IPC bridge、SWR、emitter)保持一致,无过度工程化。


问题清单

🔵 LOW — autoTitle.ts 中 filter + [0] 可用 find 替代

文件src/renderer/utils/chat/autoTitle.ts,第 7–13 行

问题代码

const lines = withoutThinkTags
  .replace(/\r/g, '')
  .split('\n')
  .map((line) => line.trim())
  .filter((line) => line && line !== '```');

const firstLine = lines[0] ?? '';

问题说明:oxlint prefer-array-find 规则建议使用 find 替代 filter()[0],避免创建中间数组。

修复建议

const firstLine = withoutThinkTags
  .replace(/\r/g, '')
  .split('\n')
  .map((line) => line.trim())
  .find((line) => line && line !== '```') ?? '';

🔵 LOW — pageSize: 1000 获取全部消息仅为找第一条用户消息

文件src/renderer/hooks/chat/useAutoTitle.ts,第 21–25 行

问题代码

const messages = await ipcBridge.database.getConversationMessages.invoke({
  conversation_id: conversationId,
  page: 0,
  pageSize: 1000,
});

问题说明:为了找到第一条用户消息,获取了最多 1000 条消息。对于大多数会话这不是问题,但对于长对话可能产生不必要的 IPC 开销。可考虑未来提供更精准的查询接口(如按 position 和 type 筛选),当前实现可接受。


汇总

# 严重级别 文件 问题
1 🔵 LOW autoTitle.ts:7-13 filter + [0] 可用 find 替代(lint 建议)
2 🔵 LOW useAutoTitle.ts:21-25 pageSize 1000 获取全部消息仅为找首条用户消息

结论

批准合并 — 无阻塞性问题。方案设计合理,代码结构清晰,测试覆盖了核心逻辑(autoTitle 工具函数、useAutoTitle hook、conversation 页面联动)。两个 LOW 级别建议可在后续迭代中优化。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua piorpua added bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed and removed bot:reviewing Review in progress (mutex) labels Mar 31, 2026
@piorpua piorpua added bot:reviewing Review in progress (mutex) and removed bot:ci-waiting CI failed and author notified — snoozed until new commits are pushed labels Mar 31, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit 6c1f1b3 into iOfficeAI:main Mar 31, 2026
12 of 14 checks passed
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants