Skip to content

feat: add Kiro CLI as built-in agent with proper process group cleanup#42

Draft
thepagent wants to merge 6 commits intoopenclaw:mainfrom
thepagent:fix/kill-agent-on-queue-owner-exit
Draft

feat: add Kiro CLI as built-in agent with proper process group cleanup#42
thepagent wants to merge 6 commits intoopenclaw:mainfrom
thepagent:fix/kill-agent-on-queue-owner-exit

Conversation

@thepagent
Copy link

@thepagent thepagent commented Mar 3, 2026

Summary

Adds Kiro CLI as a built-in agent and fixes orphan child processes caused by wrapper binary patterns.

Problem

kiro-cli acp is a wrapper that forks kiro-cli-chat as the actual ACP server. The old agent.kill() only killed the wrapper — the child became an orphan and accumulated over time.

spawn "kiro-cli acp"  (pid N)
        └─ forks "kiro-cli-chat acp"  (pid N+7)  ← actual ACP server

agent.kill()  →  kills pid N only
                 pid N+7 reparented to init  💀 orphan

This affects any agent using a wrapper binary pattern.

Fix

Spawn with detached: true so the agent becomes a process group leader. On close, use process.kill(-pgid, SIGTERM) to kill the entire group.

process.kill(-N, SIGTERM)  →  kills pgid N (includes N+7)  ✅

Falls back to child.kill() if process group kill is unsupported.

Tests

Two new tests in test/process-group-kill.test.ts prove the fix:

  1. process group kill terminates parent and grandchild (no orphan) — verifies the fix works
  2. killing only parent pid leaves grandchild as orphan (demonstrates the bug) — reproduces the original bug

Changes

  • src/agent-registry.ts — add kiro: "kiro-cli acp" as built-in agent
  • src/client.tsdetached: true on spawn + process.kill(-pgid) in terminateAgentProcess
  • src/session-runtime.ts — add onAgentPid callback to runQueuedTask / runSessionPrompt
  • test/agent-registry.test.ts — update for 6 agents
  • test/process-group-kill.test.ts — new: prove process group kill vs orphan

Related

… processes

kiro-cli is a wrapper that forks kiro-cli-chat as the actual ACP server.
Sending SIGTERM to the wrapper does not kill the child process, which
becomes an orphan and accumulates over time.

Fix: spawn the agent with detached:true so it becomes a process group
leader, then use process.kill(-pgid, SIGTERM/SIGKILL) to kill the entire
process group including all child processes.

Also adds onAgentPid callback to runQueuedTask/runSessionPrompt to allow
callers to track the agent pid for cleanup purposes.
@thepagent thepagent force-pushed the fix/kill-agent-on-queue-owner-exit branch from 8f14577 to bec9f62 Compare March 3, 2026 00:32
@thepagent thepagent changed the title fix: kill entire process group on agent close to prevent orphan child processes feat: add Kiro CLI as built-in agent with proper process group cleanup Mar 3, 2026
thepagent added a commit to thepagent/claw-info that referenced this pull request Mar 3, 2026
thepagent added a commit to thepagent/claw-info that referenced this pull request Mar 3, 2026
thepagent added a commit to thepagent/claw-info that referenced this pull request Mar 3, 2026
* docs: update acp_kiro.md with process group fix and PR #42 reference

* fix: correct acpx PR link to openclaw/acpx#42

* ci: retrigger check-commit-author

* ci: retrigger after check-commit-author fix

---------

Co-authored-by: thepagent <[email protected]>
@osolmaz
Copy link
Contributor

osolmaz commented Mar 3, 2026

Is this ready and tested? happy to merge it

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.

2 participants