Repository navigation
Conversation
…erson Where every session shares one model server that serves one request at a time, cron runs overlapping each other or an interactive turn buy no parallelism: they pile into the same queue and every run pays the wait. Three settings, all read at every lane decision so a reload applies without a restart: - cron.max_concurrent caps how many agent cron runs execute at once (default 4; 0 uncapped). Runs past the cap wait with their run-log row open. Workflow jobs and source runners take no slot; each has its own cap. - cron.pause_when_interactive_busy holds a due fire while a person's session is mid-turn, and cron.interactive_grace_minutes (default 5) after the last one ended. Manual runs never wait. - CronJob.on_busy says what a held fire does: queue (defer and run when the lane quiets, in deferral order), skip (wait for the next fire), or protect (run regardless, never preempted). An interactive turn starting reclaims the model: agent cron runs in flight are stopped the way Stop stops a web turn (protect aside), and runs whose turn starts into the busy lane are stopped by the same hand-over at their own start event. Every outcome where the run produced nothing (deferred, skipped, yielded, cancelled) closes its row as the neutral missed status, never success or error: success would fool the interval anchor and the startup catch-up, and a pause is not a failure. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit b6257cd. Configure here.
| if session_id is not None: | ||
| self._lane_sessions.pop(session_id, None) | ||
| self._preempted.discard(session_id) | ||
| await self._lane.release() |
There was a problem hiding this comment.
Hard stop skips lane cleanup
High Severity
A hard stop cancels the cron run's task, and that cancellation stays pending until uncancel() is called. The handler then awaits log_cron_finish and _lane.release without clearing it, so those awaits are cancelled too: the log row stays open and the lane slot is never returned. A deferred run is the scan task itself, so swallowing the error in _resume_deferred also drops or strands the rest of the queue.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit b6257cd. Configure here.
| logger.info( | ||
| "Not running the deferred %s: a run of it is still going", job_id, | ||
| ) | ||
| return False |
There was a problem hiding this comment.
Deferred run overlaps scheduled fire
Medium Severity
_resume_deferred removes a job from _deferred before the run starts, and that run is not a scheduler instance. _may_start blocks a scheduled fire only for an in-flight catch-up or delivery, not for origin deferred. After the deferred run has begun, the job's next scheduled fire starts a second run beside it.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit b6257cd. Configure here.
AI review gate — Cursor Bugbot found issues
Unresolved findings (2): What to do:
Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically. |
|
Nerve PR review · 🟡 Merge after small fixes This adds a cron lane: a cap on concurrent agent cron runs, an opt-in pause while a person is mid-turn, per-job Completeness: 36 tests, docs, validate warnings; no migration. Before merge:
Worth considering:
Checked: full suite in an offline sandbox at |


Why
Where every session shares one model server that serves one request at a time (a local one, or any serialized backend), cron runs overlapping each other or an interactive turn buy no parallelism: they pile into the same queue, and every run pays the wait of the ones ahead of it. This adds the cron lane: a run cap, a pause that hands the model to the person, and a per-job policy for held fires.
What
Three settings, all read at every lane decision, so a change follows a config reload without a restart:
cron.max_concurrent(default 4,0uncapped): how many agent cron runs may execute at once. Runs past the cap wait on the lane with their run-log row open, so the wait reads as a run in progress, not a fire that went missing. Workflow jobs take no slot (the run has its ownworkflows.max_concurrent_runs), source runners hold no model turn.cron.pause_when_interactive_busy(+cron.interactive_grace_minutes, default 5): while a person's session is mid-turn — or less than the grace after the last one ended — a due fire does not start. A person's session is any session that is neithercron:norworkflow:. Manual runs never wait.CronJob.on_busy(queuedefault /skip/protect): a held fire defers and runs when the lane quiets (deferral order, one at a time, busy check re-made before each, one queued entry per job, superseded by a real fire); or waits for its next fire; or runs regardless and is never preempted.Yielding the model: an interactive turn starting reclaims the model — the agent cron runs in flight are stopped the way Stop stops a web turn (
protectaside). A run whose turn starts into the busy lane after the hand-over already ran (cron turns queue on the engine's semaphore before registering as running) is stopped by that same hand-over at its own start event.Log honesty: every outcome where the run produced nothing — deferred, skipped, yielded, cancelled — closes its row as the neutral
missedstatus, the same one a scheduler-dropped fire carries.successwould fool the interval anchor and the startup catch-up into counting the work as done;errorwould raise health notices for a pause working as configured. Cancelled runs close their own row from inside the cancellation rather than leaving it "going" forever.Config coercion follows the house pattern:
from_dictkeeps the written value (floored at 0), the service getters apply the ceilings at every decision (so a reload of a changed value applies), andnerve config validatewarns above the ceilings (64 / 240).Tests
tests/test_cron_lane.py: 36 tests — config coercion and validate warnings,on_busyround-trip, lane serialization and per-decision limit reads, busy/grace accounting, defer-then-resume, skip, protect, manual passthrough, preemption (including a stop that answers only after the run completed, a killed leg, and the start-into-a-busy-lane path), cancelled-behind-the-cap row closing, scan survival across a cancelled deferred leg, listener wiring.Targeted regression (all
test_cron*,test_config*, workflow-cron, docs-cron-paths, lockdown, cli-reload, usage-by-cron-job): 1626 passed, 3 skipped.Docs:
docs/cron.mdgains the "The cron lane" section and theon_busyjob field;docs/config.mdgains the key table and the hot-reload row.🤖 Generated with Claude Code
Note
Medium Risk
Touches core cron execution, session preemption via
stop_turn, and run-log semantics on shared model servers—high-impact scheduling path but bounded by defaults and extensive tests.Overview
Adds a cron lane so scheduled agent jobs don't monopolize a shared, serial model server. Global settings
cron.max_concurrent(default 4,0= uncapped),cron.pause_when_interactive_busy, andcron.interactive_grace_minutesare read on every lane decision and apply on config reload without restart.CronJob.on_busy(queue/skip/protect) defines what happens when a fire is due during the pause: defer until the lane is quiet, skip until the next fire, or run without preemption. Manual runs bypass the pause.CronServiceimplements a slot-limited_CronLane, tracks interactive sessions via the engine's running listener, defers jobs with a resume scan, and preempts in-flight cron runs (exceptprotect) when a person starts a turn—logging yields, skips, and slot waits asmissedso catch-up and health notices stay honest.Validation warns when values exceed ceilings (64 concurrent / 240 grace minutes). Documentation and
tests/test_cron_lane.pycover config, deferral, preemption, and shutdown behavior.Reviewed by Cursor Bugbot for commit b6257cd. Bugbot is set up for automated code reviews on this repo. Configure here.