google-gemini / google-gemini/gemini-cli
/compress command is not persistent across session resume
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
The `/compress` command, which summarizes chat history to save tokens, is not persistent across session exits and resumes. When a user runs `/compress`, the in-memory chat history is correctly replaced by a summary, but this change is not written back to the session file on disk. Consequently, when the session is resumed later (using `--resume` or `/resume`), the CLI loads the original, uncompressed history from the session file, effectively losing the compression.
**Repro Steps:**
1. Start a chat with `gemini`.
2. Build up some history with several messages.
3. Run `/compress` and wait for completion.
4. Exit the CLI.
5. Resume the session with `gemini --resume latest`.
6. Observe that the history has reverted to its uncompressed state.
### What did you expect to happen?
Running `/compress` should persist the compressed history (the summary) to the session file on disk so that subsequent resumes of the same session correctly load the compressed state.
### Client information
Client Information
OS: darwin (macOS)
Version: Current (detected in local development)
### Login information
N/A (General bug in persistence logic)
### Anything else we need to know?
Investigation shows that in `packages/core/src/core/client.ts`, the `tryCompressChat` method correctly replaces the `this.chat` object with a new `GeminiChat` initialized with the compressed history:
```typescript
this.chat = await this.startChat(newHistory, resumedData);
```
However, the `ChatRecordingService` (which manages the session file) is initialized with `resumedData` (which points to the existing session file) but is not explicitly instructed to overwrite the file's message history with the new `newHistory`. The `initialize` method in `ChatRecordingService` merely points to the existing file without clearing or updating its messages.
Contributor guide
Assessment
This issue has not been assessed yet.