Skip to content

refactor(subagent): unchain the approval-outcome ternary - #14654

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-toplevel
Sep 28, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-toplevel

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the subagent approval audit label readable at a glance, with no behaviour change.

SubagentManager._approve_and_log in src/kiro_crew/subagent.py chose its SEL outcome label with a chained conditional expression that tested approval_sent is not False twice. It was the last chained ternary the module-simplification detector found on main.

Why it matters

This label is an audit field. A reader checking which approvals get recorded as rejected_transport_floor had to untangle a nested a if x else b if y else c inside a call's keyword arguments.

Not a goal

  • Changing any audit label, or which inputs produce it.
  • Touching the single-arm outcome ternaries in task_executor.py, eval/runner.py, slack/handler.py or dashboard/handlers/hooks.py. They are not chained, and each lives in another module.
  • Adding tests for the approve_tool-returned-False path, which was untested before this PR too.

What changed (motivation → approach → change)

The outcome is now picked by a guard-first if/elif/else just above the sel().log_tool_invocation(...) call, and passed in as outcome=outcome.

approval_sent metadata has a truthy reason label (before and after)
False any rejected_transport_floor
anything else yes auto_approved
anything else no approved

The one ordering difference: metadata.get("reason") now runs before sel() instead of after. Both are side-effect free here (every caller passes a dict literal or None, and sel() returns the singleton log), so nothing can observe it.

Backwards compatibility

Compatible: the same three labels come out for every input. An exhaustive differential over 56 approval_sent × metadata combinations, including None, 0, "", {} and falsy reasons, matched in every case.

Tests

No test changes. The existing suites that drive this function pass locally: test_subagent.py, test_subagent_coverage.py (asserts the auto_approved / approved labels), test_subagent_startup_pressure.py and test_transport_permission_floor.py (pins one approve_tool call in _approve_and_log; unchanged). 503 passed.

Gates run on the Python 3.12 CI-parity venv: flake8, isort, mypy, check_black_formatting.py, check_subprocess_encoding.py, check_brand_name.py, check_harness_parity.py, docs_lint.py --test, docs-lint.sh, check_per_file_coverage.py --test and verify_vendor_manifest.py, all exit 0. scripts/scrub-lint.sh is not in the tree; that scan runs in CI only.

A five-lens review fleet (AUTOSDE blocking rules, behaviour preservation, import semantics, security keystone, comment accuracy) found no defects. It raised one wording nit: the commit message called approve_tool returning False a "failed" approval, when the provider contract says the transport rejected it. The commit message was corrected. Nothing was dropped.

Backend-only diff: nothing under website/, .github/ or scripts/ changes, so CI's changes job reports only_backend=true and the frontend suites were not run locally.

Manual verification

N/A: unit coverage is sufficient. This is a pure refactor of one expression, and its equivalence was checked by running both forms over every input combination.

Screenshots / video

Why no screenshot: backend-only refactor of one audit-label expression; nothing renders differently.

Related Issues

no linked issue: a readability sweep from the module-simplification campaign, not tracked by an issue.

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

@bolichen97
bolichen97 requested a review from a team as a code owner September 28, 2026 07:44
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Make the subagent SEL approval-outcome label selection readable by replacing its chained ternary with a guard-first if/elif/else, producing the identical label for every input.
Not a goal: changing any audit label or its inputs, touching the non-chained sibling outcome ternaries in other modules, or adding new test coverage.

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

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

Behavior-preserving refactor of a chained ternary into guard-first if/elif/else; the three outcome labels map identically for every input, no surface rendered.

[DESIGN-REVIEWED] 7277527

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 7277527

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

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

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 727752735fbf87a6755ceba75f59c5f9d6a87072 — 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: PASS

Nothing to check. The three output labels are provably unchanged across all approval_sent×metadata cases, and only the reordered metadata.get("reason") read moves earlier — side-effect-free on a dict/None.

What this change ships

Inventory (1 item) — 1 justified

Intent: Make the subagent approval audit-label selection readable; a pure refactor (neither fix nor capability addition).

  1. The outcome label is chosen by a guard-first if/elif/else instead of a doubly-nested ternary inside the log_tool_invocation call — justified

[FIRST-PRINCIPLES-REVIEWED] 7277527

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 727752735fbf87a6755ceba75f59c5f9d6a87072 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7277527

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

@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 Sep 28, 2026
_approve_and_log picked its SEL outcome label with a chained
conditional expression that re-tested `approval_sent is not False` in
two arms. Resolve it with a guard-first if/elif/else instead: an
approval the transport rejected (approve_tool returned False) is the
transport-floor rejection, an approval carrying a metadata reason is
auto_approved, anything else is approved. Same three labels for every
input; no behaviour change.
@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from ce62bdb to 7277527 Compare September 28, 2026 12:30
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_remote_crew_chaining.py since this head went green (631f8e6 -> 6a8cb5e); CI re-running.

The prior head's only red was Backend Tests (3.12, 2) (+ the Coverage Gate that fails closed on it): two TestTheHopOwnershipInvariantHolds cases in test/test_remote_crew_chaining.py, a file this PR does not touch and that #14651 changed on main. Both pass locally on the rebased head (test_remote_crew_chaining.py + test_subagent*.py: 1620 passed), so this is not attributed to the subagent.py diff.

@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 Sep 28, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) September 28, 2026 15:40
@bolichen97
bolichen97 merged commit fa67021 into main Sep 28, 2026
97 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-toplevel branch September 28, 2026 16:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 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