Repository navigation
fix(acp): name the authored agent in every runtime child's environment - #21115
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merge, trigger the Suggestions
[DESIGN-REVIEWED] 4357e69 Description read[DESCRIPTION-READ] e93b82fc68eed7315356e9bce0a06fb89e7537dbc1277ce2aa3c01a3a4a8dc9b 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 |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The new product env var stores a pid→agent record the gateway already keeps and serves. Its only reader is a Nightly test. Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: make the Nightly process-leak gate recognise the gateway's own background runtime on KAS hosts. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 4357e69 Description read[DESCRIPTION-READ] 1066ac25916a12b1f1ecbad578bbbdd60570f9b244045a2ecdad89e9b79e84f5 That sha256 names the PR description this verdict read. Recompute it with |
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: |
Set KIROCREW_RUNTIME_AGENT beside KIROCREW_SPAWN_INSTANCE on every AcpRuntime child. A host that binds its agent over the wire (the KAS relay) carries no --agent in argv, so the environment is the one per-process record of which agent a live runtime runs. The process-leak gate reads it through the inventory and falls back to the --agent argv word, so the gateway's own background runtime is recognised on every host and a session runtime that outlives its slot still fails. Fixes #21105
c30f46d to
4357e69
Compare
Problem / Motivation
Goal: The Nightly process-leak gate recognises the gateway's own background runtime on every agent host, so a KAS-default install is not reported as leaking its own runtime.
Scheduled Nightly run 38859654182 (head
ded6af9b), jobProcess Leak Invariant + Chaos (Linux), failstest/e2e/test_process_leak_invariant.py::test_closing_every_session_leaves_nothingwith:The survivor is exactly the one background runtime the gate expects (
EXPECTED_BACKGROUND_RUNTIMES = 1). The gate identifies it by the agent it runs, read from the--agent <name>word in argv. A fresh data home boots the KAS engine (#20359), whose argv isacp --agent-engine v3 --auth-method cliwith no--agent-- the agent is bound over the wire via_meta.kiro.customAgents+session/set_mode-- so the helper answers""and the runtime is classified as foreign.The product kept no per-process record of a KAS runtime's authored agent: the pid registry lines are
<gw>:<pid>[:<token>], the child environment carries the spawn instance, data home and scratch path only, the scratch label is the literalruntime, and the skill-projection sidecar is keyed by an alias absent from a KAS argv.Why it matters
Nightly Build is red on every scheduled run until this lands, which hides any real leak the same gate would catch. It is the same class as #20571 / #19664: a Nightly-only gate reddened by a
mainmerge with no PR signal.Not a goal
EXPECTED_BACKGROUND_RUNTIMESor loosening the gate: a session runtime that outlives its slot must still fail, on every host.gateway.logor adding a log-level knob to the e2e harness.test/e2e/test_process_chaos.py: it selects victims from registry entries and reads no agent.What changed (motivation → approach → change)
Symptom: the gate reads the agent from argv; a wire-bound host has none there. Root cause: nothing on the process named the agent it was spawned for. Change: the product names it, and the gate reads that.
src/kiro_crew/constants.py:KIROCREW_RUNTIME_AGENT_ENV = "KIROCREW_RUNTIME_AGENT", documented besideKIROCREW_SPAWN_INSTANCE_ENV/KIROCREW_SPAWN_HOME_ENV.src/kiro_crew/acp/runtime.py:_env_after_markersetsKIROCREW_RUNTIME_AGENTtoself._agenton everyAcpRuntimechild, in the same step and by the same carrier as the spawn instance token.self._agentis the authored name at that point (a stored skill-view alias is mapped back at the top of_spawn_admitted), the same value theAcpRuntime spawned ... agent=%slog line carries. Not a secret: the same name is visible in argv on the command-line host.test/e2e/process_inventory.py:read_environ_value/runtime_agentread/proc/<pid>/environ;ProcessFact.runtime_agentis populated for every live process the inventory classifies and shown insummary(). The module stays stdlib-only and restates the variable name asRUNTIME_AGENT_ENV.test/e2e/test_process_leak_invariant.py:_authored_agent(home, fact)answers fromfact.runtime_agentfirst, then from the--agentargv word with the existing skill-view alias resolution, else""(foreign). It pinsRUNTIME_AGENT_ENV == kiro_crew.constants.KIROCREW_RUNTIME_AGENT_ENVso a rename on either side fails by name instead of reading every runtime as foreign.Because a KAS session runtime now carries its own agent too, a session survivor reads as that agent -- not
kirocrew-lite-- and still fails the foreign check;EXPECTED_BACKGROUND_RUNTIMESstays1.Backwards compatibility
Compatible: one environment variable is added to agent children; nothing that works today stops working. The variable is set after the agent-environment scrub, next to
KIROCREW_SPAWN_INSTANCE, and read only by the e2e gate.Removes nothing: the diff adds a variable, a reader and a dataclass field; no path, key, record or function is hidden, renamed or deleted.
Tests
test/test_per_runtime_process_resources.py::TestRuntimeNamesItsScope::test_the_child_environment_names_the_authored_agent: the runtime's marker step puts the authored agent (kirocrewin the capture) in the child's environment, with and without the cgroup wrap.test/test_acp_launch_goldens.py+test/fixtures/acp_launch_goldens.json: theAcpRuntime-served golden (codex) gainsKIROCREW_RUNTIME_AGENT: kirocrew;KIROCREW_RUNTIME_AGENTis added to the contributed-key list so the pass-through allowlist can never mask it.test/e2e/test_process_leak_invariant.py(Nightly,KIROCREW_E2E=1): resolves the background runtime through the environment record on the KAS host and through argv on the command-line host.Static gates run locally on the touched files:
black --check,ruff check(0.9.0),mypy(src + e2e modules) -- clean. No local pytest run; CI is the verification.Manual verification
N/A — the failing gate is the Nightly
Process Leak Invariant + Chaos (Linux)job; its next scheduled run onmainafter merge is the verification, and the unit coverage above pins the environment write itself.Related Issues
Fixes #21105
Pattern harvest
Rule candidate: review-prompt
Pattern: a test identifies a product process by an argv flag that only one of several hosts emits; identity a test needs should be recorded by the product on the process (environment / registry), not inferred from a host-specific command line.
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.