google-gemini / google-gemini/gemini-cli
bug: MCP progress events publish NaN/negative progressPercent to the UI
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
## What happened?
`CoreToolScheduler.handleMcpProgress` validates `payload.total` but **never validates `payload.progress`** before dividing by it. With a valid total and a missing/non-numeric `progress`, the computed `progressPercent` is `NaN` (`Math.min(100, NaN) === NaN`), which is stored on the tool call and published to the UI via `TOOL_CALLS_UPDATE`. Negative progress values are also passed through unclamped.
## Affected code
`packages/core/src/scheduler/scheduler.ts:153-167`:
```ts
const validTotal =
payload.total !== undefined &&
Number.isFinite(payload.total) &&
payload.total > 0
? payload.total
: undefined;
this.state.updateStatus(callId, CoreToolCallStatus.Executing, {
progressMessage: payload.message,
progressPercent: validTotal
? Math.min(100, (payload.progress / validTotal) * 100)
: undefined,
```
## Why this is wrong
Progress payloads originate from external MCP servers (`notifications/progress` cross an event-emitter boundary), so field shapes are not guaranteed. `undefined / n === NaN`, and nothing downstream filters `NaN`. The asymmetry — `total` carefully validated, `progress` not — shows the guard was intended for both.
## How can this be reproduced?
Have an MCP server emit `notifications/progress` with `{ progressToken, total: 10 }` and no `progress` field while a tool call is executing; observe `progressPercent: NaN` on the scheduled call state and in the UI update payload.
## What did you expect to happen?
Non-finite or negative progress should be treated as absent (`progressPercent: undefined`).
## Suggested direction
Validate `Number.isFinite(payload.progress) && payload.progress >= 0` alongside `validTotal`.
---
*Found by source audit on current `main` (commit `5411f113c`); platform-independent. No open issue/PR covering this was found (searched: MCP progress NaN).*
Contributor guide
Research direction
Start in packages/core/src/scheduler/scheduler.ts at CoreToolScheduler.handleMcpProgress, especially lines 153-167, and inspect how updateStatus publishes TOOL_CALLS_UPDATE state. Verify the progress validation against missing, non-finite, negative, and valid values; done means invalid progress produces progressPercent: undefined while valid progress remains correctly bounded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100