google-gemini / google-gemini/gemini-cli

bug: background-process history evicts still-running entries (insertion-order FIFO ignores status)

Open Beginner friendly
#29,056 0 comments 0 reactions 0 assignees View on GitHub
area/agent status/need-triage
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

## What happened?

Background-process history is capped with a plain insertion-order FIFO: when full, the *oldest inserted* entry is deleted regardless of whether that process is still running. A session that backgrounds many long-lived processes can evict the record of a **live** process; its exit handler then finds no history item and no-ops, so `listBackgroundProcesses()` permanently loses a running process and its exit status is never recorded.

## Affected code

`packages/core/src/services/shellExecutionService.ts:1501-1506`:

```ts
if (history.size >= MAX_BACKGROUND_PROCESS_HISTORY_SIZE) {
const oldestPid = history.keys().next().value;
if (oldestPid !== undefined) {
history.delete(oldestPid);
}
}
```

`Map` iteration is insertion order; nothing checks the evicted entry's `status`. The exit path looks the item up by pid (~lines 796-803 / 1280-1286) and silently does nothing when missing.

## How can this be reproduced?

1. Background `MAX_BACKGROUND_PROCESS_HISTORY_SIZE` long-running commands, keeping the earliest alive.
2. Background one more command.
3. The first (still-running) entry disappears from `listBackgroundProcesses`; when it eventually exits, no completion is recorded.

## What did you expect to happen?

Eviction should prefer completed/failed entries; running processes should never be evicted while alive.

## Suggested direction

Scan for a terminal-status entry to evict first (`history.values().find(v => v.status !== 'running')`) and only fall back to oldest-insertion if all entries are live (or raise the cap).

---

*Found by source audit on current `main` (commit `5411f113c`); platform-independent. No open issue/PR covering this was found (searched: background process list eviction).*

Contributor guide

Open the contributing guide

Research direction

Start in packages/core/src/services/shellExecutionService.ts at the history-cap logic around lines 1501-1506, then read the exit paths around lines 796-803 and 1280-1286. Verify that eviction selects a terminal-status entry before a running one, and reproduce the described sequence to confirm live processes remain listed and later record their exit status.

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
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.