60 Commits
Author SHA1 Message Date
w3cjandClaude Sonnet 5.5 df00ffa8e2 feat(fuzztarget): name the file when a test line is too long
When the fuzz-target search reads a _test.go line over 1 MiB, it now
wraps bufio.ErrTooLong in a *fs.PathError with Op read and the file's
path relative to the checkout. Before, --fetch-crashes printed only
"looking for X in the checkout: bufio.Scanner: token too long", so the
file couldn't be told apart. The CLI's existing path quoting applies to
the new error, so a folder name with a newline is quoted and the message
stays on one line. The error still matches bufio.ErrTooLong.

Only that one error is wrapped. The 1 MiB limit, the files searched,
permission skips and other read errors are unchanged, and the CLI needs
no change. Tests cover the search directly and the stderr line and
fetch_error through the CLI, with an ordinary path and one with a
newline.

Spec: acceptance cases
AC-1: The checkout has `internal/q/q_test.go`, whose second line is 1 MiB + 1 bytes long, and no file reaches a `FuzzParse` declaration before the search gets to it. `ciwatch --fetch-crashes <sha>` for a run with a `crash-FuzzParse` artifact prints this line once on stderr: `ciwatch: can't fetch crash-FuzzParse of run <id>: looking for FuzzParse in the checkout: read internal/q/q_test.go: bufio.Scanner: token too long`. With `--json`, that crash's `fetch_error` is `looking for FuzzParse in the checkout: read internal/q/q_test.go: bufio.Scanner: token too long`. The exit code is 1, as before.
AC-2: Same as AC-1, but the file is `p\nq/q_test.go` (the folder name contains a newline). The message reads `… in the checkout: read "p\nq/q_test.go": bufio.Scanner: token too long`. It stays one line on stderr and no stderr line starts with `q/`. `fetch_error` has the same quoted text.
AC-3: `Declaring` called directly on the AC-1 file system returns an error where `errors.As` finds a `*fs.PathError` with `Op == "read"` and `Path == "internal/q/q_test.go"`, and `errors.Is(err, bufio.ErrTooLong)` is true.
AC-4: A file whose declaration comes before its over-long line is still found, with no error, as it is today.

Spec: non-goals
- Raising or removing the 1 MiB line limit.
- Changing which files are searched. One over-long file still stops the whole search, even if another file declares the target.
- Other errors from the search: open and read I/O errors, permission skips, an unreadable root. Their text stays as it is, including any absolute path in an `os.File` read error.
- Using `reason()`/`Skipped` for this case. A too-long line isn't a permission error, so it is never skipped.

Spec: inference
none

Spec: approved with
Approved under CJ's standing delegation: no inference, a one-error wrap that reuses quoteErr. Your answer is accepted: only bufio.ErrTooLong is wrapped.

Built in steps:
- test(fuzztarget): name the file when a test line is too long
- feat(fuzztarget): name the file when a test line is too long

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 00:24:51 -07:00
w3cjandClaude Sonnet 5.5 7c4f7c74a2 feat(cli): show no jobs under a kept run that wasn't completed
A run that drops out of gh run list is kept at its last listed state,
but its jobs were still fetched with gh run view. A run last seen
in_progress could then show an in_progress row above jobs that GitHub
now reports as completed. ciwatch now skips the jobs fetch for a run
that the latest list doesn't have and that was last seen in any status
other than completed. Its table row has no job rows under it, and in
--json its jobs array is empty with no jobs_error. The existing "no
longer listed" warning still explains it, and the exit code is still 4.

A kept run last seen completed is fetched at its reported attempt as
before, and so are runs that never drop out, runs that come back before
the last list, and every run under --once. The rule is a small method
on listed, keptUnfinished, and docs/json.md says when jobs is empty for
this reason.

The new tests cover the table for in_progress, queued, waiting,
requested and pending, the --json output, and a rerun's new attempt
that drops out. The test for a kept run that passed now checks the full
table with its job rows, so a skip that is too broad would fail it.

Backlog: TestWatchRunVanishesInProgressJSON checks only in_progress.
It could loop over the same five statuses as the table test. It is off
this feature's path because the behaviour works and the table subtests
already cover every status that isn't completed, so it only makes the
test stricter.

Spec: acceptance cases
1. AC-1: A run last seen `in_progress` drops out and is still missing at the last list (`ciwatch <sha>`). The table shows its row `CI  in_progress` with no job rows under it. `gh run view` isn't called for it. Stderr has the existing `ciwatch: run <id> (CI) is no longer listed for this commit` line once. Exit code is 4.
2. AC-2: Same as AC-1 with `--json`. That run's `jobs` is `[]` and it has no `jobs_error`. Its other fields come from its last listed state. Exit code is 4.
3. AC-3: Under `--rerun-failed`, a run's new attempt is last seen `in_progress` and then drops out for good. Its row is `CI  in_progress` with no job rows, and there's no `gh run view` for it. The warning ends with `; not waiting for it`. Exit code is 4.
4. AC-4: A kept run last seen `completed` (failure or success) gets its jobs fetched and shown exactly as today. That includes failure blocks, `--go-tests` and crash hints. Exit codes are 1 and 0, as today.
5. AC-5: A run that drops out and comes back before the last list is reported with its jobs, exactly as today.
6. AC-6: Runs that never drop out, including in `--once` mode, which never tracks dropped runs, report their jobs exactly as today. All existing golden files stay byte-for-byte the same.
7. AC-7: Statuses other than `in_progress` that aren't completed (`queued`, `waiting`, `requested`, `pending`) on a kept run are treated like AC-1.

Spec: non-goals
- Looking up the missing run by ID to get its real current state.
- Marking the run as kept in `--json`, or adding any new field.
- A new stderr line, or a table note such as "(jobs not shown)". The existing "no longer listed" warning is the explanation.
- Changing how a kept completed run's jobs are fetched, or what attempt they're fetched at.
- Kept runs' artifacts, timeouts and crash lookups. These already skip runs that aren't completed.

Spec: inference
none. The rule rests only on two facts ciwatch already has: whether the run was missing from the last list (`listed.missing`), and the status from its last listing.
**Behaviour.** No new flags, and exit codes are unchanged. Example: CI was `in_progress` when it dropped out, and Docs passed:
```
$ ciwatch abc1234
ciwatch: run 111 (CI) is no longer listed for this commit
WORKFLOW  STATUS       CONCLUSION
CI        in_progress
Docs      completed    success
  build   completed    success
$ echo $?
4
```
Today, rows such as `  test  completed  failure` would appear under `CI  in_progress`.

Spec: approved with
Approved under CJ's standing delegation: no inference, and the choice removes the mismatch from both the table and --json. Your answers are accepted: no placeholder line, and kept completed runs are still fetched at their reported attempt.

Built in steps:
- test(cli): no job rows under a kept run that wasn't completed
- feat(cli): don't fetch jobs for a kept run that wasn't completed

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 00:21:40 -07:00
w3cjandClaude Sonnet 5.5 cadb249813 feat(cli): quote checkout paths inside fetch error text
When --fetch-crashes can't fetch a crash input, the error text could
carry a path from the checkout exactly as it is. A folder named with a
newline split one stderr line into two and put a raw newline into the
--json fetch_error.

A new helper, quoteErr, walks an error's chain, following both single
and multi-error unwraps. For each *fs.PathError whose path quotePath
would change, it rebuilds that error's text with the quoted path and
keeps the text wrapped around it. The fuzz-target search error, the
error from placing a downloaded input and the fallback in reason all
use it, so stderr and fetch_error hold the same single line. Printable
paths print exactly as before, and errors with no path error in their
chain, such as a failed gh run download, are unchanged. Paths with a
quote or a backslash are quoted too, the same rule quotePath already
applies to the skipped, fetched to and is declared in messages.

Tests cover a newline path and an ordinary path for the search error
and for placing an input, and a gh download failure. denyFS now carries
the error it fails with, so the search can fail with EIO as well as
permission denied.

Not covered, as approved: *os.LinkError, because nothing on these paths
returns one, and git's own stderr, such as the error from finding the
checkout root.

Backlog:
- A _test.go line over 1 MiB gives "bufio.Scanner: token too long"
  without naming the file (fuzztarget.go:76 returns the scanner error
  unwrapped). Wrapping it in a *fs.PathError would name the file and
  quoteErr would then quote it. Off the path: the error has no path at
  all, so it isn't about quoting.
- No test covers the quoteErr fallback in reason (cli.go:465). Off the
  path: it can't be reached today, since a skipped entry is always a
  permission *fs.PathError, and the behaviour works.

Spec: acceptance cases
1. AC-1: The fuzz-target search fails on a non-permission error, `open` of `p\nq/q_test.go` returning EIO. Stderr gets the single line `ciwatch: can't fetch crash-FuzzParse of run <id>: looking for FuzzParse in the checkout: open "p\nq/q_test.go": input/output error`, and `fetch_error` is that text after `run <id>: `. Exit code 1.
2. AC-2: Placing an input fails under a declaring folder named `p\nq`, because `p\nq/testdata/fuzz/FuzzParse` is a regular file. Stderr gets the single line `ciwatch: can't fetch crash-FuzzParse of run <id>: mkdir "<root>/p\nq/testdata/fuzz/FuzzParse": not a directory`, and `fetch_error` holds the same message. No file is written, and the exit code is 1.
3. AC-3: AC-1 with the ordinary path `internal/q/q_test.go` prints `… looking for FuzzParse in the checkout: open internal/q/q_test.go: input/output error`, unquoted, the same as today.
4. AC-4: AC-2 with a folder named `p q` prints `… mkdir <root>/p q/testdata/fuzz/FuzzParse: not a directory`, unquoted, the same as today.
5. AC-5: A failed `gh run download` (no path error in the chain) still puts gh's text into `fetch_error` unchanged.
6. AC-6: The search is permission-denied on a folder whose name has a newline. The existing `skipped "…" … : permission denied` line is unchanged, and so is the test that covers it.

Spec: non-goals
- Escaping text that doesn't come from the checkout: target names, artifact names, gh and git output, job names. This includes the error from `git rev-parse --show-toplevel` (see Questions).
- Changing which paths the search skips, or what it does with a checkout root whose name ends in whitespace.
- Error text that has a path in it but no `*fs.PathError` in its chain. There is no structured path to find there, and guessing at one from the text is open-ended.
- The table on stdout. It already says only `not fetched`.

Spec: inference
none

Spec: approved with
Approved under CJ's standing delegation: no inference, printable paths are unchanged, and it uses the same quotePath rule as the shipped messages. Your answers are accepted: leave out *os.LinkError until a rename appears; git's own stderr stays out of scope with no follow-up; paths with " or \ are quoted, as elsewhere.

Built in steps:
- test(cli): quote checkout paths inside fetch error text
- feat(cli): quote checkout paths inside fetch error text

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 00:17:30 -07:00
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
w3cjandClaude Sonnet 5.5 dc8f08c556 feat(cli): keep runs that drop out of the list in the report
A run that was listed and then missing from a later gh run list used to
disappear from the table, the JSON and the exit code without a word, so
a failure seen earlier could end as exit 0. Only rerun runs were kept
before, and only during the wait for new attempts.

A new listed type remembers the last state of every run and which runs
the latest list lacks. Its observe method warns once per disappearance
and returns the list with each missing run put back at its last state,
before the next run of its last list that is still present. It replaces
withGone. watch observes every list except under --once, checks "no
runs found" on the merged list, and waits only for the runs that are
listed, so a missing run isn't waited for and an empty list after a
non-empty one no longer fails. watchAttempts shares watch's listed, so a
run that dropped out during the first watch is warned about once in
total. A rerun run keeps the "; not waiting for it" warning and other
runs get the plain "is no longer listed for this commit" line. A run
that comes back is reported at its latest state, in gh's order.

The usage text, docs/json.md and the comments now say this applies to
every run, not only reruns. Runs that never drop out, and every --once
call, behave as before, and no golden file changed. The tests are in
vanish_test.go.

Backlog:
- A kept run still has its jobs fetched when the report is built, so a
  run last seen in_progress can show job rows newer than its row. Off
  the path because looking up a missing run's real state is a non-goal.
- The usage text in internal/cli/cli.go has a very short line, "known
  state. The", from a hand rewrap. Off the path because it is cosmetic
  and nothing is lost or misleading.
- TestWatchRunReappears doesn't assert the fresh progress line when a
  run comes back. Off the path because it is test tightness on
  behaviour that already works.

Spec: acceptance cases
- AC-1: Without `--once`, poll 1 lists CI (failure) and Docs (success). From poll 2 on, only Docs is listed. Stderr gets exactly one line, `ciwatch: run <ci-id> (CI) is no longer listed for this commit`. The table shows CI `completed failure` with its jobs, in its old place before Docs. Exit code 1 (this also covers the task's AC-2).
- AC-2: Same, but Docs is the run that drops out, after `completed success`, and CI is listed throughout as success. There is one warning, both rows are shown and the exit code is 0.
- AC-3: A run last seen `in_progress` drops out and stays out. There is one warning, the watch doesn't wait for it, and it ends once the listed runs complete and the grace period is over. The row reads `in_progress`, the exit code is 4, and there is no "drop --once" line.
- AC-4: A run is listed, missing, listed again (now with a later state), missing again, then listed for good. Stderr has the warning twice, once per disappearance. The report and exit code come from its last listed state.
- AC-5: Every run is missing from a later list (the list comes back empty) after a non-empty one, once the grace period is over. Each run gets one warning, the report holds all of them at their last state, and there is no `no runs found` error. If no list ever had a run, `no runs found` and exit 4 stay as they are.
- AC-6: With `--rerun-failed`, a non-rerun run (Docs, success) drops out during `watchAttempts` while CI's rerun is waited for. Docs gets one warning in the new wording, and the table still shows it as success. A rerun run that drops out still gets today's warning, ending in `; not waiting for it`.
- AC-7: With `--rerun-failed`, a failed run that dropped out during `watch` and is still missing gets exactly one warning in total. It is reported at its last known state (failure, exit 1). `watchAttempts` doesn't warn about it again.
- AC-8: Runs that never drop out, and every `--once` call, behave exactly as today. All existing tests and golden files pass unchanged.

Spec: non-goals
- Looking up a missing run by its ID (`gh run view <id>`) to get its real current state.
- Telling a deleted run apart from one pushed past the 100-run list limit.
- Marking a kept run in `--json` or in the table. The schema and golden files stay as they are.
- Not rerunning a failed run that has dropped out. `--rerun-failed` still asks GitHub to rerun it, as it does any failed run it knows of.
- Waiting for a missing run to come back.

Spec: inference
none. A run's absence from `gh run list --json` output is a fact. ciwatch reports the last state gh gave and doesn't guess why the run is missing.

Spec: approved with
Approved under CJ's standing delegation: no inference (absence from gh run list is a fact, and the last state gh gave is reported), the acceptance cases cover the task's drafts, and the non-goals hold. Your three answers are accepted: the plain warning for non-rerun runs and the '; not waiting for it' suffix for rerun runs; --rerun-failed still tries a dropped-out failed run; a run that comes back takes gh's order and gets a fresh progress line.

Built in steps:
- test(cli): runs that drop out of the list stay in the report
- feat(cli): keep runs that drop out of the list in the report
- docs(cli): say that every run that drops out is kept

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 00:01:49 -07:00
w3cjandClaude Sonnet 5.5 d0ec3f29ce feat(cli): quote checkout paths in stderr and table output
A file or folder name from the checkout was printed as it is, so a
name with a newline, a carriage return or an escape sequence could fake
an extra ciwatch line on stderr. Add quotePath, which returns a path
as strconv.Quote writes it when that escapes anything in it, and the
path unchanged otherwise. Spaces and printable non-ASCII letters stay
unquoted; a name with a quote or a backslash is quoted, so it can't
pass itself off as an already-quoted path.

quotePath is used for the path in the skip warning, for each file in
the "is declared in" message, and for the directory a crash input was
fetched to, in the Ctrl-C "was fetched to" line and in the table's
"fetched to" and "already present in" lines. The directory has the
same defect, so it is included. The --json fetch_error carries the
escaped declared-in text, as it copies the stderr message. The --json
fetched_to stays the raw path, and the declared-in files still sort as
raw bytes. Ordinary paths print exactly as before. The README says
that such paths print quoted.

Backlog:
- No test covers a path with a backslash, or the table's "already
  present in" line with a path that needs quoting. Both go through
  quotePath and work; it is test tightness only.
- Paths inside error text still print raw: reason(s.Err) for errors
  that aren't a *fs.PathError, the "looking for ... in the checkout"
  message, and the stageAndPlace errors. The design lists this as a
  non-goal, and a follow-up task for it was not created.

Spec: acceptance cases
AC-1: With `--fetch-crashes`, an unreadable folder `internal/x\nciwatch: fake` (the name has a real newline) prints one line on stderr: `ciwatch: skipped "internal/x\nciwatch: fake" while looking for fuzz targets: permission denied`. The `\n` here is a backslash followed by `n`. No line on stderr starts with `ciwatch: fake`, and the exit code is unchanged (1).
AC-2: `FuzzParse` is declared in two files, `a\x1b[2K_test.go` and `b/b\r_test.go`. stderr has the single line `ciwatch: can't fetch crash-FuzzParse of run <id>: FuzzParse is declared in "a\x1b[2K_test.go", "b/b\r_test.go"`, with no raw ESC or CR byte. The `--json` `fetch_error` holds the same escaped text. Exit code 1.
AC-3: If one declaring file is `a_test.go` and the other has a control character, only the odd one is quoted: `declared in "a\x01_test.go", b/b_test.go`. The paths sort as raw bytes, the same order as today.
AC-4: A single file declares the target, in folder `p\nq`. The input is downloaded to the real `p\nq/testdata/fuzz/FuzzParse`. stderr shows `ciwatch: crash-FuzzParse of run <id> was fetched to "p\nq/testdata/fuzz/FuzzParse"` and the table line ends `: fetched to "p\nq/testdata/fuzz/FuzzParse"`. The `--json` `fetched_to` stays the raw path; the JSON encoder escapes it.
AC-5: Paths that only contain printable characters print unquoted. That includes spaces and non-ASCII letters such as `é`. A path containing `"` or `\` is quoted, so a name can't pass itself off as an already-quoted path.
AC-6: Ordinary paths print exactly as today in all three messages and the table. The current tests (`skipWarning`, `declared in a_test.go, b/b_test.go`, `was fetched to …`) and the golden `--json` files pass unchanged.

Spec: non-goals
- Changing which paths are skipped, or how the search walks the checkout.
- Escaping text that doesn't come from the checkout: target names, artifact names, `gh` and `git` output, job names.
- Paths inside error text: walk errors at `cli.go:363`, errors from `stageAndPlace`, and the `Toplevel` error. See the follow-up task.
- Telling a comma inside a name apart from the `, ` that separates names in the "declared in" list.
- Changing any `--json` field other than `fetch_error`, which already copies the stderr message.

Spec: inference
none

Spec: approved with
Approved under CJ's standing delegation: no inference, and ordinary paths are unchanged. Answers: (1) yes, include the fetched-to path (AC-4), since it's the same defect; (2) yes, fetch_error carries the escaped text. The follow-up about paths inside error text is not created now; the review's triage can raise it again if it matters.

Built in steps:
- test(cli): expect checkout paths quoted in messages
- feat(cli): quote checkout paths in messages
- docs(readme): say checkout paths print quoted

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 23:55:57 -07:00
w3cjandClaude Sonnet 5.5 ee089d0c5d feat(cli): report a job that hit its time limit
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]>
2026-11-23 23:50:33 -07:00
w3cjandClaude Sonnet 5.5 d108f34228 feat(steplog): start a step's log window at its group line
The jobs JSON gives whole seconds, so lines the previous step printed
in the second a failed step started fell inside the step's window. They
were counted in its earlier lines, and a previous ##[error] line could
end the window early. In the recorded devvm log, the lint step's two
"Finished in" lines were counted for the test step.

Parse now treats the first ##[group] line stamped in a step's start
second as the start of the step's own lines. Lines taken before it in
that second, and untimestamped lines that follow them, are dropped, and
a dropped ##[error] line no longer ends the window. If no ##[group] line
falls in the start second, including a log that ends in it, the window
is exactly what it was. Nothing outside the start second changes. For
the recorded devvm log the tail is unchanged and its omitted count goes
from 263 to 261.

The change relies on GitHub writing a log in order and starting each
step with a ##[group] line. A step that prints a ##[group] line in its
first second without a header of its own loses its lines before that
group; that is under a second of output. Memory stays bounded: the lines
go straight into the span's tail, which keeps at most 2*Tail lines.

Tests cover the shared-second cut, an untimestamped follower, a previous
##[error] line with and without the step's own, two group lines in the
start second, and the cases that must not change. A new fixture, written
by hand from real lines of the recorded devvm log, drives a CLI test.

Backlog:
- TestRunStepLeavesOutPreviousStepsSameSecond (internal/cli): the
  "omitted":0 check in --json also passes with the old code, since the
  fixture's window is short. Asserting on the first line or the line
  count would tighten it. Off path: the test as a whole already fails
  on the old code.
- The design's AC-1 case 5 (a step with only pre-group lines is left
  out) can't be reached, because the group line is in the window and is
  kept. No test row covers it. Rewording the case or pinning the
  intended behaviour would remove the ambiguity. Off path: spec wording;
  no reachable input gives wrong output.

Spec: acceptance cases
1. **AC-1:** The step's span starts at 10:00:05. The log has `prev a` (10:00:05.1), `prev b` (10:00:05.2), `##[group]Run go test` (10:00:05.3), `go test` (10:00:05.4) and `##[error]x` (10:00:06). The step's lines are `##[group]Run go test`, `go test`, `##[error]x`, with `Omitted` 0.
2. **AC-1:** A line without a timestamp after `prev b` (it belongs to `prev b`) is left out with it.
3. **AC-1:** If the previous step's lines in the shared second include `##[error]prev`, the failed step's window doesn't end at that line. Its tail ends at its own `##[error]` line, as in AC-1 case 1. If the step has no `##[error]` of its own, its tail ends at its last line in the window.
4. **AC-1:** If the start second has more than one `##[group]` line (the step's header, then a group the step itself prints), the cut is at the first one. The step's own group and the lines after it are kept.
5. **AC-1:** If the step's only lines are in its start second and come before its `##[group]` line, then nothing is left. The step is left out, as a step with no lines is today.
6. **AC-2:** For the recorded `devvm-44705166834.log` and the span `Run mise run test` from 08:47:47 to 08:52:20, the tail is unchanged, but `Omitted` drops by the 2 lint lines. Its 40 lines go from 263 omitted to 261: the 301 lines from line 400 to line 700, less 40. With a short log written by hand from the same real lines, `ciwatch HEAD` exits 1, and the step's block starts `##[group]Run mise run test`, with no `[lint:code]` or `Finished in` line.
7. **AC-3:** If no `##[group]` line falls in the step's start second, the window is exactly what it is today. That covers start-second lines with no group line, a group line stamped before `startedAt`, and every existing `TestParse` case. `devvm-short-step.log` also keeps its current output.
8. **AC-3:** If the start second's lines are the last lines of the log (EOF before the second ends), they're kept as today, unless a `##[group]` line came first.

Spec: non-goals
- Using step names from the log (`##[group]Run <name>`), or matching the `Run ` prefix.
- The other end of the window: lines of the next step within a second of the failed step's completion. These are still kept when the step has no `##[error]` line.
- Showing passed steps; changing `Whole`, `--json` fields or exit codes.
- Logs where gh labels lines with real step names (the attempt logs). They're treated by time as today.

Spec: inference
- **That the step's lines start at its own `##[group]` line, and that GitHub writes the log in order.** In the start second, a line before the first `##[group]` line is taken to be the previous step's. GitHub starts every `run:` and `uses:` step with `##[group]Run …`, and the log comes in the order it was written.
- **When the guess is wrong:** Take a step that doesn't start with a group header (say a post step) but prints a `##[group]` in its first second. Its own lines from before that group are dropped. That's under a second of output, and only when a group line appears in that same second. If the previous step prints a `##[group]` in the shared second, the cut lands at that group line. Some of the previous step's lines are then still shown, which is today's behaviour, never worse. With no group line in the start second, nothing changes.

Spec: approved with
Approved by CJ as designed, including the inference (the first ##[group] line in the step's start second marks where its lines begin) and your two assumed answers: cut at any ##[group], and AC-2 shown by the Omitted count plus the short fixture from real lines.

Built in steps:
- test(steplog): cut a step's window at its group line
- feat(steplog): start a step's window at its group line
- fix(steplog): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 23:03:49 -07:00
w3cjandClaude Sonnet 5.5 c0df4e27d8 feat(cli): say when a failed rerun call reran anyway
A gh run rerun call can fail after GitHub has already accepted the
rerun, for example when the connection resets while gh waits for the
reply. Until now ciwatch only warned about the call and never looked at
that run's attempts again, so it reported the old attempt.

ciwatch now remembers each run whose rerun call failed, with its attempt
at the time, and checks it in every list that watchAttempts takes. A run
listed at a higher attempt is announced once on stderr as "run <id>
(<workflow>) was rerun after all (attempt N)", then waited for and
reported like an accepted rerun, with its jobs and logs from the new
attempt. When every call failed, there is one extra list with no wait
before it, so the single-run case is checked too. When no higher attempt
shows up, nothing changes except that extra list.

If the extra list fails, a warning names the error and the original
attempt is reported with exit code 1, so an optional check can't turn a
known failure into a pending one. Ctrl-C during it still exits 4. A run
whose call failed and that a list no longer has is warned about as no
longer listed and kept in the report at its last known state, instead of
dropping out of it. The usage text gains a sentence about the new line.
There are no new flags, exit codes or changes to --json output.

Left from review:
None.

Backlog:
- If the extra list shows a new run still in progress and a later list
  then fails, the first snapshot is returned and the new run is missing
  from the report. Off the feature's path: it needs a run outside the
  rerun feature to start mid-check, and the report stays accurate for
  the snapshot it shows.
- TestRerunCallFailsExtraListFails could also check the exact warning
  prefix, "can't check whether the failed rerun calls took effect". Off
  the feature's path: it only tightens a test of behaviour that works.
- The design's non-goal says a failed-call run that stops being listed
  is handled as before, but it is now warned about and restored to the
  report. Off the feature's path: only the wording of the spec, since the
  behaviour is better than it asks for.

Spec: acceptance cases
1. AC-1: `--rerun-failed` with one failed run, `CI` 44858310690 at attempt 1. The rerun call fails with `connection reset by peer`. The next list shows that run at attempt 2. stderr has the existing warning `ciwatch: can't rerun the failed jobs of run 44858310690 (CI): …`, then exactly once `ciwatch: run 44858310690 (CI) was rerun after all (attempt 2)`. The line doesn't repeat on later polls.
2. AC-2: Continuing AC-1, the run moves through `in_progress` at attempt 2 to `completed success` at attempt 2. ciwatch waits for it. The table shows the run as `completed success`, and the jobs and logs come from attempt 2 (`--attempt 2`). The exit code is 0.
3. AC-3: The same as AC-2, but attempt 2 ends in `failure`. Exit code 1, and the failed jobs and logs come from attempt 2.
4. AC-4: Two failed runs. CI's call fails and Fuzz's is accepted. While ciwatch waits for Fuzz's attempt 2, a list shows CI at attempt 2. The line from AC-1 is printed for CI, and both runs are waited for and reported at attempt 2.
5. AC-5: The call fails and no later list shows a higher attempt. This covers both the all-calls-failed case (one extra list) and the mixed case. stderr has only the warning. The original attempt is reported, its jobs and logs come from that attempt, and the exit code is 1, as today. The only difference: when every call failed, ciwatch now makes one more `gh run list` call than before (8 instead of 7 in the existing fixture).
6. AC-6: A run detected as rerun after all, which then stops being listed. ciwatch prints the existing `ciwatch: run … is no longer listed for this commit; not waiting for it` warning and reports the run at the last state it saw, as it does for an accepted rerun.
7. AC-7: Every call failed and the extra list fails, for example with a network error after its retries. stderr gets `ciwatch: <error>` and the exit code is 4, the same as when a list during a rerun wait fails today. Ctrl-C during that list also exits 4.

Spec: non-goals
- Retrying the rerun call, or waiting for a while to see whether a failed call took effect. Only the lists ciwatch takes anyway, plus the one extra list, are checked.
- Telling who started the new attempt. A higher attempt is reported as "rerun after all" whoever started it.
- A failed-call run that stops being listed before any higher attempt shows up. It is handled as today.
- Any change to `--json` output or `docs/json.md`. The new line goes only to stderr.

Spec: inference
- **Timing:** the check assumes a new attempt is already visible in `gh run list` by the time of the lists ciwatch takes. If GitHub shows it later than that, ciwatch misses it and behaves as today (AC-5): the warning stays, and the original attempt is reported truthfully as that attempt. The guess can only cause a missed detection, never a false "rerun after all".
- **Who started it:** a higher attempt is taken to come from ciwatch's own failed call. If someone else started it in the meantime, the line still says "rerun after all". The attempt reported is still the one GitHub has, so the report stays correct. (This is a stated non-goal.)
**Behaviour.** There are no new flags or exit codes. Example:
```
$ ciwatch --rerun-failed HEAD
ciwatch: can't rerun the failed jobs of run 44858310690 (CI): gh: exit status 1: connection reset by peer
ciwatch: run 44858310690 (CI): queued (attempt 2)
ciwatch: run 44858310690 (CI) was rerun after all (attempt 2)
ciwatch: run 44858310690 (CI): completed success (attempt 2)
<table of attempt 2>            # exit 0
```
The new line comes right after the progress lines of the list that revealed the new attempt. The usage text gains one sentence: "A run whose rerun call failed but that GitHub reran anyway is said so and waited for like the others."
**Code** (all in `internal/cli/cli.go`, no new dependencies):
- `rerun` returns a second map, `failedCalls map[int64]int`: run ID to attempt, for each call that failed. It isn't filled when the context was cancelled.
- In `App.Run`, call `watchAttempts` when `want` or `failedCalls` is non-empty. With `want` empty, the existing loop ends after one list once all runs are completed. That one list is AC-5's extra list.
- `watchAttempts(ctx, sha, prev, want, failedCalls, w)`: after `progress` on each list, any run in `failedCalls` that is listed with `Attempt` above its recorded attempt is announced, moved into `want` with the recorded attempt, and removed from `failedCalls`. After that it goes through the same wait and gone handling as any accepted rerun. Its doc comment changes to match.
- Update the usage text.
**Tests** (in `internal/cli/rerun_test.go`, using the existing `fakeOpts`/`lists`/`attemptRun` helpers and the recorded runs `ciRun` and `ciRun2`, whose recorded attempt 2s are in `run-list-rerun-attempt2*.json`; the in-between states are derived from those, as the existing tests already do):
- `TestRerunCallFailsRerunAfterAll` (AC-1, AC-2): `rerunErr` for `ciRun`. The lists are failed@1, then in_progress@2, then success@2. It expects the line exactly once (count it), exit 0, `calls.attempt[ciRun] == "2"`, and a table of `completed success`. It fails today because nothing announces the attempt or waits for it.
- `TestRerunCallFailsRerunAfterAllFails` (AC-3): `ciRun2` with failure@2. It expects exit 1 and the jobs and log from attempt 2.
- `TestRerunCallFailsMixedRerunAfterAll` (AC-4): a variant of `TestRerunFailedCallFails` where CI's list also goes to attempt 2. It expects the line for CI, both runs at attempt 2, and no line for Fuzz.
- `TestRerunAfterAllVanishes` (AC-6): CI detected at attempt 2 in progress, then gone from the list. It expects the no-longer-listed warning and CI reported in progress at attempt 2 (exit 4, as for an in-progress accepted rerun that vanishes).
- `TestRerunFailedCallFailsOnEveryRun` (AC-5) gets updated: 8 list calls, and no "rerun after all" line. `TestRerunFailedCallFails` (AC-5, mixed) and `TestRerunCallFailsReportsListedAttempt` additionally assert that the line is absent.
- `TestRerunCallFailsExtraListFails` (AC-7): every call fails, and the 8th list returns a network error. It expects exit 4 and the error on stderr. A Ctrl-C variant cancels during that list and also expects exit 4.

Spec: approved with
Approved by CJ, including the timing inference (it can only miss a detection, never cause a false one). One change to AC-7: if the extra list after every call failed itself fails (network error after retries), print a warning on stderr naming the error and report the original attempt as today, with exit 1, not exit 4. An optional check failing must not turn a known failure into pending. Ctrl-C during that list still exits 4 with 'context canceled'. Your other answers are accepted: one extra list with no wait, and the line names the attempt seen on the poll that detected it.

Built in steps:
- test(cli): say when a failed rerun call reran anyway
- feat(cli): say when a failed rerun call reran anyway
- fix(cli): keep a failed-call run the extra list lacks
- fix(cli): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:52:59 -07:00
w3cjandClaude Sonnet 5.5 c2cee2baa4 feat(cli): fetch jobs and logs for the reported attempt
ciwatch now asks for the jobs and the failed-step logs of every run by
the attempt on the run's row, so the row, its jobs, its steps and its
logs come from one attempt. Before, only a run that stopped being listed
after a rerun had its jobs fetched by attempt. When a rerun call failed
but GitHub reran the jobs anyway, the table mixed attempt 1's run with
attempt 2's jobs, and gh refused the log while attempt 2 was running.

FailedLog takes the attempt and passes --attempt before --log-failed
when it is 1 or more. App.Run always calls RunJobsAttempt, which leaves
out --attempt for a run whose attempt gh didn't report, so those calls
are as they were. watchAttempts no longer returns the runs that went
missing, since nothing else needs them. The usage text says the jobs and
logs shown are those of the attempt reported. Retries and Ctrl-C work as
before, and every retry carries the same --attempt.

Tests cover each case: the gh call for attempts 0, 1 and 2, a failed
rerun call with attempt 2 in progress, a run that vanishes after a
rerun, a single-attempt run, and the retries. The fixtures are the logs
gh printed for two attempts of one run, recorded read-only, and a
hand-written in-progress jobs file derived from a recorded run.

Backlog:
- Crash artifacts are still listed and downloaded for the whole run, so
  after a rerun they can include inputs from an earlier attempt. GitHub
  can't select artifacts by attempt, so this needs a timing inference
  and is off the path of this change.
- TestSingleAttemptCallsUnchanged compares only the table output of
  attempt 1 with attempt 0; it could compare the --json output too. The
  encoder doesn't read the attempt differently, so this only tightens
  the test.
- When another run's rerun succeeds, watchAttempts lists the runs again,
  so a run whose rerun call failed but was reran anyway shows up at its
  new attempt. Its jobs and logs still match. Re-listing after a failed
  rerun call is a non-goal, and a separate task covers saying so.

Spec: acceptance cases
1. **AC-1:** A run reported at attempt N ≥ 1 has its jobs fetched with `gh run view <id> --attempt N --json jobs`. This holds for every run, not only runs that stopped being listed. The job rows come from attempt N even when GitHub's latest attempt is N+1.
2. **AC-2:** `--rerun-failed`, the rerun call for run R fails (for example a network error), and GitHub holds attempt 2 of R, still in progress. ciwatch reports R at attempt 1, `completed`/`failure`, with attempt 1's jobs. Each failed job's log is fetched with `gh run view R --attempt 1 --log-failed --job <job>`, and its failed-step lines are shown. There is no "can't fetch the log" warning. The exit code is 1.
3. **AC-3:** A run whose attempt gh didn't report (`attempt` 0) has its jobs and logs fetched exactly as today, with no `--attempt`. The table, the `--json` output (the golden files stay as they are) and the exit codes don't change.
4. **AC-4:** Without `--rerun-failed`, a run at attempt 1 gets `--attempt 1` on its jobs and log calls. Apart from that argument, the calls are the same and so are the output and the exit code.
5. **AC-5:** A run that stops being listed after a rerun is still reported at its last known attempt, with its jobs and logs fetched by that attempt. This is today's behaviour for jobs; logs are new.
6. **AC-6:** Network retries and Ctrl-C work as they do now for the jobs and log calls. The `--attempt` argument is the same on every retry.

Spec: non-goals
- Showing or comparing more than one attempt of a run.
- Telling the user that a failed rerun call reran anyway. That's the blocked task "Say when a failed rerun call reran anyway".
- Tying crash artifacts to an attempt. `GET /actions/runs/{id}/artifacts` and `gh run download` have no attempt filter. Artifacts are still listed and downloaded for the whole run, as today (see Follow-up tasks).
- Re-listing runs after a failed rerun call to pick up the new attempt.

Spec: inference
none. ciwatch passes the attempt from gh's own `attempt` field to gh's `--attempt` flag. Nothing is guessed from timing or from text.

Spec: approved with
Approved under CJ's standing delegation. Answers: (1) yes, narrow AC-2 to jobs and logs; GitHub can't select artifacts by attempt, and the artifact follow-up needs a timing inference, so it goes to CJ separately, not into this task; (2) confirmed read-only: devvmhq/devvm run 43529187615 has two attempts, and gh run view --attempt 1/2 --log-failed --job returns different failed jobs (132242348233 and 132254736456) and different logs, so gh honours --attempt with --log-failed; record its jobs and logs read-only as the two-attempt fixture; (3) yes, attempt-1 runs get --attempt 1 too.

Built in steps:
- test(cli): jobs and logs come from the reported attempt
- feat(cli): fetch jobs and logs for the reported attempt
- test(gh): ask for the logs by the run they were recorded from
- fix(gh): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:15:48 -07:00
w3cjandClaude Opus 5.5 a4b22e44f6 build: upgrade the factory pack to v0.6.3
v0.6.3 lands a run that started before main was squashed by moving its own commits onto the squashed main, instead of merging the pre-squash commits back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 22:08:50 -07:00
w3cjandClaude Sonnet 5.5 60c88ccf6c feat(cli): stop waiting for a rerun that drops out of the list
With --rerun-failed, ciwatch waited until every rerun run showed a
later attempt, so a run that stopped appearing in gh run list made it
wait forever, and the run vanished from the report. It now remembers
the last state it saw of each rerun run. When a poll doesn't list one,
it warns once per disappearance (run <id> (<workflow>) is no longer
listed for this commit; not waiting for it) and stops waiting for it.
The watch ends once every listed run is complete and every rerun run
that is still listed is past its attempt. A run that is listed again
is waited for as before, and a second disappearance warns again.

The report puts a missing run back at its last known state, in the
place it had in the first list, and the exit code comes from that
state. Its jobs are fetched with gh run view --attempt for the attempt
it is reported at, because GitHub may already hold a later one. The
advice to drop --once is now printed only with --once, since without it
a pending run can only be one that dropped out of the list. The usage
text and the exit codes in docs/json.md say so. The --json schema and
the golden files don't change.

Left from review:
The artifacts of a run reported at an older attempt are listed for the
whole run (internal/cli/cli.go), so a crash input from a later attempt
that ran after the run dropped out could show under the older row. A
normal rerun already has the same limit. Whether GitHub returns other
attempts' artifacts needs checking against a real rerun.

Backlog:
TestRerunVanishesInProgress checks the CI row's status but not that its
jobs were asked for with --attempt 2. It is test tightness: the same
code path is checked in TestRerunVanishesBeforeNewAttempt.
The pending > 0 && opts.once guard in internal/cli/cli.go relies on
parseArgs rejecting --once with --rerun-failed. A comment or test
tying the two together would help if that rule is relaxed. It is docs
and style: the current behaviour is correct.

Spec: acceptance cases
- AC-1: A run was rerun, and a later poll doesn't list it. stderr gets `ciwatch: run <id> (<workflow>) is no longer listed for this commit; not waiting for it` once. The line isn't repeated on later polls while the run stays missing. The watch ends as soon as every listed run is complete and every rerun run that is still listed has gone past its attempt.
- AC-2: The missing run was last seen as `completed failure` on attempt 1, because it dropped out before attempt 2 was ever listed. The report shows it as `completed failure` with attempt 1's jobs, and the exit code is 1. The `--rerun-failed` hint isn't printed.
- AC-3: The missing run was last seen as `in_progress` on attempt 2, and every other run passed. The report shows it as `in_progress`, and the exit code is 4. stderr doesn't contain the `drop --once to wait for them` hint, because that advice is wrong here.
- AC-4: Two runs are rerun and one of them drops out. ciwatch keeps polling until the other one's new attempt completes, and the report shows that new attempt's result.
- AC-5: A rerun run is missing from one poll and listed again on the next, still in progress. ciwatch waits for it again until its new attempt completes, the report shows that result, and the `no longer listed` warning appeared exactly once.
- AC-6: A run reappears and then drops out a second time. The warning is printed a second time, because each disappearance gets one warning. The report shows the state it had the last time it was listed.
- AC-7: Ctrl-C while the run is missing behaves as it does today: `ciwatch: context canceled`, no table, and exit code 4.

Spec: non-goals
- Rerunning the missing run again, a time limit on waiting, and searching other commits or the run by ID.
- Runs that drop out of the list without having been rerun, either in the first watch or after the reruns. Today they vanish from the report without a word. That's a separate follow-up below.
- Marking a missing run in the `--json` output or the table. The stderr warning is the only signal, so the JSON schema and golden files don't change.
- Telling a deleted run apart from one that fell past `gh run list`'s 100-run limit.

Spec: inference
none. "No longer listed" means only that the latest `gh run list` didn't include the run, which ciwatch knows for certain. It doesn't guess why, or whether the run will come back. If the run comes back while ciwatch is still watching, ciwatch picks it up (AC-5). If it comes back after ciwatch has exited, the report shows the last state ciwatch saw.

Spec: approved with
Approved under CJ's standing delegation (2026-11-23): Inference is none (it acts only on what gh run list returned); the acceptance cases cover the task's drafts and add the second disappearance, Ctrl-C and the --once hint; the non-goals hold. Your answers are accepted: one warning per disappearance, and no mark in --json for now. Your follow-up is created as its own dex task.

Built in steps:
- test(cli): cover a rerun run that drops out of the list
- feat(cli): stop waiting for a rerun that drops out of the list
- docs(cli): describe a missing rerun run in the watchAttempts comment
- fix(cli): fetch a missing rerun run's jobs by attempt

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:08:50 -07:00
w3cjandClaude Opus 5.5 c6e4509520 build: upgrade the factory pack to v0.6.2
v0.6.2 ends a design's sections at any heading style, so the inference check and the recorded spec read only their own section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 22:01:04 -07:00
w3cjandClaude Sonnet 5.5 99d26f4a0c feat(fuzztarget): skip unreadable folders when finding fuzz targets
The search for the test file declaring a fuzz target used to stop at the
first permission error, so one unreadable folder anywhere in the
checkout made --fetch-crashes give up on an input even when its
declaration sat in a readable package. Declaring now returns a Result
holding the declaring files and the folders and _test.go files below
the checkout root that it was not allowed to read. It skips those and
carries on. Other errors, and an unreadable root, still stop the search
as before, and the skipped paths found before such an error are still
returned with it.

fetchCrashes prints one warning on stderr for each skipped path, naming
the path relative to the checkout and the permission error, before that
input's own lines. A path is warned about once per invocation, however
many inputs search the checkout. If the only declaring file was in an
unreadable folder, the input is reported as declared nowhere, after the
warning. The --json output, the hint line and the exit codes are
unchanged, and a readable checkout behaves exactly as before.

Tests wrap the checkout in a file system that denies chosen paths, so
they don't depend on chmod. They cover an unreadable folder, an
unreadable file, a declaration only in an unreadable folder, one
warning for two inputs, ignored folders never entered, an unreadable
root, and the JSON staying the same.

Backlog:
- Paths with newlines or control characters are printed as they are in
  the skip warning and in the existing "is declared in" message, so a
  crafted name could fake stderr lines. Off the feature's path: it is
  hardening across existing messages, and the unescaped printing was
  there before this change.
- A folder that can be listed but not entered gets one warning for each
  file and subfolder inside it, not one naming the folder. Off the
  feature's path: it is output style, the spec says each path is warned
  about once in walk order, and nothing is lost or wrong.

Spec: acceptance cases
1. AC-1: The checkout has `internal/secret/` (unreadable) and `internal/p/p_test.go` declaring `FuzzParse`, and the run has the artifact `crash-FuzzParse`. With `--fetch-crashes`, stderr shows `ciwatch: skipped internal/secret while looking for fuzz targets: permission denied` once, then the input is fetched to `internal/p/testdata/fuzz/FuzzParse` as today. The exit code is 1 because the run failed.
2. AC-2: The only file declaring `FuzzParse` is inside the unreadable `internal/secret/`. stderr shows the skip warning, then `ciwatch: can't fetch crash-FuzzParse of run <id>: no _test.go file declares func FuzzParse(f *testing.F)`. The hint line and the table's `not fetched` are the same as today, and the exit code is 1.
3. AC-3: An unreadable `_test.go` file (`internal/q/q_test.go`) is skipped the same way. The warning names the file, and a declaration elsewhere is still found.
4. AC-4: The run has two crash artifacts (`crash-FuzzParse` and `crash-FuzzOther`) and the checkout has one unreadable folder. The warning appears once, not once per input, and both inputs are handled as in AC-1 and AC-2.
5. AC-5: An unreadable folder inside a folder Go ignores (`testdata`, `vendor`, `.x`, `_x`) produces no warning, because the search never enters it.
6. AC-6: An unreadable checkout root still fails the same way: `looking for FuzzParse in the checkout: …`, a retry hint, and no skip warning.
7. AC-7: A readable checkout behaves exactly as today: the same stdout, stderr and `--json`, and the golden files don't change.
8. AC-8: With `--json`, the skip warning goes to stderr only. The JSON is unchanged: `fetch_error` and `fetched_to` are the same as without the unreadable folder.

Spec: non-goals
- Skipping `node_modules` or other folders Go doesn't ignore, and making the search faster (for example, one walk for all targets).
- Skipping errors that aren't permission errors: I/O errors, a folder that disappears during the walk, a line longer than 1 MiB. These still stop the search as today.
- Changing the "exactly one declaring file" rule because something was skipped. If one readable file declares the target, the input goes there, even if an unreadable file might declare it too.
- Adding the skipped paths to the `--json` output, or changing the hint line.
- Following symlinks (`WalkDir` doesn't, today or after).

Spec: inference
none
**Behaviour**
There are no new flags or exit codes. The only change is a new warning line on stderr, printed before that input's own lines:
```
$ ciwatch --fetch-crashes c4b4c02
ciwatch: skipped internal/secret while looking for fuzz targets: permission denied
ciwatch: crash-FuzzParse of run 44709305563 was fetched to internal/p/testdata/fuzz/FuzzParse
…table…
```
The path is the slash path relative to the checkout root, the same form as `FuzzParse is declared in a_test.go, b/b_test.go`. The reason is the underlying `PathError.Err` text (`permission denied`), not the whole `open …: permission denied` string. Warnings come in walk order (lexical). Each path is printed at most once per invocation.
**Code**
- `internal/fuzztarget/fuzztarget.go`:
  - `Declaring` returns `(Result, error)`, with `Result{Files []string; Skipped []Skipped}` and `Skipped{Path string; Err error}`.
  - In the `WalkDir` callback: when `err != nil`, `p != "."` and `errors.Is(err, fs.ErrPermission)`, it records the path and returns `fs.SkipDir` for a folder, or `nil` for a file. The same applies to the error from `fsys.Open(p)` on a `_test.go` file, and to a permission error from reading it (`sc.Err()`).
  - Every other error is returned as today.
- `internal/cli/cli.go` `fetchCrashes`:
  - Keeps a `warned map[string]bool` for the whole call.
  - After each `Declaring`, prints `ciwatch: skipped %s while looking for fuzz targets: %s` for each new `Skipped` path, before the `switch`. The rest of the code uses `res.Files`.
- No new dependency.
**Tests** (written first; each fails before the change)
- `internal/fuzztarget/fuzztarget_test.go`: a small test `fs.FS` wrapper around `fstest.MapFS`. Its `Open` returns `&fs.PathError{Err: fs.ErrPermission}` for chosen paths. It deliberately doesn't implement `ReadDirFS`, so `WalkDir` goes through `Open`. This avoids `chmod`, which root ignores. Table cases:
  - AC-1: `internal/secret` denied and `internal/p/p_test.go` declares the target. Want `Files = [internal/p/p_test.go]` and `Skipped = [internal/secret]` with `ErrPermission`. This fails before the change because `Declaring` returns an error.
  - AC-2: only `internal/secret/s_test.go` declares it and `internal/secret` is denied. Want `Files` empty and `Skipped` set.
  - AC-3: `internal/q/q_test.go` denied. Want it in `Skipped`.
  - AC-5: `testdata/x` denied. Want nothing skipped.
  - AC-6: the root `.` denied. Want an error.
  - A non-permission error (`fs.ErrInvalid`) on a subfolder still returns an error.
  - AC-7: the existing cases, updated to read `Result.Files`, still pass.
- `internal/cli/fuzz_test.go`, through the `App.OpenDir` seam wrapping the checkout's `fstest.MapFS` with the same denial:
  - `TestFuzzFetchSkipsUnreadable` (AC-1, AC-3): uses `realCheckout` and wraps `os.DirFS` so a download really happens. Checks the warning on stderr exactly once and the "was fetched to" line.
  - `TestFuzzFetchOnlyDeclaredInUnreadable` (AC-2): checks that the warning comes before the "no _test.go file declares" line, that the hint is unchanged, and the exit code is 1.
  - `TestFuzzFetchSkipWarnsOnce` (AC-4): uses the existing `twoCrashes` artifact JSON and counts the warning lines (1).
  - `TestFuzzFetchSkipJSON` (AC-8): `fuzzJSON` gives the same `fuzz_crashes` as without the denial, and the warning is on stderr.
  - AC-7 is covered by the existing tests and golden files passing unchanged.
**Questions**
1. Should a folder that disappears during the walk (`fs.ErrNotExist`) also be skipped? I'd assume no: the task covers unreadable paths only, so that case stays an error, and it can be a follow-up if wanted.
2. When something was skipped and exactly one readable file declares the target, should the fetch still go ahead? I'd assume yes, as AC-1 of the draft says ("still finds a declaration elsewhere"), with the warning telling the user what wasn't searched.
3. Should the AC-2 hint mention the skipped folder? I'd assume no: the draft says "as today", and the warning line just above it already names the folder.

Spec: approved with
Approved by CJ, with your three assumed answers: a folder that disappears mid-walk stays an error; with exactly one readable declaring file the fetch goes ahead, with the warning; the hint doesn't repeat the skipped folder.

Built in steps:
- test(fuzztarget): skip unreadable folders and files
- feat(fuzztarget): skip unreadable folders when finding fuzz targets
- style(cli): join test paths with filepath.Join
- fix(fuzztarget): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:01:04 -07:00
w3cjandClaude Sonnet 5.5 a27a5b9cc1 feat(cli): list crash inputs written before Ctrl-C
Pressing Ctrl-C partway through --fetch-crashes used to print only the
context canceled error, although some crash inputs may already have been
copied into testdata/fuzz. ciwatch now prints one line for each input it
wrote during this invocation, as "<artifact> of run <id> was fetched to
<dir>", before the error line, then exits 4 with no table as before. An
input counts as written when its folder is set and it wasn't already
present, since files are placed only after the download succeeds, so an
interrupted download and an input whose files were all there already are
never listed. Lines come out in the order the inputs were fetched.

fetchCrashes now checks the context before each input, after finding the
checkout, and after searching for the declaring file, so a cancel that
lands before an input that would be skipped no longer ends with the
table and exit 1. The artifact listing and the download return the
context's own error when it is done, so the last stderr line is always
context canceled even when a killed gh fails with its own error. The
README describes the new output. The fake gh in the tests gains an
afterDownload hook so a test can cancel once an input is placed.

Spec: acceptance cases
1. AC-1: The context is cancelled after `crash-FuzzParse` is written and while `crash-FuzzOther` is downloading. stderr has `ciwatch: crash-FuzzParse of run 44729305066 was fetched to internal/p/testdata/fuzz/FuzzParse`, then `ciwatch: context canceled` as the last line. Exit code 4, stdout empty. The file is in the checkout.
2. AC-2: The context is cancelled during the first download. stderr has no `was fetched to` line. Exit code 4, stdout empty, the checkout is unchanged. Same result for a cancel before fetching starts, for example while listing jobs.
3. AC-3: The download that was interrupted isn't listed. In AC-1, there's no line for `crash-FuzzOther`, and nothing from it is in the checkout or the staging folder.
4. AC-4: An input whose files were all already in the checkout before the run isn't listed, since this run wrote nothing. An input where some files were new and some already present is listed.
5. AC-5: The context is cancelled after an input is written, and the next input is skipped before its download because no file declares its target. The output is as in AC-1: the written input is listed and the exit code is 4, with no table and no exit 1. Today this case prints the table and exits 1.
6. AC-6: Inputs from two runs, with a cancel after both of the first run's inputs are written. Both are listed, one line each, in the order they were fetched (run order, then artifact order).

Spec: non-goals
- Cleaning up partial downloads (staging already removes them) and resuming downloads.
- Printing the table or `--json` output on Ctrl-C. The `--json` stdout stays empty, and the list goes to stderr either way.
- A cancel after the last input is placed. `fetchCrashes` has already returned, so the full report prints as it does today.
- Listing inputs that were already present, or inputs that failed for reasons other than Ctrl-C.
- A second Ctrl-C, or `SIGTERM`/`SIGKILL`.

Spec: inference
none

Spec: approved with
Approved by CJ, with the AC-5 guard and your three assumed answers: only this invocation's writes are listed; '<artifact> of run <id> was fetched to <dir>' before 'context canceled'; the guard is in scope. For the AC-5 test, pick the smallest seam change to fakeOpts.

Built in steps:
- test(cli): list crash inputs written before Ctrl-C
- feat(cli): list crash inputs written before Ctrl-C
- fix(cli): treat Ctrl-C while checking an input as an interrupt
- fix(cli): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:01:04 -07:00
w3cjandClaude Opus 5.5 247489c386 build: upgrade the factory pack to v0.6.1
v0.6.1 reads a design's Inference section of 'none' followed by a reason as none, instead of flagging it at the design gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 22:01:04 -07:00
w3cjandClaude Sonnet 5.5 0cb5a807c8 feat(cli): report crash inputs that are already present
With --fetch-crashes, gh refuses to overwrite a file, so a crash input
that was already committed was reported as a fetch error with a
warning, though it was where it belongs. Each artifact is now
downloaded into a new staging directory under App.TempDir, and its
files are copied into the target directory, each created only if it
doesn't exist. A file that exists counts as present and is left alone.
The staging directory is always removed, and a failed or interrupted
download no longer leaves half an artifact in the checkout. If the
copy fails partway, the files it already wrote are removed. Each
attempt of a retried download starts from an empty directory.

When every file was already present, the table line ends ": already
present in <dir>" and the JSON entry has already_present with
fetched_to and no fetch_error. A fetch that writes a new file keeps the
"fetched to" line. An artifact without files is the fetch error
"artifact crash-<Target> has no files".

When an input is skipped or fails, the last stderr line, after the
rerun hint, now says what to do next: the declaration to add, the
files to download by hand, the checkout to run in, or how to try again,
in the plural when several inputs failed for the same reason. The exit
code still comes from the runs alone. README, the usage text and
docs/json.md describe the new behaviour.

Backlog:
- The plural hint for several inputs declared in more than one file,
  "download them by hand: gh run download <run> -n <artifact> -D
  <package>/testdata/fuzz/<Target>", is made of placeholders, so it
  can't be pasted as it is. Off the path because the output matches
  the approved spec and the warnings above it name each file.
- If Ctrl-C arrives just after gh run download succeeds, the files are
  still copied and not reported. Off the path because reporting what
  was written on interrupt is the separate Ctrl-C task.

Spec: acceptance cases
AC-1: Every file in the artifact already exists in `internal/p/testdata/fuzz/FuzzParse`:
- The table line is `  FuzzParse (crash-FuzzParse, run 44729305066): already present in internal/p/testdata/fuzz/FuzzParse`.
- Nothing on stderr mentions the input: no `can't fetch` warning and no fetch hint.
- The JSON entry has `"fetched_to":"internal/p/testdata/fuzz/FuzzParse","already_present":true` and no `fetch_error`.
- The existing files are left byte-for-byte unchanged.
AC-2: The artifact has at least one file that doesn't exist yet in the target directory:
- The new file is written there, and any existing file is left unchanged.
- The line stays `…: fetched to internal/p/testdata/fuzz/FuzzParse`.
- The JSON has `fetched_to`, and no `already_present` or `fetch_error`.
- The target directory is created if it's missing.
AC-3: Any crash input is skipped or fails. The last stderr line is a single hint, and it comes after the rerun hint:
- **No `_test.go` declares the target:** `ciwatch: crash-FuzzParse of run 44729305066 not fetched; declare func FuzzParse(f *testing.F) in a _test.go file, then run: ciwatch --fetch-crashes <sha>`
- **The target is declared in more than one file:** `ciwatch: crash-FuzzParse of run 44729305066 not fetched; FuzzParse is declared in more than one file, so download it by hand: gh run download 44729305066 -n crash-FuzzParse -D <package>/testdata/fuzz/FuzzParse`
- **No git checkout:** `ciwatch: crash-FuzzParse of run 44729305066 not fetched; run ciwatch --fetch-crashes <sha> inside the repository's checkout`
- **The download or the copy failed, including after retries:** `ciwatch: crash-FuzzParse of run 44729305066 not fetched; to try again: ciwatch --fetch-crashes <sha>`
- **Several inputs not fetched:** if they all failed for the same reason, the line uses that reason's next step in the plural: `ciwatch: 2 fuzz crash inputs not fetched; to try again: …`. If the reasons differ, it's `ciwatch: 2 fuzz crash inputs not fetched; see the warnings above, then run: ciwatch --fetch-crashes <sha>`.
The per-input `can't fetch …` warnings still appear above the hint.
AC-4: The downloaded artifact contains no files. ciwatch reports `fetch_error` `artifact crash-FuzzParse has no files`, the line ends `: not fetched`, and the "try again" hint is printed.
AC-5: The download fails, or Ctrl-C interrupts it. The checkout is unchanged and the staging directory is removed. On Ctrl-C ciwatch exits 4 with no table, as it does today.
AC-6: The exit code still comes only from the runs. With a failed run, ciwatch exits 1 whether the input was fetched, already present or not fetched.

Spec: non-goals
- Comparing file contents. A file with the same name counts as present even if its bytes differ.
- Deduplicating inputs that have different names.
- Overwriting or deleting existing files.
- A per-file report for an artifact that is partly present (AC-2 just says `fetched to`).
- Reporting what was written when ciwatch is interrupted (the blocked task "Report written crash inputs on Ctrl-C").
- Changing the output without `--fetch-crashes`.

Spec: inference
none. "Already present" is decided by `O_EXCL` on our own write, not by parsing gh's error text.

Spec: approved with
Approved by CJ, with your four assumed answers: already-present isn't a skip and gets no hint; already-present inputs keep fetched_to; the 'which file to remove' example is dropped; the fetch hint comes after the rerun hint, as the last line.

Built in steps:
- test(cli): report crash inputs that are already present
- feat(cli): report crash inputs that are already present
- docs(cli): describe already-present crash inputs
- fix(cli): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-23 22:01:04 -07:00
w3cj 9f43de9344 feat(cli): name the run that replaced a cancelled run
For a cancelled run, ciwatch named the newest run of its workflow on
the branch, which is whatever ran last today, not the run that came
straight after. It now makes one lookup limited to runs created at or
after the cancelled run, using the new gh.Runner.RunsSince in place of
LatestRun. It passes --branch, --workflow by ID, --created with the
cancelled run's createdAt in RFC 3339 UTC, and --limit 100.

From the result, firstAfter names the earliest run that is for another
commit and was created strictly after the cancelled run, the lowest ID
on a tie. The order gh prints the runs in doesn't matter. When no run
qualifies, including a rerun of the same commit or a run of another
commit created in the same second, the run stays plainly cancelled. If
the lookup returns 100 runs, the oldest may have been cut off, so the
run stays plainly cancelled and stderr says that ciwatch can't name
the run after it.

The row note, the hint line, newer_run, the retries, the Ctrl-C
handling and the exit codes are unchanged. The README and docs/json.md
say "first run after it" instead of "newer run", and the README notes
that gh run list --created needs a recent gh, tested with 2.103.3.
The tests use a lookup recorded read-only from devvmhq/devvm, where the
run after 43361281082 is 43361860563 for 90694a4, not the newest run.

Backlog:
- testdata/gh/run-list-latest-newer.json is no longer used by any
  test. Deleting it is housekeeping, not behaviour, and AGENTS.md says
  to ask before deleting anything not created by the task.
- The "cancelled run itself" case in TestCancelledWithoutNewerRun still
  uses run-list-latest-self.json, which was recorded from the old
  --limit 1 call. Recording a --created lookup would make it faithful,
  but it is test tightness: the behaviour already works and is checked.

Spec: acceptance cases
- AC-1: For each completed cancelled run on a branch, ciwatch runs exactly one `gh run list --branch <branch> --workflow <workflow id> --created >=<createdAt as RFC 3339 UTC> --limit 100 --json <run fields>`. It names the run in the result whose commit differs from the cancelled run's and whose `createdAt` is strictly later, with the earliest `createdAt`, lowest ID on a tie. The order gh prints the runs in doesn't matter.
- AC-2: For devvm's cancelled run 43361281082 (commit 8da71a0, created 2026-11-13T03:47:33Z), fed the recorded lookup output, the named run is the first one created after it. That is presumably 43361860563 for 90694a4; I'll confirm it when the output is recorded. It is not the newest run in the list. The table shows `CI completed cancelled (newer run 43361860563 for 90694a4)`, the last stderr line is `ciwatch: run 43361281082 (CI) was cancelled; to watch the newer run: ciwatch 90694a4…`, and the exit code is 3.
- AC-3: When no run qualifies, the run is reported as plainly cancelled, with no note, no hint, no `newer_run`, and exit code 3. That covers four results: an empty result, only the cancelled run itself, only runs of the same commit (for example a rerun of it), and only runs of another commit created in the same second.
- AC-4: If the lookup returns 100 runs, the oldest may have been cut off. The run stays plainly cancelled and stderr gets `ciwatch: can't name the run after run 43361281082 (CI): 100 or more runs since it`. The exit code is still 3.
- AC-5: Task C's behaviour holds with the new call. A failed lookup warns and keeps the run plainly cancelled after the retries. Ctrl-C during a lookup reports the interrupt once and exits 4. Two cancelled runs get two lookups and two hints in table order. A failure alongside a cancellation still exits 1.

Spec: non-goals
- Proving why the run was cancelled, whether by concurrency, by hand, or by a timeout.
- Following chains: the named run is not looked up in turn, even if it was cancelled too.
- More than one lookup per cancelled run, including paging past 100 runs.
- Runs of other branches or other workflows, and runs created before the cancelled one.
- Changing the note, hint or JSON wording, or the docs' field descriptions beyond "newest" → "first after".

Spec: inference
- **The first run after is the one that replaced it.** ciwatch infers this from the order of `createdAt` timestamps. If the run was cancelled by hand and another commit's run came later for an unrelated reason, ciwatch still names that run. That's no worse than task C, which named the newest run, and the hint only names a run to watch; it doesn't claim a cause.
- **Timestamps are whole seconds.** A run of another commit created in the same second can't be ordered against the cancelled run, so it isn't named (AC-3). If it really was the replacement, the run is shown plainly cancelled, which is the safe failure.
- **gh lists newest first.** The selection doesn't depend on that (AC-1). Only the 100-run guard in AC-4 does: it assumes a full page may be missing the oldest runs. Being wrong only costs a warning.

Spec: approved with
Approved by CJ, including its inference (first run of another commit created strictly after the cancel, by createdAt) and its assumed answers: strictly later, --limit 100 with the AC-4 guard, and a README note on the gh version (checked: gh 2.103.3 has --created). Record the AC-2 fixture read-only from devvmhq/devvm and confirm the named run from it.

Built in steps:
- test(cli): name the first run after a cancelled run
- feat(cli): name the run that replaced a cancelled run
- docs(cli): say a full page also leaves a run plainly cancelled
- test(cli): cover the lowest-ID tie-break for the named run
- fix(cli): polish from review
2026-11-23 22:01:04 -07:00
w3cjandClaude Opus 5.5 64696658ac build: upgrade the factory pack to v0.6.0, with its write hook
v0.6.0 holds the review to any user-hittable defect on the feature's
path, judged by impact rather than odds, triages the backlog for the
final review, carries the spec into squashed commits, detects churn
with a script, keeps recorded data out of prompts, and puts a design's
inference at the top of its gate. Its write-blocking hook is now on for
this project through .claude/settings.json, the one shared file under
.claude/. mise's .mise/locks/ is committed with mise.lock, because a
fresh worktree whose mise.lock differs from what's installed needs it
to install dex.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 11:04:33 -07:00
w3cjandClaude Sonnet 5.5 ec5df75774 feat(cli): rerun failed jobs with --rerun-failed
When a run ends in failure or timed_out, ciwatch now ends its stderr
with a hint naming --rerun-failed, after the crash and newer-run hints.
With the flag, it makes one gh run rerun <id> --failed call for each
such run, then goes back to watching the commit until every run has
completed and every accepted rerun has a higher attempt than the one it
was rerun from. The table, the --json document and the exit code are of
the new attempts only.

The attempt number comes from gh run list, which now asks for the
attempt field. The progress lines add (attempt N) from the second
attempt on, and --json gives attempt on each run; it is 0 when gh
doesn't report it, which docs/json.md says. The rerun call is never
retried, since a rerun isn't safe to repeat. A call that fails is a
warning on stderr, ciwatch doesn't wait for that run's new attempt, and
its original attempt is reported. Each run is rerun at most once per
invocation, so a second failure, or a run first seen failing after the
reruns, is reported and not rerun. Runs that passed or were cancelled
are never rerun. --rerun-failed with --once is a usage error, caught
before any gh call, because --once doesn't wait for new attempts.

Runner.RerunFailed joins the calls without --json in AGENTS.md. The
README documents the flag and the gh version it was tested with.

Backlog:
- watchAttempts waits forever if a rerun run drops out of the gh run
  list output; warn, or treat a missing run as done.
- If gh run rerun fails with a network error after GitHub accepted the
  rerun, its new attempt is waited for but no line says a rerun
  happened.
- After a failed rerun call, jobs, logs and artifacts are fetched
  without --attempt, so they can mix attempts with the run row.
- The rerun hint is printed with --once while runs are in progress,
  next to the 'drop --once' line; check that it reads well.

Built in steps:
- test(cli): rerun failed jobs with --rerun-failed
- feat(cli): rerun failed jobs with --rerun-failed
- docs: fix the README's claim about the last stderr line
- fix(docs): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 23:03:02 -07:00
w3cjandClaude Sonnet 5.5 78e454b2ed feat(cli): find fuzz crash inputs from run artifacts
For each failed run (failure or timed_out), ciwatch now lists the run's
artifacts once and takes those named crash-<Target> as fuzz crash
inputs, instead of guessing from test names in logs. They are listed
under the table, given as fuzz_crashes on the run in --json, and the
last stderr line names --fetch-crashes. Runs with no such artifacts show
nothing about fuzzing and make no download.

With --fetch-crashes, each input is downloaded with gh run download into
testdata/fuzz/<Target>/ beside the one _test.go file in the checkout
that declares the target. The new fuzztarget package finds that file,
skipping testdata, vendor and dot or underscore directories. If no file
or more than one declares the target, ciwatch warns, names the files it
found, and skips that download. Output says where each input went, and
--json adds fetched_to or fetch_error.

A failed listing or download is a warning and a JSON field
(artifacts_error, fetch_error), never a change to the exit code. Both
calls retry network errors with the shared backoff. A run with more than
100 artifacts is checked only for the first 100, and says so. The gh
runner gains Artifacts, DownloadArtifact and Toplevel; docs/json.md,
the README, the usage text and AGENTS.md are updated, and a golden file
records the new JSON.

Left from review:
none; the one minor finding (Toplevel marking a git error as a network
error, internal/gh/gh.go) was fixed.

Backlog:
- fuzztarget.Declaring stops the walk on any unreadable entry; it could
  skip them instead.
- fetchCrashes walks the checkout once per crash input; one walk could
  collect all the targets.
- Declaring doesn't skip node_modules or other large directories that
  Go doesn't ignore.
- Ctrl-C during --fetch-crashes exits 4 with no table, so inputs already
  written to disk go unreported.
- When --fetch-crashes skips or fails a download, there is no closing
  hint line saying what to do next.

Built in steps:
- test(cli): fuzz crash inputs from run artifacts
- feat(cli): fetch fuzz crash inputs from run artifacts
- fix(cli): test the missing-checkout path, rewrap usage
- fix(gh): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 23:03:02 -07:00
w3cjandClaude Sonnet 5.5 c282df82ff feat(cli): name the newer run for a cancelled run
A cancelled run is now reported once. For each completed cancelled run
on a branch, ciwatch makes one `gh run list --branch <branch>
--workflow <id> --limit 1` call for the newest run of the same workflow
on that branch. If that run is for another commit and was created after
the cancelled run, the table row ends in `(newer run <id> for <short
sha>)`, `--json` adds `newer_run` with `id` and `sha` to the run, and
stderr ends with one hint line per such run, in table order, giving the
command to watch it: `ciwatch <sha>`. Otherwise the run is reported as
plainly cancelled. A run created in the same second as the cancelled one
is not named. Exit codes are unchanged: 3 for a cancelled run, and 1 if
another run failed.

ciwatch no longer claims the newer run caused the cancellation and does
not follow chains. The `--follow` flag, `followed_from`, `superseded_by`
and the chain, time-window and event logic are removed with their tests
and fixtures, so `--follow` is now a usage error (exit 2). A lookup
that runs out of retries warns on stderr and leaves the run plainly
cancelled, and Ctrl-C during a lookup prints no table and is reported
once.

The usage text, README, docs/json.md and AGENTS.md describe the new
behaviour, and the report-doc test now looks inside nested objects so
`newer_run.id` and `newer_run.sha` are held to the schema doc.

Backlog:
- A cancelled run with an empty headBranch, such as one from a tag or a
  detached ref, gets no lookup, and no test covers that skip.
- When a cancelled run was re-run and the re-run is still in progress,
  nothing is named; a hint saying the commit is being re-run might help.

Built in steps:
- test(cli): hold cancelled runs to the newest-run lookup
- feat(cli): name the newer run for a cancelled run
- fix(cli): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 23:03:02 -07:00
w3cjandClaude Sonnet 5.5 66aca3d68e feat(cli): show the end of each failed step's log
For a failed job, ciwatch now shows the last 40 lines of each failed
step, whatever language or tool the step ran, instead of only the
failing Go tests. It fetches the job's log once with gh run view
--log-failed, which labels every line UNKNOWN STEP, so the new
internal/steplog package finds each step's lines by the step's
startedAt and completedAt from the jobs JSON. It strips gh's prefix,
the timestamp, a byte order mark, a trailing carriage return and both
forms of colour code, and ends a step at its last ##[error] line. A
failed job with no failed step in the jobs JSON shows the end of the
whole log as (job log); a failed step with no line in its window shows
(no failed step in the log).

The table puts "… N earlier lines" above a step's lines when some were
left out, and --json gives each step as name, lines and omitted, with
omitted 0 when nothing was left out. A log that can't be fetched keeps
its warning and the runs' exit code, shows (log unavailable) and sets
log_error, which replaces tests_error.

The Go test parser now runs only with the new --go-tests flag, and its
failing tests follow the steps in the table and in --json. The jobs
fetch also decodes each step's name, conclusion and times through
RunJobsWithSteps. The golden file, docs/json.md, the README and
AGENTS.md change with the output.

Backlog:
- Start each step's window after the previous step's completion, so the
  previous step's last lines from the same second aren't counted
  (internal/steplog).
- Treat a cancelled step in a timed_out job as the failed step, so it is
  named instead of falling back to (job log).

Built in steps:
- test(cli): hold failed-step log tails to the approved cases
- feat(cli): show the end of each failed step's log
- test(cli): drop a redundant check from the few-lines test
- fix(gh): polish from review

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 23:03:02 -07:00
w3cjandClaude Sonnet 5.5 60cc0091e2 feat(cli): make --json a versioned, documented contract
The --json output now carries a top-level "schema" field, currently 1,
beside "sha" and "runs". The encoder's types move out of cli.go into an
exported Report, Run, Job and Test in report.go, and both the JSON and
the table are written from that one structure, so every run and job in
the JSON has its row in the table. The output is otherwise unchanged:
no field changes its meaning, and the table prints exactly what it did
before.

docs/json.md describes every field of schema 1 with its type and when it
is present, and lists the exit codes 0 to 4. It says schema 1 freezes at
the first release. Tests hold the contract: one fails if the encoder
writes a field the document does not list, or the document lists a
field the encoder lacks or gives it another type; one checks that the
exit codes in the document match the constants; a golden file in
testdata/golden holds the output for the recorded run-list-failure
fixture byte for byte, so changing the output means updating it in the
same commit. AGENTS.md and the README point at the new files.

Backlog:
- Extend walkFields in report_test.go for bool, struct and map fields
  (such as a future newer_run object) before the later v1 tasks add
  them.
- Make TestExitCodesDocumented check the exit codes' meanings, not only
  their numbers.
- Make TestTableFromReport's shape-check message give each run's job
  count, not only the number of runs.

Built in steps:
- test(cli): hold --json to a versioned, documented contract
- feat(cli): version the --json output and draw the table from it

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 23:03:02 -07:00
w3cjandClaude Opus 5.5 096773b31c build: upgrade the factory pack to v0.5.0
v0.5.0 has designs state acceptance cases and non-goals that are approved with them, holds the review to that spec with everything else as backlog notes, stops and asks when review fixes go in circles, fixes minor findings in a polish step inside the run, and has fix runs wait for a final review before landing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 21:32:15 -07:00
w3cjandClaude Opus 5.5 9402dbc1a3 docs(agents): edit files with the editor tools
Every agent working on ciwatch edits files with its editor tools, not sed, perl, python or heredocs, as the factory's prompts now also say.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 21:16:19 -07:00
w3cjandClaude Sonnet 5.5 dadc040524 test(cli): check which jobs' logs a timed-out run fetches
TestRunTimedOutJobGetsFailingTests used a fake gh that answered the log
call with the jobs JSON, so it never checked that the log was fetched
for the timed-out job only, nor that the job's failing tests reached the
output. It now uses fakeWith with the gotestsum-failures.log fixture
from testdata/logs and two new gh fixtures, a timed-out run and its jobs
(the timed-out job and a skipped one). It checks the exact job ids whose
logs were fetched, which are the timed-out job's only, and that the
job's failing test appears in the output. The test was first shown
failing against an expectation that also listed the skipped job, then
corrected. No code outside the tests changed.

Left from review:
- internal/cli/cli_test.go: the rewrite no longer checks the --json
  output, where the old test checked that the timed-out job had a tests
  key and the skipped job had none.
- testdata/gh/run-view-44707997310-timed-out.json: this and
  run-list-timed-out.json are hand-edited copies of recorded run
  44707997310, not captured from a real timed-out run, and their names
  don't say so.

Built in steps:
- test(cli): check which jobs' logs a timed-out run fetches
- fix(cli): expect only the timed-out job's log in the timed-out test

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 0b3daf954a feat(cli): show the failing tests of failed jobs
For each failed or timed-out job in a completed run, ciwatch now runs
gh run view --log-failed --job, parses the log with testlog, and shows
only the failing tests with their lines instead of leaving you to read
the whole log. Runs still in progress are skipped, since gh serves no
logs for them.

The table gets one block per failed job after the tabwriter flushes, so
the free-form lines don't break the columns. A job that fails with no
tests found says so, and a package crash is labelled with the test that
was running. The table shows at most App.MaxTestLines lines of each
test, 20 by default, then a line saying how many more there are. In
--json a failed job gets a tests array, which is empty when nothing was
found, or tests_error when the fetch failed; --json keeps every line.

The fetch is retried like the jobs fetch, and after a network give-up
the remaining jobs get one try each. A failed fetch warns on stderr and
never changes the exit code. Ctrl-C while fetching exits 4 with no
table.

Runner.FailedLog is the one gh call without --json, because the log has
no JSON form; AGENTS.md notes the exception.

Left from review:
- internal/cli/cli_test.go: TestRunTimedOutJobGetsFailingTests uses a
  fake gh that answers the log call with the jobs JSON, so it doesn't
  check that the log was fetched for the timed-out job only. It should
  use fakeWith with a log fixture and check the job ids fetched.

Built in steps:
- test(cli): failing tests of failed jobs in table and --json
- feat(cli): show the failing tests of failed jobs

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 3c2ea0e621 fix(testlog): match build errors to their package, name crashed test
Build errors from several packages were held as one block of stray
lines and given to the first package's FAIL line, so a package could
get another package's errors, and the errors were dropped when an ok
line came between. The parser now reads each "# pkg" header and the
compiler output after it as a block of its own, which no marker
discards. A block continues only on compiler output (error lines,
indented notes, vet lines, "too many errors"), so a crash from the
next package stays with that package. A "[build failed]" or "[setup
failed]" line claims the block whose header names its package or its
external test package. For a "command-line-arguments" header, the
directory of a file in the error lines is matched against the package
path. The claimed block becomes that package's (package) failure.
Blocks nobody claims are kept in a separate (build) failure instead of
being dropped.

A crash during a verbose run also lost the name of the test that was
running. The (package) failure now has a RunningTest field holding it,
empty when unknown. The crash-detection rules are unchanged.

The fixtures are real go test output generated locally from throwaway
packages with compile errors and a panicking goroutine, in a temp
folder outside the repository, because devvm's CI has no build
failure. Paths were rewritten to /tmp/ciw and /go. Each finding has a
failing test written first, plus table cases for the edge cases.

Left from review:
- internal/testlog/testlog.go: a package that fails only because a
  dependency did not compile gets no (package) entry of its own, as
  the errors sit under the dependency's header.
- internal/testlog/testlog.go: dedupe can drop RunningTest when a go
  test entry repeats a gotestsum one or two entries are merged.
- internal/testlog/testlog.go: a lone "# word" line from a CI script
  opens a build block and can produce a false (build) failure.
- internal/testlog/testlog.go: the (build) failure is added after the
  whole log is read, not in log order.
- One commit on the branch is missing the Co-Authored-By trailer.

Built in steps:
- test(testlog): reproduce mixed build errors and unnamed crash test
- fix(testlog): split build errors by package, name the crashed test
- fix(testlog): address review findings

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 b1e44b9e0a fix(testlog): keep crashes, every summary and plain failures
The go test log parser lost or misplaced output in four cases, and
each is fixed. Indented result lines such as "--- FAIL: TestA/sub" or
"--- PASS:" inside a gotestsum "=== FAIL:" block now stay in that
block, so a panic after them is kept with the test instead of being
cut off. A crash with no "--- FAIL:" line of its own (a goroutine
panic, os.Exit, log.Fatal, or a verbose test that never finished,
ending in "FAIL<TAB>pkg") is reported as a failure named "(package)"
with its lines, rather than attached to the previous failure or lost.
A panic without "[recovered" after a failing test, or an unindented
non-panic line after it, closes that test, while a failing Example
keeps its unindented got/want lines and TestMain output after the
run's own "FAIL" is not taken for a crash.

Every gotestsum DONE line is now kept in Result.Runs in log order,
and Result.Summary is their total, so a job that runs gotestsum twice,
as devvm's scripts/test.sh does, counts both runs. A fixture recorded
from a devvmhq/devvm CI test job with both runs covers it.

Plain go test "--- FAIL:" entries are no longer all dropped when
gotestsum reported a failure. Only one that repeats a gotestsum entry
is dropped, matched by name and by package, allowing for gotestsum's
module-relative path. Plain entries from a separate go test step are
kept, as is one whose package can't be told apart.

Left from review:
- internal/testlog/testlog.go: build errors from several packages are
  held as one block of stray lines and given to the first package's
  "FAIL<TAB>pkg" line, so a package can get another's errors, or the
  errors are dropped if an "ok" line comes between. No recorded log
  shows a build failure.
- internal/testlog/testlog.go: the "(package)" entry doesn't name the
  test that was running when a verbose run died; takeOut moves its
  output without keeping the name.

Built in steps:
- test(testlog): reproduce four log parser gaps
- fix(testlog): keep crashes, sub results and every summary
- fix(testlog): address review findings
- fix(testlog): address review findings
- fix(testlog): address review findings
- fix(testlog): address review findings

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 f8767bf998 feat(testlog): parse failing tests out of a go test log
Add internal/testlog, a parser for the log of a CI job that ran go
test or gotestsum. Parse returns each failing test's package, name and
the lines that follow it, plus gotestsum's DONE summary with its test,
skipped, failure and error counts. It is not wired into the command
yet.

The parser takes off the gh job and step prefix, the Actions timestamp
and ANSI colour codes, including gh's "^[" form. It reads both
gotestsum's "=== FAIL:" blocks and go test's "--- FAIL:" lines, and
with -v it attaches the output under a test's "=== RUN" or "=== NAME"
line to that test. It drops SKIP and PASS blocks so their lines never
reach a failure. Lines that look like markers but belong to a message,
such as a diff's "--- Expected", and blank lines inside a message are
kept. Panics are kept whole, including their blank lines. A "test timed
out" panic becomes one failure for each test it lists as running.
Package-level failures are named "(package)". When gotestsum and go
test report the same failure, one entry is kept, with the most lines.
Lines are read without a length limit, and read errors are returned
with context.

Tests use recorded logs from devvm's CI (Linux and macOS failures and a
passing run) and small logs for go test output, in testdata/logs.
AGENTS.md lists the new package and the logs.

Left from review:
- internal/testlog/testlog.go: an indented "--- FAIL:" line inside a
  gotestsum block starts a go test entry, so the lines after it, such
  as a panic, are lost from that test.
- internal/testlog/testlog.go: in plain go test output, a crash with no
  "--- FAIL:" line (a background goroutine panic, os.Exit, log.Fatal)
  is added to the previous failure or lost.
- internal/testlog/testlog.go: only the last DONE line becomes the
  Summary, so a job that runs gotestsum twice (unit tests, then e2e)
  reports only the second run.
- internal/testlog/testlog.go: when a log has any gotestsum failure,
  all go test "--- FAIL:" entries are dropped, including those from a
  separate plain go test step.

Built in steps:
- test(testlog): add failing tests for the go test log parser
- feat(testlog): parse failing tests out of a go test log
- fix(testlog): report read errors with context and check counts
- fix(testlog): address review findings
- fix(testlog): address review findings
- fix(testlog): address review findings

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Opus 5.5 94232b0162 build: upgrade the factory pack to v0.4.0
v0.4.0 gives each review round the branch's earlier findings and rates only problems on input the project really sees as major, and adds the review workflow for continuing a run whose review hit its cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 0982ecd16a fix(cli): say what --follow drops and why it didn't follow
With --once --follow, ciwatch moved on from a commit as soon as a
cancelled run had a newer push behind it, and the commit's runs still in
progress were dropped without a word. And when a cancelled run's newer
commit had already been watched, nothing said why ciwatch did not follow
it, so the run showed as superseded with no explanation.

With --once, each run still in progress is now named on stderr before
ciwatch moves on, and the line that says it is following is printed by
the caller after that. A newer commit that was already watched gets its
own stderr line. The README now says exactly what --once --follow does:
it follows at once, and the dropped runs are not in the table.

The comment on supersededBy said the event filter excludes a fork's pull
request, which holds only when the cancelled run is a push; it now says
so, and the long line is wrapped.

The fixtures run-list-failure.json, run-list-success.json and
run-list-in-progress.json had been edited by hand to add fields and
lacked headBranch and headSha. They are re-recorded with the current
--json field list from the same devvmhq/devvm runs, using read-only gh
calls. Only the in-progress statuses are derived: run 45017063720 has
since completed, so its record is set back to in_progress with no
conclusion. The decoding test now expects the recorded values,
including the schedule event of the Fuzz run.

Left from review:
- internal/cli/follow_test.go: the already-watched test only checks that
  "already watched" appears on stderr, not the run, the commit or that
  ciwatch did not follow back, and no test shows a plain chain stays
  silent.
- internal/cli/follow_test.go: the in-progress test matches any line
  with "in progress" and "Docs", not the run ID or commit, and does not
  check that the dropped run is missing from stdout.
- internal/cli/cli.go: the dropped-run line gives no hint to drop
  --once to wait for the run, as the other in-progress line does.

Built in steps:
- test(cli): cover --follow dropping runs and silent skips
- fix(cli): say what --follow drops and why it didn't follow

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 23b1428833 feat(cli): follow a run that a newer push cancelled
When a run is cancelled because a newer commit on the same branch
started its own runs, ciwatch now says so and names that commit. The
table row ends in "(superseded by <sha>)", --json adds superseded_by to
the run, and without --follow the last stderr line is a hint to rerun
with --follow. With --follow ciwatch watches the newer commit instead,
keeps following if that one is cancelled by a still newer push, stops
after 20 commits with a warning, and never goes back to a commit it has
already watched. The JSON sha is the last commit watched and
followed_from lists the ones left behind. Nothing prompts.

The newer push is the first run of the same workflow, with the same
event, on the same branch, for another commit, created after the
cancelled run and no later than a minute after it stopped. gh is asked
for that window by workflow ID, since a name can be shared or be a file
path. A run cancelled by hand with a push only long after stays plainly
cancelled, as does a run replaced by a later run of the same commit, and
a full page of 20 runs in the window counts as uncertain because the
first push may be cut off. A lookup that runs out of retries warns and
leaves the run cancelled, as the jobs fetch does, and Ctrl-C during the
lookup stops without a table.

gh run list now asks for the workflow ID, update time, head branch, head
commit and event, and a new BranchRuns call lists a branch's runs in a
window. The recorded fixtures gained those fields, and new ones record
superseded, chained, by-hand and newer-commit histories.

Left from review:
- README.md: says ciwatch moves on only after every run of the current
  commit has completed, but with --once --follow it follows as soon as a
  cancelled run is found, dropping runs still in progress.
- internal/cli/cli.go: with --follow, a run cancelled by a commit
  already watched shows "superseded" but nothing on stderr says why
  ciwatch did not follow it.
- testdata/gh/run-list-failure.json, run-list-success.json and
  run-list-in-progress.json: edited by hand to add fields, so they lack
  headBranch and headSha and are no longer purely recorded output.
- internal/cli/cli.go: the supersededBy comment says the event filter
  excludes a fork's pull request, which only holds when the cancelled
  run is a push; one line of it is also too long.

Built in steps:
- test(cli): cover following a run a newer push cancelled
- feat(cli): name and follow a run that a newer push cancelled
- fix(cli): print the usage on real lines and tidy the list helper
- fix(cli): address review findings on following a cancelled run
- fix(cli): address review findings on newer-push lookup
- fix(cli): address review findings on newer-push lookup
- fix(cli): address review findings on following a newer push

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 4efed9cecd fix(cli): tighten network-error retries and document the jobs fallback
Three findings from the review of the retry work. markNetwork searched
the whole error text, so markers were also looked for in the URLs gh
quotes. It now removes quoted URLs first and matches the markers only in
gh's own message. Once one run's gh run view ran out of retries, the
remaining runs got a single try with no backoff for the rest of the
fetch, even after a later call succeeded. The full retries now come back
as soon as a jobs call succeeds. The README's Usage section now says
that a jobs fetch that runs out of retries warns on stderr, shows (jobs
unavailable) and keeps the runs' exit code instead of exiting 4.

Each behaviour finding has a test that failed first.

Left from review:
The URL finding can't happen with real gh output, because every marker
contains a space and a quoted URL contains none, so a repository named
no-such-host was never marked. The regex is a guard for a case that
hasn't been seen, and its test builds the error inline with spaces in
the URL instead of using a recorded file, and has no positive case
(internal/gh/gh_test.go).
Full retries come back only after a jobs call succeeds, not after a
non-network failure such as a 404, which also shows GitHub answered, so
a short blip on a later run still gets no retry (internal/cli/cli.go).

Built in steps:
- test(cli): reproduce retry misclassification and stuck no-retry mode
- fix(cli): retry only real network errors, and again after a success

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Opus 5.5 45e0fb056e build: upgrade the factory pack to v0.3.0, with mise run squash
v0.3.0 adds bin/squash, which turns each task's stacked commits and merge into one commit before a push, keeping the stacks on the task branches. mise run squash runs it, and AGENTS.md says to squash before every push.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 8c11dca7bc feat(cli): retry gh through network errors with backoff
A gh call that fails with a network error, such as a dial failure or a
missing host, or with a temporary HTTP 502, 503 or 504 from GitHub, used
to end the watch with exit 4 at once, throwing away a watch that might
have run for minutes. Both gh run list and gh run view are now retried
with capped exponential backoff, in the watch and with --once. The wait
starts at 1s, doubles and stops growing at 30s, for up to 8 retries per
call, and each retry writes a line to stderr naming the call, the kind
of error and the cause. Only when the retries run out does ciwatch give
up and exit 4. Other errors, such as HTTP 401 and 404, and a cancelled
context still fail at once, and Ctrl-C during a backoff wait stops
immediately.

The gh package marks these failures with ErrNetwork and ErrTemporary,
matched on the error text in RunList and RunJobs so it also works when
tests replace Exec. The marked error keeps gh's own text. The cli
package wraps both calls in a generic retry helper driven by new
Backoff, MaxBackoff and Retries fields on App, set to 1s, 30s and 8 by
New. The clock is the injected one, so no test sleeps. The README
describes the retries.

When gh run view runs out of retries, the run list was already read, so
the exit code still comes from the runs, with a warning and (jobs
unavailable) in the table. Once one run's jobs have given up, the
remaining runs get a single try each instead of a full backoff apiece.
Existing tests that used HTTP 502 as an error that is not retried now
use HTTP 401. The recorded stderr fixtures are in testdata/gh.

Left from review:
- internal/gh/gh.go: markNetwork searches the whole error text,
  including the request URL, so a non-network error whose URL contains a
  marker, such as a repository named no-such-host, would be retried.
- internal/gh/gh.go: the marker "error connecting to api.github.com"
  matches only github.com, so a network error against a GitHub
  Enterprise host is not retried.
- internal/cli/cli.go: after one run's jobs give up, Retries stays 0 for
  the remaining runs even if a later call succeeds and the network is
  back.
- internal/cli/cli.go: running out of retries while listing jobs keeps
  the runs' exit code instead of exiting 4, and the README doesn't say
  so; the choice is worth confirming with the task owner.
- internal/cli/cli_test.go: no test cancels during a gh run view backoff
  wait, only during a gh run list one.

Built in steps:
- test(gh,cli): failing tests for retrying gh through network errors
- feat(cli): retry gh through network errors with backoff
- test(cli): cover gh run view running out of retries
- fix(cli): address review findings

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 21:10:47 -07:00
w3cjandClaude Sonnet 5.5 f32ed9ef08 fix(cli): wait out the watch grace period for old commits
The grace period counted from the earliest run's createdAt, so a
commit whose runs had finished long ago exited on the first list and
missed the runs of a re-push. Comparing GitHub's createdAt with the
local clock also let a local clock running ahead end the period before
the first poll.

The end of the period now comes from graceEnd. If a run was created
within the grace period before ciwatch started, it counts from the
earliest such run, as before. Otherwise it counts from ciwatch's own
start, so an old commit waits the grace period once and a re-push
shows its new runs. It never ends before one interval has passed
since the start, whatever the clocks say. The README's usage paragraph
says so.

TestWatchCancelledWhileWaiting passed even without the select on
ctx.Done(), because the fake clock's channel was already ready. The
fake clock can now hold its wait open, so the test fails without that
case. Tests that used old recorded runs and expected a single list now
pass --once or expect the grace wait.

Left from review:
- internal/cli/cli_test.go: TestWatchRepushedCommitFindsNewRuns gives
  the new run the same old createdAt as CI, so a run created after
  ciwatch started, which moves the end of the period later, is not
  tested.
- internal/cli/cli_test.go: TestWatchGraceWaitsAnIntervalWhateverTheClocks
  uses a two-minute skew that passes through the old-run path, so it
  doesn't exercise the one-interval minimum. A skew between Grace
  minus Interval and Grace would.
- internal/cli/cli_test.go: TestWatchCancelledWhileWaiting waits for
  the fake clock outside the failsafe select, so it hangs rather than
  fails if watch returns before it waits.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:57:38 -07:00
w3cjandClaude Sonnet 5.5 c26197675b fix(cli): count the watch grace period from ciwatch's start when old
The grace period counted from the earliest run's createdAt. For a
commit whose runs finished long ago, that deadline was already past,
so ciwatch exited on the first list and missed the runs of a re-push.
Comparing GitHub's createdAt with the local clock also let a local
clock running ahead end the period before the first poll.

The end of the period now comes from graceEnd. If a run was created
within the grace period before ciwatch started, it counts from the
earliest such run, as before. Otherwise it counts from ciwatch's own
start, so an old commit waits the grace period once and a re-push
shows its new runs. It never ends before one interval has passed since
the start, whatever the clocks say. The README's usage paragraph says
so.

Tests that used old recorded runs and expected a single list now use
--once, or expect the grace wait.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:56:46 -07:00
w3cjandClaude Sonnet 5.5 312c3e5479 test(cli): failing tests for watch grace period findings
The grace period counts from the earliest run's createdAt, so a commit
whose runs all finished long ago exits at once and misses the runs of a
re-push. Tests for an old commit and a re-pushed commit expect ciwatch
to wait the grace period once from its own start, and fail because it
lists a single time.

The deadline also compares GitHub's createdAt with the local clock. A
test with a local clock two minutes ahead expects at least one interval
to pass before the grace period can end, and fails because it exits on
the first list.

TestWatchCancelledWhileWaiting passed even without the select on
ctx.Done(), because the fake clock's channel was already ready. The
fake can now hold the wait open until the test cancels, so the test
fails with a timeout when that case is removed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:55:54 -07:00
w3cjandClaude Sonnet 5.5 b31da25cbe feat(cli): watch runs until they are all done
ciwatch now polls gh run list until every run for the commit has
completed and a grace period after the push is over, so runs that start
a little late are included. Each time a run appears or changes it
writes one progress line to stderr, then it fetches the jobs once and
prints the table or the JSON document as before, so stdout stays a
single document that can be piped. --once keeps the single check, with
no progress lines, and its in-progress message now hints to drop
--once.

The grace period counts from the earliest run's createdAt, or from when
ciwatch started if there are no runs yet, so a commit whose runs all
finished long ago exits at once. Running out the grace period with no
runs, a gh failure partway through, or Ctrl-C exits 4 with no table.
The poll interval (10s), the grace period (60s) and the clock are
fields on App, so the tests control them and none sleeps on the real
clock. gh.Run gains Created, decoded from the createdAt that RunList
now asks for, and the recorded run lists carry each run's real
createdAt. The README documents the usage and --once.

Left from review:
- internal/cli/cli.go: the grace period counts from the earliest run's
  createdAt, which is not the push. A new push of a SHA that already has
  old finished runs exits at once and can miss the new runs.
- internal/cli/cli.go: the deadline compares GitHub's createdAt with
  the local clock, so a local clock running a minute or more ahead ends
  the grace period before the first poll.
- internal/cli/cli_test.go: TestWatchCancelledWhileWaiting would still
  pass without the select on ctx.Done(), because the fake clock's
  channel is already ready and the fake gh fails on a cancelled context.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:54:49 -07:00
w3cjandClaude Sonnet 5.5 9bb02b25e0 test(cli): cover watch edge cases found in self-review
The self-review found no behaviour that departs from the design, but
three paths had no test. Add tests that runs without createdAt count the
grace period from when ciwatch started, that --once with no runs checks
once and says so, and that a failing first list exits 4 without a
table. Also drop a needless local alias of the --json option in Run.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:49:48 -07:00
w3cjandClaude Sonnet 5.5 5d8a44dced feat(cli): watch runs until they are all done
ciwatch now polls gh run list until every run has completed and a
grace period after the push is over, so runs that start late are
included. It writes one progress line to stderr for each run that
appears or changes, then fetches the jobs once and prints the table or
JSON as before. --once keeps the single check, with no progress lines,
and its in-progress message now hints to drop --once.

The grace period counts from the earliest run's createdAt, or from when
ciwatch started if there are no runs, so an old finished commit exits
at once. Running out the grace period with no runs, a gh failure, or
Ctrl-C exits 4 with no table. The poll interval, the grace period and
the clock are fields on App, defaulting to 10s, 60s and the real time.
gh.Run gains Created, decoded from the createdAt that RunList now asks
for. The README documents the usage.

Two older tests that check stderr is quiet now pass --once, since
watching writes progress there.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:49:16 -07:00
w3cjandClaude Sonnet 5.5 3ddee3a39d test(cli): failing tests for watching until runs are done
Add the tests for polling until every run completes: polls until all
runs complete, grace period finds a late run, stops when the grace
period ends, an old commit does not wait, no runs after the grace
period exits 4, progress lines only on change, --json stays one
document, cancelling while waiting, a list error mid-watch, and --once
not waiting. Add TestRunListDecodesCreatedAt in gh, and createdAt to
the recorded run lists, taken from gh run view.

The fake helpers now set a fake clock, an interval and a grace period
on the App, and play a different gh run list output per call. The
existing in-progress tests pass --once.

Every new test fails now. The cli tests do not compile because
App.Clock, App.Interval and App.Grace do not exist, and the gh tests do
not compile because gh.Run has no Created field. Once they compile, the
args checks fail too, since gh run list does not yet ask for createdAt.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:48:29 -07:00
w3cjandClaude Sonnet 5.5 08af5cc1a9 fix(cli): show when a run's jobs couldn't be listed
When gh run view failed for a run, ciwatch only warned on stderr and
left that run's jobs empty, so --json showed an empty jobs array exactly
like a run with no jobs and the table showed nothing. A reader of stdout
alone couldn't tell the two apart.

The run now keeps the error. In --json it appears as a jobs_error string
on that run, omitted when empty, and the table prints an indented
(jobs unavailable) row under it. The exit code still comes from the runs
alone.

Two tests also counted from the rows they had built instead of from
ciwatch's output, so they would have passed with wrong output.
TestRunPrintsTable now counts the table's rows from stdout, and
TestRunInProgressPrintsJobs counts the in_progress and queued jobs from
stdout.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:43:20 -07:00
w3cjandClaude Sonnet 5.5 4de2984351 fix(cli): show when a run's jobs couldn't be listed
When gh run view failed for a run, ciwatch only warned on stderr and
left the run's jobs empty. The output then looked the same as a run
with no jobs, so a reader of stdout couldn't tell them apart.

The run now keeps the error. In --json it appears as a jobs_error
string on that run, omitted when empty, and the table prints an
indented (jobs unavailable) row under it. The exit code still comes
from the runs alone.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:42:48 -07:00
w3cjandClaude Sonnet 5.5 d46cdf5638 test(cli): failing tests for showing when a run's jobs are unavailable
When gh run view fails for a run, ciwatch warns on stderr but prints
that run with no jobs, so --json shows an empty jobs array exactly like
a run that has none, and the table shows no sign of the failure. A
reader of stdout alone can't tell the two apart.

TestRunJSONShowsJobsError expects a jobs_error string on the run whose
jobs failed and none on the others, and TestRunJobsErrorKeepsRunExitCode
now expects an indented (jobs unavailable) row under that run. Both
fail until the failure is shown in the output.

TestRunPrintsTable and TestRunInProgressPrintsJobs now count rows and
the in_progress and queued jobs from stdout instead of from the
expected rows the test builds, so wrong output can't pass them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:42:36 -07:00
w3cjandClaude Opus 5.5 7f327c8179 build: upgrade the factory pack to v0.2.1
v0.2.1 leaves recorded data, such as the gh fixtures in testdata, out of the diff the review and message prompts get, which made the last task's run cost three times the one before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 11:41:53 -07:00
w3cjandClaude Sonnet 5.5 b7fc721630 feat(cli): show each run's jobs in the table and --json
A failed run did not say which job failed. ciwatch now runs gh run
view <id> --json jobs once for each run it lists, one after another,
and shows each run's jobs and their conclusions under it. The exit
code is still worked out from the runs alone, so a failed job in a
successful run (continue-on-error) does not change it.

The gh package gains a Job type and Runner.RunJobs, which decodes the
jobs and ignores their steps and timestamps. The table prints each job
indented under its run. With --json every run has a jobs array, which
is empty rather than null when a run has no jobs. Jobs of a run still
in progress show their current status with an empty conclusion.

If gh run view fails for one run, stderr names the run and the error,
and that run is shown without jobs. If the context is cancelled while
jobs are being fetched, ciwatch prints the error, writes nothing to
stdout and exits 4.

The tests use recorded gh run view output in testdata/gh. The
in-progress jobs fixture, run-view-45017063720-in-progress.json, is
derived rather than recorded: it is a finished run with job statuses
edited to in_progress and queued and conclusions emptied, and it is
consistent with run-list-in-progress.json.

Left from review:
- internal/cli/cli.go: in --json a run whose jobs could not be listed
  shows "jobs": [], the same as a run with no jobs, so only stderr
  tells them apart. The table has the same gap.
- internal/cli/cli_test.go: the row count in TestRunPrintsTable and the
  in_progress and queued count in TestRunInProgressPrintsJobs are
  taken from the expected rows, not from ciwatch's output, so they
  check the fixtures only. checkTable still checks the real output.
- internal/cli/cli.go: jobs are fetched one run at a time, up to 100
  calls before anything prints. The design leaves concurrency out of
  scope.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:40:26 -07:00
w3cjandClaude Sonnet 5.5 e1c625210c refactor(cli): report the real error when a jobs fetch is cancelled
The self-review found that the cancellation check ran even when the
jobs fetch succeeded, and it printed the context's error instead of
the fetch's. It now acts only when the fetch failed and the context
is done, and prints the fetch's error.

TestRunCancelledWhileFetchingJobs now also checks that stderr names
the cancellation and has no per-run warning.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-22 11:38:15 -07:00