Skip to content

refactor(subagent): unchain the memory-deferral detail ternary - #17916

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
refactor/simplify-subagent_manager
Oct 8, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
refactor/simplify-subagent_manager

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the subagent memory-deferral detail read top to bottom, so a reader sees at a glance which of the three messages a held spawn gets.

spawn_impl in subagent_manager/admission/gate.py built memory_detail through a ternary nested inside another ternary's else arm: unknown_note if lane_held else (… if unknown_usage else …). The second condition sits mid-expression between two f-strings, so a reader has to unpack precedence to learn which text a lane-share hold, an unknown headroom and a measured shortfall each produce. It is one of two chained ternaries the module-simplification detector still reports as actionable in the backend.

Why it matters

Nothing is broken today. The trap is for the next reader of a user-facing line. This string is the reason a spawn waits: it reaches the spawn_run tool result, the Slack "Queued subagent" reply, the spawn API's reason_detail, and the refusal text when the task store cannot record the wait.

Not a goal

  • Changing any behaviour: the three strings, the order their conditions are tested in, the audit emit, or the wait payload.
  • The comments around this block, which the review below checked and found true.
  • Any other file in subagent_manager. One module per PR, and this one stays at one site.

What changed (motivation → approach → change)

Readability only; nothing behaves differently. The nested ternary is now an if lane_held: / elif unknown_usage: / else: block. Each arm assigns memory_detail the same f-string it produced before.

The block stays where the ternary was: after the deferral's audit emit and before the pressure-hold cleanup. It adds no call, await, try or new name. memory_detail is already bound to "" earlier in the function, so mypy keeps inferring str.

Backwards compatibility

Compatible: every combination of lane_held, unknown_usage and the figures yields the same string as before.

Removes nothing: one expression is rewritten as one if statement; no field, function or name goes away.

Tests

No new tests: the change preserves behaviour, and existing tests drive all three arms. A serial coverage run of 11 admission and spawn test files (736 tests) executes every new line and all four branch arcs, with gate.py at 83% (the file is not baselined; the floor is 80%).

Local gates (Python 3.12): flake8, isort, mypy, check_black_formatting.py, check_subprocess_encoding.py, check_comment_history.py, 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 and test_flake_pattern_ratchet.py all exit 0. Eight admission and spawn test files, including the ones that assert these detail strings, pass: 567 tests. scripts/scrub-lint.sh is not in the checkout; that scan runs as CI's internal-content-scan job. Backend-only diff, so CI reports only_backend=true and the frontend suites cannot newly fail.

Pre-PR review: seven read-only reviewers (AUTOSDE rules, behaviour preservation, import semantics, security keystone and boot path, comment accuracy, and mirrors of the Opus and GPT CI contracts) found no code defect. The GPT mirror ran on a fallback model, so it is weaker evidence than the CI lane. Independent verifiers checked the three notes raised:

  • Kept: the commit message said an unknown reading "adds the floor". The figure is the bar (the floor plus this start's price and the starts still warming), and one cause read nothing at all. Reworded to "an unknown headroom adds the GB it needs".
  • Dropped: a claim that the "the UI says 'waiting for memory' figure-less" comment is false. The spawn_run result, the Slack reply and the spawn API all show that exact note with no figures.

Manual verification

N/A — unit coverage sufficient: the change is one expression inside a function existing tests drive through all three arms. Evaluating the old and new forms over 756 input combinations (non-bool truthy and falsy lane_held, None and 0.0 prices, -1.0 readings) gave identical results; a reviewer's independent harness over 23,040 combinations also matched name-read order and raised exceptions.

Screenshots / video

Why no screenshot: backend-only refactor of one Python module; 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

@bolichen97
bolichen97 requested a review from a team as a code owner October 7, 2026 22:59
@bolichen97
bolichen97 requested a review from CrysisDeu October 7, 2026 22:59
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of af0e309c2821181026ca78b3491a395144010401 — 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.

What this change ships

Inventory (1 items) — 1 justified

Intent: let the next reader of gate.py see at a glance which of the three memory-deferral messages a held spawn gets. This is an ADDITION (readability refactor), not a FIX.

  1. The nested ternary that builds memory_detail becomes an if/elif/else block that yields the same three strings in the same order — justified

[FIRST-PRINCIPLES-REVIEWED] af0e309

Description read

[DESCRIPTION-READ] 5c0b3081de3160d9cfc7bc51d374459f720b6c62e840c0bbdc85c17ce87ca38e

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

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision af0e309c2821181026ca78b3491a395144010401 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 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

Pure equivalent refactor.

No findings.

[OPUS-REVIEWED] af0e309

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

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] af0e309

Description read

[DESCRIPTION-READ] 0dfc93b93f079c0512539c7edf8da4f20ccfff9751f7df4aaecc353627fac6d7

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] af0e309

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

@bolichen97

bolichen97 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

CI attribution — all six reds on 8a95c63d3b are main's, not this diff.

Jobs Failing test Cause on main
Backend Tests (3.12, 6), Backend Tests (Windows) (6) test/test_session_control_doc.py::test_every_tabulated_refusal_code_is_one_the_source_raises the doc still tabulates remote_target_unsupported, which #17662 stopped raising — #17902 / #17900
Backend Tests (3.12, 2), Backend Tests (Windows) (2) test/test_http_server_bind_ratchet.py::test_bare_http_server_constructions_match_the_recorded_count the ratchet landed in #17450 counting 15 sites while 16 exist — #17908 / #17900
Coverage Gate, PR Readiness — fail closed on backend-test=failure from the four jobs above

Each shard has exactly that one failure (e.g. shard 6: 1 failed, 22922 passed). Both tests fail identically on a pristine origin/main worktree at 828dd0b2ba (2 failed, 1 passed, run serially on Python 3.12). This PR touches only src/kiro_crew/subagent_manager/admission/gate.py, which neither test reads. Open fixes: #17903, #17906, #17907, #17909. Not re-running: the reds repeat until one of those lands; this branch gets rebased onto the fixed main then.

@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 7, 2026
@bolichen97
bolichen97 force-pushed the refactor/simplify-subagent_manager branch from 8a95c63 to 98f8ac2 Compare October 8, 2026 00:23
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto 972b78218b to pick up #17909, which fixes the main break behind the six reds attributed above; on that base both previously failing tests pass (test_session_control_doc.py and test_http_server_bind_ratchet.py: 12 passed). The diff is unchanged (one file, +7/−8). Gates and the 748 targeted admission/spawn tests are green locally on the new head 98f8ac28ed; CI re-running.

@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 8, 2026
@bolichen97
bolichen97 force-pushed the refactor/simplify-subagent_manager branch from 98f8ac2 to 36d07d9 Compare October 8, 2026 01:13
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_runtime_reconcile.py (import-graph overlap; #17935) since this head went green (972b78218b -> 6c15ee7614); CI re-running. Locally on the new head 36d07d9adf: gates green, and test_runtime_reconcile.py plus the 11 admission/spawn test files pass (878 tests). Diff unchanged: one file, +7/−8.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 8, 2026
The memory floor's deferral detail picked one of three strings through
a ternary nested inside another ternary's else arm. Spell it as
if/elif/else with the same branch order: a lane-share hold names only
its note, an unknown headroom adds the GB it needs, and a measured
shortfall reports the figures. Every string, and the order its
conditions are tested in, is unchanged.
@bolichen97
bolichen97 force-pushed the refactor/simplify-subagent_manager branch from 36d07d9 to af0e309 Compare October 8, 2026 07:36
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in import-graph overlap files since this head went green (6c15ee7 -> aee834c); CI re-running.

The one red on the prior head, Backend Tests (Windows) (8), was test_subagent_memory_wake.py::TestOneEventStartsAWaitingSpawn::test_a_sampler_tick_starts_it_and_runs_only_while_a_start_waits failing 3600.0000000000005 <= 3600 — the float round-trip flake tracked in #17876 and fixed on main by #17957, which this rebase picks up. This diff (one memory_detail ternary rewritten as if/elif/else in admission/gate.py) does not touch the sampler. The diff is byte-identical to the reviewed head; local gates and 398 admission/spawn/memory-wake tests pass on the new base.

@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 readiness: checking Automated validation is still running labels Oct 8, 2026
@github-actions github-actions Bot added the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 8, 2026 09:47

@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.

Approved on maintainer request after review: refactor (1 file). The nested conditional expression for memory_detail becomes an if/elif/else with the same three branches in the same order (lane held, unknown usage, low memory) and the same strings, so behaviour is unchanged.

@KiroCrewCaptain
KiroCrewCaptain merged commit ed28128 into main Oct 8, 2026
102 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the refactor/simplify-subagent_manager branch October 8, 2026 09:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 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