Skip to content

ci(audits): one proactive audit a night, with quota gate and carry-over - #5404

Merged
kovtcharov-amd merged 8 commits into
amd:mainfrom
kovtcharov:ci/audit-rotation
Oct 30, 2026
Merged

kovtcharov-amd merged 8 commits into
amd:mainfrom
kovtcharov:ci/audit-rotation

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

The proactive Claude reviews were failing about half the time, and each failure was lost. The code and security audits failed 5 of the last 10 nights, and the doc walkthrough failed 4 of its last 5 runs. Running three audits every night used up both Claude accounts' weekly limit by mid-week, so most of those runs stopped before reviewing anything and blamed a missing file. The next run never went back for the missed work. Now one audit runs each night between 2 and 4am Pacific, so each audit runs every third night. Each run checks Claude is available before starting, and says plainly when it isn't. It picks up everything since its last successful run, starts from what merged since then, and checks against the bug types past audits missed. The dedup pass no longer re-files duplicates that were already closed: 34 of them were closed alongside this change.

Test plan

  • python -m pytest tests/unit/test_audit_synthesis_prep.py tests/unit/test_audit_history.py tests/unit/test_audit_rotation.py tests/unit/test_require_claude.py tests/unit/test_recent_changes.py tests/unit/test_miss_analysis.py tests/unit/test_claude_audit_workflow_contract.py tests/unit/test_closed_duplicates.py -q passes (277 tests)
  • After merge: gh workflow run claude-audit-rotation.yml -R amd/gaia -f dry_run=true. The summary names tonight's audit and the next five nights, and nothing is dispatched.
  • After merge: gh workflow run claude-nightly-audit.yml -R amd/gaia -f dry_run=true. Check the preflight summary: the mode, a window reading "since this audit's last successful run", the Claude probe passing, and "Recent changes read first". At the end, "Dry run confirmed: no issue created".
  • After merge: gh workflow run claude-weekly-doc-walkthrough.yml -R amd/gaia -f doc_filter=docs/quickstart.mdx -f dry_run=true. The guide is walked, "Using bash.exe from …" appears, and the dry-run watermark step passes (it crashed before this change).
  • After merge: gh workflow run claude-security-audit.yml -R amd/gaia. Semgrep scans tui, installer and .github/workflows, and the SARIF uploads.
  • First scheduled night (10:13 UTC): the dispatched run is titled "… rotation night N", files at most what's new, and an issue it files carries audit-cluster / audit-key markers.
🔍 Technical details

