Skip to content

fix(cli): preserve shell session id for backgrounding#25132

Closed
SH20RAJ wants to merge 4 commits intogoogle-gemini:mainfrom
SH20RAJ:fix-shell-exec-session-id
Closed

fix(cli): preserve shell session id for backgrounding#25132
SH20RAJ wants to merge 4 commits intogoogle-gemini:mainfrom
SH20RAJ:fix-shell-exec-session-id

Conversation

@SH20RAJ
Copy link
Copy Markdown
Contributor

@SH20RAJ SH20RAJ commented Apr 10, 2026

Fixes #25111

Summary

Preserve the current session ID in the interactive shell execution config so backgrounding can resolve the active PTY/session later.

Validation

  • npm test packages/cli/src/ui/hooks/useExecutionLifecycle.test.tsx

SH20RAJ added 4 commits April 7, 2026 19:19
…ogle-gemini#24820)

- Import uiTelemetryService and call hydrate when resuming via --resume
- This ensures the session ID and metrics are correctly restored, so the quit summary shows the correct resume command

Fixes google-gemini#24820
@SH20RAJ SH20RAJ requested a review from a team as a code owner April 10, 2026 17:00
@github-actions
Copy link
Copy Markdown

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

@github-actions github-actions Bot closed this Apr 10, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 interactive shell sessions, when backgrounded, would lose their session context, preventing proper resumption. By ensuring the session ID is consistently captured and preserved within the shell execution configuration and restored upon session resume, the system can now reliably manage and re-attach to backgrounded PTY sessions. This enhances the stability and user experience of the CLI's interactive features.

Highlights

  • Session ID Preservation: The current session ID is now preserved within the interactive shell execution configuration, addressing issue Interactive shell backgrounding can fail due to missing sessionId #25111.
  • Backgrounding Fix: This change enables backgrounded interactive shell sessions to correctly resolve their active pseudo-terminal (PTY) and session upon resumption.
  • Configuration Update: The setShellExecutionConfig method in the core configuration was updated to properly merge and preserve all existing shell execution properties, including the new sessionId.
  • Telemetry Hydration: The uiTelemetryService is now hydrated with resumed conversation data to restore session ID and metrics, ensuring continuity.
  • Test Coverage: New and updated tests ensure the sessionId is correctly handled and that configuration updates preserve existing settings.
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.

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
Copy Markdown
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 introduces session ID tracking within the shell execution lifecycle and implements telemetry hydration when resuming sessions. It also expands the setShellExecutionConfig method to support additional properties such as colors, sandbox configurations, and permissions, accompanied by new unit tests. Feedback was provided regarding the implementation of setShellExecutionConfig, noting that the manual mapping of properties is redundant and brittle, and suggesting a more dynamic approach to merging configuration updates.

Note: Security Review did not run due to the size of the PR.

Comment on lines 3336 to 3369
this.shellExecutionConfig = {
...this.shellExecutionConfig,
terminalWidth:
config.terminalWidth ?? this.shellExecutionConfig.terminalWidth,
terminalHeight:
config.terminalHeight ?? this.shellExecutionConfig.terminalHeight,
showColor: config.showColor ?? this.shellExecutionConfig.showColor,
pager: config.pager ?? this.shellExecutionConfig.pager,
defaultFg: config.defaultFg ?? this.shellExecutionConfig.defaultFg,
defaultBg: config.defaultBg ?? this.shellExecutionConfig.defaultBg,
sanitizationConfig:
config.sanitizationConfig ??
this.shellExecutionConfig.sanitizationConfig,
sandboxManager:
config.sandboxManager ?? this.shellExecutionConfig.sandboxManager,
sandboxConfig:
config.sandboxConfig ?? this.shellExecutionConfig.sandboxConfig,
backgroundCompletionBehavior:
config.backgroundCompletionBehavior ??
this.shellExecutionConfig.backgroundCompletionBehavior,
additionalPermissions:
config.additionalPermissions ??
this.shellExecutionConfig.additionalPermissions,
disableDynamicLineTrimming:
config.disableDynamicLineTrimming ??
this.shellExecutionConfig.disableDynamicLineTrimming,
scrollback: config.scrollback ?? this.shellExecutionConfig.scrollback,
maxSerializedLines:
config.maxSerializedLines ??
this.shellExecutionConfig.maxSerializedLines,
originalCommand:
config.originalCommand ?? this.shellExecutionConfig.originalCommand,
sessionId: config.sessionId ?? this.shellExecutionConfig.sessionId,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The implementation of setShellExecutionConfig is redundant and brittle. The spread operator at the beginning is negated by the explicit assignment of every property in the interface using nullish coalescing. Furthermore, this manual mapping requires updates whenever the ShellExecutionConfig interface changes, which is prone to errors. A more robust approach would be to merge only the defined properties from the input config using a loop or Object.fromEntries.

  setShellExecutionConfig(config: ShellExecutionConfig): void {
    const updates = Object.fromEntries(
      Object.entries(config).filter(([_, v]) => v !== undefined),
    );
    this.shellExecutionConfig = {
      ...this.shellExecutionConfig,
      ...updates,
    };
  }
References
  1. When constructing an object from multiple data sources, consistently use a merge operation (e.g., spread syntax {...a, ...b}) instead of assignment to avoid accidental overwrites and order-dependent logic.
  2. Rely on the schema as the single source of truth for configuration defaults, avoiding redundant nullish coalescing operators.

@SH20RAJ
Copy link
Copy Markdown
Contributor Author

SH20RAJ commented Apr 12, 2026

As noted on #25130, #25113 already correctly handles the preservation of shell execution config fields. Closing this PR to focus on higher priority feedback. Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive shell backgrounding can fail due to missing sessionId

1 participant