gemini-cli - 💡(How to fix) Fix Bug: `--resume` fails and chats corrupt on deleted/empty .jsonl files and invalid maxAge [1 comments, 2 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#26425Fetched 2026-05-05 06:03:51
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1labeled ×1

Error Message

Additionally, the session cleanup script throws an error during startup if an invalid maxAge format is present in the policies or settings (e.g. 1Y), which completely prevents proper cleanup of the orphan session directories.

RAW_BUFFERClick to expand / collapse

Describe the bug

When running gemini --resume or starting the CLI, the session resume and cleanup logic fails if the ~/.gemini/tmp/<project>/chats/ directory contains .jsonl files that are empty or truncated (e.g. from runaway sub-agent processes), or if the user manually deletes them, leaving behind orphan session subdirectories.

Additionally, the session cleanup script throws an error during startup if an invalid maxAge format is present in the policies or settings (e.g. 1Y), which completely prevents proper cleanup of the orphan session directories.

To Reproduce

  1. Have a runaway sub-agent or process create thousands of 1kb/empty .jsonl session files in ~/.gemini/tmp/<project>/chats/.
  2. Delete the .jsonl files manually to clean up.
  3. Set a maxAge policy with an unsupported unit like 1Y.
  4. Run gemini --resume.
  5. The CLI fails to resume properly and throws cleanup errors related to maxAge formatting and orphan subdirs.

Expected behavior

  1. loadConversationRecord should gracefully handle empty, truncated, or invalid .jsonl files without corrupting the resume state or crashing.
  2. The CLI cleanup logic should safely handle orphan session directories even if the corresponding .jsonl files were manually deleted.
  3. Invalid maxAge settings should fallback to a safe default and log a warning rather than completely disabling cleanup and polluting stdout.

extent analysis

TL;DR

Implement robust error handling for empty or truncated .jsonl files and validate maxAge format to prevent cleanup failures.

Guidance

  • Verify that loadConversationRecord can handle edge cases like empty or truncated .jsonl files without crashing.
  • Enhance the cleanup logic to safely remove orphan session directories even if corresponding .jsonl files are missing.
  • Validate maxAge format and fallback to a safe default if it's invalid, logging a warning instead of throwing an error.
  • Consider adding input validation for maxAge to prevent invalid units like 1Y.

Example

// Pseudo-code example for validating maxAge format
function validateMaxAge(maxAge) {
  const unit = maxAge.replace(/\d+/g, '');
  if (!['s', 'm', 'h', 'd'].includes(unit)) {
    console.warn(`Invalid maxAge unit: ${unit}. Falling back to default.`);
    return '1d'; // safe default
  }
  return maxAge;
}

Notes

The provided solution focuses on handling edge cases and input validation. However, a more comprehensive fix might require additional changes to the gemini CLI and its dependencies.

Recommendation

Apply workaround: Implement robust error handling and input validation as described above to prevent cleanup failures and ensure the CLI can resume properly.

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…

FAQ

Expected behavior

  1. loadConversationRecord should gracefully handle empty, truncated, or invalid .jsonl files without corrupting the resume state or crashing.
  2. The CLI cleanup logic should safely handle orphan session directories even if the corresponding .jsonl files were manually deleted.
  3. Invalid maxAge settings should fallback to a safe default and log a warning rather than completely disabling cleanup and polluting stdout.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix Bug: `--resume` fails and chats corrupt on deleted/empty .jsonl files and invalid maxAge [1 comments, 2 participants]