google-gemini / google-gemini/gemini-cli
bug: non-numeric background-PID lines become NaN entries in shell tool output (missing continue)
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
## What happened?
When parsing the background-PID file emitted by backgrounded shell commands, non-numeric lines that aren't recognized sysmond messages are logged as errors — and then control **falls through** to `Number(line)`, pushing `NaN` into `backgroundPIDs`. The result is rendered in the tool output as `Background PIDs: NaN`. A `continue` after the error log was clearly intended.
## Affected code
`packages/core/src/tools/shell.ts:750-764`:
```ts
for (const line of backgroundPIDLines) {
if (!/^\d+$/.test(line)) {
if (
line.includes('sysmond service not found') ||
line.includes('Cannot get process list') ||
line.includes('sysmon request failed')
) {
continue;
}
debugLogger.error(`background pid output: ${line}`);
// <-- missing continue
}
const pid = Number(line);
if (pid !== result.pid) {
backgroundPIDs.push(pid); // NaN !== result.pid is always true
}
}
```
## How can this be reproduced?
Background a command whose pid-file capture includes any stray text line (partial write, shell warning). The resulting `llmContent` contains e.g. `Background PIDs: 12345, NaN`.
## What did you expect to happen?
Unrecognized non-numeric lines are logged once and skipped; only valid PIDs reach `backgroundPIDs`.
## Impact
Garbage data handed back to the model in tool results (confuses downstream reasoning), plus misleading error logs.
## Suggested direction
Add `continue;` after `debugLogger.error(...)`, or restructure as an early-validation loop.
---
*Found by source audit on current `main` (commit `5411f113c`); platform-independent. No open issue/PR covering this was found (searched: background PID NaN).*
Contributor guide
Research direction
Start in packages/core/src/tools/shell.ts:750-764 and inspect the loop that parses backgroundPIDLines. Reproduce with a stray non-numeric line if needed, then verify that it is logged and skipped while valid PIDs still appear in the tool output without NaN entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 91/100