gemini-cli - 💡(How to fix) Fix Bug: sessionRetention global setting is only executed for active project, causing orphaned history growth [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#26094Fetched 2026-04-29 06:36:09
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
labeled ×1

The sessionRetention setting in ~/.gemini/settings.json is intended to be a global policy for managing session history. However, the pruning logic currently only executes during CLI startup for the currently active project. This results in "orphaned" history: sessions created in other project directories (stored as hashes in ~/.gemini/tmp) are never pruned unless those specific projects are revisited and the CLI is started within them.

Root Cause

Investigation revealed:

  • Active Project: Had only 2 sessions (correctly adhering to the 4-day limit).
  • Orphaned Projects: 321 sessions were distributed across 75+ inactive project hashes in ~/.gemini/tmp. These sessions were never purged because the projects had not been "active" recently.
RAW_BUFFERClick to expand / collapse

Description

The sessionRetention setting in ~/.gemini/settings.json is intended to be a global policy for managing session history. However, the pruning logic currently only executes during CLI startup for the currently active project. This results in "orphaned" history: sessions created in other project directories (stored as hashes in ~/.gemini/tmp) are never pruned unless those specific projects are revisited and the CLI is started within them.

Observed Behavior

A user with a maxAge: "4d" policy found that their ~/.gemini/ directory had grown to 536MB with 323 sessions dating back several months.

Investigation revealed:

  • Active Project: Had only 2 sessions (correctly adhering to the 4-day limit).
  • Orphaned Projects: 321 sessions were distributed across 75+ inactive project hashes in ~/.gemini/tmp. These sessions were never purged because the projects had not been "active" recently.

Impact

  • Disk Space Waste: Indefinite accumulation of session data and tool outputs across different workspaces.
  • Privacy/Data Retention: Explicit user instructions for short retention periods are ignored for any project not currently in focus.

Related Issues

  • #25429: Global Configuration Serialisation Failure.
  • #21568: deleteSession() does not clean tool output directories.
  • #22032: Test suites leave behind temporary directories causing disk space waste.

Proposed Solution

The sessionRetention logic should perform a global sweep of the ~/.gemini/tmp directory to enforce the maxAge and maxCount policies across all project hashes, rather than being scoped strictly to the current project.

extent analysis

TL;DR

Implement a global sweep of the ~/.gemini/tmp directory to enforce sessionRetention policies across all project hashes.

Guidance

  • Modify the pruning logic to execute a global sweep of ~/.gemini/tmp during CLI startup, rather than only checking the currently active project.
  • Verify the fix by setting a maxAge policy, creating sessions in multiple project directories, and checking that all sessions older than the specified age are pruned after restarting the CLI.
  • Consider adding a periodic cleanup task to run the global sweep at regular intervals, in addition to running it at CLI startup.
  • Review related issues (#25429, #21568, #22032) to ensure that the proposed solution does not introduce new problems with global configuration serialization, session deletion, or test suite cleanup.

Example

No code snippet is provided, as the issue does not include specific implementation details.

Notes

The proposed solution may require significant changes to the existing pruning logic and may have performance implications if the ~/.gemini/tmp directory is very large.

Recommendation

Apply the proposed workaround by implementing a global sweep of the ~/.gemini/tmp directory, as this addresses the root cause of the issue and ensures that sessionRetention policies are enforced across all project hashes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING