fix(core): pass resumed session data through config init to avoid orphan session file - #29206
Conversation
…han session file config.initialize() started the Gemini client with no resumed session data even when the process was launched via --resume, so chat recording treated the resume as a brand new conversation and opened a second, empty session file. Because the process reuses the resumed session's id, that empty file shares the same eight-character id suffix as the real conversation file. Startup retention cleanup expands deletion of a non-resumable file to every file sharing that suffix, wiping out the real session on a later launch. Thread resumedSessionData through config.initialize() -> GeminiClient.initialize() -> startChat() so chat recording reopens the existing file from the start.
|
You already have 7 pull requests open. Please work on getting existing PRs merged before opening more. |
|
📊 PR Size: size/M
|
Summary of ChangesHello, 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 addresses a critical issue where resuming a Gemini session would inadvertently create an orphaned, empty chat file. Because this orphan shared the same session ID suffix as the real conversation file, the system's automated session-retention cleanup would incorrectly identify the real conversation as corrupted and delete it. By ensuring the resumed session data is passed through the initialization chain, the application now correctly reopens the existing session file instead of creating a new one. Highlights
Using Gemini Code AssistThe 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
Customization To customize the 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the initialization flow of the Gemini CLI to accept and propagate resumedSessionData through the configuration and client initialization. This ensures that when resuming a session, the recording service reopens the existing session file instead of creating a new one, preventing potential data loss during startup retention cleanup. A unit test has been added to verify this behavior. I have no feedback to provide as there are no review comments.
Note: Security Review did not run due to the size of the PR.
The bug
gemini --resume <uuid>reuses the resumed session's id for the process(
resolveSessionIdreturnssessionData.sessionId). Butconfig.initialize()starts the Gemini client with no resumed session data:
GeminiClient.initialize()→GeminiChat.initialize(undefined)then takes the"create new session" branch in
ChatRecordingService, opening a secondJSONL file:
Because the process id is the resumed session's real id, this orphan file
carries the same eight-character suffix as the real conversation file, and
holds nothing but an initial metadata line — the recorder never uses it, since
useSessionResume'sresumeChat()call (which does receive the resumed dataand correctly reopens the real file) only runs later, in a React effect.
That empty orphan is never cleaned up on its own exit path, either — cleanup
only runs against
config.getGeminiClient().getChatRecordingService(), whichafter
resumeChat()completes points at the real file, not the orphan.The orphan is what a later startup's session-retention sweep finds:
hasResumableContentis false for it, so it is treated as corrupted, andcleanup derives the short id from its filename and expands the deletion to
every file ending in that same
-<shortId>.jsonl— including the realconversation. That's exactly what's reported in #29198: after resuming a
session and exiting without interacting, trying to resume the same session
again later shows it gone from
--list-sessionsand--resume <uuid>fails.The fix
Thread
resumedSessionDatathrough the one call site that was dropping it:packages/core/src/config/config.ts:initialize()/_initialize()acceptand forward
resumedSessionDatatothis._geminiClient.initialize(...).packages/core/src/core/client.ts:GeminiClient.initialize()acceptsresumedSessionDataand passes it tostartChat().packages/cli/src/gemini.tsxandpackages/cli/src/ui/AppContainer.tsx:the two call sites of
config.initialize()(non-interactive and interactivepaths) now pass the
resumedSessionDatathey already have in scope.History is untouched by this change —
startChat(undefined, resumedSessionData)still passes no
extraHistory, so the in-memory chat history continues to bebuilt exclusively by the later
resumeChat()call inuseSessionResume. Thischange only fixes which file chat recording targets from the start.
Test plan
Added a regression test in
packages/core/src/core/client.test.tsassertingthat
GeminiClient.initialize(resumedSessionData)forwards the data tostartChat. Verified it fails without the fix:With the fix, the full targeted suites pass:
src/gemini.test.tsxhas 9 pre-existing failures (FatalUntrustedWorkspaceError: Gemini CLI is not running in a trusted directory) that reproduce identicallyon unmodified
mainin this sandbox — unrelated to this change (headless/CItrusted-folder detection in the test environment).
npx eslintandnpx prettier --checkare clean on all changed files, andnpm run typecheckpasses across all workspaces.Fixes #29198.
This PR was prepared with AI assistance (an autonomous coding agent
investigated the issue, traced the root cause, wrote the fix, and verified it
with the tests above). A human reviewed the change before submission.