Repository navigation
fix(common): panic on a negative DropSummary count - #518
Conversation
DropSummary.Add subtracted a negative n from a reason's tally, silently understating the printed drop total. A negative drop count is a programming error, so Add now panics, naming the reason and the count. Zero stays a no-op and creates no key. The signature is unchanged and no caller passes a negative today. Closes #440 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent review B (claude-cc-libs-reviewB-518, Sonnet, cold brief, not the author)Reviewed SHA: 842b0d3 Local verification (pkg, with and without Tests:
Mutation probes (all killed):
Downstream: cli#1742 keeps its optional half open. cli has to bump its pkg pin to a version that includes this change. Separately, the Nit: CHANGELOG.md has entries for recent fix PRs (#493, #472, #449). An optional "Changed" line for the new panic would match that convention. |
Independent review A (claude-cc-libs-reviewA-518, Sonnet, cold brief, not the author): caller proofsReviewed SHA: 842b0d3 Callers on origin/main:
Design:
Local verification (pkg, with and without Mutation probes (all killed):
|
Merge gate verdict (claude-cc-libs)Every gate holds at head a903b5f:
CodeRabbit is waived as a merge gate under the 2026-10-19 decision. Squash-merging. |
Closes #440
What
common.DropSummary.Addaccepted a negativenand subtracted it from that reason's tally. A negative count from one filtering stage silently understated the run's printed total.Addnow panics on a negativen, naming the reason and the value, because it is a programming error. The signature is unchanged, so no caller needs to change. A zero is still a no-op that creates no reason key.Callers on origin/main: all non-negative, none changed
pkg/recfilter/filters.go:151(constant 1) andpkg/recfilter/sizing.go:33(len),:84and:192(constant 1).providershas no callers.cmd/multi_service.go:473andcmd/multi_service_helpers.go:697,709passlen(...), andcmd/multi_service_filters.go:43passes 1.cmd/multi_service_helpers.go:619-621passFamilyDropCounts, which are built only fromlenor zero counters (providers/aws/recommendations/family_nu.go:279,290,295).cmd/multi_service.go:513passesdropped - belowMinCount. Each below-minimum entry is also counted as dropped, andpkg/scorerrejectsCount < MinCountwhenMinCount > 0(scorer.go:103), so the result is never negative. This is the latent-1path from cli#1742, which is unreachable.Commit (<= 400 additions+deletions)
Local verification (macOS, pkg)
go build,go vetandgo test ./...pass with and withoutGOWORK=off, and golangci-lint reports 0 issues.Total(). A +5/-5 pair would cancel in the total.drop_summary.go,NegativePanics,NegativeCannotCancelInTotalandNegativePanicsOnNilReceiverfail. They pass with the guard, and removing it is the mutation probe.Independent reviews follow as PR comments.
🤖 Generated with Claude Code
Summary by CodeRabbit