bug: non-numeric background-PID lines become NaN entries in shell tool output (missing continue)

Open Beginner friendly
#29,042 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
91/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
cli

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.

Description

area/agent effort/small kind/bug priority/p2 status/bot-triaged

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:

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).

Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 4h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.