Repository navigation
refactor: split cron.py into cron_service owners behind its facade - #14615
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify none of the ~dozen open cron PRs patch the six moved private claim-fence names — the writer sweep only covered origin/main @ f54747d. [DESIGN-REVIEWED] 593fdfe Description read[DESCRIPTION-READ] cc219c0227b38af105520266896300c49077e37041739fec1ba7dcc0e6a29912 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 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsFINDING -- src/kiro_crew/cron_service/identity.py:105 -- Function-local False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the eight-seam list is exhaustive: a What this change shipsInventory (8 items) — 8 justifiedIntent: split the 7,377-line
[FIRST-PRINCIPLES-REVIEWED] 593fdfe Description read[DESCRIPTION-READ] 640bf549cb374956d915323a2839033c80240952ffc5d725b9c44e089b9d61f5 That sha256 names the PR description this verdict read. Recompute it with |
|
CodeQL:
Neither line is inside a changed hunk. The check body itself says alerts not introduced by the PR can be reported when "the code changes were too large", which fits a diff this size. The path CodeQL reports (python analysis Question for a maintainer: dismiss #883 and #905 as false positives (they are open on |
Opus 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: |
b0f11ab to
34d5ac5
Compare
|
The 7,377-line cron.py held the job record, the schedule evaluator, the crons.json format and lock, field validation, run claims, run deadline terms, the serviceless store readers and cron folders beside the service itself. Each now has one owner module under cron_service/, moved verbatim, and CronService composes them: it keeps the live state, the run lifecycle, every store transaction, the loop-stall breaker and the reaper and cancel() teardown. cron.py stays the import and patch surface. It is a plain module that binds every function, class and constant it defined as the owner's own object, and the eight names tests patch there that moved code reads are read by the owners through kiro_crew.cron on each call, so a patch still reaches them. The claim fences move onto RunClaims; CronService._claims reads through it. The reaper kill path, the two run-deadline sums, the session-key parser and the doctor's two store readers stay in cron.py, where repository guards scan or pin them. The loop-stall classifier counts a frame in cron_service/ as the cron surface, as it counts one in cron.py, so a stall in moved code keeps its attribution. The crons.json bytes, schedule math and every existing test are unchanged; owned tests that reached a claim fence directly now use RunClaims. The dashboard spec records the owner map, and the code-style and injected-messages rows that located moved code in cron.py now name its owner.
34d5ac5 to
593fdfe
Compare
|
Rebased: main moved in What the rebase carries. The only upstream change inside moved code was #14510's teardown lease/ownership gate in One placement change the rebase required. Main's new Two doc rows that located moved code in
Proof, per file. For every file, the change from the previous head
An AST comparison against main's Local gates on this head (Python 3.12, 3 workers):
Every upstream test passes unmodified. |
|
|
Reviewed at [code-reviewer] 🟢 [Tests]: one schedule golden depends on the croniter version, not on this refactor Verified clean, for the record
|
buluoray
left a comment
There was a problem hiding this comment.
LGTM. I checked this at head 593fdfe7556c. The full evidence is in my review comment above.
The cron_service owners import the kiro_crew.cron facade lazily for every name a test patches (execution.py:143, fields.py:151, folders.py:32, model.py:300), so no patch becomes a silent no-op. An AST comparison of all 79 old definitions found 63 identical and 16 changed only by that indirection. Jitter, skip_dates, timezone, one-shot deletion, the store's locking and the next-run/missed-run logic are text-identical to main. Mutations confirm the tests cover this: an owner reading a patched name directly turned 5 tests red, and removing the claim-fence check turned 3 red. One 🟢 note, not blocking: one schedule golden depends on the installed croniter version.
Problem / Motivation
Goal: Give each responsibility of the cron scheduler its own module, so changing one cron rule no longer means working inside a 7,377-line file, while every cron behavior, stored byte and import stays exactly as it is.
src/kiro_crew/cron.pyheld the whole cron subsystem in one file: the job record, the schedule and timezone math, thecrons.jsonformat and lock, field validation, run claims, run deadlines, the store readerskirocrew doctorand the dashboard use, cron folders, and the 5,126-lineCronServiceitself. A change to any one of these meant loading, reviewing and conflicting on all of them.Why it matters
Cron is one of the busiest files in the repository: more than a dozen open pull requests touch it, and each one has to be read against every unrelated rule the file carries. A contributor or an agent looking for "where does next-run math live" or "what may a
crons.jsonrecord hold" has to search the whole file, and nothing marks which code owns which rule. Giving each rule one home makes those changes smaller, easier to review, and less likely to collide.Not a goal
crons.jsonformat, error texts, log channel, or any import path callers use today.cancel()teardown, the run lifecycle or the store transactions out ofCronService; repository guards scancron.pyfor them, and the kill mechanics already live inprocess_identity.cron_script.py,cron_history.py,cron_inflight.pyorcron_trigger.py, which are already single-owner modules and are left untouched.What changed (motivation → approach → change)
Each cron responsibility now lives in one small module, so a change to one scheduling rule touches one file instead of the 7,377-line
cron.py, and nothing the scheduler does changes.src/kiro_crew/cron_service/schedule.pyparse_time_stringmodel.pyCronSchedule,CronJoband its auto-pause bookkeepingidentity.pyclaims.pyRunClaims: storing, fencing, taking and releasing a run claim, plus run generationsexecution.pystore.pycrons.jsoncodec,cron_store_lock, the store error types and record predicatesfields.pyreaders.pyfolders.pycron.pystill definesCronService, which composes these owners and keeps the live state, the run lifecycle, every store transaction, the loop-stall breaker and the reaper andcancel()teardown. The moved code is copied as is: 142 of the 160 definitions are unchanged. The other 18 are 17 service methods that now call an owner, plusreferenced_skill_names, which takes a skill key's last segment withrpartition("/")so the portability scan does not read that separator as a path.cron.pystays the import and patch surface. It is a plain module that binds every function, class and constant it used to define, as the owner's own object. Eight names that tests patch onkiro_crew.cronare read by moved code, so the owners read those eight throughkiro_crew.cronon each call, and a patch there still reaches them. The claim fences move fromCronServiceontoRunClaims, whichCronService._runsholds;_claims,_reaped_jobsand_cancelled_jobsstill read through it. Four things stay incron.pybecause read-only guards scan or pin that file: the reaper andcancel()kill path, the two run-deadline sums, the one session-key parser, and the doctor's two store readers. The loop-stall classifier install_attribution.pycounts a frame incron_service/as the cron surface, as it counts one incron.py, so a stall inside moved code keeps its attribution. The dashboard spec's Cron section records the new owner map.Backwards compatibility
Compatible: every function, class and constant
kiro_crew.crondefined still resolves there as the same object, patches onkiro_crew.cronstill reach the moved code, and the savedcrons.jsonbytes are pinned against the pre-split module. The only names that moved are five privateCronServiceclaim-fence methods (_holds_claim,_release_claim,_take_claim,_finish_taken_claim,_next_run_generation) and_run_generations, nowRunClaimsmembers; a writer sweep on origin/main @ f54747d finds no caller outside the cron tests this change updates.Tests
test/test_cron_refactor_contract.py(new) pins the facade: every name the module defined still resolves as the owner's object,CronServicekeeps every member callers reach, each of the eight seams reaches its reader and undoes cleanly (nestedmonkeypatch, andmock.patchwith and withoutcreate=True), no owner imports the facade at import time or reads a seam bare, the savedcrons.jsoncontent for the shipped fixtures (normalized to LF, with a case that forces the CRLF a Windows save writes) and a record carrying every field, and 32 schedule-math goldens across both 2026 DST changes.test/test_cron_refactor_readers.py(new) characterizes the store readers and run-identity helpers.cron_service/(POSIX and Windows spellings) still classifies as the cron surface.RunClaims; their assertions are unchanged.Local evidence on Python 3.12, workers capped at three: the owned cron manifest, with main's
test_cron_apps_secret_mask.py, passes 2,233 with 3 skipped, the 76 new cases included; the read-only dashboard, MCP, doctor and guard oracles pass 6,632 with 11 skipped, unmodified; the tests main changed since this branch first opened pass 3,871 with 8 skipped, unmodified; 194 repository-wide scanner suites pass 15,179; mypy, docs-lint, Semgrep (CI's rule set, on this diff) and the prepare-pr script gates pass.scripts/local-gate.py --dry-runselects 2,519 backend and 1,444 frontend related files, over the shared-host ceiling, so those targeted sets ran instead; this change touches nothing underwebsite/.Shared files
Three lines outside this scope's own files, each edited under an explicit, entry-scoped grant from the campaign coordinator; nothing else in those files changed:
src/kiro_crew/stall_attribution.py:49-- the_SURFACE_RULES"cron" entry gains the/kiro_crew/cron_service/path fragment;test/test_stall_attribution.pypasses unmodified.docs/system-specs/common/code-style.md:26-- the "Cron limits" row names the owners that now define those constants (cron_service/store.py,fields.py,model.py,schedule.py; the reaper intervals stay incron.py).docs/system-specs/common/injected-messages.md:516-- the[Previous run result ...]envelope row names its emitter,build_cron_session_contextincron_service/identity.py.Manual verification
Built the wheel and installed it into a fresh virtual environment: every
kiro_crew.cron_servicemodule imports from site-packages, an owner imports and runs beforekiro_crew.cronis loaded,CronServiceround-trips a job through add, reload, update and remove,CronService.createworks on a running loop, and the installedkirocrew cron add/cron listwrite and read a version-2 store.Related Issues
no linked issue: a structural refactor of the cron subsystem with no behavior change.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)