fix(budgetManager): prevent cost accumulation past limit in warn mode#10
Open
Srejoye wants to merge 1 commit into
Open
fix(budgetManager): prevent cost accumulation past limit in warn mode#10Srejoye wants to merge 1 commit into
Srejoye wants to merge 1 commit into
Conversation
In warn mode, track() called console.warn() when the projected total exceeded the limit, but then fell through to this.totalSpent += cost, committing the overrun cost anyway. This caused totalSpent and percentageUsed to grow unboundedly past the limit, making budget status meaningless after the first warning. Add an early return after console.warn() so the cost is not committed when the limit is exceeded in warn mode. The finally block still runs, so the async tracking lock is properly released. Block mode behavior is unchanged.
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.
Problem
In
warnmode,track()issued aconsole.warn()when the projected total exceeded the limit, but then fell through tothis.totalSpent += cost. The cost was committed on every over-limit call, causingtotalSpentandpercentageUsedto grow without bound — making budget status meaningless.Root Cause
src/core/budgetManager.ts→track(), lines 66–68. Afterconsole.warn(), there was no early exit. Thethis.totalSpent += coston line 72 runs unconditionally for both modes after the if-block.Fix
Add
returnafterconsole.warn(message). Thefinallyblock still runs, so the async lock is correctly released. One line changed.Behaviour
warnmode, over-limit calltotalSpentgrowstotalSpentfrozen at limitwarnmode,percentageUsedafter overrunblockmodewarnmode, under-limit callsTesting
warnmode:totalSpentdoes not increase after limit is exceededwarnmode:percentageUsedstays at the limit percentage, not beyondwarnmode: under-limit calls still accumulate normallyblockmode: still throws, completely unaffectedreleaseLock) still fires in all cases viafinallyCloses #4