makecindy / makecindy/cindy

会话结束后 claude 子进程未退出,长期累积占用 CPU 与内存

Open
#4,097 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
2.7k
Forks
401
Avg merge
21h 48m
Merged PRs (30d)
776

Description

**提交人**: Dty Ttyh
**客户端版本**: 0.1.73

---

## 现象

长时间运行 Cindy 后,会话结束(对话不再使用 / 定时任务跑完 / 子 agent 结束)时,Cindy 为该会话拉起的 claude 子进程经常不随之退出,而是长期滞留。这些进程处于休眠态(不是内核意义上的 zombie),但仍持有内存、并在滞留期间累积可观的 CPU 时间。由于每天都会开新会话,滞留进程会随 App 运行时长持续累积。

用户侧一直靠一个外部定时清理脚本(每 4 小时一轮,按空闲时长杀掉老进程)压制,但清理速度追不上新增速度:单日 6 轮共回收 22 个,仍然稳定在告警线以上,说明泄漏是持续的、不是偶发。

## 影响

- 长期占用内存,触发系统换页(观测时交换区已用约 1.6 GB / 共 3 GB),整机变慢。
- 滞留进程持续占 CPU,机器负载被抬高;曾出现负载高到影响其他定时任务按时完成的情况。
- 用户不得不自行维护一个定时 kill 脚本来兜底,且只能治标。

## 脱敏诊断摘要(用户已同意公开)

观测时刻的进程快照:

- 同时存在 16 个 claude 进程,**全部是同一个 Cindy 主进程的直接子进程**(同一 PPID),说明它们没有被 reparent 成孤儿,而是 Cindy 侧在会话结束时没有终止它们。
- 进程状态均为 S(休眠),非 defunct。
- 存活时长分布:其中 15 个在 2.5–5.6 小时之间,另有 1 个为刚启动的当前会话。多个进程已空闲 2–4 小时无任何交互。
- 每个滞留进程累计 CPU 时间约 1–4 分钟。
- Cindy 主进程已连续运行约 3.7 天未重启。
- 新增速率:约每 4 小时新出现 9 个滞留进程;曾观测到一次性清理掉 13 个后,4 小时内重新涨回 16 个。
- 内置 claude-code 版本:2.1.259。
- 平台:macOS / Apple Silicon (arm64)。

## 期望行为

会话结束、关闭或归档时,Cindy 应确保对应的 claude 子进程被可靠终止;并对长时间空闲、已无关联会话的子进程做兜底回收,使进程数不随 App 运行时长单调增长。

## 已知/未知

- 触发场景:用户无法归因到某一类会话,定时任务会话、手动关闭的对话、子 agent 均可能留下残留,看起来是普遍现象。
- 重启 Cindy 后残留是否清零:用户未验证(平时靠清理脚本处理)。不过从父子关系看,这些进程都挂在 Cindy 主进程下,随主进程退出而消失的可能性较大——真正的问题是 App 不重启时它们只增不减。
---
## 提交时的任务环境

仅代表提交时快照,不一定是故障环境。OS 来自提交客户端本机,不含 SSH 远端主机;Harness / 模型来自当前任务。与运行环境无关的反馈可忽略本段。
**OS**: darwin arm64 (25.2.0)
**Harness**: Claude Code
**Model ID**: ` claude-opus-5 `
**界面语言**: zh-CN

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Trace where Cindy creates Claude subprocesses and where session close, archive, scheduled-task, and sub-agent completion are handled; inspect the existing process ownership and cleanup paths. Done means ended sessions reliably terminate their associated processes and long-running Cindy instances do not accumulate idle Claude processes.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
backend, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.