Repository navigation
fix(acp): resolve session by exact id and handle listener cleanup on session failure - #29580
Conversation
…session failure Bypass resumable content filtering when resolving explicit ACP session UUIDs, validate session files before constructing client components, and dispose config instances on error paths to release listeners. Closes google-gemini#29288
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 resolves an issue where ACP sessions could not be resumed if they lacked conversational turns. By allowing direct session resolution via UUID and improving the lifecycle management of configuration resources and event listeners, the changes ensure that sessions are correctly handled and cleaned up, even when initialization fails. 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request enhances the Agent Client Protocol (ACP) session management by introducing support for loading empty sessions (sessions without resumable content) and ensuring proper resource cleanup. It adds an allowEmpty option to SessionSelector.resolveSession and implements resolveSessionById to bypass interactive terminal list filtering. Additionally, it wraps session loading and authentication steps in try...catch blocks to guarantee that the session configuration is disposed of on failure, preventing resource and event listener leaks. The review feedback highlights a potential resource leak in prepareSessionConfig where an error during file system service setup could leak the config object before it is returned, and provides a code suggestion to handle this failure safely.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the ACP session management to support loading empty sessions and ensures proper cleanup of session configurations by invoking dispose on failure or session termination. It introduces a new resolveSessionById helper to bypass interactive CLI filters when loading a session by its full UUID, along with comprehensive unit tests. The review feedback highlights three key areas for improvement: validating the sessionId parameter to prevent path traversal vulnerabilities, catching potential promise rejections during asynchronous configuration disposal to prevent process crashes, and ensuring numeric indices are not incorrectly routed to resolveSessionById when allowEmpty is enabled.
Note: Security Review did not run due to the size of the PR.
…s, and index routing
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces changes to session loading and resolution within the ACP session manager, including path traversal validation for session identifiers, direct session resolution by UUID, and improved resource disposal on initialization failures. The review feedback highlights two key areas for improvement: first, a potential runtime TypeError when calling .catch() on an optional-chained dispose call that may evaluate to undefined; second, an optimization to resolve the session before initializing storage to prevent unnecessary directory creation on disk for invalid session IDs.
|
/gemini review |
1 similar comment
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances the ACP session manager by adding path traversal validation for session identifiers, ensuring proper cleanup of configurations via config.dispose() during initialization or authentication failures, and introducing a resolveSessionById method to support loading empty sessions. Feedback was provided to safely handle the optional sessionData.lastUpdated property using the nullish coalescing operator (??) to prevent potential runtime issues when formatting the session display info.
There was a problem hiding this comment.
Code Review
This pull request enhances the Agent Client Protocol (ACP) session management by adding validation to reject invalid session identifiers early, refactoring session loading to handle configuration initialization and disposal robustly, and introducing a method to resolve sessions directly by UUID. Comprehensive unit tests have been added to verify these changes. The review feedback suggests wrapping configuration disposal calls in try/catch blocks across acpSessionManager.ts to prevent disposal errors from masking original authentication or initialization failures. Additionally, it is recommended to handle the optional lastUpdated property with a fallback default in sessionUtils.ts to comply with repository rules and avoid potential runtime issues.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces safe disposal of session configurations during session teardown and error handling, and adds support for resolving empty sessions by UUID (bypassing interactive terminal filters) via a new resolveSessionById method. It also adds validation to prevent path traversal via the session identifier. The reviewer recommends strengthening the session identifier validation by using a strict regular expression to prevent other potential vulnerabilities like null byte injection or control characters.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces secure session loading and proper resource disposal for the Agent Client Protocol (ACP) session manager. It adds path traversal validation for session identifiers, implements direct session resolution by UUID (bypassing interactive filters when empty sessions are allowed), and ensures that session configurations are properly disposed of during initialization failures or authentication errors. Feedback on the changes highlights a potential resource conflict where an existing session is disposed of only after the new session's configuration is initialized; disposing of the existing session beforehand is recommended to prevent port binding or file lock contention from concurrent MCP servers.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces secure session loading and proper configuration disposal in the Agent Client Protocol (ACP) session manager. Key changes include validating session identifiers against path traversal, allowing resolution of empty sessions by UUID, and ensuring config.dispose() is called during session termination or authentication failures. The review feedback highlights two critical issues: first, Storage should be instantiated with the sessionId to ensure correct scoping; second, the initialization sequence in session creation should be wrapped in a try-catch block to prevent resource leaks of partially initialized configurations when subsequent steps fail.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances session management in the Gemini CLI by introducing safer configuration disposal during authentication and initialization failures, validating session identifiers to prevent path traversal, and allowing direct session resolution by UUID. While these changes improve robustness and security, the feedback highlights two key areas for improvement: addressing a potential race condition when reloading a session due to synchronous disposal, and wrapping the initialization phase of new sessions in a try-catch block to ensure proper cleanup of active event listeners and subprocesses on failure.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request makes the Session.dispose method asynchronous to safely handle configuration disposal, introduces path traversal validation for session identifiers, and adds a resolveSessionById method to bypass interactive terminal list filtering when resolving sessions by UUID. The review feedback highlights critical resource leak issues where zombie sessions and event listeners are left behind if errors occur after session creation in newSession and loadSession. Additionally, the reviewer recommends making the session manager's dispose method asynchronous to properly await the now-asynchronous session disposals and prevent race conditions.
…ances on initialization error
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the disposal lifecycle across GeminiAgent, AcpSessionManager, and Session to be asynchronous, ensuring proper cleanup of configurations and sessions. It also introduces robust error handling during session creation and loading to prevent resource leaks, adds path traversal validation for session identifiers, and implements direct session resolution by UUID via resolveSessionById. A review comment correctly points out that the promise returned by session?.sendAvailableCommands() in acpSessionManager.ts is unhandled and suggests adding a .catch block to prevent unhandled rejections.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the session disposal lifecycle across the ACP (Agent Client Protocol) implementation to be asynchronous, ensuring proper cleanup of resources. It updates GeminiAgent, AcpSessionManager, and Session to support async dispose, and improves error handling during session creation and loading by ensuring configs and sessions are disposed of if initialization fails. Additionally, it introduces path traversal validation for session identifiers, adds a resolveSessionById helper to bypass interactive terminal filtering, and includes comprehensive unit tests. The feedback highlights an opportunity to improve reliability by explicitly catching and logging errors on floating promises in loadSession instead of bypassing the linter with comments.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the session disposal mechanism to be asynchronous, ensuring proper cleanup of configurations and sessions, and adds robust error handling and disposal during session creation and loading. It also introduces a path traversal check for session identifiers and allows resolving empty sessions via a new allowEmpty option in SessionSelector. The review feedback recommends moving deferred background tasks (such as sendAvailableCommands and streamHistory) to the very end of the initialization blocks in newSession and loadSession to prevent side-effects from executing if the session setup subsequently fails.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request transitions session disposal to be asynchronous across GeminiAgent, Session, and AcpSessionManager to ensure proper resource cleanup, and enhances session loading by allowing direct resolution of sessions by UUID. Feedback on these changes focuses on improving robustness and safety: validating sessionId with a strict regular expression to prevent path traversal bypasses, safely handling the optional messages property on sessionData with fallbacks to avoid runtime errors, and consistently trimming optional timestamp strings when formatting session display information.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request transitions the session disposal flow to be asynchronous across the ACP session management classes, adds validation to prevent path traversal via session identifiers, and introduces a mechanism to resolve empty sessions by UUID. The review feedback highlights two critical robustness improvements in AcpSessionManager: wrapping individual session disposals in try-catch blocks within dispose() to prevent a single failure from halting the entire process, and wrapping existingSession.dispose() in a try-catch-finally block during session loading to guarantee stale sessions are always removed from the manager.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the session disposal lifecycle across GeminiAgent, Session, and AcpSessionManager to be asynchronous, ensuring proper resource cleanup. It enhances error handling during session creation and loading to guarantee that sessions and configurations are safely disposed of if initialization fails. Additionally, it introduces input validation on session identifiers to prevent path traversal vulnerabilities and adds a new resolveSessionById method to bypass interactive terminal filters when resolving sessions by UUID. Comprehensive unit tests have been added to verify these changes. No review comments were provided, so I have no additional feedback to offer.
Summary
Resolves an issue where ACP
session/loadfails with"Invalid session identifier"when resuming newly created sessions without conversational turns, and addresses event listener lifecycle management when session resolution fails.Details
SessionSelector.resolveSessionByIdto allow direct resolution of session UUIDs without applying interactive CLI terminal resumable content filtering (hasResumableContent: false).resolveSessionById, even whenallowEmpty: true.AcpSessionManager.loadSessionto reject directory traversal sequences or path separators (..,/,\) before initializing session storage.AcpSessionManager.loadSessionto validate session existence on disk before instantiatingConfigandGeminiClientcomponents.config.dispose()on error handling paths inloadSession,prepareSessionConfig(including duringAcpFileSystemServicesetup), andnewSession, as well as inSession.dispose()on session termination with unhandled promise rejection protection. This unregisters listeners bound tocoreEvents(such asmodel-changed,memory-changed, andapproval-mode-changed).gemini --resumeandgemini --list-sessions) continue to filter out empty sessions as expected.Related Issues
Closes #29288
How to Validate
Run ACP session manager unit tests:
npm test -w @google/gemini-cli -- src/acp/acpSessionManager.test.tsValidates immediate
session/newfollowed bysession/load, loading populated sessions, rejection of traversal paths with format errors, and error handling without listener warnings over repeated invalid session loads.Run session utility tests:
npm test -w @google/gemini-cli -- src/utils/sessionUtils.test.tsValidates
resolveSessionById, numeric index routing, andresolveSessionwith and without{ allowEmpty: true }.Run ACP test suite:
npm test -w @google/gemini-cli -- src/acp/Verify types and linting:
Pre-Merge Checklist