Actions are refused before they are sent if they would pass the daily budget - #23
Merged
Merged
Conversation
… budget jev.noul, jev.choice, jev.score and jev.ask never checked the budget. A script that looped on an action spent without a limit. They now make the same check as contexts, AI Task and voice: estimate the request, refuse it with a message that names the estimate, what is left and the budget, and hold the estimate while the call runs.
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.
The four actions (
jev.noul,jev.choice,jev.score,jev.ask) did not check the daily budget.services._askmeasured the request only to record bytes per token after the call. A script that loops on an action could spend without a limit, butsite-docs/cost.mdsays that the check runs before the request.The actions now do the same as contexts, AI Task and (after #20) voice:
roll_over, then estimate the request withpayload_bytesandestimate_tokens.HomeAssistantErrorwith the new translation keyaction_over_budget. The message names the estimate, what is left and the budget. The call is not sent.usage.reservationwhile the call runs.The new message is in strings.json and all 13 translations.
Tests:
test_an_action_that_would_pass_the_budget_is_not_sentandtest_an_action_holds_its_estimate_while_it_runs. Both fail on 1a6c968 and pass here.Local gate: ruff, ruff format, mypy --strict, pytest (409 passed, 12 skipped, coverage 96.85%), config_flow 100%, mkdocs --strict, hassfest (0 invalid). EXIT 0.
Part of the 1.16 work. Targets
feature/1.16. It does not depend on any other part.