Skip to content

Commit 3a5fbe5

Browse files
arul28claude
andcommitted
Add Phase 3j cleanup of lingering worker processes to /finalize
The 8-shard vitest run, parallel tsup builds, and typecheck fans sometimes leave worker pools behind after the phase exits. They don't fail CI but accumulate across runs and can hold file locks. New Phase 3j kills them scoped to apps/ paths so vitest instances the user may have running elsewhere aren't affected. Adds a Cleanup line to the Phase 4 summary and the completion checklist. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 07623ee commit 3a5fbe5

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

.claude/commands/finalize.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,39 @@ git diff --name-only | sort > /tmp/finalize-session-files.txt
379379

380380
If Phase 3e fails only inside files the simplifier touched, revert the simplifier's edits to those files and re-run. Do NOT rewrite the test suite in Phase 3 — tests that drift because the feature branch refactored UI are a separate follow-up.
381381

382+
### 3j. Cleanup lingering processes
383+
384+
The parallel shards, typecheck, lint, and build commands in Phase 3 sometimes leave worker processes hanging after the phase exits — most commonly vitest worker pools from the 8-shard run, and tsup/esbuild workers from `npm run build`. They don't fail the CI check, but they sit in memory, can hold file locks, and pile up across repeated `/finalize` runs.
385+
386+
After the rest of Phase 3 passes, kill orphaned workers. Match on the project path so you only catch processes from **this** finalize run — don't nuke vitest instances the user may have running in another terminal or editor:
387+
388+
```bash
389+
# List what's lingering (agent: read this before killing anything)
390+
pgrep -fa "vitest|tsup|tsc --noEmit|eslint" | grep -E "apps/(desktop|ade-cli|web)" || echo " (no orphans)"
391+
392+
# Kill vitest workers scoped to this project
393+
pgrep -f "vitest.*apps/(desktop|ade-cli)" | xargs -r kill 2>/dev/null
394+
395+
# Kill hung build / typecheck processes scoped to this project
396+
pgrep -f "tsup.*apps/(desktop|ade-cli|web)|tsc --noEmit.*apps/(desktop|ade-cli|web)" | xargs -r kill 2>/dev/null
397+
398+
# Give them 2s to exit cleanly, then SIGKILL anything stubborn in the project path
399+
sleep 2
400+
pgrep -f "vitest.*apps/(desktop|ade-cli)|tsup.*apps/(desktop|ade-cli|web)" | xargs -r kill -9 2>/dev/null || true
401+
```
402+
403+
Never use a bare `pkill -f vitest` or `pkill -f node` — that would kill processes outside this finalize run. Always scope the pattern to `apps/desktop`, `apps/ade-cli`, or `apps/web` so only ADE-spawned workers are targeted.
404+
405+
Also watch for orphaned node-pty or Electron helper processes if the tests spawned subprocesses (rare, but happens):
406+
407+
```bash
408+
pgrep -fa "node-pty|Electron Helper" | grep -E "apps/desktop" | head
409+
```
410+
411+
Kill selectively only if the parent is clearly gone (PPID == 1 on macOS/Linux).
412+
413+
Report killed PIDs in the Phase 4 summary under "Cleanup" so the user can see what happened.
414+
382415
---
383416

384417
## Phase 4: Summary
@@ -411,6 +444,9 @@ If Phase 3e fails only inside files the simplifier touched, revert the simplifie
411444
- Build (all apps): PASS
412445
- Doc validation: PASS
413446
447+
### Cleanup:
448+
- Orphan processes killed: N (PIDs: [list] or "none")
449+
414450
### Status: Ready to push / Issues found
415451
```
416452

@@ -429,3 +465,4 @@ Before marking complete:
429465
- [ ] All tests passed (desktop sharded 8-way + ade-cli)
430466
- [ ] All apps build successfully
431467
- [ ] Doc validation passed
468+
- [ ] Orphan worker processes cleaned up (vitest/tsup/tsc) — scoped to apps/ paths only

0 commit comments

Comments
 (0)