Add scheduled task creation, and stop a bad cron unscheduling everything
Build App / compute-version (pull_request) Successful in 4s
Build Container / build-container (pull_request) Successful in 9m35s
Build App / build-linux (pull_request) Successful in 5m35s
Build App / build-windows (pull_request) Failing after 2m26s
Build App / build-macos (pull_request) Successful in 2m49s
Build App / create-tag (pull_request) Skipped
Build App / sync-to-github (pull_request) Skipped
Build App / compute-version (pull_request) Successful in 4s
Build Container / build-container (pull_request) Successful in 9m35s
Build App / build-linux (pull_request) Successful in 5m35s
Build App / build-windows (pull_request) Failing after 2m26s
Build App / build-macos (pull_request) Successful in 2m49s
Build App / create-tag (pull_request) Skipped
Build App / sync-to-github (pull_request) Skipped
Completes the Automation tab: it could list, toggle, run, log and remove tasks but not create them, so task creation still meant dropping to the CLI. Adds add_scheduled_task and update_scheduled_task, plus a task editor with cron presets and a plain-English reading of the expression. Every field is free user text, so all of it goes to the scheduler as a bare argv vector through bollard — no shell, no quoting. Validation is shape-only rather than metacharacter scrubbing: length caps, no control characters in single-line fields, no leading-dash name, absolute working_dir. Verified by round-tripping a prompt containing `; rm -rf /`, `$(id)`, backticks and newlines: it landed byte-for-byte in the task JSON with nothing executed. The scheduler CLI has no `edit`, so update is add-then-remove with the add first — a rejected edit leaves the original intact. The new id is surfaced in the editor rather than hidden. Root-cause fix, and the more serious half of this commit: triple-c-scheduler never validated --schedule, and rebuild_crontab regenerates the entire crontab and pipes it to `crontab`, which rejects the whole file if any line is malformed — with the error thrown away by `2>/dev/null || true`. A single bad schedule therefore silently unscheduled every other task in the container while reporting success. Reproduced directly. It matters because the global CLAUDE.md tells Claude to drive this CLI, so Claude could trigger it unprompted. `add` now validates the expression and exits non-zero, and rebuild_crontab reports a rejected crontab instead of swallowing it, keeping the offending file for inspection. Verified against the real CLI in this container: a bad schedule is refused without disturbing an existing task's crontab entry, and `0 9 * * 1-5`, `*/30 * * * *`, `0,30 8-17 * * *` and `0 0 1 1 *` are all still accepted. The Rust layer validates independently, agreeing with vixie cron on 23 probed expressions including `1/2` and `*/0` being invalid. 121 frontend tests, 44 Rust tests, both builds clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,28 @@ generate_id() {
|
||||
head -c 4 /dev/urandom | od -An -tx1 | tr -d ' \n'
|
||||
}
|
||||
|
||||
# Reject a malformed cron expression at the point of entry.
|
||||
#
|
||||
# Without this an invalid schedule is written to a task file, and the next
|
||||
# rebuild hands crontab a file it refuses wholesale — taking every other task
|
||||
# down with it. Deliberately shape-only: five fields, each built from `*`,
|
||||
# numbers, ranges, lists and steps. Names (JAN, MON) and `@daily` are not
|
||||
# accepted here.
|
||||
validate_cron() {
|
||||
local expr="$1"
|
||||
# Exactly five whitespace-separated fields.
|
||||
read -ra _cron_fields <<< "$expr"
|
||||
[ "${#_cron_fields[@]}" -eq 5 ] || return 1
|
||||
local field
|
||||
for field in "${_cron_fields[@]}"; do
|
||||
# A field is one or more comma-separated terms; a term is `*`, a number,
|
||||
# or a range, each optionally followed by a `/step`. Vixie only allows a
|
||||
# step after `*` or a range, which this mirrors.
|
||||
[[ "$field" =~ ^(\*(/[0-9]+)?|[0-9]+(-[0-9]+(/[0-9]+)?)?)(,(\*(/[0-9]+)?|[0-9]+(-[0-9]+(/[0-9]+)?)?))*$ ]] || return 1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
rebuild_crontab() {
|
||||
local tmp
|
||||
tmp=$(mktemp)
|
||||
@@ -37,7 +59,19 @@ rebuild_crontab() {
|
||||
echo "$schedule /usr/local/bin/triple-c-task-runner $id" >> "$tmp"
|
||||
done
|
||||
|
||||
crontab "$tmp" 2>/dev/null || true
|
||||
# `crontab` validates the WHOLE file and rejects all of it if any single
|
||||
# line is malformed. Swallowing that error silently unschedules every task
|
||||
# in the container, so report it loudly and leave the previous crontab
|
||||
# (which `crontab` keeps on rejection) in place.
|
||||
local crontab_err
|
||||
if ! crontab_err=$(crontab "$tmp" 2>&1); then
|
||||
echo "ERROR: crontab rejected the generated schedule; NO tasks are scheduled." >&2
|
||||
echo " ${crontab_err}" >&2
|
||||
echo " Offending file kept at ${tmp} for inspection." >&2
|
||||
echo " Fix or remove the task with the bad schedule, then re-run any" >&2
|
||||
echo " scheduler command to rebuild." >&2
|
||||
return 1
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
}
|
||||
|
||||
@@ -139,6 +173,12 @@ cmd_add() {
|
||||
else
|
||||
task_type="recurring"
|
||||
cron_expr="$schedule"
|
||||
if ! validate_cron "$cron_expr"; then
|
||||
echo "Error: invalid cron expression: '$cron_expr'" >&2
|
||||
echo " Expected five fields: minute hour day-of-month month day-of-week" >&2
|
||||
echo " e.g. '*/30 * * * *' (every 30 min), '0 9 * * 1-5' (9am weekdays)" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local created_at
|
||||
|
||||
Reference in New Issue
Block a user