Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/context/adaptive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl AdaptiveState {
}

fn apply(&self, budget: &[ContextSourceConfig]) -> Vec<ContextSourceConfig> {
let base_total = budget.iter().map(|entry| entry.max_pct).sum::<f32>().max(f32::EPSILON);
let base_total = budget.iter().map(|entry| entry.max_pct).sum::<f32>().max(1.0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep adaptive budget normalization based on actual totals

Clamping base_total to 1.0 changes semantics for valid configs where budget percentages sum to less than 1.0 (allowed by context validation), so scaling is no longer anchored to the real pre-adaptation total. In those cases, adaptation can inflate per-source caps and increase total allocated share beyond what the config specified, which breaks the invariant this function is supposed to preserve and can materially change context allocation behavior.

Useful? React with 👍 / 👎.

let mut adjusted = budget
.iter()
.cloned()
Expand All @@ -96,7 +96,7 @@ impl AdaptiveState {
})
.collect::<Vec<_>>();
let adjusted_total =
adjusted.iter().map(|entry| entry.max_pct).sum::<f32>().max(f32::EPSILON);
adjusted.iter().map(|entry| entry.max_pct).sum::<f32>().max(1.0);
let scale = base_total / adjusted_total;
for entry in &mut adjusted {
entry.max_pct *= scale;
Expand Down
Loading