Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Fix cross-model auto title generation reliability#34

Open
ai-jiaqian wants to merge 4 commits intoErlichLiu:mainfrom
ai-jiaqian:codex/fix-cross-model-title-generation
Open

Fix cross-model auto title generation reliability#34
ai-jiaqian wants to merge 4 commits intoErlichLiu:mainfrom
ai-jiaqian:codex/fix-cross-model-title-generation

Conversation

@ai-jiaqian
Copy link
Contributor

What's fixed

  • fix chat first-turn auto-title trigger reliability across conversation switches/resend/edit paths
  • improve provider-agnostic title extraction for OpenAI/Anthropic/Google compatible responses
  • add deterministic local fallback title generation in chat and agent flows
  • add structured title diagnostics: http_non_200 / empty_content / parse_failed with status + dataPreview
  • fix Anthropic-compatible gateway title request compatibility by removing thinking: { type: "disabled" } in title requests

Root cause

  • title trigger could be skipped due to stale message state when switching conversations
  • some gateways/models returned alternative payload shapes not covered by old parsing
  • Anthropic-compatible gateway (qianfan coding endpoint) rejected title requests with 422 because thinking.type=disabled

Validation

  • bun tests for title extraction/trigger/fallback/diagnostics all pass
  • TypeScript checks pass for shared/core/electron

Notes

  • openspec/ remains gitignored

Copy link
Owner

@ErlichLiu ErlichLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ai-jiaqian,感谢这个 PR!你识别出了多个真实存在的可靠性问题,修复方向是正确的 👍

亮点:

  • 移除 thinking: { type: "disabled" } 修复了 Anthropic 兼容网关的 422 错误,这是个真实 bug
  • firstTurnTriggeredRef 防重复触发解决了会话切换时的 race condition
  • skipAutoTitle flag 让 resend/edit 路径正确跳过自动标题
  • decideTitleTrigger 抽成纯函数设计很好

需要简化的方向(整体上请尽量减少新增代码量):

  1. title-utils.tsagent-title-utils.ts 可以合并 — 两个文件结构几乎镜像,deriveFallbackTitlederiveAgentFallbackTitle 逻辑完全相同,只是常量不同。建议共用一个工厂函数或直接合并为一个共享模块。

  2. 每个失败路径 logTitleEvent 调用了两次 — 每处失败都先 log title_failed_* 再 log title_generated_fallback,产生大量重复代码。建议封装成一个 helper 一次调用即可:

    function logFallback(reason: TitleReason, context: ...) {
      logTitleEvent(reason, context)
      logTitleEvent('title_generated_fallback', context)
    }
  3. hasKnownTitleShape 可以去掉 — 这个函数区分 empty_content vs parse_failed 对最终行为没有任何影响(都返回 fallback),只体现在日志里,增加了不必要的复杂度,建议直接删除。

  4. 请移除所有测试文件 — 目前 .test.ts 文件直接散落在 src/main/lib/src/renderer/components/chat/packages/core/tests/ 等多个目录下,请将测试文件全部从这个 PR 中移除,我们暂时不在 PR 中引入测试。

整体来说这个 PR 核心修复是有价值的,但目前新增代码量偏多(净增约 1000 行)。请按上述方向精简后重新提交,让改动更聚焦在核心 bug fix 上 🙏

@ErlichLiu
Copy link
Owner

拉取最新的代码,在最新的代码基础上进行修改哈,顺便可以解决掉目前修改的部分的冲突的问题。 @ai-jiaqian

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