Skip to content

fix: estimate missing model prices with same-backend medians - #11164

Merged
lpcox merged 4 commits into
mainfrom
lpcox-median-fallback-pricing
Nov 6, 2026
Merged

lpcox merged 4 commits into
mainfrom
lpcox-median-fallback-pricing

Conversation

@lpcox

@lpcox lpcox commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Activate median accounting for the final concrete named model with no applicable price or configured default bucket. Estimated usage now contributes to AI-credit totals, steering, configured budgets, and the hard cap instead of being silently left out of accounting.

  • Prefer the per-component median within the same serving backend and declared canonical family. If the family is unidentified or has no eligible priced members, use all eligible priced identities on that backend. Never borrow another backend's prices or strip publisher namespaces.
  • Sort each component independently using exact rational prices. Odd counts select the middle value; even counts take the exact arithmetic mean of the middle two. Zero remains a price; null/missing cache-write components are not zero donors. Cache write remains null when none is supplied. Missing reasoning uses each donor's output rate before taking its median.
  • Keep operator/configured and exact runtime/central/maintained/imported tariffs authoritative. Recognized selector policy and configured defaults retain precedence; the estimate is attempted after configured defaults, before the unchanged unknown-sentinel path. No eligible backend donors means explicit warn/proceed/exclusion, with the residual budget-undercount limitation documented.
  • Resolve donors once per canonical identity using existing source precedence, scoped central freshness/effective intervals and requested prompt-token tiers. Exclude stale provider observations, retired/removed records and policy-generated/default/estimated prices. Reuse request-pinned runtime/feed captures; no additional network fetching or execution-availability requirement.
  • Emit deduplicated, sanitized estimated_model_ai_credits_pricing warnings. Carry family/backend estimate policy, donor/component counts, source kinds and a deterministic tariff fingerprint through real HTTP/WebSocket JSONL records and reflected accounting, including partial-provider fills. Quiet probes remain quiet, and malformed prices retain sanitized errors and dispatch blocking.
  • Do not change routing, requests, model admission or automatic execution-model recovery. The bundled naming catalogue currently declares no families; absent declared family evidence in the captured catalogue, these requests intentionally use backend medians rather than a guessed prefix family.

Validation

  • Full API-proxy suite: 143 suites passed; 3,352 tests passed, 2 skipped.
  • Root shared resolver, canonical compiler and publication tests: 71 tests passed.
  • npm run build, npm run type-check, npm run models:check, changed-document Markdown lint and git diff --check passed. Commit hooks ran root lint with no errors and the production build.
  • Extended provider-free smoke ran in both the off-tree Docker application layout (not a container run) and extracted npm package, using shipped assets and compiler-generated fixture assets. All four executions prohibited network access and asserted zero network calls.
  • Smoke checks exercise actual HTTP/WebSocket charges, persisted family/backend estimate metadata, exact even-count averaging around budget boundaries, reflection, source precedence, namespace boundaries, refresh/request pins and unchanged accounting-error blocking. Unit coverage additionally includes odd/singleton medians, independently sorted components, zero/null/missing values, tiny exact decimals, aliases/duplicate IDs, stale/excluded scopes, optional reasoning, warning deduplication, quiet probes, steering and hard-cap thresholds.

No live provider inference, workflow dispatch, extra guest/container runs or merge performed.

Relates to #10295 and #10290; this does not close either parent phase.

Use exact per-component family medians after configured defaults,
falling back to the serving backend median without changing execution selection.
Charge estimates to budgets and expose warnings and provenance.

Co-authored-by: Copilot App <[email protected]>
Copilot AI adaptive review requested due to automatic review settings November 5, 2026 19:09
@github-actions

github-actions Bot commented Nov 5, 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-11164 artifact from the workflow run
  2. Unzip and open index.html in your browser

Built from commit c38d2a6

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

Unresolved pricing-resolution defects can discard valid rates, misidentify or double-count tariff donors, and apply incorrect fallbacks or freshness checks, affecting estimated credits and budget enforcement.

6 open issues
What changed in this PR

Extends AWF’s pricing resolver so concrete models without exact or configured-default prices can contribute estimated usage to AI-credit totals and budget enforcement using same-backend donors.

Changes:

  • Adds exact per-component medians, preferring declared-family donors before backend-wide donors.
  • Carries estimate warnings and provenance through accounting, reflection, and HTTP/WebSocket usage records.
  • Expands unit and offline smoke coverage and documents the estimation policy.
