feat(engine): expose context_input_budget_for_route for external budget reuse#3968
Merged
Merged
Conversation
…et reuse The internal input-budget math (window minus the window-dependent output reservation minus headroom) is private to core::engine. External hosts/wrappers that derive their own compaction trigger line end up mirroring those constants (the 500K large-window threshold, TURN_MAX_OUTPUT_TOKENS, the output-reservation split, the headroom) and silently drift when the engine changes them. Make context_input_budget_for_route pub and re-export it from core::engine so callers reuse the exact same computation (pass input_tokens = 0 for the full budget). No behavior change.
Owner
|
Merged into |
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
context_input_budget_for_route— the internal input-budget computation (window − window-dependent output reservation − headroom) that is the single source of truth for the preflight / emergency-recovery / capacity-trim decisions — ispub(super)tocore::engine.External hosts / wrappers that embed the engine and derive their own compaction or pressure trigger line have no way to reuse it, so they end up mirroring the constants: the
≥500Klarge-window threshold,TURN_MAX_OUTPUT_TOKENS, the output-reservation split inroute_output_reservation_for_window, and the headroom. When the engine later changes any of these, the mirrored copy still compiles but silently diverges — the host computes a different budget than the engine actually enforces. (In our case the host's "compact now" line drifted above the engine's emergency line, so the graceful summarize path stopped firing and every long session fell through to emergency recovery.)Change
Make
context_input_budget_for_routepuband re-export it fromcore::engine, so a host can compute the exact same budget the engine uses. Passinput_tokens = 0to get the full route budget.Purely a visibility change:
ApiProvider,RouteLimits,usize).cargo check -p codewhale-tuipasses.This lets downstream embedders reuse the engine's budget math instead of re-deriving (and drifting from) its internal constants.