Files
w3cjandClaude Sonnet 5.5 51c5299692 feat(cli): say which crash inputs came from an earlier attempt
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]>
2026-11-24 00:12:09 -07:00

5.0 KiB

AGENTS.md

ciwatch watches every GitHub Actions run for a commit until it finishes, and shows what failed: each workflow's and job's conclusion, the failing tests' names and the lines around them, fuzz crash inputs, and an exit code that says whether everything passed. It's a Go CLI that talks to GitHub only by running gh with --json. Read README.md for what it does.

Layout

Path What
cmd/ciwatch/ the entry point; the only os.Exit and the only use of the real stdin, stdout and stderr
internal/cli/ the command line: arguments, output (a compact table, or --json), exit codes
internal/gh/ the one runner every gh and git call goes through, and the decoding of its output
internal/steplog/ finds the last 40 lines of each failed step in a job's log, by the step's times
internal/testlog/ parses failing tests and gotestsum's summary out of a go test log
testdata/ recorded gh output and CI logs that the tests feed in
testdata/golden/ the exact --json output for a fixture; changing the output means updating it in the same commit
docs/ json.md: the --json schema and the exit codes; tests hold the encoder to it
mise.toml, .golangci.yml pinned tools, tasks and linters
.claude/settings.json, .mise/locks/ the factory's write-blocking hook (shell writes into files are refused; use the editor tools), and mise's npm lock for dex, committed with mise.lock
.archon/ Archon's settings and the vendored factory pack (workflows/archon-factory, from devvmhq/archon-factory), which builds each dex task; never edit the pack here, upgrade it

Tasks

mise run <task>: fmt, lint, test, build, factory -- feature|fix <dex-id> to start a factory run for a task, and squash before a push.

Rules

  • The gate: mise run fmt && mise run lint && mise run test, all passing, before starting a task and before marking it done; a gate failing at the start gets fixed first.
  • Fail-first tests: write the test for a change first and see it fail for the right reason, then make it pass.
  • Edit files with the editor tools, not sed, perl, python or heredocs.
  • Ask first before anything outward-facing (pushing, publishing, posting) and before deleting anything you didn't create.
  • A task that turns out wrong or incomplete: say so and propose the change; don't quietly do something else.

Go conventions

  • Fail by returning: functions return errors; cli.Run turns them into a message on stderr and an exit code, and only cmd/ciwatch exits.
  • Exit codes: 0 every run passed, 1 a run failed, 2 usage, 3 a run was cancelled, 4 couldn't check. They're constants in internal/cli.
  • One call without --json: gh run view --log-failed prints text and has no JSON form; Runner.FailedLog is the exception, and so is gh run view --log (Runner.JobLog); so are gh api … --jq (Runner.Artifacts, Runner.AttemptStarted and Runner.Annotations, the --jq names the fields), gh run download (Runner.DownloadArtifact) and gh run rerun (Runner.RerunFailed).
  • No prompts: ciwatch never asks a question, since agents run it without a terminal. An action it could take (fetching crash inputs, rerunning failed jobs) is a flag, and the output ends with a hint line naming the flag.
  • Streams and context are passed in: functions write to the io.Writer they're given and take their caller's ctx; forbidigo enforces both.
  • gh is a command, never a library: every call goes through one runner type with a field tests replace, always with --json and the fields named. Test seams are fields, never package variables.
  • Time is a seam too: waiting and backoff go through a clock the tests control, so no test sleeps on the real clock.
  • Dependencies: the standard library only. Adding one: ask.
  • Every //nolint names its linters and says why.

Testing

  • Tests feed recorded gh output from testdata/, captured from real runs, and never call GitHub.
  • Test behaviour through each package's API, with table tests next to the code.

Commits and tasks

  • Each task lands as a branch of stacked commits and a merge commit: the failing tests, the implementation, the self-review, each review round (its findings and the answers to them) and any formatting, each committed as its step finishes, then git merge --no-ff onto main with a message that sums up the whole change. The merge passes the gate; the failing-tests commit fails it on purpose. Before a push, mise run squash turns each task into one commit; the stacks stay on the task branches. Conventional Commits: type(scope): summary, types feat, fix, docs, test, refactor, style, build, ci, chore.
  • Every commit message ends with the trailer Co-Authored-By: Claude Sonnet 5.5 <[email protected]>.
  • Task IDs from any tracker never go in commit messages, code comments or docs.
  • AGENTS.md stays short: one line per path or rule.