After a rerun, jobs and logs come from the reported attempt, but crash artifacts are listed for the whole run. Since upload-artifact v4 an artifact name can be used only once per run, so when attempt 2 crashes the same target again, the crash artifact the run lists is attempt 1's. For a run reported at attempt 2 or later with at least one crash artifact, ciwatch now asks once when that attempt started, with the same retries as the artifact listing. A crash artifact created strictly before that start is marked: one stderr line names it, as "was uploaded by attempt 1, not attempt 2" or, from attempt 3, "by an attempt before attempt N", and --json gets "earlier_attempt": true. The input is still listed and still fetched with --fetch-crashes, and exit codes don't change. If the lookup fails, ciwatch warns once and marks nothing; after it runs out of network retries, later runs' lookups aren't retried. Ctrl-C during it exits 4 before anything is fetched. Attempts 0 and 1, and runs without crash artifacts, make no call. An artifact with no usable created_at is never marked. The comparison rests on GitHub rerunning only completed runs and on both timestamps coming from GitHub's clock. If that is wrong, an artifact created within moments of the attempt's start could be mislabelled; only the label and one stderr line are affected. gh.Artifact gains CreatedAt, Artifacts asks for created_at, and the new Runner.AttemptStarted reads run_started_at. docs/json.md, the README and AGENTS.md are updated. The tests add a fake attempts call, a recorded attempt-start fixture and a hand-written artifacts fixture. AC-1's "calls unchanged" at attempt 1 means no attempts call and the same sequence of gh calls; the artifacts --jq now asks for created_at at every attempt. Left from review: - internal/gh/gh.go: the artifacts --jq asks for created_at at attempt 1 too, so AC-1's "calls byte-for-byte unchanged" doesn't hold literally; making the query depend on the attempt wasn't worth the complexity. Backlog: - TestFuzzAttemptOneUnchanged doesn't compare stdout and stderr byte for byte with a run before the change, as AC-1 words it. Off the path: test tightness, the behaviour works. - When the attempt start doesn't parse, the warning ends with "decoding gh api output: parsing time ...", which doesn't name the attempts call. Off the path: message clarity, the line already names the run. Spec: acceptance cases AC-1: A failed run at attempt 1 with a crash artifact. Stdout, stderr, `--json` and the `gh` calls are byte-for-byte what they are today. There is no attempts call and no `earlier_attempt` field. Exit 1. AC-2: A failed run at attempt 2, where `crash-FuzzParse` has `created_at` 2026-11-13T23:58:40Z and attempt 2 started at 2026-11-14T00:15:04Z. - stderr gets exactly one line: `ciwatch: crash-FuzzParse of run 43529187615 (CI) was uploaded by attempt 1, not attempt 2` - `--json` has `"earlier_attempt": true` on that crash. - With `--fetch-crashes` it is still downloaded to the same place as today. - Exit 1, as today. AC-3: The same run, with `crash-FuzzOther` created at 2026-11-14T00:21:02Z (after attempt 2 started). No line and no field for that artifact. If a run has one artifact of each kind, only the earlier one is marked. AC-4: A run at attempt 3 with an artifact created before attempt 3 started. The line reads `… was uploaded by an attempt before attempt 3`. We can't tell whether that was attempt 1 or 2. AC-5: A run at attempt 2 where the attempts call fails (not a network error). - stderr gets exactly one line: `ciwatch: can't tell which crash inputs of run 43529187615 (CI) came from an earlier attempt: <error>` - No crash is marked, the output is otherwise as today, and the exit code doesn't change. - A network or temporary error is retried like the artifact listing, and the warning comes after the retries run out. AC-6: Ctrl-C during the attempts call, or during its backoff, prints `ciwatch: context canceled` with no table and exits 4. Nothing has been fetched yet at that point. AC-7: A run at attempt 0 (gh didn't say), or a failed run at attempt 2 with no crash artifacts. There is no attempts call and the output is as today. AC-8: A run at attempt 2 whose artifact has no `created_at`, or one that doesn't parse. That artifact is not marked and gets no line. This is the case for the existing recorded fixture, which lacks the field. Spec: non-goals - Handling two artifacts with the same name (upload-artifact v4+ makes that impossible). - Downloading by artifact ID. - Showing artifacts per attempt, or naming exactly which earlier attempt when N ≥ 3. - Changing exit codes, or skipping or refusing to fetch earlier-attempt inputs. - Marking earlier-attempt inputs in the table output (stderr carries it). - Artifacts other than `crash-Fuzz*`. Spec: inference There is one place: comparing artifact `created_at` against attempt N's `run_started_at`. It rests on two things: GitHub reruns only a completed run, and both timestamps come from GitHub's own clock. If that's wrong, an artifact created within moments of attempt N's start could be labelled the wrong way. The comparison is strict (`created_at` before start), so equal times count as the current attempt. If the guess is wrong, the only effect is a wrong label and one stderr line: fetching and exit codes don't change. Spec: approved with Approved under CJ's standing delegation, including the single-boundary inference: a wrong guess only mislabels and adds one stderr line, and fetching and exit codes don't change. Your three answers are accepted: no table mark, no mark without created_at, and no attempts call without crash artifacts. Record the attempt-start fixture read-only from the real call as planned. Built in steps: - test(cli): cover marking crash inputs from an earlier attempt - feat(cli): say which crash inputs came from an earlier attempt - docs: describe crash inputs from an earlier attempt in the README - fix(cli): polish from review Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
7.7 KiB
ciwatch
ciwatch watches every GitHub Actions run for a commit until it finishes, and shows what failed. It's meant for the minutes after a push, when you'd otherwise keep gh run watch open in one tab and dig through gh run view --log-failed in another.
It isn't usable yet: the commands are being built one at a time.
What it will do
- Find every workflow run for a commit, including runs that start a little after the push, and watch them until each completes.
- Report each workflow's and each job's conclusion, as a compact table or as JSON with
--json. - Keep watching through network errors, retrying with backoff.
- For a cancelled run, name the first run after it of the same workflow on the same branch, for another commit, if there is one, and print the command to watch it.
- For a failed job, show the last 40 lines of each failed step, not the whole log, and with
--go-teststhe failing Go tests' names and the lines around them too. - For a cancelled job whose check-run annotation says it exceeded its maximum execution time (GitHub reports such a job as
cancelled, nevertimed_out), say it timed out after the limit and show the last lines of the step it was in. - For a failed fuzz job, list the failing targets and fetch their crash inputs into
testdata/fuzz/<Target>/when you ask. - Offer to rerun a flaky job's failures.
- Exit 0 only when every run passed, with a different code for failed, cancelled, and couldn't check.
Usage
ciwatch [--json] [--once] [--go-tests] [--fetch-crashes] [--rerun-failed] <commit>
ciwatch polls until every run for the commit has completed, and keeps looking for new runs for 60 seconds after the push so runs that start late are included. If the commit's runs were created longer ago than that (a commit pushed before, or pushed again), it looks for 60 seconds from when ciwatch started instead, so the new push's runs are caught and an old commit waits that long once. It writes a progress line to stderr whenever a run changes, then prints the final table (or the --json document) to stdout. With --once it checks a single time instead, and exits 4 if runs are still going. A gh call that fails with a network error or a temporary GitHub error (HTTP 502, 503 or 504) is retried up to 8 times, waiting 1s, 2s, 4s and so on up to 30s between tries, and ciwatch says on stderr what it is waiting for; only when the retries run out does it exit 4. The exception is the jobs fetch: if fetching a run's jobs runs out of retries, ciwatch warns on stderr, shows (jobs unavailable) for that run, and keeps the exit code the runs' conclusions give rather than exiting 4.
For each cancelled run on a branch, ciwatch makes one more call, gh run list --created ">=<its createdAt>" for the same workflow (found by its ID) on the same branch, and takes the earliest run in the result that is for a different commit and was created strictly after the cancelled run. If there is one, the cancelled run's table row ends in (newer run <id> for <short sha>), --json adds newer_run (id and sha) to the run, and the last stderr lines, one per such run in table order, say ciwatch: run <id> (<workflow>) was cancelled; to watch the newer run: ciwatch <sha>. ciwatch doesn't claim the newer run caused the cancellation, and doesn't watch it on its own. Otherwise the run is reported as plainly cancelled. Either way a cancelled run exits 3, unless another run failed, which exits 1. If the look for a newer run runs out of retries, ciwatch warns on stderr and reports the run as plainly cancelled. If the call returns 100 runs, the oldest may have been cut off, so ciwatch warns can't name the run after run <id> (<workflow>): 100 or more runs since it and leaves the run plainly cancelled. Timestamps are whole seconds, so a run of another commit created in the same second isn't named. gh run list --created needs a gh recent enough to have the flag; it was tested with gh 2.103.3.
For each failed run (failure or timed_out), ciwatch lists the run's artifacts once and takes those named crash-<Target> (a Go fuzz target, Fuzz…) as fuzz crash inputs. They are listed under the table as <Target> (crash-<Target>, run <id>), --json gives them as fuzz_crashes on the run, and a stderr line says to rerun with --fetch-crashes. With --fetch-crashes, each is downloaded with gh run download into a temporary directory and its files are copied into testdata/fuzz/<Target>/ beside the one _test.go file in the checkout that declares func <Target>(f *testing.F). A file that already exists there is never overwritten; if every file was already there, the input is listed as already present. If no file or more than one declares the target, ciwatch warns and skips that download. When an input isn't fetched, the last line on stderr says what to do next. If you press Ctrl-C while fetching, ciwatch lists on stderr the inputs it already wrote, as <artifact> of run <id> was fetched to <dir>, then exits 4 with no table. A path from the checkout that has a control character, a quote or a backslash in its name is printed quoted and escaped, as Go writes a string, so it can't fake a line of ciwatch's own output; --json fetched_to stays as is. A failed listing or download is a warning and never changes the exit code. A run with more than 100 artifacts is checked only for the first 100. For a run reported at attempt 2 or later, ciwatch asks once when that attempt started; an input created before then was uploaded by an earlier attempt (upload-artifact keeps the first one when a later attempt crashes the same target), so a stderr line names it and --json marks it "earlier_attempt": true. It is still listed and fetched. If that call fails, ciwatch warns once and marks nothing.
When a run fails, the last stderr line (after the crash hint, if there is one) says to rerun with --rerun-failed. With that flag, ciwatch calls gh run rerun <id> --failed once for each run that ended in failure or timed_out (never a cancelled or passing run), then goes back to watching the commit until every rerun has a new attempt and every run has completed. A rerun keeps the run's ID and raises its attempt number, which ciwatch reads from gh run list; the progress lines add (attempt N) from the second attempt on, and --json gives attempt on each run. The table, the JSON and the exit code are of the new attempts only; the first attempt's logs and tests are not shown, and its crash inputs are listed but marked as from an earlier attempt. Each run is rerun at most once per invocation, so a second failure is reported, not rerun, and so is a run first seen failing after the reruns. A rerun call that fails is a warning on stderr, is not retried, and ciwatch doesn't wait for a new attempt of that run: its original attempt is reported. --rerun-failed can't be combined with --once, which doesn't wait (exit code 2). It was tested with gh 2.103.3.
The --json fields and the exit codes are described in docs/json.md.
Building
ciwatch needs mise and the GitHub CLI, logged in:
mise install
mise run build
The gate every change passes is mise run fmt && mise run lint && mise run test.
How it's built
Each change starts as a dex task and is built by the archon-factory workflows, vendored in .archon/workflows/archon-factory. Those workflows design the change, wait for approval, write failing tests first, implement, review the change adversarially until it can ship, pass the gate, and wait for a final approval before committing. With Archon installed (brew install coleam00/archon/archon, then archon provider add claude) and the tools from mise install, a task runs with:
mise run factory -- feature <dex-id>