-
Notifications
You must be signed in to change notification settings - Fork 0
fix(sdk): make model pricing non-blocking for dollar budgets #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,47 @@ | ||
| import type { CompiledFlowSpec } from './compile.js'; | ||
| import type { PreflightRefusal } from './preflight.js'; | ||
| import { MODEL_PRICING } from './model-pricing.js'; | ||
| import type { ResolvedCliModel } from './cli-adapter.js'; | ||
| import type { PreflightWarning } from './preflight.js'; | ||
| import { hasPricing } from './model-pricing.js'; | ||
| import { resolveAdapterKind } from './adapters/index.js'; | ||
|
|
||
| /** Frozen dollar budgets require an exact model with a frozen table price. */ | ||
| export interface BudgetStepResolution { | ||
| readonly cli?: string; | ||
| readonly model?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Dollar budgets are light enforcement: pricing never refuses a run. A step | ||
| * whose model has no frozen price journals zero dollars (see `workerSpend`), | ||
| * so it cannot trip `maxDollars`, while its reported tokens still count toward | ||
| * any token budget; priced steps still accrue and a crossed limit still stops | ||
| * the run in the kernel. This warning names each dollar-unmetered step so the | ||
| * gap is reported, not silent. | ||
| * | ||
| * Codex selects its own model when none is declared, so a Codex step is | ||
| * expected to be unmetered and says so rather than asking for a fake price. | ||
| */ | ||
| export function budgetDiagnostics( | ||
| flow: CompiledFlowSpec, | ||
| resolvedModels: ReadonlyMap<string, ResolvedCliModel> = new Map(), | ||
| ): PreflightRefusal[] { | ||
| if (flow.budget?.pricing !== 'frozen') return []; | ||
| const diagnostics: PreflightRefusal[] = []; | ||
| const declared = [ | ||
| ...Object.entries(flow.agents ?? {}).map(([agent, d]) => ({ agent, model: d.model })), | ||
| ...flow.steps.flatMap(s => s.type !== 'deterministic' && s.model !== undefined | ||
| ? [{ stepId: s.id, model: s.model }] : []), | ||
| ]; | ||
| resolved: ReadonlyMap<string, BudgetStepResolution> = new Map(), | ||
| ): PreflightWarning[] { | ||
| if (flow.budget?.pricing !== 'frozen' || flow.budget.maxDollars === undefined) return []; | ||
| const warnings: PreflightWarning[] = []; | ||
| for (const step of flow.steps) { | ||
| if (step.type === 'deterministic' || flow.budget.maxDollars === undefined) continue; | ||
| const resolved = resolvedModels.get(step.id); | ||
| const model = resolved?.model | ||
| if (step.type === 'deterministic') continue; | ||
| const resolution = resolved.get(step.id); | ||
| const model = resolution?.model | ||
| ?? step.model ?? (step.type === 'agent' && step.agent !== undefined | ||
| ? flow.agents?.[step.agent]?.model : undefined); | ||
| if (model === undefined) diagnostics.push({ | ||
| severity: 'refusal', kind: 'budget_missing_price', stepId: step.id, | ||
| message: `Step "${step.id}" needs a declared, priced model for its dollar budget.`, | ||
| }); | ||
| else if (resolved?.source === 'adapter' | ||
| && !Object.hasOwn(MODEL_PRICING, model)) diagnostics.push({ | ||
| severity: 'refusal', kind: 'budget_missing_price', stepId: step.id, model, | ||
| message: `Model "${model}" has no frozen price for budget accounting.`, | ||
| }); | ||
| } | ||
| for (const declaration of declared) { | ||
| if (Object.hasOwn(MODEL_PRICING, declaration.model)) continue; | ||
| diagnostics.push({ | ||
| severity: 'refusal', kind: 'budget_missing_price', ...declaration, | ||
| message: `Model "${declaration.model}" has no frozen price for budget accounting.`, | ||
| if (hasPricing(model)) continue; | ||
| const cli = resolution?.cli ?? step.cli; | ||
| const reason = model !== undefined | ||
| ? `model "${model}" has no frozen price` | ||
| : cli !== undefined && resolveAdapterKind(cli) === 'codex' | ||
| ? 'Codex selects its own model' | ||
| : 'no model is declared'; | ||
| warnings.push({ | ||
| severity: 'warning', kind: 'budget_unmetered', stepId: step.id, | ||
| message: `Step "${step.id}" is unmetered (${reason}); it does not count toward the dollar budget.`, | ||
| }); | ||
| } | ||
| return diagnostics; | ||
| return warnings; | ||
| } | ||
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.