bug: shell execution runs exit handling twice on spawn failure ('error' and 'close' both call handleExit)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- cli
Research direction
Start in packages/core/src/services/shellExecutionService.ts:819-838 and inspect how the child 'error' and 'close' handlers call handleExit. Reproduce the issue with a command whose spawn fails, then verify that one process run emits one exit event and performs cleanup and background-history finalization once.
Written by the indexing model from the issue text.
Description
What happened?
In the shell execution pipeline, both the child 'error' and 'close' events invoke handleExit(), and handleExit has no re-entrancy guard. Per Node's documented behavior, 'close' fires after 'error' when spawning fails — so every failed spawn runs exit handling twice: onOutputEvent({ type: 'exit', ... }) fires twice, background-history finalization runs twice, and cmdCleanup?.() executes twice. If 'error' fires mid-run on a successfully spawned child (e.g., kill/IPC failure), the result settles early on partial output before 'close' arrives.
Affected code
packages/core/src/services/shellExecutionService.ts:819-838:
child.on('error', (err) => {
error = err;
handleExit(1, null); // first settlement
});
// ...
child.on('close', (code, signal) => {
handleExit(code, signal); // second settlement for the same run
});
How can this be reproduced?
Execute a command whose spawn fails (nonexistent executable / bad sandbox path). Observe two exit output events emitted for the single run (and doubled cleanup calls).
What did you expect to happen?
Exactly one exit settlement per process run.
Suggested direction
Add a settled flag inside handleExit (return immediately on second call), matching the pattern used elsewhere in this file for stream finalization.
Found by source audit on current main (commit 5411f113c); platform-independent. No open issue/PR covering this was found (searched: shell exit event twice).
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 43
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google-gemini/gemini-cli
-
bug(core): explicit `--model gemini-3-pro-preview` silently rewritten to `gemini-3.1-pro-preview` Openarea/agent effort/medium kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
google-gemini/gemini-cli#29417 · 1 comment ·
-
area/enterprise kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
google-gemini/gemini-cli#29406 ·
-
area/agent status/need-triage
Difficulty 2/5 Half a day Newbie friendliness 78/100
google-gemini/gemini-cli#29360 ·
-
area/agent kind/bug priority/p2 status/bot-triaged
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
google-gemini/gemini-cli#29315 ·
-
area/non-interactive effort/small kind/bug priority/p2 status/bot-triaged status/need-information
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
google-gemini/gemini-cli#29308 · 2 comments ·
All issues in google-gemini/gemini-cli
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100