#13284: fix(commands): /stop now kills orphaned exec processes
agents
size: M
## Summary
- `/stop` previously only aborted the embedded agent run (`abortEmbeddedPiRun`) but left spawned exec/bash child processes running, causing resource leaks
- Now `handleStopCommand` also iterates over `listRunningSessions()`, matches by `sessionKey`, and calls `killSession()` on each orphaned process
## Test plan
- [x] New test: `commands-session.stop-process-kill.test.ts`
- [ ] CI
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR extends `/stop` handling so it not only aborts the embedded Pi run but also enumerates registered exec/bash sessions and calls `killSession()` for those matching the target `sessionKey`, addressing orphaned child processes. It also adds compaction improvements in the embedded runner: a configurable timeout for `session.compact()`, optional compaction model override, and forcing `reasoning: false` during compaction to avoid SDK summary calls triggering extended thinking. Tests were added/updated to cover compaction behavior and the new `/stop` process-kill behavior, and a small behavior tweak avoids emitting reset notifications into group chats.
Key integration points are `src/auto-reply/reply/commands-session.ts` (command handling), the process registry/kill utilities in `src/agents/*`, and compaction logic in `src/agents/pi-embedded-runner/compact.ts` backed by new config schema fields under `agents.defaults.compaction`.
<h3>Confidence Score: 3/5</h3>
- This PR has valuable fixes but includes a couple of behavior gaps that can break expected cleanup and compaction tool configuration.
- The `/stop` change relies on `listRunningSessions()`, which only returns backgrounded sessions, so some orphaned/foreground exec processes may remain. Separately, compaction’s model override is applied to model resolution, but downstream tool construction/sanitization still uses the primary provider/model IDs, so compaction runs can end up with tool policy/settings mismatched to the effective compaction model.
- src/auto-reply/reply/commands-session.ts, src/agents/pi-embedded-runner/compact.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
---
## Validation
- [x] `pnpm build` — passes
- [x] `pnpm check` — passes
- [x] `pnpm test` — new test in commands-session.stop-process-kill.test.ts
## Contribution checklist
- [x] **Focused scope**: /stop command now kills orphaned exec processes
- [x] **What + why**: described above
- [x] **AI-assisted**: Yes, Claude Code was used for implementation. Testing level: lightly tested (1 new test + manual)
Most Similar PRs
#17445: fix(pi-embedded): add aggregate timeout to compaction retry + harde...
by joeykrug · 2026-02-15
74.8%
#5467: Fix: make embedded compaction wait abortable
by yoyooyooo · 2026-01-31
74.4%
#10505: feat(compaction): add timeout, model override, and diagnostic logging
by thebtf · 2026-02-06
73.4%
#19256: feat: add 'stop all' command and fix subagent cascade on word-trigg...
by lancejames221b · 2026-02-17
73.2%
#21115: fix(agent): immediately abort active run on stop/abort message during…
by anillBhoi · 2026-02-19
72.2%
#6268: fix: add timeout to compaction retry to prevent session lockout
by batumilove · 2026-02-01
70.9%
#5593: fix(pi-embedded-runner): force-clear stuck embedded runs after timeout
by grassX1998 · 2026-01-31
70.8%
#11999: fix: add session-growth guard to prevent unbounded session store gr...
by reverendrewind · 2026-02-08
70.7%
#9085: fix: improve stability for terminated responses and telegram retries
by vladdick88 · 2026-02-04
70.7%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
70.6%