Skip to content

refactor(deploy): share the registry write and drop a dead branch - #22950

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-deploy
Oct 22, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-deploy

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make src/kiro_crew/deploy/profiles.py write its profile registry through one code path and drop a Windows check that can never run, with no change in what deploy profiles store, accept, refuse or return.

The sweep's detector finds no actionable shadowed import or chained ternary in deploy/: the one chained ternary it reported sits in profiles.py, which this pass found to be a keystone file, so it stays as written. This pass takes #16523's judgment classes for the module instead: duplicated code, dead code, and comments the code contradicts.

Why it matters

Nothing is broken today, but the module is harder to change safely than it needs to be. The registry write (temp file in the same directory, fsync, replace_with_retry, temp cleanup on any failure) was spelled out twice, in locked_registry and in save_registry, so a fix to one could miss the other. create_aws_profile carried a second Windows refusal, with its own credential_process message, that can never run because the function already refuses Windows on its first statement. And two comments gave subprocess preexec_fn (unsupported on nt) as the reason deploy refuses Windows, which is no longer true: engine.run_aws spawns through run_limited, which passes preexec_fn=None off POSIX. A reader who checked that reason would conclude the guard could go.

Not a goal

  • Any change to what the registry stores, how it is locked, which aws configure set keys are writable, which profile names, regions, accounts or roles are accepted, or any error message that can still be produced.
  • Unchaining the _parse_registry default ternary: profiles.py implements keystone controls (the _WRITABLE_KEYS allowlist, the account and role matchers spliced into credential_process, the empty-name refusal, the dropped-default clear), so its guard expressions keep their shape.
  • Windows guards for _do_recall and _do_destroy in handlers_sites.py, which have none today; adding one is a behaviour change.

What changed (motivation → approach → change)

The module behaves exactly as before: one write path instead of two copies, one Windows refusal instead of a live one plus a dead one, and guard comments that state the rule.

Where Before After
locked_registry, save_registry each built, fsynced and swapped in its own temp file, the same 17 lines both call _write_registry_file(reg), which holds that block once; both still call it under the exclusive registry lock, and locked_registry still only on a clean exit
create_aws_profile a second os.name == "nt" refusal inside the credential_process branch removed; the first-statement refusal was already the only one that could run
guard comments in create_aws_profile and handlers_sites._do_list Windows refused because the AWS call "spawns via subprocess preexec_fn" deploy features are POSIX-only, and the refusal comes before any AWS call (for profiles, so no half-written profile is left behind)

Backwards compatibility

Compatible: no signature, return value, reachable error message, lock or file format changes; _write_registry_file is module-private.

Reader: src/kiro_crew/deploy/handlers.py:_handle_profiles_post -- app -- the removed refusal sat after create_aws_profile's own first-statement Windows return, so no caller reached it (test_deploy_profiles_cov80.py::TestCreateAwsProfile::test_windows_is_refused_before_any_aws_call)

Tests

  • No test added. The helper's body is the two removed blocks moved verbatim, the deleted branch could not run, and comments carry no behaviour. Mutating the helper (dropping its temp-file os.unlink) reds 2 existing write-failure tests in test_deploy_profiles_cov80.py, so the moved code is still covered.
  • Related tests on this head (Python 3.12). The 83 test files that reference kiro_crew.deploy (test/test_cloud_ssm.py among them): 3602 passed, 3 skipped, 0 failed. The scoped runner's 144-file set, with markdown-it-py overlaid on the venv: every failure also fails, node for node, on a pristine origin/main worktree with the same interpreter (21 = 21, none only here): the auto_improvement sandbox-spawn suites and TestDoctor, which need a venv outside the data home and pip.
  • Static gates (Python 3.12). All exit 0 on the commit: flake8, isort, mypy, the black, subprocess-encoding, comment-history, brand, harness-parity and line-cap checks, the docs lint (scripts/docs_lint.py --test, scripts/docs-lint.sh), the per-file coverage self-test and the vendor manifest.
  • Pre-PR review. Seven read-only reviewers (repo rules, behaviour, imports, security and boot path, comment claims, and local mirrors of the Opus and GPT lanes, the GPT one on a Claude model) found no code defect; the behaviour one compared base and head ASTs. The security lens found that profiles.py meets the sweep detector's own "implements a control" keystone criterion and that its keystone list predated the deploy/handlers_*.py split; two independent adjudicators confirmed both, so the _parse_registry ternary keeps its shape and the comment-only handlers_sites.py hunk stays.
  • Not run locally. scripts/scrub-lint.sh is absent from the checkout (CI's internal-content-scan covers it), semgrep is not installed on this host (CI's SAST job runs semgrep/), and the frontend did not run, as nothing under website/, .github/ or scripts/ changed.

Manual verification

N/A — unit coverage sufficient: a verbatim extraction, an unreachable branch and two comments, each checked against the code.

Screenshots / video

Why no screenshot: backend-only refactor; nothing renders differently.

Related Issues

Part of #16523

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

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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 21, 2026 23:31
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) October 21, 2026 23:35
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision b8c91d2b367160e060b59a0bc373caf4d902bdc3 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b8c91d2b367160e060b59a0bc373caf4d902bdc3 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design concerns: the write helper is the two copies moved over unchanged, the removed Windows branch sits behind the function's first-statement return so it can never run, and the comment rewrites change no behaviour.

[DESIGN-REVIEWED] b8c91d2

Description read

[DESCRIPTION-READ] d03e7d78b323b2e067d1fa2be7b650f5effa69cfd73f3a516e76fa76811d6ff4

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 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b8c91d2b367160e060b59a0bc373caf4d902bdc3 — 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 does not.

First-Principles-Verdict: PASS

This PR only subtracts: two copies of the registry write become one, a branch that cannot run is deleted, and two comments that gave the wrong reason are corrected.

Notes

  • Item 1 — duplicate of src/kiro_crew/atomic_write.py:atomic_write: the new _write_registry_file still writes its own temp file, fsyncs it and swaps it in, which is the job of the repo's shared helper (atomic_write(path, content, fsync=True)). Subtraction: replace the body of _write_registry_file with one atomic_write(_registry_path(), json.dumps(reg, indent=2), fsync=True) call, once someone confirms the file permissions and the Windows retry behave the same.

What this change ships

Inventory (4 items) — 3 justified

Intent: make the deploy profile registry easier to change safely by keeping one write path and removing dead code. ADDITION (refactor; no behaviour change).

  1. Both registry save paths now share one write routine, with the same lock and file format — duplicate of atomic_write.py:atomic_write
  2. The Windows credential_process refusal message, which no caller could reach, is gone — justified
  3. The comment on the Windows guard in create_aws_profile now says deploy is POSIX-only — justified
  4. The comment on the Windows guard in _do_list gets the same correction — justified

[FIRST-PRINCIPLES-REVIEWED] b8c91d2

Description read

[DESCRIPTION-READ] 5c3176934eeebfb9f44e858f3722f58d025c7e2407e0ce2b6964d353638cd8b4

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 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] b8c91d2

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

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b8c91d2

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

@bolichen97

Copy link
Copy Markdown
Contributor Author

Real Adapter Contract Tests red on this head is main's, not this diff's.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (Windows) (7) red on this head is also main's.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): the PASS punchline raises no ask, so nothing follows from it.

The punchline restates the PR's own claim: _write_registry_file is the two removed blocks moved verbatim under the same lock, the removed Windows refusal sat behind the function's own first-statement return, and both corrected comments match run_limited (preexec_fn=None off POSIX).
Pre-PR, an AST comparison of base and head and three mutants of the moved and kept lines each confirmed this; the mutants were caught by existing tests.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): "Nothing blocks" and all three inventory items judged justified raise no ask, so nothing follows from it.

The inventory matches the diff: one verbatim extraction, one unreachable branch removed, two guard comments corrected. No default, capability, message that can be produced, or surface changes.

@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 22, 2026
@bolichen97
bolichen97 force-pushed the refactor/simplify-deploy branch from ff16be7 to 6af5fdf Compare October 22, 2026 07:33
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto ac41ba06b7 to pick up #22951, which fixes main's Real Adapter Contract Tests and test_backend_cards_advertised.py::test_no_new_runtime_site_gates_a_field_backed_line_on_a_set reds (the shard-7 Linux/Windows failures and the Coverage Gate that followed them on ff16be737d). The PR's diff is byte-identical; CI re-running on 6af5fdfab0.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 22, 2026
@bolichen97

bolichen97 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change in this PR): routing the registry write through atomic_write changes the write path's observable behaviour, and this refactor's frozen goal excludes that.