File Description
src/​model-information-contract/​pricing-resolution.js Mirrors median resolution and partial-provider merge logic.
src/​model-information-contract/​pricing-resolution.d.ts Adds estimate sources, metadata, and helper types.
shared/​model-information/​pricing-resolution.js Implements exact medians and the new fallback stage.
shared/​model-information/​pricing-resolution.d.ts Defines the shared estimate contract.
scripts/​ci/​smoke-pricing-resolution.cjs Extends offline protocol, budget, and provenance checks.
docs/​model-catalogue-publication.md Documents estimated accounting and residual unpriced usage.
docs/​awf-config-spec.md Defines donor eligibility, precedence, and estimate semantics.
docs/​adr/​0004-model-information-management.md Updates the accounting and eligibility boundary.
containers/​api-proxy/​token-tracker.schema.test.js Checks estimate metadata in serialized usage records.
containers/​api-proxy/​token-tracker-shared.js Copies estimate metadata into usage records.
containers/​api-proxy/​token-budget-log.test.js Updates the no-donor accounting scenario.
containers/​api-proxy/​token-budget-log.js Adds estimate metadata to accounting log fields.
containers/​api-proxy/​server.websocket.test.js Updates WebSocket estimate-warning expectations.
containers/​api-proxy/​server.token-guards.test.js Checks estimated charging for missing-price HTTP models.
containers/​api-proxy/​runtime-model-catalog.js Associates runtime pricing captures with capture times.
containers/​api-proxy/​provider-pricing-overlays.js Exposes operator-configured model IDs for donor selection.
containers/​api-proxy/​model-recovery.js Excludes median estimates from automatic recovery selection.
containers/​api-proxy/​model-pricing-catalog.js Exposes configured catalogue model IDs.
containers/​api-proxy/​guards/​pricing-resolution.test.js Updates precedence and partial-fill accounting expectations.
containers/​api-proxy/​guards/​median-pricing.test.js Adds median, donor, precision, and enforcement coverage.
containers/​api-proxy/​guards/​ai-credits-guard.test.js Updates estimate warnings, accounting, and priceability checks.
containers/​api-proxy/​guards/​ai-credits-guard.js Integrates estimates, warnings, and reflected metadata.
containers/​api-proxy/​catalogue-pricing.test.js Tests donor exclusions and capture stability.
containers/​api-proxy/​catalogue-pricing.js Resolves donors and builds estimate fingerprints.
containers/​api-proxy/​catalogue-loader.test.js Updates fallback expectations when central pricing is unavailable.
containers/​api-proxy/​catalogue-contract/​pricing-resolution.js Mirrors the shared resolver for the API proxy.
containers/​api-proxy/​catalogue-contract/​pricing-resolution.d.ts Mirrors estimate types for API-proxy consumers.

Review effort: Max (auto)

