Repository navigation
fix(session): reclaim untracked agent runtimes this install spawned - #12612
DcXiaoBing wants to merge 1 commit into
Conversation
|
Intent: Let the orphan sweep reclaim an untracked agent runtime once it can prove this install spawned it, so leaked |
72c8875 to
648d0d1
Compare
Design Review (Fable 5, fork) — 🔴 BLOCK (blocking)Design-level review of Design-Verdict: BLOCK Description promises a "no live owning session" reclaim conjunct the code deliberately drops and pins the opposite of — the approved contract is not the shipped one. BlockersThe kill path's safety contract in the description is not the one implemented. [DESIGN-REVIEWED] 951af8d Description read[DESCRIPTION-READ] b41573a6d1a6b7bf2cf7530092c27bc6cc1317b6ae5d233b2e524dd915092d6c 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 |
GPT 5.6 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/session_pid.py:4561 -- Reclaim ignores a live owning session
Adjudication (Opus 5) — is blocking on each finding proportionate?F1 — harm rung: UNBOUNDED-adjacent (silent SIGKILL of a live process tree and its in-flight work, unrecoverable). [ADJUDICATION] 951af8d total=0 uphold=0 downgrade=0 [ADJUDICATION-FENCED] 951af8d fenced=1 flagged=0 |
648d0d1 to
b35a6dc
Compare
First Principles Review (Fable 5, fork) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK The sweep now SIGKILLs by default what base code says awaits "a maintainer's ruling on whether an untracked runtime may be reaped at all" — no RFC records that ruling. Not justified as shipped
What this change shipsInventory (8 items) — 4 justifiedIntent: FIX — stop leaked
Blockersproduct-shape change without accepted RFC — the untracked-runtime arm of a first-class monitor (runs on every cleanup tick, [FIRST-PRINCIPLES-REVIEWED] 951af8d Description read[DESCRIPTION-READ] 1371826a0b8db52271ef245d3cb9d211309ae764a86c962c28f52e76e35e9467 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5 Review (fork) — 🔴 changes requested (blocking)Reviewed The new runtime reclaim resolves the tree from [BLOCK-MERGE] 951af8d BLOCKING — src/kiro_crew/session_pid.py:5366 An agent backgrounds a [OPUS-REVIEWED] 951af8d |
9392949 to
1d98bd0
Compare
1d98bd0 to
eec5c23
Compare
|
|
|
|
|
|
Maintainer ruling on the First Principles question: Crew may reclaim an untracked runtime tree it can prove this install spawned. Proof required per root, all of: |
4a13d97 to
951af8d
Compare
Give the untracked-MCP sweep kill authority over a leaked agent runtime tree only when the root proves this install spawned it and no live session owns it: its KIROCREW_SPAWN_HOME equals this install's data home, its KIROCREW_SPAWN_INSTANCE is a token this gateway minted (both read from the process environment), and the session leader it was spawned under is gone. The sid is a refusal input only: a live leader, a self-led root or an unreadable sid keeps the root report-only, and the sid never grants the kill. Both spawn paths stamp KIROCREW_SPAWN_HOME beside the instance and mint the instance through session_pid.mint_spawn_instance, which remembers every token it hands out. The kill phase captures the root's start identity before any other read, re-checks it before enumerating the tree by process group and instance, refuses a root whose group is led by a live process, drops vouched members a reaper already owns (fresh tracked snapshot, protected set), and binds every signal to the enumerated identity through a pidfd, so a recycled pid is never signalled on stale evidence. The work-orphan arm shares that identity-bound kill path, enumerates through _orphan_descendants instead of the ACP layer, and quotes process-controlled argv0 in logs.
951af8d to
cc81de9
Compare
|
span=5a79f647cc9c
|
|
span=99fb501fe250
|
|
span=afe7cf520521
|
|
span=0eefc344f534
|
|
span=aa5608c75f1e
|
|
span=750436447eed
|
|
span=c61715228c1e
|
|
span=8e4b7db3a8f0
|
Problem / Motivation
Goal: Reclaim leaked agent runtimes this install provably spawned, and leave every other process alone.
The periodic orphan sweep detects untracked agent runtimes that are reparented to init, but its report-only path leaves each runtime tree resident. Since #11309, #11565 and #11720 the tracked teardown path kills the whole group and records descendants, so the runtimes that still reach the report-only arm are those whose root died before the first PID-file snapshot, and every runtime on hosts without cgroup v2 scope delegation (where
session_scope_reaphas nothing to reclaim). A leakedkiro-cli acptree can retain its chat process and MCP servers, consuming about 1.2 GB until an operator intervenes.Why it matters
Repeated leaks can exhaust a long-running gateway host. One observed dev desktop accumulated 42 trees over four days, consuming 48 GB of a 61 GB host. Reclaiming them safely requires proof that this install spawned the runtime and that no live session owns it.
Not a goal
What changed (motivation → approach → change)
The sweep reclaims only runtime trees whose ownership and process identities remain provable at signal time, and whose owning session is gone.
src/kiro_crew/constants.py,src/kiro_crew/acp/runtime.py, andsrc/kiro_crew/acp/client.pystamp runtimes withKIROCREW_SPAWN_HOMEandKIROCREW_SPAWN_INSTANCE;session_pid.mint_spawn_instanceis the one minting point and remembers every token it hands out._is_reclaimable_untracked_runtimeinsrc/kiro_crew/session_pid.pyrequires ALL of:_is_untracked_managed_agent_orphan(reparented, harness argv0,KIROCREW_SPAWNED, in neither PID file), a complete tracked-PID snapshot,KIROCREW_SPAWN_HOMEequal to this install's data home, aKIROCREW_SPAWN_INSTANCEin this gateway's minted set, an age of at least_UNTRACKED_RUNTIME_MIN_AGE_SECONDS, and_work_orphan_session_leader_alivefalse (the root's session leader is gone). The sid is a refusal input only, never reclaim authority: a live leader, a self-led root (setsid-detached) or an unreadable sid keeps the root report-only; a dead launcher passes._kill_orphan_runtime_treerevalidates the root start token before group enumeration, refuses a root that does not lead its group while the group's leader is alive (a live runtime's backgrounded child), drops vouched members present on a fresh tracked-PID snapshot or in the protected set (an incomplete snapshot enumerates nothing), vouches the rest by process group and instance, rechecks each member token at signal time, and signals the root last. Recycled or unreadable identities fail closed._spawn_env_valuedecodesKIROCREW_SPAWN_HOME/KIROCREW_SPAWN_INSTANCEas UTF-8 (errors="replace"), not ASCII, so a non-ASCII data home compares equal topeek_data_home()..github/agent-sdk-boundary-baseline.txtrecords the reduced ACP import count.docs/system-specs/modules/session.mdnames the age-floor constant and documents the ownership, leader-refusal and revalidation contract.test/acp_launch_capture.pyandtest/fixtures/acp_launch_goldens.jsonnormalize and pin the runtime ownership environment. Runtimes without complete proof remain report-only, including pre-stamp processes and non-Linux environments where the required process evidence is unavailable. macOS is a follow-up:KIROCREW_SPAWN_HOME/INSTANCEare readable there viaKERN_PROCARGS2, but the leader refusal reads the target's SID through_linux_pid_sid, which no darwin helper exposes yet; it needs its own ownership proof rather than a port.Backwards compatibility
Compatible: no accepted command, configuration, or API input is rejected. Spawned runtimes receive ownership metadata, while any runtime that lacks the full proof remains report-only.
Tests
test/test_pid_lifecycle.pycovers every reclaim predicate, the leader refusal (live leader, self-led root, unreadable sid refuse; dead launcher passes), incomplete tracking snapshots, root and member PID reuse, a root whose group leader is alive (nothing enumerated), owned members dropped before signalling, identity-bound group signaling, kill ordering and caps, work-orphan subtree handling, hostile argv0 logging, and fail-closed behavior.test/test_acp_spawn_offload.py,test/acp_launch_capture.pyandtest/fixtures/acp_launch_goldens.jsonverify that both spawn paths stamp a minted instance and the ownership environment across all captured ACP launch paths.test/test_per_runtime_process_resources.pypins that the cgroup scope is named after the same minted token;test/test_kill_chokepoint_ratchet.pylowersBYPASS_BASELINEto 66 for the kill site this change routes through the identity-bound path.Manual verification
Live-host evidence confirmed the target shape: leaked runtime roots retained a dead launcher SID and sat in the dead launcher's process group rather than becoming their own session or group leaders, so the leader refusal and the group-leader refusal both pass for them. The related test suite exercises the reclaim and refusal paths; no live orphan was staged for destructive verification.
Screenshots / video
N/A — this change has no user-visible interface.
Related Issues
Fixes #11899
Pattern harvest
Not generalizable: the report-only behavior was a deliberate safety boundary pending an ownership proof; this change supplies that proof and its process-identity checks.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)