Skip to content

Security: a finding leaves its pull request or run when that is over - #661

Merged
nambok merged 1 commit into
mainfrom
fix/security-findings-release
Nov 13, 2026
Merged

nambok merged 1 commit into
mainfrom
fix/security-findings-release

Conversation

@nambok

@nambok nambok commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On the Security page an admin filtered to one repository and could select nothing: every checkbox was off, the header's too. They had closed CoderHelm's dependency fix pull request for that repository to start again and cancelled its fix run. Later, the repository's findings still read pr_open, and a finding in a pull request cannot be picked.

Root cause: nothing released a finding when its claim ended.

  • The pull request webhook (gateway/src/routes/github_webhook.rs, the closed branch from line 1899) recorded the outcome on the run (line 2036) and never told the security findings. There was no path for reopened either.
  • Cancelling a run (gateway/src/routes/api.rs, cancel_run, line 3031) and closing one wrote only the run record.
  • The only comparison with GitHub was track_prs in worker/src/passes/security_fixes.rs (line 2277), the last per-finding step of the 20 minute sweep (called at line 2256, after the sources and triage). It returns at once when the sweep's time is up (line 2287), and that time is one 300 second budget shared by every team in a fixed order (lines 54, 3900 and 3903), so a team behind others, or a team with a long sync or triage, was never compared. A failed GitHub request was read as "still open" (lines 2439 and 2442). A fixing finding was released only after 12 hours without a write (line 2293).
  • A person's request queued past a daily limit never started for a finding that kept a closed pull request's record (common/src/security_fixes.rs line 2166, f.pr.is_none()).

Which of the sweep's conditions kept this install's findings stale for a day is not something the code can say; it needs the worker's logs for that team. Every one of them is closed here.

Paths, before and now:

A claim ends by Before Now
Pull request merged Sweep only, when it had time Webhook event and every sweep
Closed unmerged by a person Sweep only, when it had time; no record of who Webhook event and every sweep; who, when and which pull request kept
Closed by CoderHelm (run closed in the app, withdrawn advisory, stale) Sweep only Webhook event and every sweep; the person who closed the run is named
Branch deleted (GitHub closes the pull request) Sweep only Same as closed unmerged
Pull request gone (repository deleted or moved) Never: read as open Released
Run cancelled or closed before a pull request After 12 hours without a write On the cancel or close, and every sweep
Run failed before a pull request After 12 hours without a write Next sweep, from the run's record
Pull request reopened Never Webhook event and every sweep while its hold is on

Changes

  • common/src/security_release.rs (new): the rules, pure. settle_pr and settle_run take what GitHub or the run record says and return the finding as it should stand with its timeline line. A pull request closed unmerged returns its findings to open, records closed_at, closed_by and closed_by_person on the pull request's record, and holds automatic fixes for 7 days; a person asking for a fix never waits on the hold. A run a person cancelled or closed holds 7 days, a failed one 1 day. "GitHub did not answer" changes nothing. Applying a fact twice writes nothing.
  • worker/src/passes/security_release.rs (new): reconcile reads GitHub once per pull request and the run records once per ticket and applies the rules. It runs for the new pr and run events, and in every sweep first for each team with its own 45 second clock, also for teams the sweep's shared budget no longer reaches (up to 240 seconds more). Bounded at 100 pull requests and 50 runs per team per sweep; the rest take their turn on the following sweeps. A team with security fixes turned off is released once a day.
  • worker/src/passes/security_fixes.rs: track_prs keeps CI, cards and descriptions and settles a merge or close through the same rules; the 12 hour guess is gone; enqueue records when a run claimed a finding; on_pr_opened leaves fixed and dismissed findings alone; new retry event.
  • Gateway: pull_request closed and reopened queue a pr event for CoderHelm's security pull requests and adopted Dependabot and Renovate ones; cancel_run and the close route queue a run event; retry_run on a security fix run whose pull request is gone queues retry instead of replaying the old plan.
  • Retry: the worker brings the unit's findings in line with GitHub, then marks the ones a new pull request can still fix as requested by that person. They start like any person's request: a plan made now, a new ticket, branch and pull request, never the closed one. While the unit still has an open pull request or a working run, Retry behaves as before.
  • requested_units no longer skips a finding because it keeps a closed pull request's record.
  • Groups carry the run's ticket and prefer a member's open pull request over an older closed one.
  • Incident case ap_closed_pr_keeps_findings and its row in docs/incidents.md.

How today's stale records are repaired: no step by a person. After deploy the first sweep (within 20 minutes) reads each pull request a finding records as open. The closed one answers "closed, by this login, at this time", and its findings go back to open with that record. Findings left fixing by an ended run are released from the run's record the same way.

Not in this pull request: infrastructure findings keep their own records and have no path for a pull request closed unmerged. They have no selection on the page, so this incident does not reach them, but the same gap is there.

Verification

  • cargo fmt --check --all, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass locally: common 2,292 passed, gateway 912, worker 1,774, none failed.
  • Each release path has a test: merged, closed by a person, closed by CoderHelm, gone, reopened (and not pulled back once a new run or request has it), run cancelled, run failed, no run on record, a pull request the run opened and never recorded.
  • The sweep: a missed webhook heals with one read for 274 findings; a second sweep writes nothing and does not ask who closed it again; GitHub down changes nothing and the next sweep heals; 250 pull requests are all read within three sweeps; running out of time reports what is left.
  • The person-closed record: who, when and which pull request on the finding and in the group's JSON; automatic planning skips the findings for 7 days and takes them after; a person's request takes them at once.
  • Retry: the gateway's decision, the worker's marking, and the request that results (one bundle, new ticket and branch, never joining the closed pull request).
  • Planted break: with the old f.pr.is_none() back, the incident case's retry test fails.
  • Not verified live: nothing was deployed and no AWS or GitHub call was made against an install. The repair of the stale records and the webhook path are proven by tests on fakes of GitHub and the run records only.

A finding in a fix pull request that a person closed stayed `pr_open`,
and one claimed by a cancelled fix run stayed `fixing`, so the Security
page could not select it and nobody could ask for a new fix. A
repository had 274 findings in that state a day after its pull request
was closed.

Why: the pull request webhook recorded the close on the run and never
told the findings; cancelling or closing a run wrote only the run; and
the one comparison with GitHub was the last step of the scheduled sweep
(`track_prs`), behind the time budget every team's sources and triage
share, reading any failed GitHub request as "still open". A `fixing`
finding waited 12 hours on a guess.

- `common::security_release`: the rules. A pull request merged fixes
  the finding; closed unmerged gives it back with who closed it and
  when on the pull request's record, and automatic fixes wait 7 days (a
  person asking never waits); reopened, the finding is in it again; gone
  from GitHub, released. A run that ended without a pull request
  releases its findings (7 days after a person cancelled or closed it,
  1 day after it failed). GitHub not answering changes nothing. A fact
  applied twice writes nothing.
- `worker::passes::security_release`: reads GitHub and the run records
  and applies the rules. Called by the new `pr` and `run` events and by
  every sweep, first for each team, on a clock of its own, for teams the
  sweep's budget never reaches too, at most 100 pull requests and 50
  runs per team per sweep, the rest in turn. A team with security fixes
  off is released once a day.
- Gateway: a security pull request closing or reopening, a cancelled
  run and a closed run queue those events.
- Retry on a fix run whose pull request is gone is a new request for
  the unit's findings as they stand: a new plan and a new pull request,
  never the closed one. A request queued past a daily limit now starts
  although the finding keeps its closed pull request's record.
- The groups list carries the run's ticket and prefers a member's open
  pull request, for the dashboard's reasons and links.

Incident case `ap_closed_pr_keeps_findings`.
@nambok
nambok merged commit ebe9e08 into main Nov 13, 2026
10 checks passed
@nambok
nambok deleted the fix/security-findings-release branch November 13, 2026 23:01
nambok added a commit that referenced this pull request Nov 14, 2026
…n it is over (#666)

#661 gave dependency findings a release when their fix pull request
closed or their run ended. Infrastructure findings keep their own
records and had none: a closed pull request left the record `pr_open`
(the page never offered the fix again), a cancelled or failed run left
it `fixing` for good, and a reopened pull request was never noticed.

- `common::security_release` is generalised instead of copied: both
  stores are a `Claim`, and the words, the person-closed record and the
  holds (`closed_words`, `closed_record`, `run_end`) are shared.
- The worker's `reconcile` is generic over `Claim`. Both stores use the
  same reads of GitHub and the run records (`Reads`), the same `pr` and
  `run` events, and the same sweep, first for each team, with the same
  bounds.
- Infrastructure records get the closed record on their pull request, a
  hold on automatic attempts (a person asking never waits) and the time
  their run claimed them.
- What stays this store's own: a merge is recorded and never closes a
  finding (only a read of the account does); a draft the replacement
  guard holds is not closed and is left as it is; a finding on its
  runbook stays there until its code or target changes; a pull request
  the record never learned goes through the guard before it is recorded;
  a fix round that ends without settling its pull request becomes the
  guard's second step (a draft), never a ready pull request.
- "Open fix PR" and Retry check the record against GitHub first. Retry
  on an infrastructure fix run whose pull request is gone is a new
  request for the finding as it stands.

Incident case `as_infra_closed_pr_keeps_record`.
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