Skip to content

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

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

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
Copy Markdown

@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

@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 <thepagent@users.noreply.github.com>
@osolmaz
Copy link
Copy Markdown
Contributor

osolmaz commented Mar 3, 2026

Is this ready and tested? happy to merge it

@thepagent
Copy link
Copy Markdown
Author

Hi @osolmaz, yes it's basically doing well and we have a group of people using this now on daily basis. I think it's safe to ship. Will resolve the conflicts and turn into ready for review.

… 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 fa8889e to 5cd01fa Compare March 6, 2026 18:53
@thepagent thepagent marked this pull request as ready for review March 6, 2026 18:54
@Takhoffman
Copy link
Copy Markdown
Contributor

Thanks for the PR. I’m going to close this one in favor of #40.

The Kiro registry addition itself looks useful, but this branch also folds in broader process cleanup/runtime behavior changes. I want to keep the Kiro built-in addition narrow and consistent with the other provider additions, so I’m taking the smaller PR for that.

If you want, please feel free to reopen the process cleanup part as a separate focused PR. I think that piece deserves its own review on the runtime behavior rather than being bundled into the provider add.

@Takhoffman Takhoffman closed this Mar 9, 2026
vokako added a commit to vokako/acpx that referenced this pull request Mar 12, 2026
kiro-cli is a wrapper that forks kiro-cli-chat as the actual ACP
server process. When acpx sends SIGTERM to kiro-cli on session close,
only the wrapper is killed while kiro-cli-chat continues running as
an orphan process. These orphaned processes accumulate over time and
cause port/resource conflicts that result in ACP_TURN_FAILED errors
on subsequent messages in persistent sessions.

Fix: point the built-in kiro agent directly at kiro-cli-chat acp,
bypassing the wrapper entirely. This ensures clean process lifecycle
without needing process group kill logic.

Related: openclaw#42 (proposed process group cleanup approach — this commit
provides a simpler fix by avoiding the wrapper altogether)
vokako added a commit to vokako/acpx that referenced this pull request Mar 13, 2026
kiro-cli is a wrapper that forks kiro-cli-chat as the actual ACP
server process. When acpx sends SIGTERM to kiro-cli on session close,
only the wrapper is killed while kiro-cli-chat continues running as
an orphan process. These orphaned processes accumulate over time and
cause port/resource conflicts that result in ACP_TURN_FAILED errors
on subsequent messages in persistent sessions.

Fix: point the built-in kiro agent directly at kiro-cli-chat acp,
bypassing the wrapper entirely. This ensures clean process lifecycle
without needing process group kill logic.

Related: openclaw#42 (proposed process group cleanup approach — this commit
provides a simpler fix by avoiding the wrapper altogether)
vokako added a commit to vokako/acpx that referenced this pull request Mar 13, 2026
kiro-cli is a wrapper that forks kiro-cli-chat as the actual ACP
server process. When acpx sends SIGTERM to kiro-cli on session close,
only the wrapper is killed while kiro-cli-chat continues running as
an orphan process. These orphaned processes accumulate over time and
cause port/resource conflicts that result in ACP_TURN_FAILED errors
on subsequent messages in persistent sessions.

Fix: point the built-in kiro agent directly at kiro-cli-chat acp,
bypassing the wrapper entirely. This ensures clean process lifecycle
without needing process group kill logic.

Related: openclaw#42 (proposed process group cleanup approach — this commit
provides a simpler fix by avoiding the wrapper altogether)
vokako added a commit to vokako/acpx that referenced this pull request Mar 13, 2026
kiro-cli is a wrapper that forks kiro-cli-chat as the actual ACP
server process. When acpx sends SIGTERM to kiro-cli on session close,
only the wrapper is killed while kiro-cli-chat continues running as
an orphan process. These orphaned processes accumulate over time and
cause port/resource conflicts that result in ACP_TURN_FAILED errors
on subsequent messages in persistent sessions.

Fix: point the built-in kiro agent directly at kiro-cli-chat acp,
bypassing the wrapper entirely. This ensures clean process lifecycle
without needing process group kill logic.

Related: openclaw#42 (proposed process group cleanup approach — this commit
provides a simpler fix by avoiding the wrapper altogether)
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.

3 participants