fix(core): "gemini --resume crash" handle EBADF error when PTY fd is stale on session resume - #27371
fix(core): "gemini --resume crash" handle EBADF error when PTY fd is stale on session resume #27371mini2s wants to merge 4 commits into
Conversation
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 crash occurring during gemini session resumption. When a session is resumed, the system occasionally attempts to resize a PTY using a stale file descriptor, resulting in an EBADF error. By explicitly catching and ignoring this error, the service now gracefully handles the state mismatch, improving overall application stability. 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 ShellExecutionService to ignore EBADF (bad file descriptor) errors when attempting to resize a PTY. This change specifically addresses scenarios where a session is resumed and the original PTY file descriptor has become stale, preventing unnecessary errors from being thrown. I have no feedback to provide as there were no review comments to evaluate.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies the ShellExecutionService in packages/core to include EBADF (bad file descriptor) in the list of ignored errors during PTY resizing. This change ensures that stale file descriptors encountered when resuming a session do not trigger unnecessary exceptions, aligning the behavior with existing handling for ESRCH and Windows-specific PTY errors. I have no feedback to provide.
|
@gemini-code-assist Please process this PR |
|
I have reviewed the changes in |
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
Fix
ioctl(2) failed, EBADFcrash when usinggemini --resumedue to stale PTY file descriptors.Details
Add
EBADF(bad file descriptor) to the error codes that are safely ignored inShellExecutionService.resizePty()'s catch block.Background: When resuming a session, the PTY fd from the previous session has already been closed (the process exited). However,
ExecutionLifecycleService.isActive()still returnstruebecause resume re-attaches the execution. The resize call invokesioctl(fd, TIOCSWINSZ, ...)on the stale fd and getsEBADFinstead ofESRCH, causing an unhandled exception that crashes the process.Fix: Treat
EBADFthe same as the already-handledESRCHand Windows PTY exit errors — silently ignore it.Files changed:
packages/core/src/services/shellExecutionService.ts— addEBADFcheck in theresizePtycatch block (+3 lines)Related Issues
#27327
How to Validate
geminisession and run a command that spawns a background taskexitor Ctrl+Cgemini --resumeto restore the sessionioctl(2) failed, EBADFerror no longer occursUnit tests:
npm test -w @google/gemini-cli-core -- src/services/shellExecutionService.test.tsAll 27 PTY-related tests pass.
Pre-Merge Checklist