github / github/copilot-cli

`/new`  discards in-memory usage statistics without writing  `session.shutdown`  to  `events.jsonl`

未关闭
#3,994 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:sessions
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

### Describe the bug

When starting a new session with  `/new`, the CLI abandons the current session's in-memory `modelMetrics` without triggering a  `session.shutdown` event. All token usage accumulated in the outgoing session is permanently lost — it is never written to `events.jsonl` and never appears in subsequent  `/usage`  output or  `/chronicle` queries.

The only reliable way to persist usage statistics is to exit the CLI entirely with Ctrl+D, which is disruptive when the intent is simply to start a fresh session.

### Affected version

GitHub Copilot CLI 1.0.67.

### Steps to reproduce the behavior

1. Start the Copilot CLI and do some work (several turns, tool calls, etc.)
2. Run  `/usage`  — note the token totals shown
3. Run  `/new`  to start a fresh session
4. In the new session, run  `/resume`  to return to the previous session
5. Run  `/usage` 

 `/usage`  shows zero / only the new segment's usage.
The previous session's token counts are gone.
Inspecting  `~/.copilot/session-state//events.jsonl`  confirms no  `session.shutdown`  event was written for the outgoing session.

### Expected behavior

 `/usage` after step 5 shows the token totals from before  `/new`  was called (same as step 2).

### Additional context

Running `/usage` before `/new` shows the numbers correctly — they exist in memory at that point. The data is only lost because  `/new`  does not flush the outgoing session before switching.

The fix appears straightforward: trigger  `session.shutdown` (and flush `modelMetrics` to  `events.jsonl`) for the outgoing session when `/new` is invoked, before initialising the new one — the same cleanup path that Ctrl+D takes.

**Environment**

• OS: Linux (dev container)
• CLI version: 1.0.67

贡献指南

打开贡献指南

调研方向

从 `/new` 的 CLI 入口点开始,将其会话切换路径与 Ctrl+D 的关闭清理进行比较。跟踪 `session.shutdown` 和 `modelMetrics` 如何写入 `events.jsonl`;完成标准是:使用 `/new` 重启、恢复之前的会话,并在 `/usage` 和 `/chronicle` 中看到之前的总数。

由索引模型根据 Issue 内容生成。

评估

技术栈
shell
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。