Skip to content

Apply time-bound provider promotions to AI-credit accounting - #11771

Merged
lpcox merged 4 commits into
mainfrom
copilot/apply-time-bound-model-promotions
Nov 18, 2026
Merged

lpcox merged 4 commits into
mainfrom
copilot/apply-time-bound-model-promotions

Conversation

@lpcox

@lpcox lpcox commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Runtime promotions were visible in model metadata but absent from AI-credit charges, causing budgets to consume credits at list prices.

  • Promotion lifecycle: Validate discount percentages and RFC3339 timestamps; support scheduled starts and exclusive expiry. Drop removed promotions on refresh.
  • Accounting: Apply exact discounts after tier selection, only to provider-priced components. Preserve canonical rates and leave operator overrides and fallback components unchanged.
  • Auditability: Distinguish advertised promotions from applied discounts in logs, token-usage records, and reflection, including component eligibility and list/effective pricing provenance. Generate banners from validated fields and model names.

A 50% promotion halves eligible charges until—but not including—the expiry timestamp; a 100% promotion records zero credits.

@lpcox lpcox changed the title [WIP] Apply time-bound model promotions to AI credit accounting Apply time-bound provider promotions to AI-credit accounting Nov 18, 2026
@lpcox
lpcox marked this pull request as ready for review November 18, 2026 14:56
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Pinned promotion metadata allows withdrawn offers to keep discounting later request and WebSocket usage, potentially leaving usage free until the offer’s original expiry.

2 open issues
What changed in this PR

Adds time-bound Copilot promotions to AWF’s AI-credit accounting while preserving canonical rates and excluding operator and fallback pricing.

Changes:

  • Validates promotion percentages and timestamps, including scheduled starts and exclusive expiry.
  • Applies exact discounts to eligible provider-priced components after tier selection.
  • Exposes advertised and applied promotion details in logs, usage records, and reflection.
File Description
docs/​api-proxy-sidecar.md Documents promotion accounting and audit metadata.
containers/​api-proxy/​token-tracker-shared.js Persists structured promotion metadata in usage records.
containers/​api-proxy/​token-budget-log.test.js Tests promotion metadata propagation and zero-credit logging.
containers/​api-proxy/​token-budget-log.js Emits promotion details in logs and budget fields.
containers/​api-proxy/​runtime-model-catalog.test.js Tests validation, timing boundaries, refreshes, and canonical rates.
containers/​api-proxy/​runtime-model-catalog.js Validates promotions and exposes activity status and generated banners.
containers/​api-proxy/​guards/​pricing-resolution.test.js Updates discount accounting and budget expectations.
containers/​api-proxy/​guards/​ai-credits-guard.test.js Covers component discounts, pricing exclusions, expiry, and budgets.
containers/​api-proxy/​guards/​ai-credits-guard.js Applies exact discounts and records pricing provenance.

Review effort: Max (adaptive)


function getRuntimePricingFact(provider, model, catalog = runtimeCatalog) {
function getRuntimePromotion(provider, model, catalog = runtimeCatalog, options = {}) {
const promotion = normalizePromotion(findRuntimeModel(provider, model, catalog)?.promotion);
pricingObservedAt: pricingResolution.observedAt,
pricingApiVersion: pricingResolution.apiVersion,
pricingDiscountPercent: pricingResolution.discountPercent,
pricingDiscountPercent: promotion?.discountPercent,
@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in c96d95d. Pinned requests now retain captured tariffs but use live promotion metadata, and the token-usage schema distinguishes advertised discounts from applied discounts.

...(promotion.startsAt !== undefined ? { starts_at: promotion.startsAt } : {}),
active: promotion.active,
applied: false,
banner: `${record.displayName || record.id}: ${promotion.discountPercent}% promotion ` +
@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@lpcox Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation has been built for this PR.

Download preview artifact

To view locally:

  1. Download the docs-preview-pr-11771 artifact from the workflow run
  2. Unzip and open index.html in your browser

Built from commit fe12e56

@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts

…und-model-promotions

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and resolve conflicts

Merged main cleanly in c557ab7 (two-parent merge commit); no conflicts required resolution.

@lpcox
lpcox merged commit ac20fb1 into main Nov 18, 2026
39 of 41 checks passed
@lpcox
lpcox deleted the copilot/apply-time-bound-model-promotions branch November 18, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply time-bound model promotions to AI credit accounting

4 participants