Root causes (last ~2 weeks)

  • Code and security audits, Oct 7/10/12/13/14/17: every lens returned is_error in under a second with "You've hit your weekly limit". The primary account ran out on Oct 10, the secondary on Oct 12–14, both on Oct 17. The account switch fired correctly; both accounts were spent.
  • Walkthrough Oct 12: same weekly limit on every guide, queued over 57 hours on the Strix Point pool. Oct 5 and Oct 19: the xsj-aimlab-stxp images have no Git for Windows (only WSL's bash.exe). Also on Oct 5, the executor step's GITHUB_OUTPUT got UTF-16 appended by start-lemonade.ps1 under PowerShell 5.1 >>. Sep 21–28: Application Control blocked LemonadeServer.exe and the job landed on Strix Halo machines; both were fixed by the move to the xsj-dispatch pool on Oct 1.
  • The walkthrough's two dry-run steps had a literal \n mid-command, so dry_run=true always failed.

Schedule. One cron, 13 10 * * * = 03:13 PDT / 02:13 PST. Only 10:00–11:00 UTC is inside 2–4am Pacific in both seasons. Slot = days since epoch mod 3 → code audit, security audit, doc walkthrough. The audits lost their own crons; workflow_dispatch still runs any of them on demand. Deep code sweep: whenever the last successful one is over 8 days old (every third turn, retried on the next turn if it fails).

Dedup bug. The 2026-09-07 burst (78 issues) predates the dedup pass: the run checked out main 7 hours before #3310 merged. Three duplicate pairs still got through after #3310 (#3832/#3471, #3825/#3414, #5199/#4875). Backlog matching compared findings against issue titles only, so a same-section duplicate worded differently scored 0.05–0.15, below the 0.18 threshold. Now matching includes each audit issue's own markers (all 13 known pairs rank 1st–2nd). Closed duplicates hand their keys to the open canonical, so consolidating into #1077/#4331 does not trigger re-filing. Both syntheses share the claude-audit-issue-filing concurrency group. The security audit files to private code scanning, not issues, so it cannot duplicate the other two.

Closed as duplicates (34): into #4331: #3204 #3413 #3422 #3439 #3466 #3476. Into #1077: #3173 #3412 #3418 #3426 #3429 #3430 #3433 #3437 #3442 #3449 #3454 #3455 #3464 #3468 #3475 #3477 #3482. Into #3198: #3436 #3462. Others: #3425→#3169, #3457→#3195, #3440→#3180, #3486→#3064, #3471→#3832, #3414→#3825, #3434 #3485→#3219, #5199→#4875.

Miss-analysis (merged fix PRs, Jun 21–Oct 19). 29 of 1005 (3%) closed an issue an audit filed first. Missed, by title: no deadline 90 (#5346 #5384 #5380), release/CI ordering 71 (#5127 #5147), Windows behaviour 38 (#5018 #5377), dishonest status 36 (#5112 #5317), shared state across processes 34 (#5337 #5282 #5378), model output handling 27 (#4973 #5103), doc drift 27, cold start / non-default setup 26 (#4951 #5130). About 380 more were Agent UI/TUI or agent-behaviour fixes, which a static read rarely catches. Noise: of the audit issues closed as duplicate or not planned, 31 were duplicates of #1077, 12 of the test-coverage umbrella #2988, and 6 each of #4331, #3149, #3308 and #2922. What changed: scripts/audit/missed_bug_classes.md has a checklist per class and a "Don't report" list, and all three prompts read it at run time. The code audit gets a deterministic list of calls with no deadline. The security audit's semgrep run and worklist now cover TypeScript, Go, the installer and the workflows. scripts/audit/miss_analysis.py refreshes the evidence monthly.

Recent changes. Each audit's first job writes recent-changes.md: first-parent commits since the commit its last successful run checked out, read from the run history, with PR title, a short body excerpt and the paths each touched, capped at 30 KB. If that commit is unknown it covers 3 days and says so.

@github-actions github-actions Bot added documentation Documentation changes installer Installer changes devops DevOps/infrastructure changes tests Test changes labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

The three proactive Claude audits now take turns, one per night, instead of all running every night and exhausting the weekly Claude quota mid-week. Each run checks the account before starting work and resumes from its last successful run, so a lost night's commits and guides are picked up on the next turn rather than skipped. The design holds up, and nothing blocks the merge.

One gap: the security audit's final step wasn't given the "stop if Claude is out of quota" guard that the other two audits got. On a night with no quota it still fails, but with the misleading "the audit did not run" error the PR is meant to replace. It's a one-line fix.

Real-world evidence

N/A: this PR only changes CI workflows, scripts and tests, and no evidence bundle was produced. The changes only run on GitHub Actions after merge, so the verdict rests on static review. pytest wasn't available on this review runner and no CI test results were visible, so the new unit tests weren't run here either. The PR's post-merge dry-run checklist is the right way to confirm it on GitHub Actions.

🔍 Technical details

🟢 The security audit's synthesis job isn't gated on preflight success (.github/workflows/claude-security-audit.yml:494)
The code audit and the walkthrough both changed their synthesis if: to require needs.<preflight>.result == 'success'. The security audit didn't. When the probe fails, preflight fails, the audit matrix is skipped, and synthesis still runs (!cancelled(), and skip is not 'true'). It then fails at "Only 0/3 lenses produced findings — the audit did not run", a second error that hides the quota message. It doesn't upload an empty SARIF, so no alerts are cleared; the cost is a confusing failure.

    if: >-
      github.repository == 'amd/gaia' && !cancelled() &&
      needs.preflight.result == 'success' && needs.preflight.outputs.skip != 'true'

🟢 A hand dispatch with target_ref gets recent changes from main
recent_changes.py runs in preflight against the default checkout. The lens job then checks out target_ref, so during a backtest recent-changes.md describes commits that may not exist in the tree under audit. This is harmless for rotation nights. A line in the lens prompt saying to ignore the file when target_ref is set would avoid confusing a backtest.

Strengths

  • Using the run history as the state store works well: run-name's "rotation night N", the mode in the lens job names, and the walkthrough job names together make the window and the guide rotation reproducible without a state branch. Hand dispatches and dry runs are kept out of that history.
  • audit_history.py and recent_changes.py fail loudly when gh or git can't answer ("Refusing to guess tonight's audit scope…") instead of falling back to a fixed window. Removing || echo 0 from the high-severity count follows the same rule.
  • The PortableGit fallback is pinned and checksum-verified, and it fails with the runner name when Application Control blocks it. Both broken \n dry-run commands are fixed, and both synthesis jobs share one concurrency group so the two filers can't race on the backlog.

The code and security audits failed 5 of the last 10 nights and the doc
walkthrough 4 of its last 5 runs, mostly because three audits spent both
Claude accounts' weekly cap mid-week. Every lens was then refused in under a
second and the runs blamed a missing artifact, and each failed night's work
was silently skipped.

- claude-audit-rotation.yml is now the only scheduler: one audit a night at
  10:13 UTC (2-3am Pacific all year), picked by epoch-day mod 3, so each
  audit runs every third night. Adding an audit is one line in
  scripts/audit/audit_rotation.py.
- Each audit probes Claude once before any lens or self-hosted job and stops
  with the account and reset time in its summary (require_claude.py).
- Each audit scopes itself from its own last successful rotation run: the
  code audit reviews everything since then (deep sweep when the last one is
  over 8 days old), the walkthrough walks the 10 guides that waited longest
  or that a recent merge changed (audit_history.py).
- Each audit writes recent-changes.md (merged PRs since its last run's
  commit, capped at 30 KB) and reads missed_bug_classes.md, checklists for
  the bug classes fix PRs show audits missing; miss_analysis.py refreshes
  its evidence.
- Dedup: closed duplicates hand their keys to the open canonical, and
  backlog matching reads an audit issue's own keys, not just its title.
  Both syntheses share one filing concurrency group.
- Walkthrough: provisions a pinned PortableGit where a runner has no Git
  Bash, fixes the literal \n that broke dry runs, and caps a guide at 50 min.
  start-lemonade.ps1 no longer appends UTF-16 to GITHUB_OUTPUT, which
  corrupted the executor step's output.
- Security audit: semgrep and the worklist now cover TypeScript, Go, the
  installer scripts and the workflows.
…unded queries

One doc guide that failed every turn stopped all ten from being recorded, so the
walkthrough rotation was stuck on the same guides. A partial night is now filed
and each guide is judged by its own matrix job. A guide that fails 3 turns running
while others finish is backed off to one retry every 9 days and flagged loudly.
A night where every guide failed is not held against any of them.

- "Changed since its last walk" uses each guide's own last-walked commit, and
  changed guides take at most half the slots.
- Security synthesis now requires preflight to have passed, as the code audit
  already did, so a refused quota probe no longer reads as "the audit did not run".
- An explicit mode=normal dispatch never escalates to a deep sweep. With no usable
  history it reviews the last 7 days and the summary says what that leaves out.
- Run history reads jobs lazily: newest successful runs only, stopping at the first
  deep sweep or once every guide is resolved.
- Closed duplicates are read from GitHub's MarkedAsDuplicateEvent as well as
  "Duplicate of #N" text, via small paged GraphQL queries that fail at a hard cap.
- recent_changes looks up exactly the PRs the window's commits name (capped at 150,
  stated in the file) instead of a 1000-PR search.
- A refused quota probe now dispatches claude-account-switch.yml. The rotation
  starts audits with GITHUB_TOKEN, and GitHub does not document workflow_run firing
  for such a run's completion.
@kovtcharov-amd kovtcharov-amd added the ready_for_ci Run CI workflows on draft PR without requesting review label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This replaces three nightly Claude audits with one audit a night, rotating between them. Each run checks first that Claude has quota, and when a night is lost to the usage limit, the next turn of that audit picks up its work. I traced the main failure paths and they all hold: a refused probe stops the run before any lens or Strix Point runner starts, and it asks the account switch to run. A failed night doesn't move the window forward, and the walkthrough no longer throws away a whole night because one guide failed. Nothing blocks merge. The two notes below are small robustness gaps in the new "recent changes" summary.

Real-world evidence

N/A: CI and workflow change only. No evidence bundle was produced, and the new workflows can only run after merge (the PR's test plan lists dispatch dry-runs to do then). The verdict rests on static review. The PR's unit tests could not be run here because pytest isn't installed on this runner.

🔍 Technical details

Issues

🟢 The recent-changes summary drops file paths for true merge commits (scripts/audit/recent_changes.py:102-105). With --first-parent, git log --name-only lists no files for a merge commit unless you add --diff-merges=first-parent. Today's squash-merge history isn't affected. But any real merge on main would show "Paths: none", and its files would never reach changed-paths.txt, so the normal-mode no-deadline grep would skip them.

            "--first-parent",
            "--diff-merges=first-parent",

🟢 A malformed PR-lookup response passes silently (scripts/audit/recent_changes.py:154-157). When gh api graphql exits 0 but its stdout won't parse, data = {} and every commit quietly falls back to its subject line. That breaks the PR's own fail-loudly rule. Raise when the exit code is 0 and the JSON doesn't parse, the same way the non-zero branch does.

🟢 Older backlog snapshots crash (scripts/audit/prepare_synthesis.py:3233). backlog["closed_duplicates"] raises KeyError on any --backlog-file written before this change. Only tests use that path, so it's minor. If a missing key should mean "no duplicates", say so explicitly in the loader.

Checked and fine

  • Gating: every lens, walkthrough and synthesis job requires needs.<preflight|discover>.result == 'success', so a non-zero exit from require_claude.py really stops the run. request-account-switch reads the failed job's claude_verdict output, which is still populated.
  • The account switch's workflow_run list was updated to the new display names, and nothing else live still references "Claude Nightly Audit" or "Claude Weekly Doc Walkthrough". The only remaining mention is a historical plan under docs/superpowers/plans/.
  • Synthesis downloads every artifact, so audit-findings/recent-changes/recent-changes.md exists where the prompts expect it, and the findings-*.json counts don't pick it up.
  • Both preflights use fetch-depth: 0, so base_sha..HEAD and git diff <sha> resolve.
  • audit (<dimension>, <mode>) and the walkthrough's default matrix name match DEEP_JOB_RE and WALK_JOB_RE.

Strengths

  • History lives in the run records themselves (head_sha, job names), so the carry-over needs no state branch. The rotation night title filter keeps hand-dispatched dry runs from counting as completed work.
  • Per-guide walk records with backoff, plus "a failure counts only if another guide in the same run finished", separate a bad guide from a bad night. This is the right model.
  • Two fixes that matter beyond the audits: the PowerShell >> writes in the installer scripts became Add-Content, and the walkthrough's literal \n dry-run steps now work, which ends two separate classes of silent "crash".

…pshot

A PR lookup that exited 0 with non-JSON output quietly dropped every PR
description from the recent-changes file; it now stops the run. A
--backlog-file snapshot missing a list is refused by name instead of
raising a bare KeyError. git log also passes --diff-merges=first-parent
explicitly so a merge commit lists its paths on any git version.
@kovtcharov-amd kovtcharov-amd added ready_for_ci Run CI workflows on draft PR without requesting review and removed ready_for_ci Run CI workflows on draft PR without requesting review labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

The three proactive Claude audits now take turns, one a night, instead of all three running every night and using up the weekly quota by mid-week. Each run checks Claude is available before it starts anything, and picks up everything since its last successful run, so a night lost to the limit is covered on the next turn instead of being skipped. All the notes from the two earlier reviews are fixed in the latest commits. I found nothing new that blocks the merge, only one stale comment.

Real-world evidence

N/A: this PR changes only CI workflows, audit scripts and tests, and no evidence bundle was produced. The new workflows can only run on GitHub Actions after merge, so the verdict rests on static review. pytest isn't installed on this review runner, so the 277 unit tests weren't run here either. The PR's post-merge dry-run checklist is how to confirm the change on GitHub Actions.

🔍 Technical details

Earlier findings, now fixed

  • Security synthesis now requires needs.preflight.result == 'success', as the other two audits' synthesis jobs do (claude-security-audit.yml:524).
  • recent_changes.py passes --diff-merges=first-parent, stops on a PR lookup that exits 0 with non-JSON output, and prepare_synthesis.py refuses an old --backlog-file snapshot by name instead of raising a bare KeyError.

🟢 The cost-ceiling comment still describes the old cadence (.github/workflows/claude-nightly-audit.yml:93-98)
It still says "paid up to 7x/week", "a deep Sunday", "claude-security-audit.yml (also nightly)" and "the Sunday deep run". The header's new CADENCE and MODES sections say every third night, with an interval-based deep sweep. Reword it to match, e.g. "paid every third night … ~$30 on a deep sweep", and drop the Sunday references.

Checked and fine

  • Window logic: a run that skips because there were no commits still counts as a success, so the window moves forward without losing anything. An explicit mode=normal never escalates to a deep sweep, and a gap over 7 days does escalate on auto.
  • Per-guide walkthrough records only count a failure when another guide in the same run finished, so a quota night doesn't back off all ten guides. The WALK_JOB_RE and DEEP_JOB_RE patterns match the job names the workflows produce.
  • request-account-switch reads claude_verdict from a failed preflight, which is still populated. All three workflows gate their lens or walk jobs on preflight success.
  • The files=$(grep … | while …) || true and xargs grep … || true pipelines survive set -euo pipefail when nothing matches.

Strengths

  • The run history is the state store (run-name "rotation night N", the mode in each lens job's name, and per-guide job names), so carry-over needs no state branch, and dry runs and hand dispatches are kept out of it.
  • audit_history.py and recent_changes.py stop with an actionable error when gh or git can't answer, instead of guessing a window. This follows the no-silent-fallbacks rule where it matters most.
  • The PortableGit fallback is pinned and checksum-verified, the installer scripts' >> writes became Add-Content, and the walkthrough's dry-run steps with a literal \n mid-command are fixed.

@kovtcharov-amd kovtcharov-amd added ready_for_ci Run CI workflows on draft PR without requesting review and removed ready_for_ci Run CI workflows on draft PR without requesting review labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

The three proactive Claude audits now take turns, one per night, instead of all running every night and draining the weekly Claude quota by mid-week. Each audit checks that Claude can answer before it spends anything, and it scopes its work from its own last successful run, so a night lost to the quota is picked up on the audit's next turn. The scheduling, carry-over and gating hold up on a read-through: a quota refusal stops the run before any lens or synthesis job starts, then requests an account switch. I found nothing blocking.

Real-world evidence

N/A: this PR changes CI workflows, audit scripts and docs only, and no evidence-bundle.md was produced. The verdict rests on static review. The workflows can only run from main after merge (the rotation dispatches with --ref main), which the PR's post-merge dry-run checklist covers. The new unit tests were still pending in CI when I reviewed, and I couldn't run them here without the full package install.

🔍 Technical details

Issues found

🟢 The test plan says "the next six nights" but the summary prints tonight plus five (scripts/audit/audit_rotation.py, schedule(day, 6)). The table starts at day, so a reviewer following the post-merge checklist will count one row short. Either change the call to schedule(day, 7) or reword the test-plan item.

What I checked and found sound

  • Gating. The audit and synthesize jobs in both static audits require needs.preflight.result == 'success', so a refused probe no longer leaves synthesis failing on a missing artifact. request-account-switch keys only on claude_verdict == 'quota', never on credential, which is correct.
  • Carry-over window. resolve_window opens at the created_at of the last successful run, before that run's checkout. The windows therefore overlap rather than leave a gap. MAX_NORMAL_GAP (7 days) and --deep-every-days 8 escalate to a deep sweep after roughly three lost turns.
  • History reads. _gh raises SystemExit with context instead of guessing, which follows the fail-loudly rule. fetch_history filters on --branch main, which matches the rotation's --ref main.
  • Renamed workflows. claude-account-switch.yml's workflow_run list matches the new name: values. The only stale "Claude Weekly Doc Walkthrough" reference left is in a historical plan doc.
  • PortableGit fallback. It is pinned by SHA-256 and refuses to run on a mismatch.
  • Add-Content instead of >> in the two PowerShell scripts fixes the UTF-16 corruption of GITHUB_OUTPUT/GITHUB_ENV under PowerShell 5.1.

Strengths

  • Each new script is stdlib-only and exposes --history-file/--now hooks, so the scheduling logic is unit-testable without hitting the API.
  • The quota probe reuses util/classify_claude_probe.py, so "out of quota" means the same thing in the canary, the account switch and the audits.
  • Partial walkthrough sweeps now file what they found and list the unverified guides in the job summary, instead of discarding the whole night.

After merging main, the three new quota-probe steps were still pinned to
claude-code-action v1.0.240 while every lens, synthesis and account-switch
step moved to v1.0.262. The probe would then test a different bundled CLI
than the one that resolves the audit model, so it could pass while the
lenses fail, or stop a night the lenses could have run.

- Bump the probe pins to v1.0.262.
- Contract test: every claude-code-action step across the audits and the
  account switch shares one pin.
- Skill: move the label-history paragraph back inside the Naming note; the
  new sections had split it off under "Missed bug classes".
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Merged main and fixed one thing the merge exposed: the new quota probes were still on the old claude-code-action version while everything else moved to the newer one, so the probe could have tested a different CLI than the audits actually run. All steps now share one version, and a contract test keeps it that way.

🔍 Technical details
  • main bumped every claude-code-action step to 925afb53 (v1.0.262); the three probe steps added here stayed on ed670b4c (v1.0.240). The bundled CLI is what resolves --model, so a mismatched probe can pass while lenses fail, or the reverse.
  • New test_the_quota_probe_runs_the_same_claude_code_action_as_the_lenses fails on the pre-fix tree and passes now.
  • Also moved the label-history paragraph in the weekly-audit-patterns skill back inside its Naming note (the new sections had split it off under "Missed bug classes").
  • The 277 tests from the test plan pass locally on the merged tree.

…ure text

The CI path-coverage check from main read two doc paths in
test_audit_synthesis_prep.py as files the unit lane depends on. They are
strings inside a synthetic audit backlog, so editing those guides cannot
change the test's result.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 30, 2026
Merged via the queue into amd:main with commit 063ff26 Oct 30, 2026
87 of 88 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the ci/audit-rotation branch October 30, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps/infrastructure changes documentation Documentation changes installer Installer changes ready_for_ci Run CI workflows on draft PR without requesting review tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant