github / github/copilot-cli

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

Aperta
#3,994 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:sessions
Lingua principale
Shell
Stelle
11.2k
Fork
1.9k
Merge medio
14h 16m
PR unite (30g)
6

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Parti dal punto di ingresso della CLI per `/new` e confronta il relativo percorso di cambio sessione con la pulizia dello spegnimento tramite Ctrl+D. Traccia come `session.shutdown` e `modelMetrics` vengono scritti in `events.jsonl`; il lavoro è completato quando, riavviando con `/new` e riprendendo la sessione precedente, vengono visualizzati i totali precedenti in `/usage` e `/chronicle`.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
shell
Ambito
cli
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.