Repository navigation
feat: add session title generation telemetry - #4699
Conversation
🦋 Changeset detectedLatest commit: 7e3feb6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e3feb68e9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const track = ( | ||
| result: Omit<SessionTitleGenerationFinishedEvent, 'duration_ms' | 'trigger' | 'source'>, | ||
| ): void => { | ||
| this.telemetry.track2('session_title_generation_finished', { |
There was a problem hiding this comment.
Preserve session context for late title telemetry
When a session is closed, reloaded, or deleted while the title HTTP request is pending, its telemetry binding is disposed before this call runs. BoundTelemetryService.ambient() then deliberately falls back to the App context, so session_title_generation_finished is sent without the session id; capture a withContext snapshot before the first await (or finish/cancel the attempt before teardown) so late completion remains attributable to the session.
Useful? React with 👍 / 👎.
| const title = result.title.slice(0, MAX_GENERATED_TITLE_LENGTH); | ||
| const applied = await this.metadata.setGeneratedTitleIfUncustomized(title, { force }); | ||
| if (!applied) return undefined; | ||
| if (!applied) return { reason: 'custom_title' }; |
There was a problem hiding this comment.
Distinguish disposal from a custom-title race
When a session is closed, reloaded, or deleted while the title request is in flight, SessionMetadata.setGeneratedTitleIfUncustomized() can return false from prepareWrite() solely because the metadata service has been disposed, even though no custom title exists. This line maps every false result to reason: custom_title, corrupting the new reason breakdown; confirm titleKind before selecting that reason or add a lifecycle-specific reason.
Useful? React with 👍 / 👎.
commit: |
Requirement or Bug
自动生成 Session 标题此前没有独立的可观测数据,无法从客户端遥测判断生成是否成功、耗时多久,以及失败集中在哪个阶段。本 PR 为实际生成过程增加匿名完成事件,同时不采集标题、对话或后端错误原文。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
在共享的标题生成服务中统一记录
session_title_generation_finished,CLI/TUI、Desktop、Web 和 SDK 的既有调用链都会覆盖到,不需要增加客户端埋点或修改请求契约。关键行为:
trigger沿用现有调用语义:force: true记为manual,其余记为auto;现有 SDK 中force的含义和返回值均不改变。source保留first_turn、digest、user_prompts三种输入来源。duration_ms覆盖从提取标题输入、请求标题接口到本地标题写入结束的耗时。unavailable,意外异常归为error并继续按原逻辑抛出。reason使用有界枚举;error_type只记录错误类名。标题内容、对话内容、后端响应和错误消息不会进入该事件。阅读顺序:先看
packages/agent-core-v2/src/session/sessionTitle/sessionTitleService.ts的生成与上报,再看packages/agent-core-v2/src/app/telemetry/events.ts的字段定义;测试集中在既有sessionTitleService.test.ts。Behavior Changes and Affected Users
telemetry = false和各入口既有的遥测开关force行为不变受影响模块与覆盖:
fetch响应桩覆盖自动成功与固定 125ms 耗时、手动生成、201 字标题截断、请求失败、意外异常、无输入与已有标题跳过;同时断言标题及错误原文未进入事件。验证结果
origin/main上全量 Vitest:877 个测试文件通过、5 个跳过;17,605 个测试通过、21 个跳过,0 失败。@moonshot-ai/agent-core-v2TypeScript 类型检查及tsdown构建通过。pnpm lint通过,0 errors;仓库既有 warnings 保留。Checklist
/approve).(无关联 issue,需求来自本次标题遥测讨论)gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.(用户调用方式、配置及标题行为未改变,无需更新文档)