Repository navigation
refactor(cron): bind CronService members from cron_service/service - #20862
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] ef2184b Description read[DESCRIPTION-READ] dab2ded29af615a598aa20b65e8e68e2d9617cd52c19570ff87da74319a86287 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 every future What this change shipsInventory (8 items) — 8 justifiedIntent: get the cron service under the 2,000-line file cap without changing how any job is scheduled, run, cancelled or stored. ADDITION (structural refactor).
[FIRST-PRINCIPLES-REVIEWED] ef2184b Description read[DESCRIPTION-READ] 740209c9e7506730849bc44a749f0f9780d47696a61e66b234b8504d58499900 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: |
88b7f8c to
8d7c577
Compare
Move the behaviour of the 5,061-line CronService class out of the 5,594-line cron.py into twelve owner modules under kiro_crew/cron_service/service/, one responsibility each: the lifecycle, the reaper and cancel, ending a run's processes, job writes, removal, ownership, the runs in flight, the wake timer, a run's execution, the result merge, the loop-stall breaker, and the service's copy of the store. Each member body moves as a module-level function whose first parameter is self, and the class binds it by name, so every member stays the same function object on the class, an instance and its owner, and the service's state stays on the instance. cron.py keeps every module-level statement, __init__, the _claims view, the loop-safety guard, the static bindings and the seven store-lock cores whose log lines carry code-scanning alerts keyed by its path, and it stays a plain module: a moved member reads every name tests patch on kiro_crew.cron, and every name cron.py defines, through the facade on each call, as the existing cron_service owners do. test/test_cron_service_bindings.py pins the member inventory, the bindings and that patch reach. Source-reading tests whose construct moved now read its owner; the spec, the docs and two baseline row sets follow. Part of #20192
8d7c577 to
ef2184b
Compare
|
rebutted
|
buluoray
left a comment
There was a problem hiding this comment.
Reviewed at ef2184badaf561cba38b55ab5aad215826098654 (merge-base 7f7c38b8d3), and on a local merge of this head into current main (818b437153). The merge is clean, including the overlap with #20761, which touched test/test_slack_gateway_cron_exec_coverage.py, test/test_sandbox_interpreter_enoent_retry.py, cron_dispatch.py, cron_history.py and the cron spec.
What I verified independently
No member was dropped or changed. I parsed CronService at the merge-base: 132 class-body entries, counting the _claims getter and setter separately. I resolved each one against the live class at head through CronService.__dict__ and compared ASTs. Before comparing I stripped docstrings, the self: CronService annotation and the function-local from kiro_crew import cron as seams import, and rewrote seams.X back to X.
- 126 functions are identical after that normalisation; 0 changed; 0 missing.
- The 6 non-function class attributes are all still present.
- Kind (static/class/property/plain) and coroutine-ness match for every member.
- No class attribute was added.
dir(kiro_crew.cron)loses onlyCollection,Coroutine,ExitStack,Iteratorandcontextmanager. Nothing insrc/,test/orapps/reads any of them throughkiro_crew.cron, on the merged tree.copyis still bound, so the PR body's list of six is one too many, which is harmless.- Every module-level def or class in the old
cron.pyis still defined there.
Name resolution in the moved code. I walked the bytecode of every moved function, nested code objects included:
- No
LOAD_GLOBALis unresolved in its owner's globals, so there is no latentNameError. - All 42 distinct
seams.<attr>reads resolve onkiro_crew.cron. - The names an owner reads bare and
kiro_crew.cronalso binds are all the same object in both places (60 names). The ones tests patch there,cron_script,timeandrandom, are patched as module attributes (kiro_crew.cron.cron_script.kill_running_process,kiro_crew.cron.time.time,kiro_crew.cron.random.uniform), so those patches still reach the owners. - Importing an owner on its own (
wake_timer,run_execution,store_sync,job_removal) does not importkiro_crew.cron, which confirms the cycle is avoided at import time. - Owners add no module-level state; each has only
logger = logging.getLogger("kiro_crew.cron"), so nothing is duplicated.
Collected test ids. On the 11 pre-existing test files this PR edits, base collects 863 ids and head collects 888. The difference is 25 added ids: the 13 + 12 per-owner parametrisations in test/metrics/test_business_counters.py and test/test_process_identity_structural.py. One id was renamed, CRON_FIRES-cron.py → CRON_FIRES-cron_service/service/run_execution.py. No id was removed. The merged tree collects the same 888.
Patch reach, mutation-checked. I made wake_timer.py:233 read admission_check bare, imported from kiro_crew.resource_status, instead of seams.admission_check. Two tests went red:
test/test_cron_service_bindings.py::test_an_owner_reads_every_facade_name_through_the_facade[...wake_timer]- 8 behavioural tests in
test/test_admission_gate.py, includingTestCronExprPassthrough::test_manual_run_completed_during_await_is_not_double_fired
I restored the file and confirmed git status was clean. So the new guard and the existing behaviour tests each catch a patch that no longer reaches the code, independently of each other.
Cron security paths.
_vet_script_contentslives insrc/kiro_crew/mcp_cron.py:1465, which this PR does not touch.- The secret-grant kill on removal (
job_removal.py:295-320,bump_grant_epoch/grant_epoch_ids) is in the identical set above. - So are the
expect_secret_env*compare-and-set checks inupdate_job(nowjob_writes.py) and the timeout and deadline paths (run_execution.py_execute_with_timeout,run_teardown.py_reaper_loop). - The six alert-keyed store-lock cores (
_update_job_locked,_enable_job_locked,_remove_job_locked,_remove_job_if_locked,_delete_history_of,_audit_requested_removal) plusaudit_one_shot_removaland_guard_off_event_loopstay in the class incron.py, as described.
Spec. docs/system-specs/modules/learn-cron-dashboard.md now carries the owner table (around lines 325-344). I found no spec or RFC line that still places a moved member's body in cron.py. _sleep_out_jitter (spec line 630) is still defined in cron.py:415. The cron.py:114 / :193 references in rfc-perpetual-agent.md:999-1001 are explicitly pinned to commit 30f5d6983.
CI. On this head the latest run of each check is 88 success and 11 skipped, with no failures. There are no prior human reviews; the bot lanes report no blocking findings.
Blocking
None.
Follow-ups (non-blocking)
test/test_slack_gateway_cron_exec_coverage.pygrows from 2,334 to 2,352 lines here, and is 2,367 after merging withmain. Its baseline row is 2,303.scripts/check_file_line_cap.pyonly reports this ("a baselined file must not grow"); it does not fail the check. The file was already over its row onmain(2,349), but this PR adds to it.- PR body:
copyis listed as dropped fromkiro_crew.cron, but it is still bound there. docs/request-for-change/rfc-tips-kit.md:163citescron.py::CronService.create(...). That still resolves as a class attribute, but the body is now incron_service/service/service_lifecycle.py.
What I ran / did not run
Ran on the merged tree:
- The 11 edited test files plus
test_cron_service_bindings.py,test_cron_refactor_contract.py,test_campaign_facades_base_public_names.py,test_cron_reaper_ephemeral.py,test_runtime_death_is_a_process_event.py,test_gateway_cron_exec.py,test_gateway_cron_turn.pyandtest_slack_gateway_composition_contract.py: 1,615 passed. test/test_cron*.pyplustest/test_mcp_cron*.py: 3,723 passed, 1 skipped.
Not run: the full suite, mypy and semgrep. I relied on CI for those. I did not re-run the PR's own replumb audit script; the AST comparison above is my own, done independently.
Problem / Motivation
Goal: Keep the cron service's code under the repository's 2,000-line file cap without changing how any cron job is scheduled, run, cancelled or stored.
src/kiro_crew/cron.pyis 5,594 lines, and theCronServiceclass alone is 5,061. It is one of the files.github/file-line-cap-baseline.txtstill lists over the cap, and it changes about 16 times a week, so every cron fix lands in a file nobody can hold in their head and that the next feature PR pushes further past the cap.Why it matters
Every cron change today edits one 5,600-line file: reviews are slow, conflicts between unrelated cron fixes are common, and the line-cap rule (no hand-written file over 2,000 lines) cannot be met while the class is one block. Splitting it by responsibility gives each part of the service — the reaper and cancel, job writes, removal, the timer, a run, the result merge, the store — a file of its own to change.
Not a goal
crons.jsonbytes and the schedule math are pinned unchanged.cron.py's path.What changed (motivation → approach → change)
cron.pycould not shrink by moving whole definitions, because almost all of it is one class. The class's state is shared by every member, so it stays on the instance; the members move instead.Each
CronServicemember is now a module-level function insrc/kiro_crew/cron_service/service/whose first parameter isself(clsforcreate; the three static members take neither), and the class binds it by name (cancel = _run_teardown.cancel). A member is therefore the same function object on the class, on an instance and in its owner, and a patch of it on the class or an instance reaches every caller. Twelve owners each hold one responsibility:service_lifecycle.pycreate,start,stoprun_teardown.pycancelrun_kill.pyjob_writes.pyjob_removal.pyjob_ownership.pyrun_registry.pywake_timer.pyrun_execution.pyrun_merge.pystall_breaker.pystore_sync.pycron.py(now 1,162 lines) keeps every module-level statement, the class's state (__init__), the_claimsview, the loop-safety guard, three existing static bindings, and the seven store-lock cores above. It stays a plain module, astest_cron_refactor_contract.pyrequires, so a moved member reads every name tests patch onkiro_crew.cron, and every namecron.pydefines, through the facade on each call (from kiro_crew import cron as seams, thenseams.<name>) — the rule the existingcron_service/owners already follow. The owners sit undercron_service/because the loop-stall classifier counts a frame there as the cron surface. They sit in a subpackage because the contract pins the seams the flatcron_service/*.pyowners read.Backwards compatibility
Compatible: every name
kiro_crew.cronbound before still resolves there as the same object (test_campaign_facades_base_public_names.py,test_cron_refactor_contract.py);CronServicekeeps all 131 members with the same kind, coroutine-ness and signature, each the same function object on the class and its owner (test_cron_service_bindings.py); a patch onkiro_crew.cronreaches the moved code (corpus-derived check in the same file).Removes nothing: no column-0 public function, key or record leaves a product file. Every moved member is still an attribute of
CronService, and the only namescron.pystops binding are six standard-library and typing imports nothing reads (copy,ExitStack,contextmanager,Collection,Coroutine,Iterator), which are not part of its surface.Tests
test/test_cron_service_bindings.pypins the binding contract (L33): the frozen inventory of all 131 members (kind, coroutine-ness, signature digest, owner), each class attribute being its owner's function, no unboundselffunction left in an owner, no zero-argumentsuper()/__class__/ name-mangled attribute in a bound function, no owner importingkiro_crew.cronat import time (call time only, asseams, as the function's first statement), noasync defreaching a blocking call throughseams(a spelling the sync-io gate cannot see), every name the test trees patch onkiro_crew.cron(literal-loop patches included) read by the owners through the facade (from bytecode), the owners' field docstrings, thekiro_crew.cronlogger, and the cron stall surface for each owner. Each scan has a self-test that fails on a planted violation.-n0and one at-n 3, 262 passed each; it reads no clock, sleeps nowhere and binds no port.Manual verification
N/A — this is a structural move with no user-visible surface; the behaviour is covered by the cron test suite (234 test files run locally, below) and the move/replumb audits.
Move audit
move_audit.py:src/kiro_crew/cron.py: 5594 -> 1162 lines; moved 13.6% (python-ast). The audit compares exact syntax trees, so a member counts as changed once it gains itsself: CronServiceannotation or black re-indents its docstring.replumb_audit.py, every BASE member against its new home once the allowed transforms are undone): 0 CHANGED. Of 132 units, 42 are identical, 68 differ only in docstring indentation (black re-indented them), 20 are replumbed (51name -> seams.namereads, 39 distinct member/name pairs, in 21 members, plus one insertedseamsimport each) and 2 are reworded (the comment-history gate's "no longer":_drain_pending_removals_lockeddocstring,_run_job_isolatedcomment, both now present tense).--minimaladd the same lines in every changed file;cron.py+163/−4,595 both.REAPER_MODULESaccounts for about 65 KB).Source pins
cron.py(a universal or negative half) now readscron.pyjoined with everycron_service/serviceowner; a positive pin points at the owner that holds its construct.test_process_identity_structural.pyREAPER_MODULES:cron.py+ everycron_service/serviceownertest/metrics/test_business_counters.pyCRON_FIRESowner →run_execution.py; bounded-attrs scan + every owner (_cron_service_modules())test_session.pyends_conversation=Truerowcron.py→cron_service/service/run_kill.pytest_sandbox_interpreter_enoent_retry.py_execute's reader:cron.py+run_execution.py;cancel's reader (_cron_source):cron.py+ every ownertest_cron_remove_rows_structural.pyself._jobswriter scan:cron.py+ every ownertest_spawn_admission_verdict_census.pywake_timer.pytest_remove_slot_for_history_key.pycron.py+ every ownertest_slack_gateway_cron_exec_coverage.pycron.py+ every owner, counting aseams.<name>()callee as<name>Each was proven to reach its construct: 21 mutations, each red with the construct broken in its new home (or a violation planted in an owner outside the construct's home) and green once restored.
CI path references
None: no workflow path filter or explicit file list names
cron.py.Notes for reviewers
py/clear-text-logging-sensitive-dataalerts keyed bycron.py's path (fix: bind Ctrl+G to the agent monitor so the crew hint works #1065, feat(discord): ingest inbound attachments #1053, Hoist the four function-localkiro_crew.agentimports to module scope (no cycle exists) #1050 open; fix(sweep): verify process identity before the orphan sweep kills a PID #767, feat(dashboard): surface a session's GitHub/GitLab issues in the sidebar and side panel #768, fix(security): scope two self-protection deny rules to command structure #905 dismissed as false positives). They stay in the class, with_remove_job_if_locked, which shares_remove_job_locked's docstring and keeps the diff aligned when they stay together; moving them would raise them again as new alerts. Precedent: B10 keptplatform_compat's alerted helpers in place.logging.getLogger("kiro_crew.cron"), the same object the facade'sloggeris, so caplog-by-name tests and log filters see no change.cron_history.py,slack/gateway_runtime/cron_dispatch.py,test_cron_first_run_tab.py(4),test_cron_gateway_integration_run_lifecycle.py(2),test_slack_cron_remove_audit.py(1); docs: learn-cron-dashboard (module map, service-members table, the class paragraph and where new cron work goes), session.md, metrics.md, runtime-ownership.md, resource-protection.md, rfc-perpetual-agent.md (line cites → symbols), rfc-session-address-model.md, skills/kirocrew-app-dev/SKILL.md.cron.pyrow leaves.github/file-line-cap-baseline.txt; sevenrfc-perpetual-agent.mdline-ref rows leave.github/docs-lint-baseline.txt.local-gate.py --dry-runselects 1,927 backend + 463 frontend test files, over the host's cap, so this ran instead: the 237 test targets that reachkiro_crew.cronor scan the tree, at-n 3: 15,326 passed, 49 skipped, 5 xfailed, 0 failed. The new guard passed 5 times at-n0and once at-n 3(262 tests). Coldmypy src/kiro_crewis clean (2,443 files); semgrep (the CI configs,--baseline-commit) reports 0 new findings; an installed wheel built from the commit imports every new module.Related Issues
Part of #20192
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)