Skip to content

fix(secret-sweep): say what a re-run really reads, and log its own-record lookup (#950) - #966

Merged
scuttletoby merged 2 commits into
mainfrom
fix/sweep-rerun-own-record
Nov 22, 2026
Merged

scuttletoby merged 2 commits into
mainfrom
fix/sweep-rerun-own-record

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Part of #950.

What was wrong

A re-run of a secret sweep never found its own earlier attempt's record. The logs of the live re-run (attempt 2 of the 2026-11-22 dispatched sweep on main) show why. It is the second candidate in #950: once a re-run starts, GitHub no longer lists the earlier attempt's artifact.

  • The re-run's upload step runs with overwrite: true. When it finds an artifact of that name, it deletes it and logs Artifact '…' (ID: …) deleted (upload-artifact v7.0.2, deleteArtifactInternal). Attempt 2's log has no such line, so the artifact backend did not see attempt 1's record either.
  • Attempt 1's record (the ID its upload logged) is now 404. It is gone from the run's artifact list and from the repository's list by name. Only attempt 2's record is left.
  • No API lists one attempt's artifacts (runs/{id}/attempts/{n}/artifacts is 404; an attempt's artifacts_url is the run's).

So the lookup cannot be fixed. This PR does the other half of point 3: the headers and comments now describe what really happens. It also adds the logging from point 1, so a re-run's log shows both checks.

The first candidate (the called workflow not seeing the caller's GITHUB_WORKFLOW_REF) is unlikely. GitHub documents that a called workflow's github context is the caller's, and fork-checks-ran.py already relies on that. The new log line confirms it on the next live re-run.

Changes

  • Read step (fork-secret-scan.yml): on a re-run (attempt 2 or later) it logs
    attempt N of run R, workflow ref …: the sweep's, so its own earlier record is looked for first (or not the sweep's …),
    and, when it asks about its own run, this run's own records listed: 0|1. The lookup itself is unchanged.
  • Scan step: the 20-minute time-limit error used to say "Re-run the job". A re-run cannot see the partial record the stopped attempt kept, so the error now says to start a new run (or wait for the next daily one). Only a new run goes on from the tips the stopped run proved. The two comments that said "a re-run … goes on from there" are corrected the same way.
  • Headers (fork-secret-sweep.yml, the read and keep steps): "meant to … not yet confirmed (Secret sweep: a re-run does not find its own earlier attempt's record #950)" is replaced with what a re-run really reads.

State cases (each has a contract test; red on main's workflow, green here)

State What a re-run reads Test
Runs again: re-run of a normal sweep (its own record not listed, as live) the newest earlier sweep's record, like a new run; logs listed: 0 a re-run whose first attempt's record is not listed (#950)
Runs again: re-run of a reset_record run the empty record; no older run is listed, so the reset holds a re-run of a reset_record run whose first attempt's record is not listed (#950)
Runs again: re-run of another workflow's run (fork-tests.yml) its own run is never asked about; logs not the sweep's existing case, log assertion added
Runs again: its own record is listed (not seen live; kept as the safe first choice) its own record; logs listed: 1 existing #703 cases, log assertion added
Stops half-way: a re-run, then the lookups fail half-way reads the newest earlier sweep's record (read=found) and keeps the same partial record a first attempt keeps a re-run whose own record is not listed, then the scan's lookups fail half-way
Stops half-way: the 20-minute limit the error says to start a new run, not a re-run time_limit_case asserts the message
Old state: the newest earlier record expired the one before it … whose newest earlier run's expired: the one before (#950)
Empty state: the newest earlier record is header-only that empty record (read=found) … kept an empty one (#950)
No state: no earlier sweep kept one (or all expired) a first run (read=none) … no earlier sweep kept one (or it expired): a first run (#950)
A first attempt nothing new logged a first attempt: … no re-run log (#950)

All of these were safe before, and nothing is skipped. The change is to what the run logs, what the comments say, and the time-limit advice.

Left for #950

  • Point 2: re-run one sweep once (after merge, on main) and read the two new log lines. Expected: workflow ref …/fork-secret-sweep.yml@refs/heads/main: the sweep's … and this run's own records listed: 0. If it lists 1, the own-record path works after all and the comments need another look.

Checks

  • python3 -B .github/scripts/fork-contracts.test.py: all 736 checks pass. With main's fork-secret-scan.yml and this test file, the new cases, the pinned texts and the time-limit case fail.
  • actionlint 1.7.12 on .github/workflows/fork-*.yml: clean.
  • vp run check:changed: pass.

🤖 Generated with Claude Code

…cord lookup (#950)

A re-run of a sweep never found its own earlier attempt's record. The
live re-run's logs show why: once a re-run starts, GitHub no longer lists
the earlier attempt's artifact (the re-run's upload with overwrite found
none to delete, and the record is gone from the run and the repository).
No API lists an earlier attempt's artifacts, so the lookup cannot be
fixed; a re-run reads as a new run does, which is safe.

- On a re-run, the read step logs whether the workflow ref was the
  sweep's and how many of the run's own records were listed.
- The headers and comments say what a re-run really reads.
- The scan's 20-minute limit now says to start a new run, not a re-run:
  only a new run goes on from the tips the stopped run proved.
- Contract tests: a re-run whose own record is not listed, with an older
  record, an empty one, an expired one, none at all, and a reset run;
  a re-run that then stops half-way keeps the same partial record as a
  first attempt; the log lines; the new time-limit message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: merge-path · reviewer: lens agent · read at: 2d60465
verdict: safe to merge
covered: issue #950 (body; it has no comments), the PR body, the full diff of fork-secret-scan.yml, fork-secret-sweep.yml and fork-contracts.test.py; the read step, the scan step's partial-record gate (partial, keep) and the keep step around the changes.
checks: ran python3 -B .github/scripts/fork-contracts.test.py: 692 ok, 44 failed, every one of them jq: command not found (this machine has no jq; the fake gh needs it). Without jq the read step goes to read=failed (fail closed), so no new case could be judged here; the CI job with jq was still pending when this was read. actionlint is not installed here. Checked the PR's evidence on the live re-run with read-only API calls: the run lists one record artifact, the one attempt 2 uploaded; the ID attempt 1's upload logged is now 404; runs/{id}/attempts/1/artifacts is 404 and both attempts' artifacts_url is the run's; attempt 2's upload log has no "deleted" line for an earlier artifact. Both attempts re-ran every job, and both logged "no earlier sweep on main kept a record".
state: runs again: the lookup is unchanged; a re-run's own record is still taken only when its own run lists exactly one, unexpired, under the sweep's workflow ref, otherwise the newest earlier sweep's (a reset run's re-run: the empty record), so a re-run that sees nothing rechecks more, never less. Stops half-way: partial and keep are unchanged; a re-run after a stop loses the stopped attempt's partial record (GitHub drops it), so it redoes that work. That is slower, not a miss. Old, empty or missing records: unchanged paths (expired skipped, header-only read as empty, none means a first run); the new e2e cases cover each one on a re-run. Gates: only comments, two ::notice lines and one ::error text change; no if:, output, permission, token or gate is touched, so nothing new blocks or passes a PR or a merge. The notices print only run id, attempt and workflow ref (a ref cannot hold :, so it cannot start a workflow command); no secret.
blocker: none
major: none
minor: fork-secret-scan.yml:478 and :488: the other two half-way stops (a failed runs or jobs lookup) also keep a partial record but still say "Re-run the job". A re-run is safe but cannot see that record either. Fine for a passing API failure, but it does not match the comment at :434-438.
minor: fork-secret-scan.yml:470: "a new run goes on from the tips this one proved" holds only when partial was set. When the read failed, nothing is kept and a new run starts from the older record. Safe, but the text says more than happens.
minor: fork-secret-scan.yml:77 and fork-secret-sweep.yml:20: "once a re-run starts GitHub lists no earlier attempt's artifact" rests on one re-run of all jobs. The proven claim is that the re-run job's own earlier record is gone. Narrowing the text to that (or leaving it until #950 point 2's log) would match the evidence. The code does not depend on it: the listed=1 path stays tested.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: lens agent · read at: 2d60465
verdict: safe to merge
covered: the full diff (fork-secret-scan.yml, fork-secret-sweep.yml, fork-contracts.test.py), the whole read step and the scan step's deleted-tip loop around it, #950 (every point; it has no comments), the PR body
checks: python3 -B .github/scripts/fork-contracts.test.py on the head: 692 ok, 44 red, all 44 only jq: command not found (jq is not installed on this machine; the read-step e2e cases and pr-guard's script need it). The same file in CI on this head ("Workflow lint and upstream drift"): all pass, including every #950 case and the half-way case. Revert test: main's fork-secret-scan.yml with this test file turns the time-limit case, its three mutant checks and the pinned-text checks red; the #950 read-step cases assert the two new log lines, which main does not print, so they are red there too. Live claims checked read-only against the API: the dispatched sweep re-run of 2026-11-22 lists one record (attempt 2's); attempt 1's artifact ID (from its upload log) is 404 at actions/artifacts/{id}; runs/{id}/attempts/1/artifacts is 404; attempt 1's artifacts_url is the run's; attempt 2's upload (overwrite: true) logged no deletion. actionlint is not installed here.
state: runs again (re-run): the lookup is unchanged; its own run is still asked first and lists none, so it reads the newest earlier sweep's record (reset run: the empty one), never a newer or foreign one, and checks more tips than a new run would, never fewer: fails closed. Stops half-way: the time limit still exits 2 and keeps only what partial allows; a re-run does not see that partial record (now said), a new run does. Old, empty, missing records: expired skipped to the one before, header-only read as found, none read as a first run; all unchanged and now each pinned with the re-run log. Log output: only attempt number, run id, the workflow ref and a 0/1 count; no token, record content or secret is printed. Quoting: both new lines are [[ ]] || echo under set -e with the command substitution quoted; safe.
blocker: none
major: none
minor: the time-limit error (.github/workflows/fork-secret-scan.yml:470) says "a new run goes on from the tips this one proved", but when the read step ended failed (partial empty, :353-357) nothing is kept, so a new run reads the older record again; e.g. "a new run goes on from what this one kept" would hold in every case
minor: this run's own records listed: N (:158) counts records after the jq filter (name, not expired, workflow_run.id), not what the API listed, so for #950 point 2 a 0 alone does not prove the API listed none; the 404 by artifact ID already shows that, so only the log's wording is loose
minor: the new comments say GitHub "lists no earlier attempt's artifact" (:76-79, :111-114, :530; fork-secret-sweep.yml:20-21), but the evidence shows the re-run job's earlier artifact is deleted (404 by ID), and the evidence covers only the re-run job's own artifact, not every artifact of the run. Consequence worth one line in the header: a normal sweep's re-run that fails before the scan writes its record leaves its run with no record at all, so the next sweep reads an older one (safe, only more lookups)

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: lens agent (Claude) · read at: 2d60465
verdict: safe to merge
covered: issue #950 (all three points; it has no comments), the PR body, the full diff of .github/workflows/fork-secret-scan.yml, .github/workflows/fork-secret-sweep.yml and .github/scripts/fork-contracts.test.py, the whole read step and the scan step's deleted-tip lookups as they stand at this head, and the live dispatched sweep on main of 2026-11-22 (attempts 1 and 2, their job logs and artifacts).
checks: python3 -B .github/scripts/fork-contracts.test.py at this head: 692 ok, 44 fail, every one because jq is not installed on the machine I ran it on (the test's fake gh calls jq; with no jq the read step ends read=failed, i.e. closed). So the read-step cases, including the new #950 ones, are not proven by my run; CI's run of this file is the proof for those. With main's fork-secret-scan.yml and this test file, the time-limit case (the step is past 20 minutes at the first lookup), its three mutants and the pinned-text checks go red; they are green at this head. Live: attempt 1 uploaded the record and logged its ID; attempt 2's upload (overwrite) logged no deleted line; attempt 1's artifact ID is now 404; the run and the repository list only attempt 2's record; runs/{id}/attempts/1/artifacts is 404 and attempt 1's artifacts_url is the run's. actionlint is not installed here; not run.
state: fresh run: the read step's logic is unchanged and the two new lines print only on attempt 2 or later, so a first attempt reads and logs as before. Runs again: a re-run of a normal sweep finds its own run listing nothing and reads the newest sweep record whose commit this one has, as a new run does; a re-run of a reset run finds nothing of its own and takes the empty record; if GitHub ever does list its own record, it reads that, which is the #703 path (a record only this job writes). Every path checks more tips, never fewer. Stops half-way: a re-run cannot use the partial record of the stopped attempt (GitHub drops it when the re-run starts), so it repeats the stopped attempt's lookups: more work, not a missed secret. A new run reads that partial record, so the new time-limit text is right. Old, empty or missing records: an expired record is skipped for the one before it; a header-only record is read as found; no record at all is a first run. These behave as on main, and the new cases pin them. What blocks a PR: no change. The read step runs only on schedule and workflow_dispatch, the new lines only log, and the exit codes and conditions are the same. The only text that changed is the time-limit error.
blocker: none
major: none
minor: the flat statements "no re-run goes on from its own earlier attempt's record" (.github/workflows/fork-secret-sweep.yml:20-23) and "a re-run cannot see them" (.github/workflows/fork-secret-scan.yml:470) rest on one live case: a "Re-run all jobs" of a run that succeeded. A run that stops at the time limit fails, and the usual button for a failed run is "Re-run failed jobs", which was not tried. GitHub most likely drops a re-run job's earlier artifacts in that mode too. If it does not, the code is still safe (it reads its own record, listed: 1), but these sentences would be wrong. Worth adding a "Re-run failed jobs" of a failed sweep to #950 point 2, or keeping the read step's "so far" wording in these two places.
minor: the two other errors that keep a partial record after a lookup fails half-way still say "Re-run the job" (.github/workflows/fork-secret-scan.yml:478, :488). Under this PR's own reading, such a re-run does not resume from the partial record. It starts again from the older record, and if the first attempt stopped late it can hit the 20-minute limit, which then gives the right advice. This is safe and fine for a short network failure, but the advice differs from the new time-limit text and the corrected keep() comment at :437.

🤖 Generated with Claude Code

@scuttletoby
scuttletoby merged commit ca4ba57 into main Nov 22, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant