Repository navigation
fix(cli): apply --max-instances once run-wide, not per service and region #1725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e01fc7
fix(cli): apply --max-instances once run-wide, not per service and re…
cristim f6c0821
test(cli): pin the --max-instances selection order, not just the total
cristim 326112e
fix(cli): drop recommendations --max-instances truncates below --min-…
cristim 93fe75e
refactor(cli): hoist the --max-instances refusal above the duplicate …
cristim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Scale cost and savings fields when the cap reduces
Count.ApplyInstanceLimitcopies each recommendation and edits onlyCount.EstimatedSavingsandCommitmentCostkeep their pre-cap values.reporter.RenderSummaryandsumPassedRecsboth sum those fields.A run capped from 8 instances to 2 therefore prints and confirms the savings and upfront commitment of 8 instances. The operator sees a number that does not describe the purchase.
Scale the per-instance economics with the reduced count, or state in the table and the prompt that the figures are pre-cap.
Sketch: scale the monetary fields inside the truncation step
adjusted := rec if rec.Count > remaining { + ratio := float64(remaining) / float64(rec.Count) adjusted.Count = remaining + adjusted.EstimatedSavings = rec.EstimatedSavings * ratio + adjusted.CommitmentCost = rec.CommitmentCost * ratio + adjusted.OnDemandCost = rec.OnDemandCost * ratio }🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, and deliberately out of scope here. Tracked as #1611.
Your reading of the consequence is exactly right: a run capped from 8 instances to 2 prints and confirms the savings and upfront commitment of 8, so the operator approves a number that does not describe the purchase. It is a money-display defect on the approval screen, which is the worst place for one.
Three reasons it is not being fixed in this PR.
It is not introduced here.
ApplyInstanceLimithas always assigned.Countand leftCommitmentCost,OnDemandCost,EstimatedSavingsandRecurringMonthlyCostdescribing the pre-truncation quantity. Pre-fix,sumPassedRecsalready summed a post-cap set carrying those same stale fields; the cap simply ran per (service, region) instead of once. This PR changes where the cap is applied, not what the helper does to the fields, and it reduces how often the desync fires (once per run rather than once per service/region) without making any instance of it worse.The fix belongs one level down, at the point
Countis mutated.ApplyCountOverridehas the identical defect in the opposite direction: it raisesCountand leaves the costs low, so--override-count 10on aCount = 1recommendation understates the upfront by 10x. Fixing onlyApplyInstanceLimithere would leave the sibling broken and mean touching the same lines twice. Both should route throughcommon.ScaleRecommendationCoststhe wayapplyCoverage(cmd/helpers.go:173-178) andapplyTargetCoverageRIalready do, with a guard foroldCount == 0, and the regression test has to assert the cost fields rather thanCount— a test that only checksCountpasses today with the bug present.Folding a cost-model change into a cap-placement change would make both unreviewable. This PR is already carrying the placement fix, a
--min-countinteraction, a fail-closed guard and four regression tests on a money path. Cost scaling touches every consumer of those fields — the confirmation prompt, theUpfrontPaymentandEstimatedSavingsCSV columns, theTOTALrow, andpkg/common/audit.go'sEstimatedCost— and deserves its own diff and its own review.#1611 has been updated with this analysis, including that the fix should land at the mutation point so it covers both helpers together.
Not resolving this thread; leaving it visible with the justification attached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristim, acknowledged. The defect predates this PR and the current change does not worsen it.Deferring the cost-model fix to
#1611is appropriate. The fix should scale costs at everyCountmutation point, includingApplyInstanceLimitandApplyCountOverride, with regression tests for the monetary fields and zero-count handling.I will leave this thread unresolved, as requested.
✏️ Learnings added
You are interacting with an AI system.