Repository navigation
refactor(subagent): bind SubagentManager methods from subagent_parts - #21278
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One thing to check: the posture panel's "Subagent results" sink now names What this change shipsInventory (8 items) — 8 justifiedIntent: bring
[FIRST-PRINCIPLES-REVIEWED] 5af2122 Description read[DESCRIPTION-READ] ace8a717ae5338da26934a66f0d812e7ec423aaec7e45ab75640af74084a8f67 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that every bound [DESIGN-REVIEWED] 5af2122 Description read[DESCRIPTION-READ] 645e9b64619e8c86c5b6183e0eb952d70fbcf8e6ef053f95b5951b5d84f234a5 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 |
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: |
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: |
|
|
7e0e096 to
6ea18bb
Compare
Sensitive change review
|
|
subagent.py is still 4,697 lines after its module-level helpers moved out, almost all of it the SubagentManager class. This second step moves the class, SubagentInfo and the delivery contract into subagent_parts, leaving subagent.py a 709-line facade under the 2,000-line cap. The class is split by binding: each *_surface module holds methods as functions taking self, and manager.py binds them as class attributes, so the attribute is the moved function and mocks, autospec, signatures and SubagentManager patches see what the one-module class had. compose keeps every moved function on subagent.py's globals, so each kiro_crew.subagent.<name> patch still reaches it. Two ACP names reach the moved code through kiro_crew.agent_sdk.drivers, lowering the facade's agent-sdk boundary count from 7 to 6. The security posture "Subagent results" sink row now names subagent_parts/run_output.py, the module that redacts subagent results, since subagent.py keeps no redactor call.
6ea18bb to
5af2122
Compare
Sensitive change review
|
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer. The triage automation held this on a size, path, category or move-check rule only; every review lane is clean.
Problem / Motivation
Goal: Bring
src/kiro_crew/subagent.pyunder the 2,000-line cap by movingSubagentManager,SubagentInfoand the delivery contract into focusedkiro_crew.subagent_partsmodules, with no change in behaviour.This is the second of two PRs (the first, #20401, moved the module-level helpers). After it,
subagent.pywas still 4,697 lines, almost all of it theSubagentManagerclass (about 4,000 lines). The campaign in #20192 caps hand-written files at 2,000 lines, and a class that size cannot be cut by moving whole definitions.Why it matters
SubagentManageris where every subagent change lands. One 4,000-line class is read in fragments by people and review lanes alike, and edits to unrelated parts of it conflict. Each responsibility of the manager now has one module, so new code has an obvious home andsubagent.pystays a small facade.Not a goal
subagent_manager/coordinators or theirbind_component_globalsmechanism.kiro_crew.subagent, and everySubagentManager.<name>member stays the same kind with the same signature.compose()copies (tracked in refactor: share one compose() helper across facade packages #20421).What changed (motivation → approach → change)
subagent.pydrops from 4,704 to 709 lines; no file in the family is over 1,100 lines.manager.pySubagentManager: constructor, class attributes, properties, the durable task queue, one binding per other methodadmission_surface.pyrun_record.pySubagentInfoand the scope fields it carriesterminal_surface.pymonitor_surface.pyrun_surface.py_run,_run_inner, the provider seam, queue-depth and pending-work queries, the off-loop writersdelivery.pydelivery_is_parked, the teardown gate's idscontinuation_surface.pycancellation_surface.pyconfig_surface.pyThe class is split by binding, not by mixins or forwarding stubs. Each
*_surfacemodule holds methods as plain functions takingself, andmanager.pybinds them as class attributes (spawn = _admission_surface.spawn). The class attribute IS the moved function, soMagicMock(spec=SubagentManager), autospec,inspect.signature, andSubagentManager.<name>patches see exactly what the one-module class had. The sharedkiro_crew._facade_compose.compose()(called withhost=SubagentManager) runs every moved function onsubagent.py's globals, so the ~1,500kiro_crew.subagent.<name>patch targets keep reaching moved code.Two ACP names the moved code needs reach it through
kiro_crew.agent_sdk.driversinstead of a new ACP import:acp_vocabre-exportsInFlightToolTracker, anddrivers/acp.pygains aprovider_labelwrapper.subagent.py's agent-sdk boundary edge count drops from 7 to 6.Backwards compatibility
Compatible: every name
kiro_crew.subagentbound at the base still resolves there to the same object (test_campaign_facades_base_public_names.py), everySubagentManagermember keeps its kind and signature (test_subagent_parts_composition_contract.pyinventory of the 213 base members), and everykiro_crew.subagent.<name>patch still reaches the moved code.Reader: src/kiro_crew/subagent_manager/cancellation.py:delivery_is_parked -- subagent -- imports it from kiro_crew.subagent, which re-exports the same object; test_session.py
The security posture panel names
subagent_parts/run_output.pyinstead ofsubagent.pyfor the "Subagent results" sink (see Registries below).SubagentManager.__module__is nowkiro_crew.subagent_parts.managerandSubagentInfo.__module__iskiro_crew.subagent_parts.run_record; nothing reads them (pickle,copyreg,shelve,reprand error-text greps: no hits).SpawnApprovalUnreachablekeepskiro_crew.subagent, because a traceback, a log line and a pickle name an exception by its module. Bound methods keep theirSubagentManager.<name>qualname.Tests
test/test_subagent_parts_composition_contract.py(extended): the 213 baseSubagentManagermembers keep their kind, coroutine-ness and signature (the binding'sselfannotation left out), each bound member IS its owner's function, no bound function needs the class body (zero-argumentsuper(),__class__, a name-mangled attribute; with self-tests), the host module may import only its collaborators, bound functions keep theirSubagentManager.<name>qualname, every class an owner defines reports its owner module except the one named exemption, andSpawnApprovalUnreachablereportskiro_crew.subagentand resolves there.test/test_subagent_parts_provider_label.py(new): the SDKprovider_labelwrapper andSubagentManager._provider_label_ofanswer exactly whatkiro_crew.providers.acp.provider_labelanswers for every provider kind (anAcpProviderper backend before and after its startup swap, a bareAcpSessionProvider, a spec'd mock, a non-ACP object) and every label the helper can return; the standaloneClaudeCodeProvidersentinel still wins.test/test_subagent_parts_config_surface.py(new): a reload that cannot size the cap keeps the cap in force, a limit that does not parse keeps the limit in force, and a broken cap-raise hook does not block the raise.monkeypatchandcaplog; no clock, sleep, port or order assertion. Each passed 5 runs at-n0and one at-n 3.Local runs on this head (Python 3.12,
-n 3):source_corpus,rglobandos.walkusers,test_transcript_derivation_seam.py,test_link_screen_hold_pin.py)mypy src/kiro_crewsubagent_partsowner (CI's--cov=kiro_crew)scripts/local-gate.py --dry-runselects 2,261 backend and 894 frontend test files, so the sets above stand in for it; CI runs the full suite.Manual verification
subagent.py; re-running it reproduces every generated file and the contract test byte-for-byte.kiro_crew.subagentand everykiro_crew.subagent_partsmodule.Related Issues
Part of #20192
Move audit
move_audit.py --origin src/kiro_crew/subagent.pyagainst main reports most class members as changed, because a bound method gains aself: SubagentManagerannotation, loses@staticmethod(the class bindsstaticmethod(owner.f)instead) and dedents its docstring. A normalized-AST supplement (strip exactly those three edits,inspect.cleandocdocstrings) compares the rest:The two that still differ are the planned edits: the
_audit_idsdocstring now names where the helper is bound, and_provider_label_ofimportsprovider_labelfromkiro_crew.agent_sdk.drivers.acpinstead of the providers layer. The three non-function units are the binding tuple, thecomposecall, andSpawnApprovalUnreachable, whose class body gains__module__ = "kiro_crew.subagent"and a comment saying why. The only other added code inmanager.pyis the 17 class-level field annotations (see Composition mechanism).git diffandgit diff --minimaladd the same lines in every changed file.Composition mechanism
The shared
kiro_crew._facade_compose.compose, called withhost=SubagentManager, runs every moved function onsubagent.py's globals and gives each bound method itsSubagentManager.<name>qualname back. The class body stays inmanager.pywith its constructor, class attributes, properties and the durable task queue it opens and closes, and declares the 17 instance fields mypy reports[has-type]for in a surface module (_admission: SpawnAdmissionCoordinator, ...): a surface importsmanager.pyonly for type checking, so mypy checks it before it infers them from__init__; every other method is a binding grouped under one comment per surface. Each surface's docstring lists the manager fields it reads and writes. An owner that callsos,time,subprocessorsocketimports it asimport <module>underTYPE_CHECKING, soscripts/check_sync_io_in_async.pystill sees moved coroutines (a plantedtime.sleep(1)in one is flagged).Moved classes report their owner module as
__module__(SubagentManager,SubagentInfo, the callback Protocols,_AgingIdSet,_BareStateView); no reader exists (pickle,copyreg,shelve,repr, error-text greps). The moved exceptionSpawnApprovalUnreachablesets__module__ = "kiro_crew.subagent", which the contract test pins.Logger (L25): owners define no logger and log through the facade's
kiro_crew.subagentlogger.Source-reading tests re-pointed
Path or row changes only, assertions unchanged; each proved by a mutation in the new home that turns the test red:
test/test_subagent_scale.py: the draw-count scan reads the facade joined withsubagent_parts/*.py, and the_mint_agent_idcheck readsinspect.getsource(SubagentManager._mint_agent_id)(the method moves toadmission_surface.py, where a text slice keyed on method indentation would run past it). Mutation: move the draw into a helper right after the method; the text slice stays green, the test goes red.test/test_agent_sdk_capabilities.py:_COMPOSED_OWNERSgains"subagent.py": "subagent_parts", so the harness-identity ratchet reads the 16 owner modules.test/test_ws_event_scoping_frames.py: the_fire_eventscan readssubagent_parts/*.pytoo (_fire_eventmoves torun_surface.py).One integration fix beyond a path change, granted for this PR because the split is what breaks it:
test/test_taskq_bridge_bindings.py_manager_methods(): readsSubagentManager's methods from the class (vars(SubagentManager): functions, static and class methods, properties) instead of parsingclass SubagentManagerinsubagent.pyfor itsdefs. The class now binds most methods from its owners as attributes, sodefparsing no longer sees them, and pointing it atmanager.pywould count every bound method call as a field. The derived set equals the one main'ssubagent.pygives (207 = 207), and the assertions are unchanged. Mutations: dropping one name fromtaskq_bridge_reads'Reads:line turns the test red (1 failed); a helper that sees no methods turns it red (3 failed).Registries, docs and CI path references
test/campaign_facade_inventories/kiro_crew.subagent.json: 13reboundrows for the names this PR moves (SubagentManager,SubagentInfo, the delivery contract);base_public_namesunchanged (check_inventory.py: 225 of 225)..github/agent-sdk-boundary-baseline.txt:subagent.py7 -> 6 (theprovidersimport_provider_label_ofneeded now goes throughkiro_crew.agent_sdk.drivers.acp.provider_label;InFlightToolTrackeris re-exported bykiro_crew.agent_sdk.drivers.acp_vocab)..github/file-line-cap-baseline.txt: thesubagent.pyrow is deleted (709 lines).src/kiro_crew/security_posture.py: the "Subagent results"_REDACTION_SINKSrow namessubagent_parts/run_output.py, the module that redacts subagent results, becausesubagent.pykeeps no redactor call. This is the one visible change: the security posture panel names that module for this sink.run_output.pymoves fromNON_EGRESS_REDACTION_MODULESto the sink row. The admission, continuation, monitor and terminal surfaces joinNON_EGRESS_REDACTION_MODULES(moved redactor calls, no new transport). Proof: striprun_output.pyof everyredactspelling andTestRedactionSinkRegistrystays green with the row atsubagent.py; with the row atrun_output.py, 2 of 5 fail.docs/system-specs/modules/subagent.md§ Composition: the full owner table, the binding rule, where new methods go, and which moved classes report which__module__.subagent.pyas the home of a moved method now name its surface:resource-protection.md,context-management.md,config.md,learn-cron-dashboard.md, four RFCs and one RFC plan,injected-messages.md, a comment insubagent_manager/admission/pump.py, docstrings intest/test_agent_refactor_contracts.pyandtest/test_cron_gateway_integration.py, themcp_gateway/backend_liveness.pycite inrun_limits.py, and twosecurity_posture.pycomments that name the subagent sink.Risks
subagent.pyas the home of moved code: "the off-loop twin in subagent.py" inslack/gateway_runtime/cron_fire.py, and the one indashboard/handlers/files.py. Both files belong to other live splits, so the corrected paths are relayed to them and change after this PR merges.References not edited
Two test comments still name
slack/gateway.pyfor code the gateway split moved; they sit in files outside this PR's claim. Follow-up: #21320.test/test_subagent_coverage.py:1621:slack/gateway.py->slack/gateway_runtime/runtime_charge.pytest/test_subagent_undelivered_notice_restart.py:116: "gateway.py_subagent_done" ->gateway_runtime/subagent_wiring.pyChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)