Skip to content

fix(desktop): TODOのStopでclaudeが止まらない問題を修正#195

Merged
MocA-Love merged 4 commits into
mainfrom
fix/191-todo-stop-process-group
Apr 16, 2026
Merged

fix(desktop): TODOのStopでclaudeが止まらない問題を修正#195
MocA-Love merged 4 commits into
mainfrom
fix/191-todo-stop-process-group

Conversation

@MocA-Love
Copy link
Copy Markdown
Owner

概要

Issue #191 の対応。AgentManager で Stop を押しても Claude がしばらく動き続けたり、完全に止まらなかったりする症状があった。

根本原因

`supervisor.abort()` は `currentChild.kill("SIGINT")` を呼ぶだけで、`claude -p` が spawn した子孫プロセス(Node-side の agent loop、MCP サーバ、tool helpers など)には一切シグナルが届いていなかった。`claude` の直接の wrapper が終了しても、実際に Anthropic API と話している孫プロセスが残り続けるので UI 的には止まっていない状態に見える。

修正

  1. `spawn` 時に `detached: true` を指定し、子を独立したセッションリーダにする(Windows 以外)。
  2. 新ヘルパー `killProcessTree(pid, signal)` を追加:
    • POSIX: `process.kill(-pid, signal)` で負の PID 指定によりプロセスグループ全体にシグナル送信。失敗時は直接 pid にフォールバック。
    • Windows: `taskkill /PID /T /F`。
  3. `abort()` と `onAbort` ハンドラで `child.kill` を `killProcessTree` に置換。SIGINT → 1.5 秒後 SIGKILL の二段構えはそのまま。

Test plan

  • 長時間走るタスクで Stop → claude とその子孫プロセスが全て終了する
  • 即時終了する短いタスクでも従来どおり正常に完了する
  • Stop 後にセッションが aborted 状態で DB に残る

Closes #191

supervisor.abort() は currentChild に SIGINT を送るだけで、
claude -p が spawn する子孫プロセス(MCPサーバ等)には信号が
届いていなかった。結果 Stop を押しても Anthropic API との
通信を続けるケースがあった。

spawn 時に detached: true を指定して子をセッションリーダに
し、-pid で process group 丸ごと SIGINT→SIGKILL する
killProcessTree ヘルパー経由で終了させるように変更。
Windows は taskkill /T /F にフォールバック。

Closes #191
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@MocA-Love has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 40 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 41 minutes and 40 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f3ad2b3-eaef-4f98-8f8e-c3b63693db04

📥 Commits

Reviewing files that changed from the base of the PR and between 58c8e6f and d2a2b57.

📒 Files selected for processing (1)
  • apps/desktop/src/main/todo-agent/supervisor.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/191-todo-stop-process-group

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e543ecb2bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +134 to +135
if (child.pid && !child.killed) {
killProcessTree(child.pid, "SIGKILL");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard delayed SIGKILL against exited child PID reuse

killProcessTree now sends signals via process.kill(...) instead of child.kill(...), so ChildProcess.killed never flips to true. As a result, this timeout guard always passes and sends SIGKILL 1.5s later even if the process already exited after SIGINT; if the PID has been reused in that window (rare but possible on busy systems), the follow-up kill can target an unrelated process group. Please gate on exitCode/signalCode (or clear the timer on close) rather than child.killed.

Useful? React with 👍 / 👎.

): void {
if (process.platform === "win32") {
try {
spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid blocking main process with synchronous taskkill

The Windows implementation uses spawnSync("taskkill", ...), which blocks Electron’s main thread until the OS command finishes. In Stop flows, terminating a large or slow process tree can take noticeable time, and this synchronous call can freeze IPC/UI responsiveness during that period. Using an async process API would preserve behavior without stalling the main event loop.

Useful? React with 👍 / 👎.

- killed フラグではなく exitCode/signalCode を見て SIGKILL の
  二段目を判断。ついでに 'close' で timer を clear して
  PID 再利用の誤射を防ぐ
- Windows の taskkill を spawnSync から非同期 spawn に変更
  (stdio: ignore, detached, unref) して Electron main を
  ブロックしないようにした

Refs: Codex review on PR #195
@MocA-Love MocA-Love merged commit 380d27e into main Apr 16, 2026
6 checks passed
@MocA-Love MocA-Love deleted the fix/191-todo-stop-process-group branch April 16, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] TODO機能でStopとか教えてるのにclaudeが動き続けてしまったりする。

1 participant