makecindy / makecindy/cindy

feat: 普通任务空闲后自动释放 Claude CLI 子进程,避免长期运行内存持续增长

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

Description

### 使用场景 / Use case

日常在 Desktop 里开很多任务,做完一个就切下一个,很少手点「归档」。Cindy 常驻不退出,跑几天。

### 当前问题 / Current limitation

每个打开过并发过消息的任务都会拉起一个常驻的 Claude Code CLI 子进程,任务不归档 / 不删除,进程就一直挂着,哪怕几天没碰。实测(macOS,Cindy 2.1.259 内置 claude):

- Cindy 进程树 161 个进程,共 10.1 GB RSS
- 其中 46 个 claude CLI 子进程占 8.1 GB,单个 150–260 MB,全部 state=S、CPU≈0,最长已挂 30+ 小时
- SIGTERM 掉其中空转超 1 小时的 41 个后,进程树降到 39 个进程 / 2.8 GB,任务再发消息按 resume 正常恢复

代码层面:

- CLI 子进程只在 `session.close()` 时被杀(`packages/maker-core/src/agents/claude-code/index.ts` 的 `close()`),触发它的只有归档 / 删除 / 切 Agent / 上下文溢出滚动,没有空闲超时。
- 空闲释放目前只给 Orca worker 做了(`apps/desktop/src/main/maker-ipc/orcaIdleReleaseWatcher.ts`,设置项 `workerIdleReleaseMinutes`),普通任务不走它。
- 进程死掉后 handle 走 `teardownDeadHandle` → Session 自动 close → 下次 send lazy 重建并 resume,所以关掉空闲进程不丢历史。

### 期望方案 / Proposed solution

给普通任务加一个空闲回收:任务空转 N 分钟(无 turn 在跑、无排队输入、无后台任务)→ 关掉 CLI 子进程,任务在列表里不动、不改状态,下次发消息按现有 resume 路径自动重建。可以复用 `orcaIdleReleaseWatcher` 的 scan / 单飞 / 加锁骨架,加一个独立设置项(默认开,可调分钟数)。

### 已考虑的替代方案 / Alternatives considered

- 用户手动归档:可行但依赖习惯,多数人不会主动点。
- 定期重启 Cindy:能清,但一刀切,也不该让用户承担。

Contributor guide

Open the contributing guide

Research direction

Start by reading packages/maker-core/src/agents/claude-code/index.ts, especially session.close(), then compare the scan, single-flight, and locking behavior in apps/desktop/src/main/maker-ipc/orcaIdleReleaseWatcher.ts. Trace teardownDeadHandle and the existing resume path to verify idle processes can be released safely; done means an independently configurable idle setting releases only eligible ordinary-task CLI processes while preserving task state and allowing the next message to resume.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.