feat(budget): per-model budget fallback chains - #1
Open
kusonooyasumi wants to merge 1 commit into
Open
Conversation
kusonooyasumi
force-pushed
the
pr1-model-routing
branch
from
July 21, 2026 06:37
ac98a94 to
7a1b9cf
Compare
kusonooyasumi
force-pushed
the
pr2-budget-fallbacks
branch
from
July 21, 2026 06:39
00fc8be to
2c24efe
Compare
kusonooyasumi
marked this pull request as ready for review
July 21, 2026 07:02
Add cumulative per-model spend caps that fall back to a cheaper model when a cap is reached, instead of stopping the whole scan. - llm.model_budgets_usd and llm.model_fallbacks (validated for cycles, self-references, and missing budgets) define the fallback graph. - resolve_budget_model skips already-exhausted layers when an agent is created or resumed; the usage hook switches all agents sharing an exhausted model to the next layer at a response boundary (discarding the boundary response so tool calls don't double-execute). - chain_uses_chat_completions_tools keeps the tool schema compatible across every layer of a fallback chain. - Usage ledger and TUI stats attribute tokens/cost to each model actually used. The scan-wide --max-budget-usd remains a hard stop.
kusonooyasumi
force-pushed
the
pr2-budget-fallbacks
branch
from
July 21, 2026 07:34
2c24efe to
7bbb669
Compare
Owner
Author
Credential consistency for budget fallbacksBuilding on the per-call credential fix in the routing PR, this PR's fallback path was updated so a fallback model re-resolves its credential rather than inheriting the exhausted model's key.
New test |
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.
Summary
Adds per-model spend caps with fallback chains: when a model reaches its cumulative budget, agents move to a cheaper configured model instead of the whole scan stopping.
Behavior
--max-budget-usdremains a hard stop and takes precedence.Config
{ "llm": { "model": "openai/gpt-5.4", "subagent_model": "z-ai/glm-4.7", "model_budgets_usd": { "openai/gpt-5.4": 20.0, "z-ai/glm-4.7": 10.0 }, "model_fallbacks": { "openai/gpt-5.4": "z-ai/glm-4.7", "z-ai/glm-4.7": "deepseek/deepseek-chat" } } }Validated for cycles, self-references, and fallback sources that lack a budget.
Implementation notes
strix/core/model_routing.py(new):resolve_budget_modelskips already-exhausted layers at agent create/resume;chain_uses_chat_completions_toolskeeps the tool schema compatible across every layer.Test plan
pytest tests/test_budget_fallbacks.py— chain resolution + case-insensitive lookup, cycle/missing-budget rejection, exhausted-layer skip, cross-chain tool schema, per-model usage grouping, hydration without double-counting, and the response-boundary switch (single + multi-layer + stale in-flight).ruff+mypyclean.