Skip to content

fix(acp): name the authored agent in every runtime child's environment - #21115

Merged
bolichen97 merged 1 commit into
mainfrom
fix/21105-leak-gate-kas-agent
Oct 16, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/21105-leak-gate-kas-agent

Conversation

@CrysisDeu

Copy link
Copy Markdown
Contributor

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), job Process Leak Invariant + Chaos (Linux), fails test/e2e/test_process_leak_invariant.py::test_closing_every_session_leaves_nothing with:

1 tracked process(es) that are not the gateway's own background runtimes survived closing every session: pid=2485 agent=?
  pid=2485 ppid=2396 unit=kirocrew-rt-c4d349a212734f6f.scope :: python3 .../fake_acp_backend.py acp --agent-engine v3 --auth-method cli

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 is acp --agent-engine v3 --auth-method cli with 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 literal runtime, 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 main merge with no PR signal.

Not a goal

  • Changing EXPECTED_BACKGROUND_RUNTIMES or loosening the gate: a session runtime that outlives its slot must still fail, on every host.
  • Parsing gateway.log or adding a log-level knob to the e2e harness.
  • Touching test/e2e/test_process_chaos.py: it selects victims from registry entries and reads no agent.
  • Any change to how KAS binds its agent over the wire.

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 beside KIROCREW_SPAWN_INSTANCE_ENV / KIROCREW_SPAWN_HOME_ENV.
  • src/kiro_crew/acp/runtime.py: _env_after_marker sets KIROCREW_RUNTIME_AGENT to self._agent on every AcpRuntime child, in the same step and by the same carrier as the spawn instance token. self._agent is the authored name at that point (a stored skill-view alias is mapped back at the top of _spawn_admitted), the same value the AcpRuntime spawned ... agent=%s log 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_agent read /proc/<pid>/environ; ProcessFact.runtime_agent is populated for every live process the inventory classifies and shown in summary(). The module stays stdlib-only and restates the variable name as RUNTIME_AGENT_ENV.
  • test/e2e/test_process_leak_invariant.py: _authored_agent(home, fact) answers from fact.runtime_agent first, then from the --agent argv word with the existing skill-view alias resolution, else "" (foreign). It pins RUNTIME_AGENT_ENV == kiro_crew.constants.KIROCREW_RUNTIME_AGENT_ENV so 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_RUNTIMES stays 1.

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 (kirocrew in 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: the AcpRuntime-served golden (codex) gains KIROCREW_RUNTIME_AGENT: kirocrew; KIROCREW_RUNTIME_AGENT is 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 on main after 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 16, 2026 06:49
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4357e69cc796d91b5e287eec9ea57e2cd1985e15 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4357e69cc796d91b5e287eec9ea57e2cd1985e15 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Before merge, trigger the Process Leak Invariant + Chaos (Linux) job on this branch with workflow_dispatch; its next Nightly run on main is currently the only proof.

Suggestions

  • Run the e2e gate on the PR head once and link the run. Then both new paths (KAS reading the environment, the command-line host falling back to --agent) are shown working before main depends on them.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 4357e69cc796d91b5e287eec9ea57e2cd1985e15 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • Item 1 — duplicate of src/kiro_crew/session_allocation_parts/companions.py:469 runtime_pids(): the description says "The product kept no per-process record of a KAS runtime's authored agent". But _append_companion_runtime_rows already emits {"key": "Background runtime", "agent": background_agent, "pid": …}, and GET /api/sessions/memory (dashboard/routes/system.py:80) serves those rows. The gate's client is still connected to the live gateway when _split_background_runtimes runs. A grep for KIROCREW_RUNTIME_AGENT in src/ finds 0 readers, only the setter at acp/runtime.py:2391.
    Subtraction: delete KIROCREW_RUNTIME_AGENT_ENV, its write in _env_after_marker, the golden row, the contributed-key entry and test_the_child_environment_names_the_authored_agent. Have _split_background_runtimes take the background pid from /api/sessions/memory. Items 3–4 then go too.
    Clears when: the env var is replaced by the gateway's existing runtime_pids record, or the PR names a case where the gate must classify a pid that record cannot name.

What this change ships

Inventory (6 items) — 5 justified

Intent: make the Nightly process-leak gate recognise the gateway's own background runtime on KAS hosts. This is a FIX.

  1. Every agent-runtime child's environment now names its authored agent — duplicate of runtime_pids() / /api/sessions/memory
  2. The leak gate reads a runtime's agent from /proc environ first, then from argv — justified
  3. The inventory's failure output prints agent= per process — justified
  4. The gate checks that the test's restated env-var name equals the product's — justified
  5. Launch golden and contributed-key allowlist include the new variable — justified
  6. A unit test pins the environment write, with and without a scope wrap — justified

[FIRST-PRINCIPLES-REVIEWED] 4357e69

Description read

[DESCRIPTION-READ] 1066ac25916a12b1f1ecbad578bbbdd60570f9b244045a2ecdad89e9b79e84f5

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4357e69cc796d91b5e287eec9ea57e2cd1985e15 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4357e69

Verdict parsed from the review's SHA-scoped output markers for commit 4357e69cc796d91b5e287eec9ea57e2cd1985e15.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4357e69cc796d91b5e287eec9ea57e2cd1985e15: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4357e69cc796d91b5e287eec9ea57e2cd1985e15 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4357e69

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4357e69cc796d91b5e287eec9ea57e2cd1985e15: <one-sentence reason>

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
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 16, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/21105-leak-gate-kas-agent branch from c30f46d to 4357e69 Compare October 16, 2026 07:26
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 16, 2026
@bolichen97
bolichen97 merged commit 02928b1 into main Oct 16, 2026
105 checks passed
@bolichen97
bolichen97 deleted the fix/21105-leak-gate-kas-agent branch October 16, 2026 08:15
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 16, 2026
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.

Nightly leak gate: test_closing_every_session_leaves_nothing classifies the KAS-default background runtime as foreign (agent=?)

2 participants