fix(scheduler): reject zero/negative interval in every_N cooldown parsing#93
Open
shaun0927 wants to merge 1 commit intolsdefine:mainfrom
Open
fix(scheduler): reject zero/negative interval in every_N cooldown parsing#93shaun0927 wants to merge 1 commit intolsdefine:mainfrom
shaun0927 wants to merge 1 commit intolsdefine:mainfrom
Conversation
After PR lsdefine#76 wrapped _parse_cooldown in try/except, parse('every_0h') still returns timedelta(0). The cooldown check at check() then always fires the task on the next 120s scheduler cycle, in effect running a side-effectful task continuously instead of every N hours. Add a positive-interval validation inside the existing try block so the malformed case falls through to the existing 'fallback to 20h cooldown' warning path, the same way 'every_h' or 'every_xyz' do. Builds on the guard introduced by PR lsdefine#76.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After PR #76 (which fixed the
ValueError/IndexErrorcrashes frommalformed
every_*repeat values),_parse_cooldown('every_0h')stillsilently returns
timedelta(0):Inside
check(), the cooldown gate is:With
cooldown = timedelta(0),(now - last) < cooldownis False from thefirst cycle onward, so the task fires on every 120-second scheduler tick
instead of every N hours. For a side-effectful prompt (e.g. anything that
posts a message, schedules another task, or triggers a code_run with
external calls) this is a runaway loop.
Fix
Add a positive-interval guard inside the existing
tryblock so themalformed value falls through to the same warning + 20h fallback that
every_handevery_xyzalready use:if repeat.startswith('every_'): try: parts = repeat.split('_') n = int(parts[1].rstrip('hdm')) + if n <= 0: raise ValueError(f'positive interval required, got {n}') u = parts[1][-1] if u == 'h': return timedelta(hours=n) if u == 'm': return timedelta(minutes=n) if u == 'd': return timedelta(days=n) except (ValueError, IndexError): pass # fall through to warning belowThis keeps the change radius local to
_parse_cooldownand reuses PR #76'sexisting fallback path; no new control flow is added.
Verification
REPL on the patched function:
Builds on PR #76.