Repository navigation
fix: close the stdin of a dead runtime so its kiro-cli tree exits - #31476
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The change adds one pipe release inside the existing kill path. The defect has a measured reproduction, and a test that fails without the fix. What this change shipsInventory (3 items) — 3 justifiedIntent: when a macOS session is closed, its kiro-cli tree exits, even if the launcher process in front of kiro-cli died first. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] f9da353 Description read[DESCRIPTION-READ] ffbbb4ab606a171b409154eec137b430c6ed08b2a97c7dc98e3ef43b085ff2a1 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the patch removes nothing, the release is limited to the gateway's own pipe end, and the macOS-only branch has live before-and-after runs. [DESIGN-REVIEWED] f9da353 Description read[DESCRIPTION-READ] bd788d92635ee7f74c11240a16c6497a4ba109c63ab09722d3a0709370f23b34 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
3e0d9b6 to
93fce4e
Compare
|
[operator: bolichen97] Rebased: main moved in docs/system-specs/modules/cli.md, docs/system-specs/modules/subagent.md, src/kiro_crew/acp/kas_agents.py, src/kiro_crew/acp/worker_pool.py, test/test_kas_agents_mcp_servers.py and test/test_worker_pool_cancel_reap.py since this head's CI started (85ce466 -> b3c17ad); CI re-running on 93fce4e. None of those is a file this PR changes, and the PR's own diff is byte-identical to the one on 3e0d9b6. The previous head's in-flight runs were cancelled before this push. |
|
[operator: bolichen97] On 3e0d9b6 the GPT 6.1 and Opus 5.5 lanes computed verdicts but could not publish them (the GitHub API rate limit hit while they read this PR). Both withheld verdicts report no blocking findings. The Opus verdict carried one note: that the new test patches |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
93fce4e to
6a0fcd6
Compare
|
[operator: bolichen97]
|
|
[operator: bolichen97] Rebased: main moved in docs/system-specs/modules/acp-client.md, docs/system-specs/modules/metrics.md, src/kiro_crew/acp/kas_secret_storage.py, src/kiro_crew/acp/liveness.py, src/kiro_crew/acp/session_handle_dispatch.py, src/kiro_crew/acp/session_handle_watchdog.py, test/test_acp_stale_recovery.py, test/test_acp_watchdog_working_bound.py and test/test_mcp_grant_kas.py since this head's CI started (b3c17ad -> 89a6107); CI re-running on 6a0fcd6. Of those, only The new base also carries #31469, which raises the security package line budget. |
|
[operator: bolichen97]
|
|
/ai-review override fable 6a0fcd6 false-positive: agent: [operator: bolichen97] the test's liveness check and cleanup call the real kiro_crew.platform_compat; its patches land on the per-test _StubbedPlatformCompat that the autouse fixture binds to rt.platform_compat. With the _release_stdin hunks reverted the test fails its post-kill wait (prove.py PROVEN on this tree). Disposition: issuecomment-6690374257 |
Human judgment recorded@bolichen97 recorded a false-positive release (class
This decision applies only to this commit. A new push requires a new judgment. |
2bac360 to
bd4d2d6
Compare
|
[operator: bolichen97]
|
|
[operator: bolichen97] Rebased onto #31625 (c0e9c2e -> 39717a0), the main fix this PR was waiting for: it raises the security package line budget that all three red shard-2 Backend Tests jobs on 2bac360 failed on ( This is the rebase onto a red-main fix, not a green-age re-sync, so it does not draw on the re-sync budget, which the three earlier re-syncs on this PR have spent. None of the three files this PR changes moved on main, and the PR's own diff is byte-identical to the one on 2bac360. On the rebased head the related backend tests plus the line-budget test pass locally (11 files, 788 tests) and |
|
[operator: bolichen97] The two red shard-7 Backend Tests jobs on bd4d2d6 (Linux 3.12 and Windows) are one test, The fix is #31803. This PR waits for it: no push and no override for that red. The five AI review lanes on bd4d2d6 (Design, First Principles, GPT 6.1, Opus 5.5, UX) failed before any of them produced a verdict: each one hit the shared GitHub API rate limit while reading this PR. Each lane has been re-run once. |
|
[operator: bolichen97]
|
|
/ai-review override fable bd4d2d6 false-positive: agent: [operator: bolichen97] line 717 patches the per-test _StubbedPlatformCompat that the autouse _fast_kill_windows fixture binds to rt.platform_compat, not the module; the test's _still_running wait and finally cleanup read the real kiro_crew.platform_compat. prove.py is PROVEN on this head: with _release_stdin reverted the test fails. |
Human judgment recorded@bolichen97 recorded a false-positive release (class
This decision applies only to this commit. A new push requires a new judgment. |
When the process Kiro Crew spawned for a kiro-cli session is not the one that reads its stdin (a wrapper or launcher sits in front of kiro-cli) and it dies before its tree does, for example killed during the initialize handshake, the descendants keep the write ends of stdout and stderr. asyncio's subprocess transport then never sees every pipe close, never finishes, and never closes stdin, so kiro-cli reads no EOF. On macOS no member of the leaderless group can vouch for it and no descendant was recorded yet, so nothing signals the tree either: kiro-cli, its engine and any MCP server it had started keep running after the session is closed, for the life of the gateway. AcpRuntime's POSIX kill now aborts its own write end of the root's stdin before it drops the handle. It signals nothing: only holders of the pipe's other end, which are this spawn's own tree, see the EOF. It uses the stdin pipe's abort rather than close, which waits for buffered bytes to drain, and never the subprocess transport's close, which kills a root that is still running. Part of #19141
bd4d2d6 to
f9da353
Compare
|
[operator: bolichen97] Rebased onto main 7c364bc, which carries the fix for main's red |
|
[operator: bolichen97]
|
|
[operator: bolichen97] The five AI review lanes (Design, First Principles, UX, GPT 6.1, Opus 5.5) failed twice on head f9da353 on the CI installation token's API rate limit, before any of them posted a verdict (first at 23:08Z, then the rerun at 00:48Z). That is an infrastructure outage, not a review finding, so I re-ran each of the five lanes once more on the same head. No code change. |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on f9da353, no conflict, no open change request.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the runtime kill now aborts the write end of the dead root's stdin so the tree it left reads EOF and exits, with a regression test. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/acp-client.md.
…1476) When the process Kiro Crew spawned for a kiro-cli session is not the one that reads its stdin (a wrapper or launcher sits in front of kiro-cli) and it dies before its tree does, for example killed during the initialize handshake, the descendants keep the write ends of stdout and stderr. asyncio's subprocess transport then never sees every pipe close, never finishes, and never closes stdin, so kiro-cli reads no EOF. On macOS no member of the leaderless group can vouch for it and no descendant was recorded yet, so nothing signals the tree either: kiro-cli, its engine and any MCP server it had started keep running after the session is closed, for the life of the gateway. AcpRuntime's POSIX kill now aborts its own write end of the root's stdin before it drops the handle. It signals nothing: only holders of the pipe's other end, which are this spawn's own tree, see the EOF. It uses the stdin pipe's abort rather than close, which waits for buffered bytes to drain, and never the subprocess transport's close, which kills a root that is still running. Part of #19141 (cherry picked from commit 15ec103)
Problem / Motivation
Goal: Closing a session on macOS ends its kiro-cli and everything below it, even when the process Kiro Crew started in front of kiro-cli died first.
On macOS, when the process Kiro Crew spawns for a session is a wrapper or launcher in front of kiro-cli, and that process dies during the
initializehandshake, kiro-cli and everything below it keep running after the session is closed. Measured on macOS 26.7.2 with kiro-cli 3.1.0 started through such a wrapper launcher: kiro-cli, its engine and the launcher (reparented to PID 1) were still alive 14 minutes after the close, and exited only when the gateway stopped. A stock kiro-cli install, where the spawned process is kiro-cli itself, was not tested for this case. A kiro-cli kept alive this way would also keep alive any language server it had started.Why it matters
Each leaked tree is a whole agent: kiro-cli, its engine and any MCP server it had started, holding memory and CPU until the gateway restarts, and every session whose start fails this way adds one more. #19141 shows what leftover processes cost on a Mac once they pile up: a load average above 100 and a machine that stopped responding.
Not a goal
AcpClient): it already closes its pipes after every kill.What changed (motivation → approach → change)
The process Kiro Crew spawns is not always the one that reads its stdin: a wrapper or launcher can sit in front of kiro-cli and hand it the same pipes. When that spawned root dies first, its descendants still hold the stdout and stderr pipes, so asyncio's transport never finishes and never closes stdin, and kiro-cli never reads EOF. Linux reaches that tree through the vouched group signal. macOS cannot vouch the group, so a tree whose root died before any descendant was recorded had nothing that ended it.
The POSIX kill in
AcpRuntimeaborts its own write end of the root's stdin before it drops the process handle (runtime_tree_kill._release_stdin). kiro-cli reads EOF and exits, and its engine follows. Nothing is signalled: only the holders of that pipe's other end, which are this spawn's own tree, see the EOF. It uses the stdin pipe'sabort, becauseclosewaits for buffered bytes to drain, and not the subprocess transport'sclose, which would kill a root that is still running.The ACP client spec records this release next to the leaderless-group rule it completes.
Backwards compatibility
Compatible: the kill sends exactly the signals it sent before, and closes one pipe end of the process it is tearing down.
Removes nothing: no record, path, key or function goes away; a pipe end the dead runtime no longer uses is released instead of being held until the gateway exits.
Tests
test/test_acp_runtime_kill.py::test_kill_releases_stdin_so_the_tree_a_dead_root_left_reads_eofstarts a real root that exits at once and leaves a child holding its pipes and blocked on stdin. With both signal paths unable to reach anything (the macOS shape),kill()must still make that child exit. With the release removed the child is still running 60 s afterkill(). The test's liveness check reads the kernel through functions bound at import, before any fixture or patch runs, so no stub on the kill path reaches it.Proof: PROVEN test/test_acp_runtime_kill.py::test_kill_releases_stdin_so_the_tree_a_dead_root_left_reads_eof (head f9da353)
Determinism: 10/10 runs at
-n0; 5/5 at-n 2 --dist loadgroup --max-worker-restart=2besidetest/test_pid_lifecycle_teardown.pyandtest/test_runtime_bindings.py; the whole file in a shuffled order (seed 4127), 22 passed. The flake-pattern ratchet passes, and the related backend set (8 files) passes.Manual verification
macOS 26.7.2 (Apple silicon), kiro-cli 3.1.0, pyright 1.1.414, an isolated gateway on its own data home, sessions driven through the dashboard API on a project with
.kiro/settings/lsp.json. On this machine thekiro-clionPATHis a wrapper: the process the gateway spawns is that wrapper, which starts a launcher, which starts the real kiro-cli on the same stdin. Survivors were checked 60 s or more after each close.initializehandshakeIn the last row's After runs the kill was the gateway's own cleanup of the failed handshake; two of the three sessions were then closed, after kiro-cli was already gone.
The same leak reproduces outside the gateway, through the same wrapper: with the parent holding the pipes, 4 of the 6 processes were still running 20 s after the spawned root was killed, and those 4 exited within 1.9 s once only stdin was closed.
The live runs used the fix on 07ab5da; the branch sits on 7c364bc. Between the two, of the three files only
acp-client.mdchanged, in sections outside the kill path;runtime_tree_kill.pyand the test file did not change.Related Issues
Part of #19141
Sibling sweep
Swept: git grep -n "_process = None" -- src/kiro_crew; git grep -n "_proc = None" -- src/kiro_crew
Sibling: src/kiro_crew/acp/client_lifecycle.py -- not affected --
_reset_statecloses stdin, stdout and stderr after every kill, a dead root includedSibling: src/kiro_crew/imessage/rpc.py -- not affected --
close()closes stdin before it reaps the childSibling: src/kiro_crew/computer_use/overlay.py -- not affected -- its teardown closes stdin before it reaps the child
Sibling: src/kiro_crew/mcp_gateway/manager.py -- not affected -- the daemon is spawned with stdin set to DEVNULL
Sibling: src/kiro_crew/power.py -- not affected -- the child is spawned with stdin set to DEVNULL
Sibling: src/kiro_crew/instances/ssh_tunnel_manager_child.py -- not affected -- no stdin pipe is opened to the tunnel child
Sibling: src/kiro_crew/history_index_worker.py -- not affected -- a multiprocessing worker with no stdin pipe from the gateway
Pattern harvest
Rule candidate: review-prompt
Pattern: a teardown drops an asyncio subprocess handle spawned with
stdin=PIPEwithout closing stdin, so descendants of a root that died first never read EOF.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.