Skip to content

Commit 8cb2586

Browse files
committed
fix(plugin): history budget now factors in execute_threshold_percentage
The compressor budget formula was context_limit × history_budget_percentage but the agreed design was context_limit × execute_threshold × history_budget_percentage. With execute_threshold=40% and history_budget=15%, the budget was 150k instead of the correct 60k. Fixed in both transform.ts and execute-status.ts.
1 parent d8da98b commit 8cb2586

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/plugin/src/hooks/magic-context/execute-status.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ export function executeStatus(
143143

144144
const budgetTokens =
145145
historyBudgetPercentage && contextLimit > 0
146-
? Math.floor(contextLimit * historyBudgetPercentage)
146+
? Math.floor(
147+
contextLimit *
148+
(Math.min(executeThresholdPercentage, 80) / 100) *
149+
historyBudgetPercentage,
150+
)
147151
: null;
148152
const budgetUsage = budgetTokens
149153
? ((historyBlockTokens / budgetTokens) * 100).toFixed(0)

packages/plugin/src/hooks/magic-context/hook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export function createMagicContextHook(deps: MagicContextDeps) {
185185
compartmentTokenBudget:
186186
deps.config.compartment_token_budget ?? DEFAULT_COMPARTMENT_TOKEN_BUDGET,
187187
historyBudgetPercentage: deps.config.history_budget_percentage,
188+
executeThresholdPercentage: deps.config.execute_threshold_percentage,
188189
historianTimeoutMs: deps.config.historian_timeout_ms ?? DEFAULT_HISTORIAN_TIMEOUT_MS,
189190
getNotificationParams: (sessionId) =>
190191
getLiveNotificationParams(sessionId, liveModelBySession, variantBySession),

packages/plugin/src/hooks/magic-context/transform.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface TransformDeps {
6868
};
6969
compartmentTokenBudget?: number;
7070
historyBudgetPercentage?: number;
71+
executeThresholdPercentage?: number | { default: number; [modelKey: string]: number };
7172
historianTimeoutMs?: number;
7273
getNotificationParams?: (
7374
sessionId: string,
@@ -264,6 +265,13 @@ export function createTransform(deps: TransformDeps) {
264265
deps.historyBudgetPercentage && contextUsage.percentage > 0
265266
? Math.floor(
266267
(contextUsage.inputTokens / (contextUsage.percentage / 100)) *
268+
(Math.min(
269+
typeof deps.executeThresholdPercentage === "number"
270+
? deps.executeThresholdPercentage
271+
: (deps.executeThresholdPercentage?.default ?? 80),
272+
80,
273+
) /
274+
100) *
267275
deps.historyBudgetPercentage,
268276
)
269277
: undefined,

0 commit comments

Comments
 (0)