Skip to content

Comments

fix(core): ensure directory exists before writing conversation file#18429

Merged
scidomino merged 1 commit intogoogle-gemini:mainfrom
godwiniheuwa:fix/chat-recording-ensure-directory
Feb 18, 2026
Merged

fix(core): ensure directory exists before writing conversation file#18429
scidomino merged 1 commit intogoogle-gemini:mainfrom
godwiniheuwa:fix/chat-recording-ensure-directory

Conversation

@godwiniheuwa
Copy link
Contributor

Summary

Fixes a crash where writeConversation() would throw ENOENT if the parent directory was cleaned up after initialization (e.g. by OS temp cleanup or Conductor process management).

  • Added fs.mkdirSync(path.dirname(...), { recursive: true }) before writeFileSync
  • This is a no-op when the directory already exists, so no performance impact
  • Follows the same pattern used in promptProvider.ts
  • Added test verifying mkdirSync is called before writeFileSync

Test plan

  • All 21 chatRecordingService tests pass
  • Delete ~/.gemini/tmp/<hash>/chats/ dir while running, send a message - should not crash

Fixes #15398

@godwiniheuwa godwiniheuwa requested a review from a team as a code owner February 6, 2026 09:06
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @godwiniheuwa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where the application would fail to record conversations if the temporary directory structure was unexpectedly removed. By proactively creating the necessary parent directories before any file write operations, it prevents ENOENT errors, ensuring the stability and reliability of conversation data persistence, especially in environments with aggressive temporary file cleanup.

Highlights

  • Error Handling: Implemented a fix for ENOENT errors that occurred when writing conversation files to a non-existent directory, preventing application crashes.
  • File System Operations: Added fs.mkdirSync with recursive: true to ensure the parent directory exists before attempting to write conversation data, making the file writing process more robust.
  • Testing: Introduced a new test case to validate that directory creation happens correctly and in the proper order (before file writing) within the ChatRecordingService.
Changelog
  • packages/core/src/services/chatRecordingService.test.ts
    • Added a new test suite to specifically cover ENOENT error handling for missing directories.
    • Verified that fs.mkdirSync is invoked with the correct parent directory path and recursive: true option.
    • Ensured that fs.mkdirSync is called prior to fs.writeFileSync to prevent potential race conditions or errors.
  • packages/core/src/services/chatRecordingService.ts
    • Inserted fs.mkdirSync(path.dirname(this.conversationFile), { recursive: true }); within the writeConversation method.
    • Added a comment explaining the purpose of the new mkdirSync call to ensure directory existence before writing.
Activity
  • The author has provided a detailed summary of the changes and a comprehensive test plan.
  • The author confirmed that all 21 existing chatRecordingService tests pass with these changes.
  • The author outlined a manual test scenario to verify the fix by deleting the temporary chat directory and sending a message, which should no longer result in a crash.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves a potential crash in the ChatRecordingService that could occur if the conversation directory is removed after initialization. By adding a fs.mkdirSync call with the recursive: true option immediately before writing to the conversation file, the change ensures the directory path exists, making the file writing operation more robust. This is a good defensive measure that follows existing patterns in the codebase. The accompanying test is well-written, verifying not only that mkdirSync is called with the correct parameters but also that it is executed before writeFileSync, confirming the fix is working as intended. The changes are clean, targeted, and improve the application's stability.

@gemini-cli gemini-cli bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 6, 2026
The writeConversation() method called fs.writeFileSync() without first
ensuring the parent directory exists. If the temp directory gets cleaned
up after initialization (e.g. by the OS or Conductor process management),
subsequent writes crash with ENOENT.

Adds fs.mkdirSync with recursive: true before the write call, which is a
no-op when the directory already exists. This follows the existing pattern
used in promptProvider.ts.

Fixes google-gemini#15398

Co-authored-by: ruintheextinct <deepkarma001@gmail.com>
@scidomino scidomino force-pushed the fix/chat-recording-ensure-directory branch from 4c3b5a7 to 81626fc Compare February 18, 2026 20:41
@scidomino scidomino enabled auto-merge February 18, 2026 20:41
@scidomino scidomino added this pull request to the merge queue Feb 18, 2026
Merged via the queue into google-gemini:main with commit f961e0d Feb 18, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using conductor ENOENT: no such file or directory, open

2 participants