Skip to content

fix(jobs): kill the whole process group on /cursor:cancel - #17

Merged
freema merged 1 commit into
mainfrom
fix/cancel-process-group
Jul 28, 2026
Merged

fix(jobs): kill the whole process group on /cursor:cancel#17
freema merged 1 commit into
mainfrom
fix/cancel-process-group

Conversation

@freema

@freema freema commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

/cursor:cancel killed only the detached worker process, orphaning the cursor-agent child it had spawned. The orphan kept editing files and consuming Cursor credits while /cursor:status reported the job as cancelled.

Root cause: spawnBackground() starts the worker with detached: true (its own process group, delegate.mjs / review.mjs), the worker spawns cursor-agent as a plain child (same group), but cancelJob() signalled only job.pid.

Changes

  • New scripts/lib/kill.mjs#killTree(pid, signal):
    • POSIX: kill(-pid) to reach the whole group; falls back to a single-pid kill when the recorded pid is not a group leader (the foreground-job case), matching the old behaviour there.
    • Windows: taskkill /PID <pid> /T /F.
  • cancelJob() uses killTree for both the initial SIGTERM and the post-grace SIGKILL.
  • CHANGELOG entry under Unreleased; kill added to the lib list in AGENTS.md.

Test plan

  • New tests/kill.test.mjs: pid validation, single-pid fallback for a non-group-leader, false when nothing answers.
  • New case in tests/jobs.test.mjs reproducing the exact background shape (detached group-leader worker + long-running child): cancel must kill both processes. Skipped on win32.
  • npm test: 93/93 green. npm run lint: clean.

Background jobs run as a detached worker (own process group) that spawns
cursor-agent as a plain child. cancelJob() signalled only the worker pid,
so the worker died but cursor-agent kept running — still editing files and
consuming credits — while /cursor:status reported the job as cancelled.

- new lib/kill.mjs#killTree: POSIX kill(-pid) with single-pid fallback for
  foreground jobs whose recorded pid is not a group leader; taskkill /T /F
  on Windows
- cancelJob uses killTree for both the SIGTERM and the post-grace SIGKILL
- tests: killTree unit tests + a jobs test reproducing the detached
  worker + child shape, asserting both processes die on cancel

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@freema freema left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

CodeForge Review

Verdict: comment | Score: 0/10

{
  "verdict": "comment",
  "score": 7,
  "summary": "Solid, well-documented fix for the cursor-agent orphaning bug (setsid + kill(-pgid), with sane Windows/fallback handling and good test coverage).

[Session timed out after 300s. Partial output above.]

---
*Reviewed by [CodeForge](https://github.com/freema/codeforge)*

@freema
freema merged commit f50fd8d into main Jul 28, 2026
6 checks passed
@freema
freema deleted the fix/cancel-process-group branch July 28, 2026 13:51
freema added a commit that referenced this pull request Jul 28, 2026
…roup cancel (#22)

Cut the 0.5.0 changelog section covering #17/#18/#20/#21 and bump the
version in package.json, package-lock.json, and plugin.json.
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.

1 participant