Repository navigation
refactor(slack): split the cron callback into composed owners - #20761
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the 56 characterisation tests in [DESIGN-REVIEWED] 884a8d7 Description read[DESCRIPTION-READ] bd42d5a24e9b0e22bd8ce64a0c9ba7495835e37dda30fdacce227cd879bc32ad 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) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The new 160-line "one-unit" subject follower in Not justified as shipped
What this change shipsInventory (8 items) — 7 justifiedIntent: a maintainer wants the cron callback split out of a 7,272-line
[FIRST-PRINCIPLES-REVIEWED] 884a8d7 Description read[DESCRIPTION-READ] be03145bd97249521384e3ea68673d6df3ebe7459b845d603c1e31cb4d745b0e That sha256 names the PR description this verdict read. 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: |
chenmingwei23
left a comment
There was a problem hiding this comment.
Approving: readiness gate passed, no conflicts, checks green.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer after reading the review lanes: every lane is clean on this head, and the automated triage held it only on a size, path, category or doc rule.
The third step of splitting GatewayOrchestrator. _init_cron held every cron job kind in one 3,000-line closure whose regions shared locals, so it could not move by whole definitions. Each region becomes a method or function with its closure inputs as explicit parameters, and those move into five gateway_runtime owners: the callback spine and the per-fire capture (cron_fire), the command and script arms (cron_exec), the agent turns (cron_turn), the result delivery (cron_delivery) and the failure alerts (cron_failure). The class body binds each under its own name and compose() runs the owners on the facade's globals, so every patch of kiro_crew.slack.gateway.<name> still reaches the moved code. Bodies move verbatim apart from the dedent and the listed re-plumbing. The runtime-death attribution and charge stay in the facade beside the sub-agent death arms until those move. New characterization tests pin the callback's ordering, retries, cleanup and charging through on_job; guards that read the moved code by path now read the owners. Part of #20192
884a8d7
e579a1b to
884a8d7
Compare
Sensitive change review
|
|
Rebased onto main c6d6106: the branch had gone DIRTY because two doc lines this PR re-points were also edited on main. No code changed. The range-diff shows exactly those two lines, and each one keeps main's edit together with this PR's new path:
Main touched no |
|
|
|
HOLD at 884a8d7. The split reads as a faithful move. I compared the lines removed from What holds it: the user's rules reserve this for human review. It changes the security-posture redaction registry (security_posture.py L2455-L2466) and rewrites the runtime-death guard's subject rule ( This clears when a maintainer reviews those three areas. I did not run the tests or read the new characterisation tests line by line. — crew-pr-reviewer (r105) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer who read the review lane findings on this head and accepted them as follow-up work; the findings stay on the record for whoever picks them up.
Problem / Motivation
Goal: Bring
slack/gateway.pydown from 7,272 lines by splitting the cron callback, the gateway's largest remaining method, into composed owner modules, with no behaviour change.slack/gateway.pyis 7,272 lines after the second PR of this series (#20601). The repository is adopting a 2,000-line cap on hand-written files (#20192).GatewayOrchestrator._init_cronalone is 3,255 lines: one closure,_cron_callback, runs every cron job kind, so moving whole definitions cannot shrink it. This PR decomposes that closure into methods with explicit inputs and moves them out. It is the third PR of four.Why it matters
The cron callback is the gateway's most-edited code path. Every later feature or fix to cron delivery, retries or failure alerts gets a file the size of one responsibility instead of a 3,000-line closure whose locals cross a dozen regions.
Not a goal
self.call, listed below.gateway_runtime.composefacade and the binding shape of refactor(slack): compose the update path and AutoNudge from gateway owners #20443 and refactor(slack): compose boot, approvals, egress and exit from owners #20601 are reused as-is._apply_gate_verdict,_cron_failure_attribution,_charge_failure) stay ingateway.pyuntil the fourth PR.gateway_runtimeowners: three of their docstrings only name the new homes.What changed (motivation → approach → change)
_init_cronheld the whole cron run in one closure, so its regions shared locals instead of parameters and could only move together. This PR first turns each region into a method or a function whose closure inputs become explicit parameters, still ingateway.py, and then moves those methods into five owners with the binding shape of #20443 and #20601:cron_fire.py_init_cronand the_cron_callbackit registers (goal reminder, overlap-guard check, the message job's fire-time gate and first-run tab, dispatch), the per-fire capture, resolving the agent and acquiring its sessioncron_exec.pycron_turn.pyfinallyread stay plain localscron_delivery.pycron_failure.pygateway.pygoes from 7,272 to 4,035 lines; the largest new file is 909. The callback keeps its name, so stall attribution still finds a_cron_callbackframe mid-turn. The runtime-death attribution and charge (_cron_failure_attribution,_charge_failure) and_apply_gate_verdictstay in the facade beside the sub-agent death arms, because the runtime-death audit requires the ownership predicate, the shared-death streak and its success clear in one file; they move together in the fourth PR.Region bodies move verbatim apart from the dedent and these re-plumbing edits: a closure input becomes a parameter (
job,cron_execution, the capture), a call to a former closure gainsself.or the argument it closed over, the two recursive retries call theretryparameter, the single-agent failure path returns and its caller re-raises, an annotation-only import and a dead store on the sequence path are dropped, seven moved comments are reworded for the comment-history and brand gates, and_cron_quarantineis declared on the class for mypy. One facade import loses its per-line# noqa: F401, which the file-wide F401 setting already covers.Backwards compatibility
Compatible: every name
kiro_crew.slack.gatewaybound before this PR stays bound, pinned bytest_campaign_facades_base_public_names.py;_init_cronand the four failure-alert helpers keep their name, kind, signature,__module__and__qualname__, and every new member is pinned the same way by_BASE_SURFACE. Tests and the cron service still reach the callback throughCronService.create(on_job=...).Removes nothing: no public module-level function moves, 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/test_gateway_cron_turn.pyandtest/test_gateway_cron_exec.py(56 tests) characterise what the decomposition must keep, driven throughon_joband passing unchanged before and after the move: the single-agentfinallyorder and the flags each exit hands it, the deferred reset, the compaction box per fire, one charge per run, a cancellation mid-alert, the re-raised exception's identity, the ACP-death and transient retries re-entering the whole callback, the shared-death exemption and its hand-over, the_cron_callbackframe mid-stream, the message arm's order, the sequence's per-step cleanup and pre-loop deferral, and, for every command and script disposition, the claim hand-off abandoned before the overlap guard is released.test_runtime_death_is_a_process_event.pygains four self-tests of the one-unit subject rule on in-memory sources (a caller that captures the provider passes; a capture gone, a caller passingNone, and an asker nothing calls each fail; aself.call and an explicit-self call are read from the right argument; agetattror an alias that reaches the asker fails closed).-n0, one at-n 3and one in reversed order; the five owners ship in the wheel and import from it.Re-pointed guards
test_cron_failure_alert_one_spellingtest_sandbox_interpreter_enoent_retrytest_update_check_install_awarecronregistration contract reads the facade and every ownertest_slack_gateway_cron_exec_coveragetest_runtime_death_is_a_process_eventtest_chat_turn_timeout_consistency_DISPATCH_FILEScovers every gateway ownertest_turn_duration_recordedEXPECTED_SITES:cron_turn.py2, and aslack/gateway.py0 row so the facade gains no persist site unnoticedtest_transcript_derivation_seamcron_delivery.pytest_no_config_dir_in_asynctest_cron_reaper_ephemeraltest_security_postureslack/gateway.py2 -> 1,cron_exec.py1;security_posture.pylists the four redacting owners as non-egress_BASE_SURFACErows;_GUARDED_TOKEN_HOMESre-keyed for 11 tokensThe guard-subject check reads the gateway as one unit
test_the_guards_subject_is_a_provider_the_turn_actually_obtainedrequires everycaused_by_this_session(<name>)subject to be given a real value, and exempts a function parameter as filled by its caller. The cron attribution now asks about_run_provideras a parameter of the facade's_cron_failure_attribution, whilecron_turn.pyfills it, so the per-file exemption would pass even with the capture gone. The check therefore readsslack/gateway.pyand everygateway_runtimeowner as one unit: there a parameter subject is filled only when every call of its function passes a name the caller assigns a real value or itself receives as a filled parameter, and a function no call reaches fills nothing. The assertion and its message are unchanged; four self-tests pin the rule on in-memory sources, and deleting the capture or passing an unassigned name in the real tree turns it red. The fourth PR'sruntime_charge.pyis read under the same unit rule.Citations (L29)
docs/system-specs/modules/slack-gateway.mddocs/system-specs/modules/learn-cron-dashboard.md_acquire_with_model_fallback, the failure DM, the message arm's failure path, the thread claimslack/gateway.py→cron_fire.py,cron_failure.py,cron_delivery.pydocs/system-specs/modules/session.md_acquire_with_model_fallback; the ACP-death retry rowcron_fire.py;_cron_run_singleincron_turn.pydocs/system-specs/modules/governance.mdvet_job_at_fire_timeis reachedslack.gateway._cron_callback→_cron_callback(cron_fire.py) and the arms (cron_exec.py)docs/system-specs/modules/messaging.md,common/model-selection.md,turn-stats-footer.md,session-summary.mdslack/gateway.py→ the ownergateway_runtime/cron_dispatch.py,cron_verdict.py,delivery.py,slack/gateway.pycron_history.py,cron_service/execution.py,security_posture.py,mcp_gateway/daemon/cli.py,mcp_tools/spawn.pytest/test_cron_ephemeral_session.py,test_slack_cron_remove_audit.py,test_chat_turn_timeout_consistency.py,test_background_loops_compaction_reinjection.pyslack/gateway.py→cron_fire.py(_cron_capture),cron_exec.py(_deliver_script_result),cron_turn.pygateway_runtime/__init__.pyRelayed, not edited: the
slack/gateway.pycitation above_UPDATE_TIMEOUT_SECSinkiro_prerequisite.pybelongs to a file another campaign scope is splitting, so its owner re-points it (slack/gateway_runtime/update_apply.py).Manual verification
N/A — a structural move: the related suite and the characterisation tests exercise every moved region through the unchanged
on_jobentry, andtest/integration/test_boot_smoke.pyboots the gateway in-process.Move audit
move_audit.pycompares whole definitions, and the cron callback's regions were not definitions before this PR, so the audit lists_init_cronand the class as changed. The region audit (cron_region_audit.py) re-derives every region from the base and compares its tokens with the def that now holds it: 10,492 of 10,524 base tokens unchanged; every difference is one of the re-plumbing edits listed above, a reworded comment, or a pair of parentheses black drops when a dedented call fits on fewer lines.Diff alignment (L36)
git diff --numstatandgit diff --minimal --numstatagree on every changed file.Files over 2,000 lines this PR grows
All three are report-only under the line-cap guard, and their baseline rows are left as they are:
src/kiro_crew/security_posture.py, +5: the non-egress rows for four redacting owners and the reworded comment above them;test/test_slack_gateway_cron_exec_coverage.py, +15: the gate and pool readers join the facade with its owners;test/test_update_check_install_aware.py, +3: thecroncontract reads the facade and every owner..github/file-line-cap-baseline.txtlowers theslack/gateway.pyrow by hand to 4035 (that row only).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.