Repository navigation
refactor(slack): compose the gateway's sub-agent path and constructor - #21176
Conversation
slack/gateway.py was 4,035 lines after the cron split, and its target under the 2,000-line cap (#20192) is 1,200. _init_subagents alone was 1,888 lines: one closure, _subagent_done, consumes every sub-agent's terminal report, so moving whole definitions could not shrink it. The closure's phases become methods and functions whose closure inputs are parameters, and they move with the constructor, the channel hoists and the runtime-death charge into six owners under gateway_runtime: orchestrator_init, channel_boot, subagent_wiring, subagent_report, subagent_injection and runtime_charge. The update restart's body moves behind the decorated _restart_after_update, and small members and constants join the owners that read them. The class declares, without values, every field the constructor and the hoists assign; __init__ is bound under the else of if TYPE_CHECKING, whose branch gives the type checker the owner's signature. gateway.py is now 1,178 lines. Regions move verbatim apart from re-plumbing, stripped inline annotations and reworded comments. Characterisation tests drive the completion consumer through on_done before and after the move; re-pointed guards read the owners, and the delivery-routing producer list names them. Part of #20192
Sensitive change review
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the hand-written [DESIGN-REVIEWED] 7c6c23c Description read[DESCRIPTION-READ] f4dc8456014eaa65b724e60a3b7a87bb244f28fb895c2e88430e60c7b114168f 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 Check that moving What this change shipsInventory (8 items) — 8 justifiedIntent: bring
[FIRST-PRINCIPLES-REVIEWED] 7c6c23c Description read[DESCRIPTION-READ] 4e8205a9dad73de4afa18432e7f1198d640da2dfcd077e6e1652f311a8a04b54 That sha256 names the PR description this verdict read. Recompute it with |
Sensitive Change ReviewSensitive files changed:
|
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: |
|
|
|
HOLD at 7c6c23c. This needs a human review because it touches I found no defect. I recounted the redactor calls: the 32 that leave A maintainer's sign-off on the posture re-key clears this. A new push needs a fresh review. — crew-pr-reviewer (r107) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer. The triage automation held this on a size, path or move-check rule only; every review lane is clean. Any lane note is accepted as follow-up work.
Problem / Motivation
Goal: Bring
slack/gateway.pyunder the 1,200-line target by composing its sub-agent completion path, its constructor and its channel boot from owner modules, with no behaviour change.slack/gateway.pyis 4,035 lines after the third PR of this series (#20761). The repository is adopting a 2,000-line cap on hand-written files (#20192), and this file's 7-day churn puts its target at 1,200.GatewayOrchestrator._init_subagentsalone is 1,888 lines: one closure,_subagent_done, consumes every sub-agent's terminal report, so moving whole definitions cannot shrink it. This PR decomposes that closure into methods with explicit inputs and moves them out, together with the constructor, the channel hoists and the runtime-death charge. It is the fourth and last PR of the series.Why it matters
The sub-agent completion path is where every fix to wave digests, completion delivery and injection retries lands. Each of those now gets a file the size of one responsibility, and the facade, which every gateway change touches, drops to 1,178 lines, leaving room under the cap for the features that follow.
Not a goal
self.call, strip inline annotations the type checker rejects on a non-self receiver, and are listed below.gateway_runtime.composefacade and the binding shape of refactor(slack): compose the update path and AutoNudge from gateway owners #20443, refactor(slack): compose boot, approvals, egress and exit from owners #20601 and refactor(slack): split the cron callback into composed owners #20761 are reused._retrigger_recovery, which nothing calls, moves verbatim.What changed (motivation → approach → change)
_init_subagentsheld the whole completion consumer in one closure, so its phases shared locals instead of parameters. This PR first turns each phase into a method or function whose closure inputs become parameters, still ingateway.py, then moves them, with the constructor and the channel boot, into six new owners and eight existing ones:orchestrator_init.py__init__: the initial value of every field the owners sharechannel_boot.pysubagent_wiring.py_init_subagents: the manager and its callbacks, and the_subagent_donespine (tab resolution, the "done" frame, the wave peek, the routing calls)subagent_report.pysubagent_injection.pyruntime_charge.pyThe update restart's body moves to
update_schedule.pybehind the decorated_restart_after_update, which compose cannot rebind; a few small members and constants join the owners that read them (cron_fire,cron_exec,exit_path,service_boot,cron_delivery,heartbeat_turns,process_entry). The class declares, without values, every field the constructor and the hoists assign, because an inline annotation onself: GatewayOrchestratoris a type error there; a__new__fixture still getsAttributeError.__init__is bound under theelseofif TYPE_CHECKING:, whose branch gives the type checker the owner's signature, because mypy reads a class-body assignment to__init__as an incompatible override ofobject.__init__. The class body's owner bindings drop the blank row between them.gateway.pygoes from 4,035 to 1,178 lines; the largest new file is 877.Backwards compatibility
Compatible: every name
kiro_crew.slack.gatewaybound before this PR stays bound, pinned bytest_campaign_facades_base_public_names.py; every moved member keeps its name, kind, signature,__module__and__qualname__, pinned by_BASE_SURFACE;inspect.signature(GatewayOrchestrator)is unchanged, pinned bytest_gateway_orchestrator_init.py.Removes nothing: no public module-level function moves out of a product file, and every moved name stays reachable on the facade or the class.
Log lines keep the
kiro_crew.slack.gatewaylogger: the owners read the facade'sloggerthrough the composed globals.Tests
test_gateway_subagent_wiring.py,test_gateway_subagent_report.py,test_gateway_subagent_injection.pyandtest_gateway_runtime_charge.py(57 tests) characterise what the decomposition must keep, driven through the realon_doneand passing unchanged before and after the move: which tab a completion lands in and which slot its frames name, the restored tab's window load, the records that route nothing, the report's text and redaction order, the card facts, the wave's lookups, failure arms, chunk and close, the inline-collected skips, the in-flight count across a wait and a cancellation, the turn's provenance, each channel attempt's session wiring and timeout bound, the cron session's reset decision, and every arm of the injection retry. Each was proven by mutation on the code before the move (58 mutations, all red).test_gateway_orchestrator_init.py(6 tests): the class declares exactly the fields the constructor and the hoists assign, with the 75 annotations they carried inline; no declaration creates a class attribute; the constructor keeps its name, module and signature; the type checker's stub is the owner's signature.-n0, one at-n 3and one in reversed order; the six owners ship in the wheel and import from it.Re-pointed guards
test_runtime_death_is_a_process_event_GUARDED_CHARGESrow and the hand-over sites ->runtime_charge.py; the death-arm scan and the attribution-flag reachability scan read the facade and every owner_BASE_SURFACErows for every moved and new member;_GUARDED_TOKEN_HOMESre-keyed for 12 tokens; the hoisted-attribute check exempts the two files the hot-reload test readstest_channel_boot_hot_reloadorchestrator_init.pyandchannel_boot.pytootest_channel_readinesstest_memory_v2_isolationsubagent_injection.pytest_no_config_dir_in_asynctest_security_postureslack/gateway.py1 -> 0 (row dropped),subagent_injection.py1;security_posture.pyre-keys the "Slack cron / notification posts" sink fromslack/gateway.pytoslack/gateway_runtime/subagent_injection.py, which holds that row's redaction, and listssubagent_report.pyandsubagent_wiring.pyas non-egresstest_spawn_approval_channel_delivery_2381,test_spawn_approval_no_surface_2381subagent_wiring.py; the one-raising-instance count reads the facade and every ownertest_gateway_runtime_bindings_SLACK_APPLIER_PREFIXESis a bound class constant ofchannel_boottest_memory_startup,test_slack_gateway_overload_wiringcrew_log_emit, no_start_adaptive_controller) read_init_subagentsand the six completion phases it callstest_feature_videos_boot_pathself._feature_video_task = None, and the class declares the field with the annotation the constructor carriedtest_slack_gateway(the uncredentialed-probe ratchet)test_gateway_restart_uses_respawn_executabletest_session(delivery-routing producers)subagent.DELIVERY_ROUTING_MODULES, names the completion consumer's four owners (see below)Cross-scope edit (Master grant)
src/kiro_crew/subagent.py:DELIVERY_ROUTING_MODULESreplacesslack/gateway.pywithslack/gateway_runtime/subagent_wiring.py,subagent_report.py,subagent_injection.pyandruntime_charge.py: the three that write the routing fields, andsubagent_wiring.py, whose_subagent_donespine routes every completion, so a field a later change writes there is classified too; and the comment above it names those producers;docs/system-specs/modules/subagent.mdsays the same, and theINJECTION_TIMEOUTcomment insrc/kiro_crew/subagent_parts/run_limits.pynames where_subagent_donelives. Without it the producer scan reads a facade that writes none of those fields, and its stale-classification check fails.Citations (L29)
docs/system-specs/modules/slack-gateway.mddocs/system-specs/modules/subagent.md,messaging.md,heartbeat.md,memory-skills-hooks.md,common/injected-messages.md,architecture/resource-protection.mdslack/gateway.py→ the owner that holds the cited codesrc/kiro_crew/subagent.py,src/kiro_crew/subagent_parts/run_limits.py(comments)slack/gateway.py→subagent_wiring.pyfor_subagent_donesrc/kiro_crew/slack/gateway_runtime/cron_exec.py(comment)cron.py's_execute_with_timeout→CronService._execute_with_timeout(#20862 moved it)src/kiro_crew/slack/gateway_runtime/cron_fire.py(two comments)config/sections.py→config/sections_agent.py, whereagent.default_agentlives (#21129 split it)src/kiro_crew/messaging/registry.py,slack/gateway_runtime/__init__.py,channel_lifecycle.py,cron_verdict.py,delivery.py,slack/gateway.pysrc/kiro_crew/messaging/spawn_approval_delivery.py(docstring),dashboard/ws_event_scope.py(comment)slack/gateway.py→slack/gateway_runtime/subagent_wiring.py(the spawn-approval callback; the_subagent_eventclosure)src/kiro_crew/dashboard/messaging_api/teams_settings.py(two comments)slack/gateway.py→_hoist_teamsinslack/gateway_runtime/channel_boot.pydocs/system-specs/modules/learn-cron-dashboard.md_acquiredflag pattern:gateway.py→ the gateway's turn ownerstest/test_members_preview_speech_only.py(comment)slack/gateway.py→slack/gateway_runtime/subagent_report.pyManual verification
N/A — a structural move: the characterisation tests drive the completion consumer through the unchanged
on_done, andtest/integration/test_boot_smoke.pyboots the gateway in-process.Move audit
move_audit.pycompares whole definitions, so it lists the units this PR cut or re-plumbed as changed:_init_subagents(its closure's phases became methods),__init__and eight hoists (their inline annotations moved to the class),_restart_after_update(its body moved behind the decorated method),_start_channel_transports(one reworded docstring line), and the class itself. With theself:annotation, the dropped@staticmethodand docstring re-indent normalised away, 25 more units move verbatim. The region audit re-derives every region from the base and compares its tokens with the def that now holds it: 9,536 of 9,865 base tokens unchanged; every difference is one of the listed edits, a stripped annotation, a reworded comment, or a pair of parentheses black drops once an annotation is gone.Diff alignment (L36)
git diff --numstatandgit diff --minimal --numstatagree on every changed file except two, where the default diff re-shows blank lines only (accepted under L41):src/kiro_crew/slack/gateway.py236/3093 vs 234/3091 (two blank rows inside the new declaration and constructor-stub block) anddocs/system-specs/modules/slack-gateway.md28/23 vs 27/22 (one blank row).Files over 2,000 lines this PR grows
src/kiro_crew/security_posture.py, +4: the non-egress rows for two redacting sub-agent owners, the re-keyed sink row and the reworded comment above them.src/kiro_crew/subagent.py, +5 (Master grant, see above): the four routing producers and the two comments naming them.test/test_slack_gateway.py, +5 (Master grant): the uncredentialed-probe ratchet reads the probe table and the enable predicates from the owners as well as the facade.All three are report-only under the line-cap guard; their rows are left as they are.
.github/file-line-cap-baseline.txtdeletes theslack/gateway.pyrow: the facade is now 1,178 lines.CI path references
None changed.
AUTOSDE.yamlalready coverssrc/kiro_crew/slack/gateway_runtime/**/*.py, and no workflow filter or file list namesslack/gateway.py.Related Issues
Part of #20192
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.