Repository navigation
fix: preserve exact-decimal AI-credit accounting - #11157
Conversation
Keep decimal tariff precision through normalization, shared resolution, token charges and accumulation. Round only public outputs; compare exact budgets and steering thresholds. Add bounded arithmetic and provider-free distributed HTTP/WebSocket regressions. Co-authored-by: Copilot App <[email protected]>
Documentation PreviewDocumentation has been built for this PR. To view locally:
Built from commit 3f12406 |
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 93.78% | 93.77% | 📉 -0.01% |
| Statements | 92.33% | 92.33% | ➡️ +0.00% |
| Functions | 93.07% | 93.07% | ➡️ +0.00% |
| Branches | 86.57% | 86.56% | ➡️ -0.01% |
📁 Per-file Coverage Changes (1 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/nvx/one-shot-process.ts |
84.0% → 81.5% (-2.47%) | 76.8% → 74.7% (-2.11%) |
Coverage comparison generated by scripts/ci/compare-coverage.ts
There was a problem hiding this comment.
🟡 Changes recommended
Unhandled pricing errors can leave reflection responses unfinished or stop the proxy during model recovery despite valid alternative candidates.
3 open issues
What changed in this PR
Extends AWF’s shared pricing pipeline with exact-decimal accounting from source rates through token charges and budget enforcement, while keeping public numeric outputs compatible.
Changes:
- Adds bounded rational arithmetic and preserves exact rates through resolution, request snapshots and accumulated usage.
- Compares unrounded totals against budgets and steering thresholds, rounding only public outputs.
- Preserves decimal strings in generated pricing assets and expands regression coverage, provider-free smoke checks and documentation.
| File | Description |
|---|---|
src/model-information-contract/pricing-resolution.js |
Updates the host resolver copy to preserve exact rates. |
src/model-information-contract/pricing-resolution.d.ts |
Allows decimal-string source rates in host contracts. |
src/model-information-contract/exact-pricing.js |
Adds the host copy of bounded rational arithmetic. |
shared/model-information/target.generated.json |
Updates the generated catalogue revision. |
shared/model-information/pricing-resolution.js |
Preserves exact rates during selection and component merging. |
shared/model-information/pricing-resolution.d.ts |
Defines decimal-string support for pricing facts. |
shared/model-information/manifest.generated.json |
Updates compiler version and catalogue revision. |
shared/model-information/exact-pricing.js |
Implements exact arithmetic, private rate companions and output rounding. |
shared/model-information/catalog.generated.json |
Updates the generated catalogue revision. |
shared/model-information/baseline-to-target.generated.json |
Aligns comparison metadata with the regenerated catalogue. |
scripts/model-information/compile.test.ts |
Verifies compiler version and long-decimal preservation. |
scripts/model-information/compile.cjs |
Preserves source decimals and distributes the arithmetic helper. |
scripts/ci/smoke-pricing-resolution.cjs |
Expands HTTP/WebSocket accounting and boundary smoke checks. |
docs/model-catalogue-publication.md |
Documents exact accounting, compatibility and failure limits. |
docs/adr/0004-model-information-management.md |
Records the exact-arithmetic implementation and scope. |
containers/api-proxy/token-budget-log.test.js |
Updates expectations for invalid operator pricing. |
containers/api-proxy/runtime-model-catalog.js |
Normalizes provider prices exactly and preserves captured rates. |
containers/api-proxy/provider-pricing-overlays.js |
Uses exact arithmetic for operator pricing conversions. |
containers/api-proxy/model-pricing-catalog.js |
Normalizes configured catalogue rates with exact companions. |
containers/api-proxy/model-information.pricing.generated.json |
Stores maintained prices as decimal strings. |
containers/api-proxy/model-information.fallback-pricing.generated.json |
Preserves decimal strings in native compatibility prices. |
containers/api-proxy/guards/exact-pricing.test.js |
Adds arithmetic, budget, snapshot and failure regressions. |
containers/api-proxy/guards/ai-credits-guard.js |
Uses exact charges, accumulation and enforcement comparisons. |
containers/api-proxy/catalogue-proxy.test.js |
Adds long-decimal fixtures to packaged smoke coverage. |
containers/api-proxy/catalogue-pricing.js |
Adapts maintained, imported and central pricing to exact arithmetic. |
containers/api-proxy/catalogue-contract/pricing-resolution.js |
Updates the proxy resolver distribution. |
containers/api-proxy/catalogue-contract/pricing-resolution.d.ts |
Adds decimal-string source types to proxy contracts. |
containers/api-proxy/catalogue-contract/exact-pricing.js |
Ships the arithmetic helper with the proxy. |
Review effort: Max (auto)
| } catch (error) { | ||
| throwAccountingFailure(error); |
There was a problem hiding this comment.
Fixed in 6a89974: both /reflect routes now catch pricing-resolution failures before writing headers and return a sanitized 500 JSON response; dispatch blocking remains intact.
|
|
||
| function getRuntimePricingFact(provider, model, catalog = runtimeCatalog) { | ||
| const record = findRuntimeModel(provider, model, catalog); | ||
| if (record?.pricingError) throw new Error('pricing_resolution_invalid_tariff'); |
There was a problem hiding this comment.
Fixed in 6a89974: recovery skips candidates that raise pricing_resolution_error and continues evaluating other candidates.
| Object.entries(tariff.components).some(([field, item]) => { | ||
| if (typeof item.price === 'object') return field !== 'cacheWrite'; | ||
| exact.decimal(item.price); | ||
| return false; | ||
| })) { |
There was a problem hiding this comment.
Fixed in 6a89974: tariff validation now checks the unit-converted numeric projection and reports catalogue_tariff_unsupported; regression coverage confirms the loader retains the bundled fallback.
|
@copilot merge main, resolve conflicts, and address review feedback |
…ricing-accounting # Conflicts: # containers/api-proxy/model-information.fallback-pricing.generated.json # shared/model-information/baseline-to-target.generated.json # shared/model-information/catalog.generated.json # shared/model-information/manifest.generated.json # shared/model-information/target.generated.json
|
✅ Copilot review passed with no inline comments. @lpcox Add the |
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 93.78% | 93.77% | 📉 -0.01% |
| Statements | 92.33% | 92.33% | ➡️ +0.00% |
| Functions | 93.07% | 93.07% | ➡️ +0.00% |
| Branches | 86.57% | 86.56% | ➡️ -0.01% |
📁 Per-file Coverage Changes (1 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/nvx/one-shot-process.ts |
84.0% → 81.5% (-2.47%) | 76.8% → 74.7% (-2.11%) |
Coverage comparison generated by scripts/ci/compare-coverage.ts
|
🔌 Smoke Services is testing service connectivity for this pull request... |
|
🔑 Smoke Copilot BYOK AOAI (api-key) is testing Azure OpenAI BYOK (api-key) mode on this pull request... |
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤
|
|
💎 Smoke Gemini is crystallizing results on this pull request... |
|
✅ Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓
|
|
✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟
|
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓
|
|
Smoke Cloud Hypervisor completed. Cloud Hypervisor + Copilot passed.
|
|
📡 Smoke OTel Tracing reports failed. OTel tracing regression detected.
|
|
🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅
|
|
✅ Build Test Suite completed successfully!
|
|
Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.
|
|
✅ Security Guard completed successfully! Security GuardOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Smoke Claude passed
|
|
Smoke Copilot: PR "[WIP] Fix Copilot credential-placeholder assertions in daily runtime regression"
Overall: PASS — @lpcox
|
|
EGRESS_RESULT allow=pass deny=pass
Overall: PASS — cc @lpcox
|
|
fix: create issues for daily regression failures MCP connectivity ✅, GitHub.com ✅, File write/read ✅, BYOK ✅ Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra Overall: PASS
|
🏗️ Build Test Suite Results
Overall: 7/8 ecosystems passed — FAIL Java failure details
Note: .NET needed
|
|
OTEL smoke test
|
Smoke Test: Claude Engine
Overall result: PASS
|
Chroot version comparison
Not all tests passed (Node.js mismatch), so the
|
Before #11157, AWF parsed Copilot's batch_size 0, all-zero listing as no runtime price: the model was unknown and its usage unpriced, never free. Pricing it as a zero tariff would change that meaning, and Copilot's premium-request billing still lists these models as premium with multiplier 1. Keep the previous meaning; AWF's policy for unknown prices then applies. A reviewed zero-cost catalog entry remains the way to declare a model free. This reverts commit 77fd6cc. Co-authored-by: Copilot <[email protected]>
State in the comment and the test name that a batch_size 0, all-zero listing is no runtime price, as before #11157: the model is unknown, not free and not an invalid tariff. Co-authored-by: Copilot <[email protected]>
buildCommonGuardChecks ran the pricing check before the model-specific guards, so a model whose pricing can't be resolved got a 500 pricing_resolution_error even when model policy rejects it. Copilot lists some models, such as gpt-4o, with batch_size 0, which pricing rejects since #11157, so a disallowed gpt-4o got a 500 instead of a 403. This broke the Model Routing End-to-End Smoke workflow on main. Run the model-specific guards (multiplier cap, retired model and model policy) before the pricing check, so a pricing failure never hides a decision about the model. Pricing rules are unchanged: an allowed model whose tariff is invalid still fails with pricing_resolution_error. Refs #11211 Co-authored-by: Copilot <[email protected]>
buildCommonGuardChecks ran the pricing check before the model-specific guards, so a model whose pricing can't be resolved got a 500 pricing_resolution_error even when model policy rejects it. Copilot lists some models, such as gpt-4o, with batch_size 0, which pricing rejects since #11157, so a disallowed gpt-4o got a 500 instead of a 403. This broke the Model Routing End-to-End Smoke workflow on main. Run the model-specific guards (multiplier cap, retired model and model policy) before the pricing check, so a pricing failure never hides a decision about the model. Pricing rules are unchanged: an allowed model whose tariff is invalid still fails with pricing_resolution_error. Refs #11211 Co-authored-by: Copilot <[email protected]>


Summary
Make exact arithmetic authoritative from pricing sources through token charges and budget enforcement. Preserve the shared resolver and canonical fallback foundations from #11113 and #11117; no rate authoring, scope expansion, new admission policy, or shadow rollout.
Relates to #10295 and #10290. Both remain open.
Arithmetic and compatibility
String(value)representation.0.9999996no longer prematurely exhausts a one-credit budget just because it displays as one. One thousand one-token responses at USD0.0001/million retain exactly0.00001credits despite each response displaying zero.Validation
npm run models:generate/npm run models:checknpm run build/npm run type-check; commit-hook ESLint passes with warning-only existing outputnpm test --prefix containers/api-proxy -- --maxWorkers=2)scripts/ci/smoke-pricing-resolution.cjsruns real HTTP/WebSocket accounting in off-tree Docker application files and extracted npm packages, with both shipped data and compiler-generated long-decimal maintained/import fixtures. Every run enforces zero network calls. Includes tiny-response accumulation, fractional rates/batches, cache/reasoning, below/equal/above budget/hard-cap/steering boundaries, rounding ties, pins/refresh, partial fallback, and accounting-failure dispatch blocking.No live provider inference, manual workflow dispatch, container/guest/VM run, labels, or merge performed. Automatic PR CI is expected.
Concrete limits
Existing host numeric configuration schemas and upstream JSON Number parsing cannot recover original decimal spellings. Public numeric snapshots are output projections, not a restartable exact ledger. Supported decimal inputs are bounded to 420 characters, 400 mantissa digits, three exponent digits and absolute adjusted exponent 400; rational intermediates are bounded to 4,096 digits. Larger/unrepresentable values fail explicitly. Generalized tariffs/units/currencies, promotions/successors, non-token charges and broader export/reasoning migrations remain out of scope.