Repository navigation
sync: keep crontab output on API failure, fix dry-run hint - #93
Conversation
PutMonitors called fatal, and os.Exit skipped the deferred crontab print. `cronitor sync --auto file | crontab -` then installed an empty crontab. Return that failure like a shim or save failure: print the original crontab and exit 1. Verbose logs for that run go to stderr so they are not part of the pipe. The dry-run reminder no longer appends --auto --silent. Completing the run is the same command without --dry-run. Co-authored-by: August Flanagan <aflanagan@users.noreply.github.com>
|
Opus 5.5 Medium review @ d45ac35: APPROVE The fix is correct and narrow. I found no regressions and no new env vars, flags, or config ( What I verified:
Findings
|
A missing, unreadable, or unwritable file passed to sync used to print nothing and exit 0, so a pipe could install an empty crontab. Fail those runs, and print the original crontab when it is readable. Also print that crontab before a missing API key or bad --format in --auto single-file mode, and keep API keys out of the dry-run reminder. Co-authored-by: August Flanagan <aflanagan@users.noreply.github.com>
|
Opus 5.5 Medium review @ ebee7b9: REQUEST CHANGES Reviewed The code is right. The one blocker is in the docs: the new Findings[blocking] README.md:110, docs/releases/33.15.md:11, cmd/discover.go:256-257 (help): So "Use The sentence "On any failure, sync exits 1 and prints the original crontab when it can read one" also overclaims. A cobra flag-parse error ( [non-blocking] cmd/discover.go:156 / :409: the dry-run hint still prints [non-blocking] cmd/discover.go:156: harmless over-redaction edge cases. [non-blocking] cmd/sync_rerun_test.go: the new helpers have no committed tests. [non-blocking] cmd/discover.go:973-982: Checked, no issue
|
pipefail does not stop crontab - from installing empty input. Point the README, release note, and sync help at a capture-first command, and redact ping keys in the dry-run reminder. Co-authored-by: August Flanagan <aflanagan@users.noreply.github.com>
|
Opus 5.5 Medium review @ d9d2532: REQUEST CHANGES Every finding from the earlier review at ebee7b9 is fixed. The verdict is REQUEST CHANGES only because the Linux CI job fails deterministically because of a change in this PR. Previous findings: all fixed
Findings
What I ran
|
discover --auto prints the crontab on stdout, so --verbose request logs go to stderr. The notification-list bats checks were still reading stdout. Also warn that the capture-first snippet must not use --silent, because --auto --silent prints no crontab. Co-authored-by: August Flanagan <aflanagan@users.noreply.github.com>
|
Opus 5.5 Medium review @ 04571a7: APPROVE Re-review of 04571a7 against master. The previous blocker is fixed. I found nothing blocking. One verification item is only partly met: see the first finding. Checks run
Findings
Rest of the PR diff vs master
|
|
Handled the Opus @ 04571a7 non-blocking notes in 9a27d87:
Skipped 2 ( |
|
Reverted the needle change in cab37fa. CI showed that |
Summary
cronitor sync --auto file | crontab -installed an empty crontab whenPutMonitorsfailed.fatalcallsos.Exit, which skips the deferred print infinishSync. The API failure now follows the same path as a shell-wrapper or save failure: stderr gets the error, stdout gets the original crontab (not the planned rewrite), the file on disk is left unchanged, and the process exits 1.--verboselogs for that single-file--autorun, including the "Reading config" line, go to stderr so they are not installed as part of the crontab.The dry-run reminder no longer appends
--auto --silent. Completing the run is the same command without--dry-run:cronitor syncafter an interactive dry run, orcronitor sync --autowhen--autowas already set (plus whatever file or other flags were already on the command).--fileimport and Windows scheduled-task sync still callfatal; neither prints a crontab on stdout.--auto --silentstill prints nothing, which is the documented behavior.With several crontabs, or in interactive mode, an API failure no longer stops the run. Each remaining crontab is still tried, and the run exits 1 at the end. That matches the documented rule that sync exits 1 if any crontab fails, and it matches the shim and save failure paths.
Review follow-up
A single named crontab that does not exist, cannot be read, or is not writable now exits 1 with the error on stderr. It no longer prints nothing and exits 0. If the file is readable but not writable, stdout is the original crontab, the same as an API, shim, or save failure. If the file does not exist or cannot be read, there is nothing to print. Scanning several crontabs is unchanged: a missing user crontab is still skipped, and a system crontab this user cannot write is still counted in the one sudo hint.
A missing API key or an invalid
--formatstill exits 1 before a plan exists. In--autosingle-file mode, when that file is readable, sync prints it to stdout first. A missing or unreadable file prints nothing.The release note, README, and
cronitor synchelp no longer sayset -o pipefailor checking the exit code keeps a pipe from installing a failed run.crontab -still runs and installs empty input. They say to capture first:out=$(cronitor sync --auto file) && printf '%s\n' "$out" | crontab -. A direct| crontab -pipe can still install an empty crontab if sync fails before it can read the file, for example when the file is missing or a flag is invalid. Once sync has read the file, a failure prints the original crontab and exits 1.--dry-runon a single named file that can't be written now exits 1.The dry-run reminder redacts an API key passed with
-kor--api-key(-k X,-kX,-k=X,--api-key X,--api-key=X, and a short cluster such as-vkXor-vk=X) to<api-key>. It redacts a ping key passed with-por--ping-api-keyin the same forms to<ping-api-key>. A clustered=is kept, so-vk=Xprints-vk=<api-key>.Test results
cd web && npm ci && npm run buildsucceeded.go build ./... && go test ./...passed:cmd17.0slib0.6sRe-ran
cd web && npm ci && npm run build, thengo build ./... && go test ./..., after this follow-up. Both succeeded (cmd17.1s,libcached).GOOS=windows go test -c ./cmdcompiled.TestSyncAutoPrintsOriginalWhenAPIFailsstill checks that an API failure exits 1, stdout is the original crontab, the file is unchanged, and stderr is non-empty. It no longer asserts exact log strings.TestSyncAutoExitsWhenCrontabMissingOrUnwritablechecks that a missing file exits 1 with empty stdout, and that an unwritable file exits 1 with the original crontab on stdout and the file unchanged.Dev-only checks
Not committed:
cronitor sync <file> --dry-runhintscronitor sync <file>, with no--auto,--silent, or--dry-run.cronitor sync --auto --dry-run <file>hintscronitor sync --auto <file>on stderr, and the hint is not on stdout.--auto --silentwith the same API failure prints nothing, exits 1, and does not change the file.--verbosestill logs the API request on stdout.<path> does not existand nothing on stdout; a mode000file printscould not be readand nothing on stdout; a mode0444file printsis not writable. Run sync with sudo.and the original crontab on stdout. The file on disk does not change. Exit code is 1 in each case.--auto --dry-runwith-k X,-kX,-k=X,--api-key=X,--api-key X,-vkX, and-vk=Xshows<api-key>in the reminder and does not print the key.-vk=Xkeeps the=. Stdout stays the crontab.-p X,-pX,-p=X,--ping-api-key X,--ping-api-key=X,-vpX,-vp=X, and-vp Xshow<ping-api-key>and do not print the key.--format=nope, print the original crontab and exit 1 when the file is readable, and print nothing and exit 1 when it is missing.--auto --silenton a missing or read-only file prints nothing and exits 1.cronitor syncon a missing or read-only file exits 1 with the error on stderr and does not printSync complete.crontaband not committed:out=$(cronitor sync --auto file) && printf '%s\n' "$out" | crontab -leaves the crontab untouched when the file is missing (exit 1) and when a flag is invalid (exit 1, empty stdout). With a readable file that sync finishes, it installs that output. A directsync --auto <missing> | crontab -still installs an empty crontab, including underset -o pipefail(pipeline status 1, crontab empty).-e -k /pathtreats the path as the API key (-e -k <api-key>), and-kafter--is still redacted as an API key.-e -k /pathover-redaction was left as-is. It only hides too much in a printed hint.CI follow-up
Discover includes custom notification-listandDiscover omits 'notifications'now read stderr as well as stdout. On Linux,discover --autoprints the crontab on stdout and--verboserequest logs on stderr. Windows still prints those logs on stdout (that job was already green), so the checks read both streams. The omit check passes its paths intobash -c, which does not inherit the test's variables. The capture-first snippet in the README, the 33.15 note, andcronitor synchelp now says not to add--silent:--auto --silentprints no crontab, so the pipe would install an empty one.