Comment on lines +165 to +166
const time = options.catalogue?.time ?? getRuntimePricingCaptureTime(runtime, provider);
const maxAge = options.catalogue?.maxAge ?? 30 * 24 * 3600 * 1000;
Comment on lines +169 to +174
for (const record of catalogue?.snapshot.models || []) {
// Feed family evidence may enrich pricing, but feed aliases cannot extend naming policy.
models.set(record.identity.key, { ...record, identity: {
...record.identity, aliases: declared.get(record.identity.key)?.identity.aliases || [],
} });
}
Comment on lines +196 to +199
const resolved = resolve(id);
if (!resolved.identity || seen.has(resolved.identity.key)) continue;
seen.add(resolved.identity.key);
const canonical = resolved.identity.rawId;
Comment on lines +204 to +205
const resolution = resolvePricing({
identity: resolved.identity, scope, inputTokens, time, maxAge, sources: {
Comment on lines +206 to +207
operator: () => getProviderPricingFact(provider, canonical),
configured: () => getConfiguredPricingFact(provider, canonical),
Comment on lines +123 to +127
if (result?.estimate) {
const selected = Object.hasOwn(runtime.pricing, 'reasoning') ? runtime : result;
pricing.reasoning = exact.rate(selected.pricing, 'reasoning');
componentSources.reasoning = componentProvenance(selected);
}
@github-actions

github-actions Bot commented Nov 5, 2026 •

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.

@lpcox

lpcox commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

Copilot AI commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed the pricing review feedback in c02d554.

@lpcox

lpcox commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot AI commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@copilot fix this failing ci check and make sure that 'npm test' runs without any failures https://github.com/github/gh-aw-firewall/actions/runs/42098337408/job/127552257668?pr=11164

Fixed the stale smoke-test expectation in feabd54. Both failing CI suites pass locally, and full npm test now passes: 562 suites, 11,951 tests passed (7 suites and 72 tests skipped).

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

Tested by Smoke Chroot

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Smoke Cloud Hypervisor completed. Cloud Hypervisor + Copilot passed.

Cloud Hypervisor + Copilot smoke test by Smoke Cloud Hypervisor

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Smoke Claude passed

Generated by Smoke Claude for #11164

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅

🛡️ Egress verdict from Smoke Copilot Network Isolation

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Build Test Suite completed successfully!

Generated by Build Test Suite for #11164

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

Smoke Codex

Outcome: reported_no_action

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.

Generated from Smoke Codex · gpt54 · ~16 AIC · ⊞ 21.0K · ◷

🔮 The oracle has spoken through Smoke Codex

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

💎 Smoke Gemini is crystallizing results on this pull request...

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services is testing service connectivity for this pull request...

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot BYOK AOAI (api-key) is testing Azure OpenAI BYOK (api-key) mode on this pull request...

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Security Guard completed successfully!

Security Guard

Outcome: reported_no_action

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.

Generated from Security Guard · sonnet55 · ~16 AIC · ⊞ 8.2K · ◷

Generated by Security Guard for #11164

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Smoke test: FAIL

  • Fix canonical Copilot placeholder checks in daily runtime regression
  • fix: make daily Codex regression noninteractive and sidecar-backed
  • Merged PRs read: ✅
  • PR details read: ✅
  • Playwright title: ❌
  • Temp file + cat: ✅
  • Build (npm ci && npm run build): ✅
  • Overall: FAIL

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

OTEL smoke test

  • ✅ S1 Module: otel.js loads; exports startRequestSpan, setTokenAttributes, endSpan, shutdown, isEnabled, etc.
  • ✅ S2 Tests: 46/46 passed
  • ✅ S3 Env forwarding: GITHUB_AW_OTEL_TRACE_ID/PARENT_SPAN_ID in env-passthrough.ts; OTEL vars in api-proxy-env-config.ts
  • ✅ S4 Token tracker: onUsage hook present in token-tracker-http.js
  • ✅ S5 Diagnostics: /tmp/gh-aw/otel.jsonl present (1 line)

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fix canonical Copilot placeholder checks in daily runtime regression
fix: make daily Codex regression noninteractive and sidecar-backed
MCP connectivity: ✅
GitHub.com connectivity: ✅
File verification: ✅
BYOK inference: ✅
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 status: PASS cc @lpcox

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Copilot BYOK Smoke Test: ✅ PASS

Test Results:

  • ✅ GitHub MCP connectivity verified (2 recent merged PRs fetched)
  • ✅ GitHub.com reachable (HTTP 200)
  • ✅ File write/read test passed
  • ✅ Direct BYOK inference path working (agent → api-proxy → api.githubcopilot.com)

Mode: Direct BYOK (COPILOT_PROVIDER_API_KEY) with api-proxy credential injection

All smoke tests passed successfully.

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia ✅ 1/1 passed ✅ PASS
Bun hono ✅ 1/1 passed ✅ PASS
C++ fmt ✅ N/A ✅ PASS
C++ json ✅ N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world ✅ N/A ✅ PASS
.NET json-parse ✅ N/A ✅ PASS
Go color ✅ pass ✅ PASS
Go env ✅ pass ✅ PASS
Go uuid ✅ pass ✅ PASS
Java gson ❌ 0/? (not run) ❌ FAIL
Java caffeine ❌ 0/? (not run) ❌ FAIL
Node.js clsx ✅ passed ✅ PASS
Node.js execa ✅ passed ✅ PASS
Node.js p-limit ✅ passed ✅ PASS
Rust fd ✅ 1/1 passed ✅ PASS
Rust zoxide ✅ 1/1 passed ✅ PASS

Overall: 7/8 ecosystems passed — FAIL

Java failure: mvn compile could not resolve plugins from Maven Central: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty (the Java trust store is empty in this environment). ~/.m2 was also not writable (owned by root), so I used an alternate local repo.

.NET note: the first dotnet run failed because /run/user/1001 was missing. After setting XDG_RUNTIME_DIR, both projects restored, built and ran.

Generated by Build Test Suite for #11164 · copilot · auto · ~27 AIC · ⊞ 5.7K · ◷
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot: PR #11161 "Fix canonical Copilot placeholder checks in daily runtime regression"; PR #11159 "fix: make daily Codex regression noninteractive and sidecar-backed"

  • GitHub MCP ✅
  • GitHub.com connectivity ✅
  • File write/read ✅

Overall: PASS — @lpcox

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions github-actions Bot added the smoke-copilot-network-isolation Copilot network-isolation egress smoke test label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

EGRESS_RESULT allow=pass deny=pass

  • ✅ Allowed domain (api.github.com): 200
  • ✅ Blocked domain (example.com): blocked

Overall: PASS — cc @lpcox

🛡️ Egress verdict from Smoke Copilot Network Isolation
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

  • API status: ✅ PASS
  • GitHub check: ✅ PASS
  • File status: ✅ PASS

Overall result: PASS

Generated by Smoke Claude for #11164 · claude · haiku45 · ~35 AIC · ⊞ 6.1K · ◷
Add label ready-for-aw to run again

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Chroot Version Comparison

Runtime Host Version Chroot Version Match?
Python Python 3.12.16 Python 3.12.16 ✅ YES
Node.js v24.22.2 v22.23.2 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: ❌ Not all tests passed. Node.js differs between host (v24) and chroot (v22). The smoke-chroot label was not added.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@lpcox

lpcox commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot AI commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the failing ci check. make sure that 'npm test' has no failures https://github.com/github/gh-aw-firewall/actions/runs/42117523325/job/127672068997?pr=11164

The failing run compiled merge commit 33a99c0, whose base contained duplicate runHost helpers. Upstream commit 084970b (#11159) removes the duplicate, and the current PR merge-ref version has one generalized helper. No branch change was needed for that failure. Reinstalled the declared dependencies and reran full npm test: build passed, 562 suites and 11,951 tests passed (7 suites and 72 tests skipped). The linked historical run itself remains failed; it predates the upstream fix.

Bring in the upstream runHost consolidation so the PR's merged root test suite compiles.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants