Repository navigation
fix(subagent): split run_turn.py under the line cap and fix its prompt-hook test - #25950
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the split moves whole blocks before the prompt with no early returns, and patched names still resolve through the call-time facade. Notes
[DESIGN-REVIEWED] 1397b8a Description read[DESCRIPTION-READ] ff01e83a5cbdc3cb402ce88b94df9583eaa7001c98c4154bd8c8d8a04daa3558 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This is a behaviour-preserving split, required by the 2,000-line cap. The only gap: the title and description claim a test fix that is not in this diff. Notes
What this change shipsInventory (5 items) — 4 justifiedIntent: get main's line-cap gate green again by splitting
[FIRST-PRINCIPLES-REVIEWED] 1397b8a Description read[DESCRIPTION-READ] 122dafc50720979bdbf4fa09fa3bfa85294b39268debd6541d4bab17d664fa35 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Sensitive change review
|
dddd832 to
e845ffd
Compare
Sensitive change review
|
e845ffd to
ecc1331
Compare
Sensitive change review
|
Move the pre-stream steps of _run_inner_impl that close over none of its locals (the inherited approval policy, the session acquisition, the cleanup identity, the child's memory and steering, the spawn records and the prompt hooks) into subagent_manager/turn_session.py. They read the names tests patch on kiro_crew.subagent through a call-time sys.modules lookup, so every patch still reaches them. No behaviour change.
ecc1331 to
1397b8a
Compare
Sensitive change review
|
Problem / Motivation
Goal: Turn main's lint and test jobs green again by bringing
src/kiro_crew/subagent_manager/run_turn.pyback under the 2,000-line cap and fixing the sub-agent prompt-hook test that the Stop-hook change broke.Two changes merged on 2026-10-29 left main red:
src/kiro_crew/subagent_manager/run_turn.pyto 2,030 lines on origin/main (d32862446c). That is over the 2,000-line hard capscripts/check_file_line_cap.pyenforces, and the file has no row in.github/file-line-cap-baseline.txt. The baseline only shrinks, so the file has to be split.test/test_subagent_prompt_hooks.py::test_hook_time_is_not_charged_to_the_first_prompt_watchdog(added by fix(subagent): fire AgentSpawn and UserPromptSubmit hooks for a child prompt #25122) fails on main withAssertionError: a running hook is neither silence nor a stalled start. fix(subagent): fire Stop hooks when a sub-agent prompt ends #25127 made a child's Stop hooks fire through the samehook_store.firethe test fakes, so the test's per-fire callback also ran for the Stop fire after the stream, when no prompt hook is running.Why it matters
Every PR that touches
run_turn.pyfails the line-cap gate, and every PR whose run includes the sub-agent tests sees one inherited red test. Contributors cannot tell their own failures from main's.Not a goal
_stream_with_transient_retry,_fire_stop_hooks,_persist_usage_row). Those close over the turn's locals and stay in_run_inner_impl.RunEventCoordinatormember set or the facade surface.What changed (motivation → approach → change)
Commit 1,
test(subagent): count only prompt hooks in the first-prompt watchdog test:the test helper
_run_childcalls itson_firecallback only forAgentSpawnandUserPromptSubmit(a module constant_PROMPT_EVENTS), the two events fired before the prompt. The assertion is unchanged: during each of the two prompt-hook fires the run reads as running its hooks, is not first-prompt silent, and is not a stalled start. With the flag that marks hooks as running removed from production code, the test still fails.Commit 2,
refactor(subagent): split run_turn.py under the line cap:_run_inner_implis one long function. The parts before the prompt that close over none of its locals and hand back a value moved, as whole blocks, into a new sibling modulesrc/kiro_crew/subagent_manager/turn_session.py:resolve_parent_policy: the approval policy the child's tool calls inherit, with its audited fallbacks.acquire_session: the shared-runtime arm and the dedicated-process arm, returning(client, is_new, resumed, is_cc, use_session_sharing).capture_cleanup_identity: the cleanup identity captured right after acquisition.prepare_child_context: the child's memory store, crew activity and folder steering; returns the project.persist_spawn_records: model provenance, the identity sidecar,subagent_spawn, the PID record and the session record, in the same order.fire_prompt_hooks: theAgentSpawn/UserPromptSubmitfiring with its running flag and clock bookkeeping._run_inner_implruns onkiro_crew.subagent's globals (bind_component_globals), and tests patch names there (sel,time,_redact, the session re-projection helpers). The moved functions read those names through_facade(), a call-timesys.modules["kiro_crew.subagent"]lookup (the patternsrc/kiro_crew/snapshot_components.pyuses), so every existing patch still reaches them._run_inner_implimports the module locally, as it already does forprompt_hooks.The module is named
turn_session.py, notrun_*:test/test_run_bindings.pyrequires everyrun_*.pysibling to be an owner thatRunEventCoordinatorbinds members from, and these are plain functions. The lines that structural tests read inrun_turn.pystay there:publish_execution,extra_kwargs["shared_scratch"], theon_tool_callgate consult, the MCP notice seam, the one usage-row persist, and the permission ladder'ssettleandbailcalls.run_turn.pygoes from 2,030 to 1,598 lines;turn_session.pyis 561. Therun_turn.pydocstring's manager-field list now names only the fields it still reads, andturn_session.pylists its own.docs/system-specs/modules/subagent.md(Session Lifecycle) anddocs/system-specs/modules/acp-client.md(the congestion rule) name the new file.Backwards compatibility
Compatible: the moved code runs the same statements in the same order and reads the same patched names through the facade, and the import path
kiro_crew.subagent_manager.run_turnandRunEventCoordinator._run_inner_implare unchanged.Removes nothing: no function, key, record or caller-visible name is removed; code moved from one private module to a new private sibling.
Tests
test/test_subagent_prompt_hooks.py: the watchdog test and the cancelled-hook test now driveon_fireonly for the two prompt-hook events; 7 passed.info._prompt_hooks_running = Truefromturn_session.fire_prompt_hooksmakestest_hook_time_is_not_charged_to_the_first_prompt_watchdogfail (1 failed); restored afterwards.TMPDIR=/tmp python -m pytest -n auto --dist loadgroupovertest/test_subagent_*.pyplustest_run_bindings.py,test_eval_subagent_deny_notice.py,test_execution_context.py,test_hooks.py,test_turn_duration_recorded.py,test_app_spawn_capability.py,test_session_start_gate.py,test_identity_topology.py,test_member_essential_context.py,test_facade_mirror_guards.py,test_subagent_parts_composition_contract.py,test_session_sharing.py,test_continuable_followups.py,test_adaptive_startup_memory.py: 3489 passed, 2 skipped, 5 xfailed.Proof: not provable -- other: the fix is a test-only change plus a behaviour-preserving refactor, so there is no production hunk to revert
Manual verification
N/A — unit coverage sufficient: no runtime behaviour changes, and the gates below were run locally on the touched files.
python3 scripts/check_file_line_cap.py: 0 failures, 0 main-drift warnings (main showed therun_turn.py2,030-line drift warning).python3 scripts/check_black_formatting.pywith black 26.10.1: passed. black--target-version py310 --check, isort--check-onlyand flake8 on the three touched Python files: clean.mypy --platform linux src/kiro_crew/subagent_manager: no issues in 33 source files.Related Issues
Follows #25127 and #25122, which together left main over the line cap with one failing test.
Sibling sweep
Swept:
grep -rln "hook_store.fire = AsyncMock" test/Sibling: test/test_subagent_run_loop.py -- not affected -- its fakes return nothing or raise for every event, run no per-fire callback, and the file passes on this head
Sibling: test/test_subagent_stop_hook.py -- not affected -- its fake answers by event name, and the whole file passes on this head
Pattern harvest
Not generalizable: the test's callback assumed it saw only prompt-hook fires, a property of this one helper rather than a repeated shape.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.