fix(pipeline): a run reported twice the findings a scan actually produced - #385
Merged
Conversation
…uced A real scan on a live stack pushed 2 findings. The agent logged "Push completed: 2 findings created", the database held 2 — and the pipeline run recorded total_findings = 4. OnStepCompleted calls stepRun.Complete(findingsCount), which stores the count on the step run. calculateRunStats then sums exactly those step runs. Adding findingsCount on top of that sum counts this step's findings a second time. The doubled number did not stay in one column. It also reached: - the audit event metadata for both the success and failure branches - the user-facing message, "Pipeline run completed successfully with N findings" so a run that found 2 secrets told the operator it found 4, and left that claim in the tamper-evident audit trail. OnStepFailed (run.go:580) always computed this correctly from calculateRunStats alone. The two paths disagreed and only the quieter one was right, which is part of why it survived: nothing compares them. Fix: drop the extra addition at all four sites so the run total is derived purely from the step runs, matching OnStepFailed. With multiple steps the old arithmetic compounded — every completion re-added the current step's count on top of a sum that already included it. Found by running an actual scan end to end against a real agent binary rather than by reading the code; the arithmetic looks reasonable until you have a real number to check it against. The regression test was confirmed to fail against the old expression.
This was referenced Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Observed on a real run
A scan on a live stack pushed 2 findings. Every layer agreed except one:
Why
OnStepCompletedcallsstepRun.Complete(findingsCount), which stores the counton the step run.
calculateRunStatsthen sums exactly those step runs. AddingfindingsCounton top of that sum counts this step's findings a second time:It did not stay in one column
The doubled number also reached:
"Pipeline run completed successfully with N findings"So a run that found 2 secrets told the operator it found 4, and left that claim in
the tamper-evident audit trail.
The tell
OnStepFailed(run.go:580) always computed this correctly, fromcalculateRunStatsalone. The two paths disagreed and only the quieter one wasright — and nothing compares them, which is part of why it survived.
With multiple steps the old arithmetic compounded: every completion re-added the
current step's count on top of a sum that already included it.
Fix
Drop the extra addition at all four sites so the run total is derived purely from
the step runs, matching
OnStepFailed.How it was found
By running an actual scan end to end against a real agent binary — not by reading
the code.
findings+findingsCountreads perfectly plausibly; it only looks wrongonce you have a real number to check it against. That is the argument for the
end-to-end coverage added in #383: this bug sat directly on the path those tests
now cover, and was invisible until something real ran through it.
Verification
TestScanLoop_RunFindingsCountIsNotDoubledasserts the run total equals whatthe step reported, and that the step run itself holds the true number.
findings+findingsCountbreaks it.golangci-lint --new-from-rev=origin/developclean, eachchecked by exit code.