Skip to content

feat(scripts): weekly flaky-test scan and its spec (T801 t2) - #192

Merged
bketelsen merged 2 commits into
mainfrom
lucilla/flaky-test-scan
Nov 4, 2026
Merged

bketelsen merged 2 commits into
mainfrom
lucilla/flaky-test-scan

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Plan T801, task t2 (section "Gap 2: weekly flaky-test scan").

Adds scripts/flaky-scan.mjs (with scripts/lib/flaky-scan.mjs and test/flaky-scan.test.mjs) and the spec docs/specs/flaky-test-scan.md, indexed in docs/README.md and linked from the Observe station of docs/design/quality-loop.md.

  • Detection: a job (same workflow file, same job name) that concluded failure or timed_out and has a later success on the same head SHA (a later attempt or a later run) is 1 flaky event. Jobs are read only for (workflow, SHA) groups with 2+ attempts, deduped by job id. The test name comes from the failed job's log (Go, TAP, pytest), else the failed step's name.
  • Issues: 1 per key repo/workflow/job/test, with a hidden marker <!-- flaky-scan key=… -->. An open issue with the key gets 1 comment with the new events only (or nothing). Caps: 3 new issues per repository, 15 per run.
  • Safe by default: a dry run makes only GET calls. makeGh refuses every write without --apply, and with it allows only POST repos/R/issues and POST repos/R/issues/N/comments. No labels, no reruns, no workflow edits.
  • --out FILE: JSON schema_version 1 with repos[].runs, rerunAttempts, flaky[], for the daily audit's Q1 (t12).
  • Runs locally from a weekly Pocket schedule (no Actions cron, so no new cross-repository secret).

Risk tier

Risk tier: 2 — new tooling that can open issues and comments with --apply; nothing runs it in CI or on a schedule yet, and the default is read-only. No workflow, policy, or authority file changes.

Docs housekeeping

  • New docs started from their category's TEMPLATE.md
  • Every new doc indexed in docs/README.md
  • Cross-links added in both directions (spec ↔ design/quality-loop.md)
  • Conformance aliases (ADR-0029) untouched

Verification

  • node scripts/check-docs.mjs green (90 docs, 898 links)

  • make ci green locally: 85 tests pass (11 new)

  • Real dry run, read-only, --days 14 on frostyard/frostnotes, bketelsen/pi-pocket-team, frostyard/snosi (3 min 31 s, exit 0): 10 flaky keys found, for example bketelsen/pi-pocket-team/ci.yml/Test/Run the tests (run 40980615501: attempt 1 failure, attempt 2 success, 1 SHA). snosi gave 5 keys: 3 open, 2 skip (cap). snosi reached the 1,000-run API limit in 14 days; the spec says so (weekly is ~500).

  • make ci green at head 185fc5c (rebased on main 20fd8a3): 110 tests pass, 13 in test/flaky-scan.test.mjs.

Revert test (scratch worktree at 185fc5c, laterSuccess in detectFlakyEvents set to false, node --test --test-reporter=tap test/flaky-scan.test.mjs): exit 1, 8 of 13 fail:

not ok 1 - detection: rerun and later run on the same SHA
ok 2 - detection: cross-SHA, success-then-failure, and standalone attempts
ok 3 - same-attempt success does not create a flaky event
not ok 4 - dedupe keeps the first job id
not ok 5 - dry run records no write and action is open
not ok 6 - open marker comments only new events and an already reported event gives none
not ok 7 - comments read failure keeps completed opens and preserves the 15-run cap
not ok 8 - caps: 5 keys in one repo and 15 opens plus 3 skips across 6 repos
ok 9 - guard rejects dry-run writes and unknown apply writes
ok 10 - test name parsing: Go, TAP, pytest, and step fallback
not ok 11 - scanner log fetch throws and uses the failed step name
not ok 12 - --out JSON shape is pinned in the CLI output
ok 13 - profile parsing and CLI usage

Tests 2 and 3 are negative cases (0 events) that a "no event" revert cannot fail; they were proven separately: grouping by workflow only (no SHA) fails test 2, and dropping the later-attempt-or-run rule fails test 3.

Cross-review

Coder github-copilot/mai-code-2-flash (code), claude-opus-5.5 (docs); reviewer openai/gpt-6.1-sol.

  • Initial review at 469ea5c: Not ready, 3 blockers, all accepted and fixed in 185fc5c: R1 a comment-read failure dropped a repository's done actions, so the 15-per-run cap could break (now kept, with a test of 15 POSTs after the failure); R2 a success in the same attempt counted (now only a later attempt or run); R3 the cross-SHA and success-then-failure tests held no real jobs (now they do, plus a fake-gh scanner case).
  • Re-review 1 at 185fc5c (base 20fd8a3): Ready, Blocking: none. Rebase resolution checked (both spec index lines kept).

After merge (outside the graph): Lucilla adds the weekly schedule (Monday 05:30 America/New_York) writing ~/agents/odrade/reports/<date>-flaky-scan/scan.json, runs it once in dry-run mode, then with --apply. This unblocks the CI-reruns metric of t12.

Add scripts/flaky-scan.mjs: it finds GitHub Actions jobs that failed and
then passed on the same head SHA, and files 1 issue per flaky test
(1 comment with new events on an open issue with the key). Dry run by
default; only --apply writes, and a guard allows only the 2 issue writes.
Caps: 3 new issues per repository, 15 per run. --out writes the JSON that
the daily audit's Q1 reads for CI reruns.

Plan T801, task t2 (Gap 2).
… actions on a comment read failure

Cross-review R1-R3: a comments read failure no longer drops the
repository's done actions (the 15-per-run cap held only by luck), a
success in the same attempt is no flaky event, and the cross-SHA and
success-then-failure tests now hold real jobs.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 4, 2026
@bketelsen
bketelsen merged commit 8a770b5 into main Nov 4, 2026
3 checks passed
@bketelsen
bketelsen deleted the lucilla/flaky-test-scan branch November 4, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants