mirror of
https://github.com/devvmhq/ciwatch.git
synced 2026-12-01 06:13:17 -10:00
GitHub marks a job that runs past its timeout-minutes as cancelled, and
gh run view --log-failed prints nothing for it, so ciwatch showed an
unexplained cancelled job. The only sign of the timeout is the check-run
annotation "The job has exceeded the maximum execution time of <limit>".
For each cancelled job in a completed run, ciwatch now fetches its
annotations through the usual retries. When one matches that message
exactly, the job is reported as timed out after the limit: on stderr, in
the job's block header and as timed_out_after in --json. ciwatch then
reads the full job log (gh run view --log --job) and shows the cancelled
step's last lines the way failed steps are shown.
This reads GitHub's annotation text. A job without the annotation is
reported exactly as before, so a reworded message can only miss a
timeout, never invent one. A failed annotations call warns and leaves
the job as it was. A failed log call keeps the timed-out verdict and
shows (log unavailable) and log_error. Ctrl-C in either call exits 4
with no table. Conclusions, exit codes and the rerun hint are unchanged.
The full log labels each line with its step, and the steps before the
cancelled one start in the same second, so the cancelled step's lines
are picked out by that label before steplog.Parse finds its window. If
no line carries the step's name, the whole log is parsed by the step's
times instead.
Runner gains Annotations and JobLog. docs/json.md, the README and
AGENTS.md name the new field and calls. The fixtures are the recorded
timeout and the recorded annotations of the concurrency-cancelled job.
Backlog:
- The jobResult and failedLogs comments in internal/cli/cli.go still
speak of failed jobs and the failed-step log; they now also cover
timed-out jobs and the full log. Off path: comments only, behaviour is
correct.
- A timed-out job with no cancelled step, or whose cancelled step has no
lines, says "(no failed step in the log)"; "(no cancelled step in the
log)" would be more exact. Off path: wording only, the verdict and
exit code are correct.
- The annotation fixtures are the raw API JSON, not the [{message}]
shape --jq produces, so no test checks the jq expression. Off path:
test tightness; the fixtures are unedited recordings and the decoder
ignores the extra fields.
- If only some lines of a timed-out job's log carry the step's name and
the rest are UNKNOWN STEP, stepLines drops the unlabelled ones. Off
path: the same log-layout inference the design accepts for failed
steps; the verdict and exit code don't depend on it.
Spec: acceptance cases
1. **AC-1:** Fixtures: the recorded timeout (run 45339081512, job 138258094336 "slow", its annotations and its full log). ciwatch:
- writes `ciwatch: job 138258094336 (slow) of run 45339081512 (Timeout) timed out after 1m0s` to stderr.
- In the table, the job's block starts `slow (Timeout, run 45339081512): timed out after 1m0s`. Under `Sleep past the limit:` it shows these 8 lines, in order, with colour codes removed: `##[group]Run echo "starting to sleep"`, `echo "starting to sleep"`, `sleep 150`, `echo "never printed"`, `shell: /usr/bin/bash -e {0}`, `##[endgroup]`, `starting to sleep`, `##[error]The operation was canceled.`. None of the "Print before" lines and none of the "Complete job" lines (`Cleaning up orphan processes`, …) appear.
- In `--json`, the job has `"timed_out_after":"1m0s"` and `steps` holding that one step with `omitted: 0`.
- Exit code 3.
2. **AC-2:** The concurrency cancel (`run-list-cancelled.json`, run 44707997310, cancelled job 136192284970). Its annotations have no timeout message. stdout, stderr, the newer-run line and exit code 3 are all byte-for-byte what they are today. The job gets no block and no `timed_out_after`, and the full log isn't fetched.
3. **AC-3:** The annotations call for a cancelled job fails, after the usual retries for network and temporary errors. ciwatch writes `ciwatch: can't fetch the annotations of job <id> (<name>) of run <id> (<workflow>): <err>` to stderr. That job is then reported as it is today, with no block and no `timed_out_after`, and the exit code is unchanged (3).
4. **AC-4:** The annotation says the job timed out, but the full-log call fails. The job is still reported as timed out on stderr and in the block header. The block shows `(log unavailable)`, `--json` has `log_error`, the usual `can't fetch the log` warning appears, and the exit code is unchanged.
5. **AC-5:** The exit code doesn't change. A run whose only problem is a timed-out job exits 3. In a mixed set (one failed run plus one timed-out run) the exit code is whatever `exitCode` gives today. The rerun hint still counts only failed runs.
6. **AC-6:** Ctrl-C during the annotations call or the full-log call: no partial table, exit 4, the same as during the failed-log fetch today.
7. **AC-7:** An annotation whose message only resembles the timeout message (for example `The operation was canceled.`, or the timeout text without the "of <limit>" ending) doesn't make the job timed out.
Spec: non-goals
- Guessing a timeout from durations or from `timeout-minutes` in the workflow file.
- Jobs whose conclusion is `failure`, or the existing `timed_out` handling. That stays as it is.
- Changing exit codes, the run's or job's `conclusion` value, or the table's CONCLUSION column, which stays `cancelled`, as GitHub says.
- Runs that are still in progress, including with `--once`. Logs are only served once a run has completed.
- Changing the newer-run lookup for a cancelled run whose cancellation was really a timeout.
- Suggesting a rerun for a timed-out job.
- Paging past the first 100 annotations of a job.
Spec: inference
- **GitHub's annotation text.** A job counts as timed out only when one of its annotation messages matches `^The job has exceeded the maximum execution time of (\S+)$`. The limit is the captured text, shown as given. If GitHub rewords the message, ciwatch misses the timeout and reports the job as a plain cancelled job, which is today's behaviour. It can't invent a timeout from other text.
- **Where the cancelled step's lines are in the log.** This reuses `steplog.Parse`, which finds a step's lines by the step's start and end times in the jobs JSON. It starts at the `##[group]` line and ends at the last `##[error]` line, which is what keeps "Complete job" out. If GitHub changes the log layout, the block shows the wrong lines or none (`(no failed step in the log)`). The timed-out verdict and the exit code don't depend on this. Failed steps already rely on the same inference.
Spec: approved with
Approved under CJ's standing delegation (2026-11-24), including the inference: matching GitHub's annotation text can only miss a timeout, never invent one, and the step window reuses the approved steplog.Parse. Answers: (1) record job 136192284970's real annotations read-only with gh api repos/devvmhq/devvm/check-runs/136192284970/annotations into testdata/gh/ (they hold 'Canceling since a higher priority waiting request…' and 'The operation was canceled.', no timeout message), instead of a hand-written []; (2) the *-timed-out.json fixtures stay; (3) the newer-run hint stays unchanged; (4) don't copy job-log-failed.log.
Built in steps:
- test(cli): cover reporting a job that hit its time limit
- feat(cli): report a job that hit its time limit
- docs(cli): say that timed-out jobs get steps and tests too
- test(cli): compare the unchanged cancelled job byte for byte
- fix(cli): parse a timed-out job's whole log if no line names its step
- fix(docs): polish from review
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>