{"record":{"id":"7da3643ab4ea7a97","repo":"HKUDS/Vibe-Trading","slug":"cron-field-part-r-is-out-of-range-expected-low","errorCode":null,"errorMessage":"cron field {part!r} is out of range; expected {low}-{high}","messagePattern":"cron field (.+?) is out of range; expected (.+?)-(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/scheduled_research/models.py","lineNumber":52,"sourceCode":"_CRON_STEP_RE = re.compile(r\"^\\*/[1-9][0-9]*$\")\n_CRON_ATOM_RE = re.compile(r\"^([0-9]+)(?:-([0-9]+))?$\")\n_CRON_PARTS = 5\n# Inclusive (low, high) bounds per cron field: minute hour day-of-month month\n# day-of-week. Every number in a field — a bare value, a ``*/n`` step, or\n# either end of a range — is validated against these bounds so out-of-range\n# values (e.g. minute ``99``) are rejected. Day-of-week uses the cron\n# convention Sunday == 0; ``7`` is not accepted as a Sunday alias.\nCRON_BOUNDS = ((0, 59), (0, 23), (1, 31), (1, 12), (0, 6))\n\n\ndef _validate_cron_field(part: str, low: int, high: int) -> None:\n    \"\"\"Raise ``ValueError`` when one cron field is malformed or out of range.\"\"\"\n    if part == \"*\":\n        return\n    if _CRON_STEP_RE.fullmatch(part):\n        value = int(part[2:])\n        if not low <= value <= high:\n            raise ValueError(f\"cron field {part!r} is out of range; expected {low}-{high}\")\n        return\n    for atom in part.split(\",\"):\n        match = _CRON_ATOM_RE.fullmatch(atom)\n        if match is None:\n            raise ValueError(\n                f\"cron field {part!r} is not valid; each field must be *, */n, \"\n                f\"or a comma-separated list of numbers and low-high ranges\"\n            )\n        start = int(match.group(1))\n        end = int(match.group(2)) if match.group(2) is not None else start\n        if start > end:\n            raise ValueError(f\"cron range {atom!r} is reversed; expected low-high\")\n        if start < low or end > high:\n            raise ValueError(f\"cron field {atom!r} is out of range; expected {low}-{high}\")\n\n\ndef parse_cron_field(part: str, low: int, high: int) -> Optional[Set[int]]:\n    \"\"\"Expand one validated cron field into its matching values.","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/scheduled_research/models.py#L34-L70","documentation":"_validate_cron_field validates one field of a 5-field cron expression against its allowed numeric range. For step syntax (*/n), the step value n itself must fall within the field's range; a step like */61 for minutes is rejected because it is out of range for the field.","triggerScenarios":"validate_schedule('*/61 * * * *') (minute step 61 > 59), '0 */25 * * *' (hour step 25 > 23), or a programmatically generated step value exceeding the field's maximum.","commonSituations":"Building schedules from user input or templates where a computed interval (e.g. 'every 90 minutes' -> */90) ignores cron's per-field bounds; copying Vixie-cron syntax that this simplified parser treats differently.","solutions":["Keep step values within the field's range: minutes 0-59, hours 0-23, day-of-month 1-31, month 1-12, day-of-week 0-6.","For intervals exceeding the field (e.g. every 90 minutes), use the millisecond-interval schedule form or a range list ('0,30 0,1,2... * * *' style).","Validate schedule strings with validate_schedule before persisting jobs."],"exampleFix":"# before\nvalidate_schedule('*/90 * * * *')\n# after\nvalidate_schedule('9000000')  # every 90 minutes as ms interval","handlingStrategy":"validation","validationCode":"from scheduled_research.models import validate_schedule\nvalidate_schedule(f'{minute_step_in_0_59} * * * *') if 0 < step <= 59 else validate_schedule(str(step * 60_000))","typeGuard":null,"tryCatchPattern":"try:\n    validate_schedule(schedule)\nexcept ValueError as e:\n    return bad_request(f'invalid schedule: {e}')","preventionTips":["Keep step values within field bounds; use ms-intervals for large steps.","Validate at ingestion, not at execution time."],"tags":["python","cron","validation","scheduler"],"backgroundTag":"cron-expression-invalid","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}