google-gemini / google-gemini/gemini-cli
bug(ide): Windows IDE detection fallback invokes Unix-only 'ps' command, so snapshot failures silently return an empty command
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### Summary
On Windows, `getIdeProcessInfoForWindows()` in `packages/core/src/ide/process-utils.ts` has a fallback path that is guaranteed to fail: when the PowerShell process-table snapshot does not contain the CLI's own PID (e.g. `Get-CimInstance` times out after 5s, output exceeds `maxBuffer`, or PowerShell errors out), the code falls back to `getProcessInfo(myPid)` — but `getProcessInfo()` shells out to the **Unix-only** command `ps -o ppid=,command= -p `, which does not exist on Windows.
### Affected code
`packages/core/src/ide/process-utils.ts` (main):
```ts
// L94 (getProcessInfo – Unix only):
const command = `ps -o ppid=,command= -p ${pid}`;
// L181-183 (Windows fallback – broken):
async function getIdeProcessInfoForWindows() {
const processMap = await getProcessTableWindows();
const myProc = processMap.get(myPid);
if (!myProc) {
// Fallback: try to get info for current process directly if snapshot fails
const { command } = await getProcessInfo(myPid); // <- runs 'ps' on Windows
return { pid: myPid, command }; // command is always ''
}
```
On Windows, `exec('ps ...')` throws (`'ps' is not recognized`), the catch swallows it, and the function returns `{ parentPid: 0, name: '', command: '' }`. IDE detection therefore degrades **silently** to an empty command exactly when the snapshot path fails — the one situation the fallback exists for.
### Steps to reproduce
1. On Windows, simulate a failed snapshot (e.g. temporarily break `getProcessTableWindows()` or block `Get-CimInstance`).
2. Run gemini-cli inside a VS Code integrated terminal.
3. Observe that `getIdeProcessInfoForWindows()` resolves with `command: ''` instead of best-effort info; IDE companion matching/context ends up degraded without any log or warning.
### Expected behavior
When the Windows process-table snapshot fails, the fallback should either re-query the single PID via CIM (`Get-CimInstance Win32_Process -Filter "ProcessId="`) or return gracefully with a `debugLogger.warn`, rather than invoking a Unix-only utility that cannot succeed on win32.
### Environment
- OS: Windows (win32)
- Component: `packages/core` / IDE integration
- Observed on source at `main`
### Sources / context
- Introduced alongside the O(1) Windows detection optimization (#11048) and the `GEMINI_CLI_IDE_PID` override (#15842); this specifically affects the `!myProc` fallback branch.
- Related but distinct: #28677 adds timeouts to `IdeClient.getInstance()` traversal — different problem.
- Searched existing issues/PRs ("process-utils", "ide process windows ps", "getIdeProcessInfo") — no duplicate found.
Contributor guide
Research direction
Start in packages/core/src/ide/process-utils.ts, reading getIdeProcessInfoForWindows() and its !myProc fallback alongside getProcessInfo(). Exercise the failed Windows snapshot path and verify the fallback no longer invokes the Unix-only ps command. Done means it returns best-effort process information or emits the specified warning without silently producing an empty command.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, typescript
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100