fix(core): make shell tool work under Bun - #3
Closed
euxaristia wants to merge 1 commit into
Closed
Conversation
Two related runtime issues prevented `bun start`/`bun`-launched builds of gemini-cli from running shell tool calls: 1. The pty path silently captures no output under Bun — node-pty's `tty.ReadStream` wrapper around the master fd doesn't deliver data to `onData`, so the shell tool reports success with an empty result. 2. When `resizePty` does run, it hits `ioctl(2) failed, EBADF` because `destroyPtyProcess()` in `onExit` closes the master fd before the entry is removed from `activePtys`. The window is narrow on Node but widens under Bun's microtask scheduling, crashing the React render. getPty() now short-circuits to the existing `child_process` fallback when running under Bun (which already has Bun-specific `detached:false` handling). `GEMINI_PTY_INFO=node-pty` overrides for testing. resizePty() also swallows the `EBADF`/`ENOTTY` ioctl errors the same way it already swallows `ESRCH` and the Windows "already exited" message — they all mean the same thing: the pty is gone, nothing to resize. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related runtime issues prevented
bun-launched builds of gemini-cli from running shell tool calls. The first failure visible to a user is anioctl(2) failed, EBADFcrash inside a ReactuseEffect. After patching that, the shell tool stops crashing but every command returns empty output. Both stem from@lydell/node-ptynot behaving correctly when loaded by Bun.getPty()now short-circuits to the existingchild_processfallback whenprocess.versions.bunis set. The fallback path already has Bun-specific handling (detached:falseto avoid immediateSIGHUP, added in fix(core): disable detached mode in Bun to prevent immediate SIGHUP of child processes google-gemini/gemini-cli#22620).GEMINI_PTY_INFO=node-ptyoverrides the new behavior for anyone wanting to test the pty path under Bun.ioctl(2) failed, EBADFcrash on resize.ShellExecutionService.onExitcallsdestroyPtyProcess()(which closes the master fd) before the entry is removed fromactivePtysat the end of thecleanupLogStreampromise chain. A concurrentresizePty()fromShellToolMessage'suseEffectlands in that window, calls the native resize on a closed fd, andioctlreturnsEBADF. The window is narrow under Node but widens under Bun's microtask scheduling.resizePty()now treatsEBADF/ENOTTYthe same way it already treatsESRCHand the Windows "Cannot resize a pty that has already exited" message — the pty is gone, nothing to resize.The two fixes are independent but both required: the fallback gating prevents the bad state from being entered under Bun, the resize guard makes the race safe everywhere in case a stray pty path is hit (manual
GEMINI_PTY_INFO=node-ptytesting, future runtimes with similar timing).Test plan
bun startno longer crashes withioctl(2) failed, EBADFon shell tool callsbun startproduce captured output (e.g.echo hello,bun --version,which bun)GEMINI_PTY_INFO=node-pty bun startre-enables the pty path (still broken under Bun, but useful for confirming the override works)should ignore EBADF when the master fd was already closedcovers the resize swallow🤖 Generated with Claude Code