Skip to content

Commit 6e0aab7

Browse files
committed
fix(budget): cap per-core contribution + lower auto budget to curb over-selection
1 parent 776dd1f commit 6e0aab7

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

diffctx/src/config/budget.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ pub struct BudgetConfig {
55
pub auto_multiplier: f64,
66
pub auto_min: u32,
77
pub auto_max: u32,
8+
/// Per-core-fragment ceiling when sizing the auto budget. A core fragment
9+
/// that is a whole-file `Chunk` (e.g. a 2000-line unparsed template touched
10+
/// by one hunk) would otherwise inflate the budget by its entire byte
11+
/// weight, dragging in the whole repo as "context". Capping each core
12+
/// fragment's budget contribution decouples "how big are the files I edited"
13+
/// from "how much of the repo do I pull in". Does not affect whether the
14+
/// changed file is included (it always is) — only the context budget it earns.
15+
pub core_token_cap_per_fragment: u32,
816
}
917

1018
impl Default for BudgetConfig {
1119
fn default() -> Self {
1220
Self {
1321
unlimited: 10_000_000,
14-
auto_multiplier: 5.0,
22+
auto_multiplier: 3.0,
1523
auto_min: 8_000,
16-
auto_max: 124_000,
24+
auto_max: 48_000,
25+
core_token_cap_per_fragment: 1_500,
1726
}
1827
}
1928
}

diffctx/src/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn select_with_params(
341341
.all_fragments
342342
.iter()
343343
.filter(|f| state.core_ids.contains(&f.id))
344-
.map(|f| f.token_count)
344+
.map(|f| f.token_count.min(BUDGET.core_token_cap_per_fragment))
345345
.sum();
346346
let auto = (core_tokens as f64 * BUDGET.auto_multiplier) as u32;
347347
auto.clamp(BUDGET.auto_min, BUDGET.auto_max)

0 commit comments

Comments
 (0)