Skip to content

scheduler: stale unclaimed jobs stop blocking; admin cancel for unclaimed scheduled jobs - #183

Merged
teddashh merged 1 commit into
mainfrom
feat/schedule-job-cancel-stale-overlap
Nov 19, 2026
Merged

teddashh merged 1 commit into
mainfrom
feat/schedule-job-cancel-stale-overlap

Conversation

@teddashh

Copy link
Copy Markdown
Collaborator

Why

A scheduled job that stays not_started and is never claimed (for example, on a machine that went offline) made every later slot of that schedule skipped_overlap. Without it, target validation would still skip the whole run because that target has an active job. There was no sanctioned way to clear such a job without a raw DB edit.

What

(a) Stale unclaimed jobs stop blocking

  • The overlap check ignores a never-claimed (lease_token NULL) not_started job created more than one cron interval of its schedule (plus a 2-minute grace) before the slot. A job right after its own slot still counts as overlap, as before. Leased jobs always count.
  • A target that still holds such a stale job is left out of that run, and that is recorded in audit. The other targets still run. If every target is stale, the slot is skipped_unavailable.

(b) Admin cancel for an unclaimed scheduled job

  • New POST /v1/operator/schedule-jobs/{id}/cancel, for admin or an allowlisted operator-admin service token.
    • Requires {"reason"} and an Idempotency-Key.
    • Works only on a not_started job with no lease. The job becomes rejected.
    • Saves a receipt for replay and writes a schedule-job-cancel audit row.
    • Returns 404 SCHEDULE_JOB_NOT_FOUND for an unknown job and 412 PRECONDITION_FAILED for a claimed or finished job.
  • New clawctl-operator tool schedule_job_cancel.
  • No Hub UI button in this PR. A web form needs its own HTML route, MFA and CSRF handling; that can follow.

Tests

  • Store:
    • staleness cutoff follows the cron interval
    • a stale target is left out and the other target still runs
    • when all targets are stale the slot is unavailable
    • cancel success, replay and refusal of a claimed job
  • HTTP: operator-admin token cancel, missing reason or key, replay header, finished job (412), unknown job (404).
  • Operator agent: the tool's argument checks.
  • Route manifest and doc tallies updated.

…imed scheduled jobs

A scheduled job that stays not_started and was never claimed (for example on
an offline machine) blocked every later slot as overlap, and then target
validation skipped the whole run.

- Overlap ignores a never-claimed not_started job older than one cron interval
  of its schedule plus a two-minute grace. Leased jobs always count.
- A target still holding such a stale job is left out of that run (recorded in
  audit); the other targets still run. If every target is stale the slot is
  skipped_unavailable.
- New POST /v1/operator/schedule-jobs/{id}/cancel (admin or operator-admin
  service token): reason and Idempotency-Key required, cancels only an
  unclaimed not_started scheduled job (becomes rejected), receipt replay and
  schedule-job-cancel audit. CLI tool schedule_job_cancel in clawctl-operator.
- Tests for staleness, partial runs, cancel store/API/CLI; route tallies and
  docs updated.
@teddashh
teddashh merged commit 68ef582 into main Nov 19, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant