Skip to content

refactor(core): remove eslint-disable and type-asserts from shellExecutionService - #28862

Merged
DavidAPierce merged 6 commits into
mainfrom
fix/mac-pty-resource-leak
Aug 20, 2026
Merged

refactor(core): remove eslint-disable and type-asserts from shellExecutionService#28862
DavidAPierce merged 6 commits into
mainfrom
fix/mac-pty-resource-leak

Conversation

@DavidAPierce

Copy link
Copy Markdown
Contributor

Summary

This PR removes eslint-disable and unsafe type-assertions from shellExecutionService.ts on the branch fix/mac-pty-resource-leak.

Details

Previously, the dataListener and exitListener were registered by casting properties of ptyProcess (which was typed as any because ptyInfo.module.spawn returned any). By using the already type-asserted spawnedPty of type DestroyablePty instead, .onData and .onExit are fully typed from @lydell/node-pty. This removes any need for the eslint-disable block and custom assertions entirely. Additionally, unnecessary non-null assertions spawnedPty! on lines 1244 and 1250 have been removed, as the TypeScript compiler control flow correctly infers that they are defined in that scope.

Related Issues

Related to cleanup of eslint-disable comments on fix/mac-pty-resource-leak branch.

How to Validate

  1. Run npm run lint to verify eslint rules pass.
  2. Run npm run typecheck to verify TypeScript types compile.
  3. Run npm test -w @google/gemini-cli-core -- src/services/shellExecutionService.test.ts to ensure PTY execution unit tests continue to pass.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@DavidAPierce
DavidAPierce requested a review from a team as a code owner August 17, 2026 20:05
@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 refactors the 'shellExecutionService' to improve type safety and resource management. By replacing loose type assertions with proper interface usage and implementing explicit cleanup for event listeners and terminal instances, the service becomes more resilient and memory-efficient. Additionally, the error handling logic was updated to better support fallback scenarios when PTY creation fails, ensuring more stable execution across different environments.

Highlights

  • Type Safety Improvements: Removed unsafe type assertions and 'eslint-disable' blocks in 'shellExecutionService.ts' by leveraging the correctly typed 'DestroyablePty' interface.
  • Resource Leak Prevention: Implemented explicit disposal of PTY event listeners and headless terminal instances to prevent memory and file descriptor leaks.
  • Robust Error Handling: Enhanced PTY creation failure detection to include 'ENXIO' errors, ensuring reliable fallback to 'child_process' execution.
  • Testing Coverage: Added comprehensive unit tests to verify PTY event listener disposal on exit/abort and the fallback mechanism for PTY creation failures.
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 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 .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 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

  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.

@github-actions github-actions Bot added the size/l A large sized PR label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 320
  • Additions: +219
  • Deletions: -101
  • Files changed: 2

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

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.

Code Review

This pull request introduces robust cleanup of PTY event listeners and headless terminals in ShellExecutionService to prevent memory and file descriptor leaks on process exit, abort, or execution failure. It also expands the fallback mechanism to child_process when PTY creation fails with ENXIO or "Device not configured" errors, accompanied by comprehensive unit tests. The review feedback suggests capturing spawnedPty as a constant to avoid unsafe non-null assertions and correcting the indentation of the onExit callback to align with formatting standards.

Comment thread packages/core/src/services/shellExecutionService.ts
Comment thread packages/core/src/services/shellExecutionService.ts Outdated
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

Size Change: +381 B (0%)

Total Size: 35.2 MB

Filename Size Change
./bundle/chunk-3VDVTFJH.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-AVCTKMXI.js 0 B -3.65 MB (removed) 🏆
./bundle/chunk-CWNVYOM5.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-HGOCLOJU.js 0 B -16.6 MB (removed) 🏆
./bundle/chunk-KMYLJWHS.js 0 B -661 kB (removed) 🏆
./bundle/chunk-QJRF7SYD.js 0 B -13 kB (removed) 🏆
./bundle/chunk-RE4LJE3B.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-ZTH7TY4V.js 0 B -3.77 kB (removed) 🏆
./bundle/core-3LC7S4FI.js 0 B -50.7 kB (removed) 🏆
./bundle/devtoolsService-25JDCYRU.js 0 B -147 kB (removed) 🏆
./bundle/gemini-E2LXAAEV.js 0 B -614 kB (removed) 🏆
./bundle/interactiveCli-QGN7T4Z6.js 0 B -1.31 MB (removed) 🏆
./bundle/liteRtServerManager-TLLW7N4T.js 0 B -2.08 kB (removed) 🏆
./bundle/oauth2-provider-LM7OYJFV.js 0 B -9.12 kB (removed) 🏆
./bundle/chunk-3F6WD7NT.js 16.6 MB +16.6 MB (new file) 🆕
./bundle/chunk-6JY73PF3.js 3.77 kB +3.77 kB (new file) 🆕
./bundle/chunk-6U7ESAJW.js 13 kB +13 kB (new file) 🆕
./bundle/chunk-NUOZRBE7.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-OWMSLMUU.js 3.65 MB +3.65 MB (new file) 🆕
./bundle/chunk-VOAMXRKE.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-YMNERRIW.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-ZC2NWBCU.js 661 kB +661 kB (new file) 🆕
./bundle/core-LQ54W6RM.js 50.7 kB +50.7 kB (new file) 🆕
./bundle/devtoolsService-AF6UHPKO.js 147 kB +147 kB (new file) 🆕
./bundle/gemini-JE72ZYJS.js 614 kB +614 kB (new file) 🆕
./bundle/interactiveCli-OM2FIFXG.js 1.31 MB +1.31 MB (new file) 🆕
./bundle/liteRtServerManager-7SDQBU2O.js 2.08 kB +2.08 kB (new file) 🆕
./bundle/oauth2-provider-57SVDXS6.js 9.12 kB +9.12 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-L5V3KIDT.js 1.62 kB 0 B
./bundle/chunk-TUDYL3X4.js 40.3 kB 0 B
./bundle/cleanup-NHERKGX4.js 0 B -902 B (removed) 🏆
./bundle/devtools-TYCPOPV3.js 683 kB 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.38 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/https-proxy-agent-AVGR4LHR.js 490 B 0 B
./bundle/multipart-parser-E7RMVJWU.js 11.7 kB 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 5.29 kB 0 B
./bundle/sandbox-macos-permissive-proxied.sb 5.58 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.3 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.5 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.75 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 4.96 kB 0 B
./bundle/src-65GKNWUJ.js 45.4 kB 0 B
./bundle/src-U45KTUYT.js 45.7 kB 0 B
./bundle/src-XZYPU6PJ.js 352 kB 0 B
./bundle/start-2D64ESLC.js 0 B -622 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/worker/worker-entry.js 363 kB 0 B
./bundle/cleanup-V33TRDM7.js 902 B +902 B (new file) 🆕
./bundle/start-OORTIRJT.js 622 B +622 B (new file) 🆕

compressed-size-action

@DavidAPierce
DavidAPierce force-pushed the fix/mac-pty-resource-leak branch from 7c5553d to 8e417ba Compare August 17, 2026 20:14
@DavidAPierce
DavidAPierce added this pull request to the merge queue Aug 20, 2026
Merged via the queue into main with commit 30573d2 Aug 20, 2026
33 checks passed
@DavidAPierce
DavidAPierce deleted the fix/mac-pty-resource-leak branch August 20, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants