refactor(pod): drop dead code and flatten four pod-module branches - #4121
Conversation
Behaviour-preserving readability pass over src/kiro_crew/pod/, one module per the simplification campaign. No functional change. Dead code: - launchd.restart() had zero callers anywhere (no `pod restart` verb, no test, no doc; Dev Fleet's pod restart is down-then-up), and the systemd twin unit.py has no counterpart, so the backends are now symmetric. - require_pod_safe_verb's `hint = ""` initializer was unreachable: the following if/elif/else is exhaustive. De-duplication: - _ls's --json branch derived each pod's port twice per row, once for the reported value and once for the health probe. An unpinned port shells `cksum`, so it also halves that subprocess count, and the reported port can no longer differ from the one probed. - _prune computed the failed count twice, once standalone and once inside the counts comprehension. Flattening: - read_env_file's try/if-exists/for nest becomes a guarded read plus one loop. read_text() raises the same OSError family Path.exists() swallows, so the pre-check was redundant and its removal closes a check-to-use window. - _ls's empty-list early return becomes an if/else, so _print_orphans is called once instead of from two paths. - unit_is_current's nested double comprehension becomes one pass: str.startswith takes the whole tuple. Comment hygiene, in the files above only: dropped review-round markers, converted historical narration to present tense, and corrected three claims that were false of the current code — the stale-unit hazard is skipped by start_pod, not by down (unit_is_current has one caller), and read_env_file's fail-open read must not be used where absent has to be distinguished from unreadable (dev_fleet._read_pin_strict).
Design Review (Fable 5) — ✅ PASSAdvisory design-level review of All hunks verified against the description: Design-Verdict: PASS A behavior-preserving cleanup of a destructive-teardown module, with every claimed removal and equivalence verified in the code — no design-level concerns. [DESIGN-REVIEWED] 7d156e4 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsAll hunks verify as behavior-preserving. No findings. [OPUS-REVIEWED] 7d156e4 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSAdvisory premise-level review of All evidence checked: I verified First-Principles-Verdict: PASS A pure subtraction pass: every item deletes code, a duplicate computation, or a false claim, and each deletion's justification checked out against the tree. What this change shipsIntent: make the pod module's destructive-teardown code readable and its comments true — a FIX (of comment falsehoods) plus pure deletions, no new capability.
[FIRST-PRINCIPLES-REVIEWED] 7d156e4 |
The red
|
| head | red jobs | same class? |
|---|---|---|
main (run 32029075186) |
Backend Tests (3.10, 4), (3.12, 4), Coverage Gate | same shard |
fix/redos-linearity-nonwallclock-4108 (32032049872) |
Backend Tests (3.12, 4), Coverage Gate | yes — same AttributeError in TestLinkTimeBackfill, lines 818 and 842, with the same kirocrew_turn_deadline cross-context ValueError |
feat/session-control-mcp (32029833750) |
Backend Tests (3.12, 4), Coverage Gate | same shard |
Coverage Gate is purely downstream: its log shows BE: failure and it fails
closed on that alone (it also confirms ONLY_BACKEND: true for this diff, as the
description claims).
Locally on this branch, the named test passes in isolation, the whole
test_slack_options_lifecycle.py file passes (78 passed), and 1097 tests pass
across every suite that imports kiro_crew.pod.
Disposition: rebutted — not caused by this PR, and deliberately not fixed here.
TestLinkTimeBackfill's shared-state leak is a real bug worth fixing, but it is a
different module and fixing it here would smuggle a behaviour change into a
behaviour-preserving cleanup and break the one-module-per-PR rule this campaign
runs on. It needs its own PR. I have not weakened, skipped, or retried any
assertion to get around it.
Follow-up on the red shard: the fix already exists as #2848Updating my own attribution comment above with something it was missing — the I verified the linkage rather than assuming it. This does not change my disposition, it sharpens it. #4121 is red on a defect Worth flagging for prioritisation: this shard is currently red on |
Green — the re-run confirms the attribution
That closes the attribution argument rather than merely working around it: the To be explicit about what was and was not done: nothing in this PR's diff changed |
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: refactor (4 files). Criteria: no conflict, no requested changes, no security surface, AI reviewers green. Category: drop dead code and flatten four pod-module branches across pod/cli.py, launchd.py, runtime.py, unit.py -- net-negative internal cleanup with no behavior or interface change.
…irodotdev#4121) Behaviour-preserving readability pass over src/kiro_crew/pod/, one module per the simplification campaign. No functional change. Dead code: - launchd.restart() had zero callers anywhere (no `pod restart` verb, no test, no doc; Dev Fleet's pod restart is down-then-up), and the systemd twin unit.py has no counterpart, so the backends are now symmetric. - require_pod_safe_verb's `hint = ""` initializer was unreachable: the following if/elif/else is exhaustive. De-duplication: - _ls's --json branch derived each pod's port twice per row, once for the reported value and once for the health probe. An unpinned port shells `cksum`, so it also halves that subprocess count, and the reported port can no longer differ from the one probed. - _prune computed the failed count twice, once standalone and once inside the counts comprehension. Flattening: - read_env_file's try/if-exists/for nest becomes a guarded read plus one loop. read_text() raises the same OSError family Path.exists() swallows, so the pre-check was redundant and its removal closes a check-to-use window. - _ls's empty-list early return becomes an if/else, so _print_orphans is called once instead of from two paths. - unit_is_current's nested double comprehension becomes one pass: str.startswith takes the whole tuple. Comment hygiene, in the files above only: dropped review-round markers, converted historical narration to present tense, and corrected three claims that were false of the current code — the stale-unit hazard is skipped by start_pod, not by down (unit_is_current has one caller), and read_env_file's fail-open read must not be used where absent has to be distinguished from unreadable (dev_fleet._read_pin_strict).
Why no screenshot: backend-only diff — four files under
src/kiro_crew/pod/, no frontend path touched, no rendered surface exists for the pod CLI.Problem / Motivation
src/kiro_crew/pod/carries the residue that accumulates in a subsystem grownover many PRs: a function nobody calls, two values computed twice, three
control-flow shapes that nest or branch further than the logic needs, and
comments that read as a task log rather than as rationale. None of it is a bug,
and all of it is what a reader has to hold in their head before they can reason
about the destructive teardown path this module owns.
Three of those comments also make claims that are false of the current code,
which is the part that actually costs something: a reader who trusts them
mis-models when the pod's isolated HOME can be deleted.
Why it matters
This module deletes directories (
pod downreclaims a pod's isolated HOME) andgates
pod execbehind a deny-by-default allowlist. Both are paths where areviewer has to be able to see the decision at a glance, and where a comment
that names the wrong code path sends the next author to the wrong guard. The
duplicated port derivation is also a live cost: each one shells
cksum, sopod ls --jsonspawned two subprocesses per pod for one answer.What changed (motivation → approach → change)
Behaviour-preserving throughout — this is a readability pass, not a fix. Every
rewrite was proved equivalent before it landed (see Tests).
Dead code
launchd.restart()removed. Zero callers anywhere insrc/,test/,scripts/,docs/,website/,packaging/orconftest.py, includingdynamic access; there is no
pod restartverb (_VERBShas no entry,cli.mddocuments none) and Dev Fleet's/api/pod/restartisdownthenup, not akickstart. The systemd twinunit.pyhas no counterpart, so thetwo backends are now symmetric.
require_pod_safe_verb'shint = ""initializer removed — the followingif/elif/elseis exhaustive, so no path could observe it. The guard'sdecision is byte-for-byte unchanged.
De-duplication
_ls --jsonderived each pod's port twice per row (once for the reportedvalue, once as the health probe's argument). Now once. Beyond halving the
cksumsubprocesses, the reported port can no longer differ from the oneactually probed if a
PORT=pin changes between the two calls._prunecomputed the failed count standalone and inside thecountscomprehension; it now reads the one it already built.
Flattening
read_env_file'stry/if exists()/fornest becomes a guarded readplus one flat loop.
read_text()raises the sameOSErrorfamilyPath.exists()swallows, so the pre-check was redundant, and dropping itcloses a check-to-use window rather than opening one.
read_text()isall-or-nothing, so the old code's partial-result path was unreachable.
_ls's empty-list early return becomes anif/else, so_print_orphans—how an operator learns about un-reclaimed pod HOMEs — is called from one
place instead of two.
unit_is_current's nested double comprehension becomes one pass:str.startswithtakes the whole tuple._REMOVED_DIRECTIVESis nowannotated
tuple[str, ...]so that requirement is stated where it is relied on.Comment hygiene (only in the files above, per
AGENTS.md§ Code style)Dropped review-round markers, converted historical narration to present tense,
and corrected three claims that were false of the current code:
start_pod, not bydown.unit_is_currenthas exactly one caller (runtime.py:614);stop_podgateson
loaded_teardown_hook, i.e. on what systemd has loaded, so it cannotskip its refresh because of a stale file. Corrected in both places that said
otherwise (
_write_and_load_unitandinstall_backend).read_env_fileis fail-open, so the docstring now bounds who may use itand points at
dev_fleet._read_pin_strict, which exists precisely to refusethe absent-vs-unreadable conflation.
launchd.stop's docstring said "two things" above three bolded items.No security control changed shape: no sensitive-path matcher, denied-command
rule, deny-by-default guard, SEL audit emit, redaction call, credential scrub
(
build_pod_env) or path-containment check (cleanup_home) is in the diff. Noimport was added, removed, moved or hoisted, and no in-function
from X import Ywas touched.Tests
No test changes — that is the point of a behaviour-preserving pass, and the
existing suites are what hold it. 1097 passed, 2 skipped across every suite
that imports
kiro_crew.pod:test_pod.py,test_pod_launchd.py,test_pod_self_contained.py,test_pod_e2e_harness_paths.py,test_pod_e2e_video_guard.py,test_agent_home_isolation.py,test_cli_commands_coverage.py,test_dev_fleet_server_coverage.py,test_dev_fleet_node_toolchain.py,test_dev_fleet_app.py.Equivalence was also proved directly, not just observed green.
read_env_filewas differentially executed old-vs-new over 12 inputs (missing file, empty,
comment-only, no-
=, quoted values, path-is-a-directory, mode-0, unreadableparent, dangling symlink,
ELOOP,ENAMETOOLONG, invalid UTF-8) — identical results in every case, including which exception escapes._prune's count wasbrute-forced over 2000 random result sets including unknown statuses.
startswith(tuple)was checked against the nested form including theempty-tuple case.
One input class where old and new differ, deliberately accepted as unreachable:
a pod name containing a NUL byte.
Path.exists()swallowsValueError, whileread_text()raises it._NAME_RE(^[a-zA-Z0-9][a-zA-Z0-9._-]{0,60}$) gatesevery validated path, argv cannot carry NUL, and the Dev Fleet call sites only
reach it for a name already in
rt.active_names.Manual verification
N/A — unit coverage sufficient. The changed code is pure control flow and
string handling with no new external interaction; the platform-specific paths
(
systemctl,launchctl) are exercised by the suites above on every OS viatheir existing seams, and this diff adds no call to either.
Related Issues
no linked issue: campaign refactor with no filed issue behind it.
Checklist
Gates run locally (Python 3.12 CI-parity venv)
flake8·isort --check-only·mypy src/kiro_crew(982 files) ·check_brand_name.py·check_harness_parity.py·docs_lint.py --test·docs-lint.sh·check_per_file_coverage.py --test·verify_vendor_manifest.py·scrub-lint.sh --no-history— all exit 0.Frontend suites not run: the diff touches nothing under
website/,.github/or
scripts/, so CI'schangesjob reportsonly_backend=true.Pre-PR review fleet
Five independent read-only reviewers ran against this diff before it was
opened, each with a distinct lens: AUTOSDE blocking rules + the
code-review.ymlgrep contract, behaviour preservation, import semantics and test-patching seams,
security-guard/destructive-path integrity, and comment accuracy.
Found and fixed (3, all comment accuracy): the
unit_is_current-victim-patherror, converged on by two reviewers and confirmed by reading the call sites;
the
read_env_filedocstring's false "indistinguishable to every caller" claim,converged on by three reviewers with
dev_fleet._read_pin_strictas thecounter-example; and the over-promised "
{}when unreadable" summary, whichUnicodeDecodeErrorescapes. Also folded in two adjacent instances of the samebanned comment classes so the fix is not applied inconsistently within a file.
Dropped after checking (2): the NUL-byte
ValueErrordivergence, verifiedunreachable and recorded above rather than guarded speculatively; and a
suggestion to catch
ValueErrorinread_env_file, which would be a behaviourchange and therefore belongs in its own PR, not a preservation pass.