Skip to content

fix(cli): count zero-count recommendations removed by --max-instances or --min-count as dropped - #2285

Merged
cristim merged 2 commits into
mainfrom
fix/1742-negative-drop-count
Oct 20, 2026
Merged

cristim merged 2 commits into
mainfrom
fix/1742-negative-drop-count

Conversation

@cristim

@cristim cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member

Closes #1742

The go library's DropSummary.Add now panics on a negative count (go#518, already in the cli's pin). The cli could feed it one: in reportInstanceLimit (cmd/multi_service.go) a zero-Count recommendation removed by the --min-count floor was treated as unchanged (kept == rec.Count, with kept 0). dropTruncatedBelowMinCount did count it as a floor drop, so dropped - belowMinCount went negative at :519 and panicked. Example: counts [4, 0, 6], cap 7, floor 4 gives -1. A zero-Count entry the cap removed was also never reported as a --max-instances drop.

  • reportInstanceLimit now decides removal by position. The cap result is a prefix of its input, so every entry past len(after) is counted and named as dropped, whatever its Count.
  • If the floor count ever exceeded the removed count (an impossible state), it panics with context instead of clamping silently.
  • The other DropSummary.Add calls in cmd/ pass lengths or non-negative counts.

Tests (multi_service_drop_attribution_test.go): the end-to-end panic case, the zero-Count budget drop, and the impossible state. All three fail on main (two panic with negative count -1/-2).

🤖 Generated with Claude Code

…tances report

reportInstanceLimit decided "removed" by comparing the kept count with the
original count, so a zero-Count entry past the end of the cap result looked
unchanged and was skipped. dropTruncatedBelowMinCount still counted it as a
floor drop, so dropped-belowMinCount went negative and DropSummary.Add
panicked. Decide removal by position (the result is a prefix of the input)
and panic with context if the floor count ever exceeds the removed count.

Closes #1742

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

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 48 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 6853b7b2-8926-4fca-8829-60743ad16e89
📥 Commits

Reviewing files that changed from the base of the PR and between a872fc6 and 4302f8f.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • cmd/multi_service.go
  • cmd/multi_service_drop_attribution_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Merge gate verdict (claude-cc-libs)

Every gate holds at head 4302f8f:

  • Two independent reviews approve the reviewed head b19869a. The branch was then updated from main, and the PR diff is byte-identical to the reviewed diff (compared mechanically).
  • CI is green on 4302f8f, which is the reviewed change on top of current main.
  • 0 unresolved threads; MERGEABLE/CLEAN.

CodeRabbit is waived as a merge gate under the 2026-10-19 decision. Squash-merging.

@cristim
cristim merged commit ce16689 into main Oct 20, 2026
12 checks passed
@cristim
cristim deleted the fix/1742-negative-drop-count branch October 20, 2026 04:23
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.

fix(cli): DropSummary.Add silently accepts a negative count and understates other stages

1 participant