The file mode is NOT the difference: NamedTemporaryFile creates via mkstemp at 0o600, so the registry is already owner-only, as atomic_write would leave it.
The differences are real elsewhere: atomic_write stages *.tmp instead of *.json.tmp, creates the parent with mkdirs_owner_only, carries access-control xattrs and refuses on losing one, and calls atomic_write.replace_with_retry rather than the profiles binding.
test_deploy_profiles_cov80.py patches profiles_mod.replace_with_retry and globs *.json.tmp, so the swap would silently stop those failure-path tests observing anything.
This PR goes from two hand-rolled copies to one and adds no new spelling; folding _write_registry_file and deploy/pending.py:_save_raw into atomic_write(..., fsync=True) is a separate change that rewrites those tests.

Corrected: an earlier version of this comment wrongly gave the file mode as the difference.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): the PASS punchline raises no ask, so nothing follows from it.

It restates the PR's claim, which holds on this head: _write_registry_file is the two removed blocks moved verbatim, and both callers still hold the exclusive registry lock. The removed nt branch sat behind create_aws_profile's first-statement Windows return. The diff is byte-identical to the previously judged head ff16be737d.

@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 22, 2026
deploy/profiles.py wrote the profile registry through two identical
temp-file blocks, one in locked_registry and one in save_registry; both
now call one private _write_registry_file.

create_aws_profile returns for Windows before any AWS call, so its
second os.name == "nt" check inside the credential_process branch could
never run; it is removed. That guard's comment, and the matching one in
handlers_sites._do_list, named subprocess preexec_fn as the reason, but
run_limited passes preexec_fn=None off POSIX. Both comments now state
the rule the guard implements: deploy features are POSIX-only.
@bolichen97
bolichen97 force-pushed the refactor/simplify-deploy branch from 6af5fdf to b8c91d2 Compare October 22, 2026 17:50
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/server.py and test/test_cloud_ssm.py (both import kiro_crew.deploy) since this head went green (ac41ba0 -> 69b2e50); CI re-running on b8c91d2b36. The diff is byte-identical. The previous head's Backend Tests (3.12, 8) + Coverage Gate red was "The self-hosted runner lost communication with the server" (no test ran to completion, no log blob), not a test failure; this push re-runs that shard.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 22, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): the PASS punchline raises no ask, so nothing follows from it.

It restates the PR's claim, which holds on this head: _write_registry_file is the two removed blocks moved verbatim, and both callers still hold the exclusive registry lock.
The removed nt branch sat behind create_aws_profile's first-statement Windows return. The diff is byte-identical to the previously judged heads ff16be737d and 6af5fdfab0.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change in this PR): swapping _write_registry_file's body for atomic_write(..., fsync=True) changes the write path's observable behaviour, and this refactor's frozen goal excludes that.

File mode is not the difference: NamedTemporaryFile creates via mkstemp at 0o600, the mode atomic_write gives a data-home file.
The differences are real elsewhere: atomic_write stages *.tmp instead of *.json.tmp, creates the parent with mkdirs_owner_only, carries access-control xattrs and refuses on losing one, and calls atomic_write.replace_with_retry, not the profiles binding.
test_deploy_profiles_cov80.py patches profiles_mod.replace_with_retry and globs *.json.tmp, so the swap would silently stop those failure-path tests observing anything.
The lane itself conditions the subtraction on confirming those behaviours; folding this helper and deploy/pending.py:_save_raw into atomic_write is a separate change that rewrites those tests.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tier 1 auto-approve: refactor (2 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: code move with no behaviour change; the duplicated fsynced registry write is extracted into one helper, and the removed Windows branch in create_aws_profile was unreachable because the function already returns on Windows at its top.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 3) showing "in progress" on b8c91d2b36 is a stale check-run, not a pending or failing test.

  • Every step of job 119996265081, Run tests (shard 3/8) included, completed success by 18:21Z; the runner never reported the job closed.
  • The CI run 39826178578 concluded success, and Coverage Gate consumed shard 3 as success.
  • PR Readiness is success (readiness: passed); green age is FRESH.
  • No rerun from this side: nothing failed, and a rerun would only re-execute a shard that already passed.

@bolichen97
bolichen97 merged commit 0d9024a into main Oct 22, 2026
107 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-deploy branch October 22, 2026 19:05
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 22, 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.

2 participants