Skip to content

feat(providers): correlate X-CPA-TRACE-ID auth_index with usage history - #14544

Merged
diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.51from
RaviTharuma:feat/cpa-trace-auth-index
Sep 22, 2026
Merged

diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.51from
RaviTharuma:feat/cpa-trace-auth-index

Conversation

@RaviTharuma

Copy link
Copy Markdown
Contributor

Summary

  • CLIProxyAPI stamps the selected credential on X-CPA-TRACE-ID. This PR stores that opaque auth_index on usage_history for the success, streaming, and error paths. A later completed attempt backfills the column when the first write missed the header.
  • The human-readable account label is resolved at read time from the sanitized account-health projection (feat(services): expose sanitized CLIProxyAPI account health #11314). Emails, paths, tokens, and raw management payloads are dropped and are never written to the column.
  • A missing header or an unrecognized shape stays unattributed. It does not fail the request.

Related Issues

Validation

Choose the change type and focused loop from the
Contribution Golden Path. The full unit suite,
Vitest, the 60% coverage gate, and the production build all run in CI on this PR (#8329):

  • Change type: DB
  • Focused tests and category gates from the golden path: node --import tsx/esm --test tests/unit/cpa-trace-auth-index.test.ts tests/unit/cpa-auth-index-usage.test.ts tests/unit/db/migration-185-cpa-auth-index.test.ts tests/unit/chatcore-failure-usage.test.ts (12 passed); npm run check:migration-numbering; npm run check:file-size; npm run check:docs-counts; node scripts/check/check-docs-sync.mjs
  • npm run lint — ESLint on the touched TypeScript files (the same command lint-staged runs). The full eslint . suite still runs in CI.
  • Reconciled with the current active release base release/v3.8.51 (9f4d3b0ab8); focused checks rerun afterward
  • Production-code changes include a new or updated automated test in this PR
  • SonarQube is temporarily opt-in while the private project has no quota; it is not a PR gate.

Tests Added Or Updated

  • tests/unit/cpa-trace-auth-index.test.ts — opaque parse, JSON and auth_index= forms, rejection of emails/paths/secrets, header rebuild, sanitized label join
  • tests/unit/cpa-auth-index-usage.test.ts — persist plus dedup backfill on a fresh database
  • tests/unit/db/migration-185-cpa-auth-index.test.ts — upgrade from a prior usage_history and idempotent re-run when the column already exists
  • tests/unit/chatcore-failure-usage.test.ts — existing failure-usage characterization, still passing with the extra field

Coverage Notes

  • open-sse/handlers/chatCore/cpaTraceAuthIndex.ts, the usage-history write/read, and migration 185 are covered by the tests above.
  • open-sse/handlers/chatCore.ts only threads readCpaAuthIndex(providerResponse) into the three existing usage writers (failure, non-streaming, streaming). The parser and the label join live in leaves under the file-size cap. The frozen ceiling moves 6400 → 6402 because Prettier keeps the failure-usage property and the import on their own lines.

Reviewer Notes

  • This follows the scope accepted on feat(providers): correlate X-CPA-TRACE-ID auth_index with account health #11725 (2026-08-29): extract and defensively parse X-CPA-TRACE-ID in the CLIProxyAPI executor, thread the opaque auth_index into usage_history.cpa_auth_index, and resolve the label at read time. It is not a credential-selection input and it does not reimplement session affinity.
  • fix(resilience): classify CLIProxyAPI model_cooldown 429 errors as quota_exhausted #14190 classifies CLIProxyAPI model_cooldown 429s. It does not read this header.
  • Migration 185_usage_history_cpa_auth_index.sql is nullable. The documented migration count moves from 178 to 182 so README, AGENTS.md, and llm.txt match the files on this branch (the tip was already ahead of that prose).
  • The index is not copied onto the dashboard by itself. getUsageDb / getUsageHistory return cpaAuthIndex and cpaAccountLabel.

Persist the opaque auth_index on usage_history and resolve the sanitized
account-health label when history is read (#11725).
# Conflicts:
#	AGENTS.md
#	README.md
#	docs/i18n/am/llm.txt
#	docs/i18n/ar/llm.txt
#	docs/i18n/az/llm.txt
#	docs/i18n/bg/llm.txt
#	docs/i18n/bn/llm.txt
#	docs/i18n/bs/llm.txt
#	docs/i18n/cs/llm.txt
#	docs/i18n/da/llm.txt
#	docs/i18n/de/llm.txt
#	docs/i18n/el/llm.txt
#	docs/i18n/es/llm.txt
#	docs/i18n/et/llm.txt
#	docs/i18n/fa/llm.txt
#	docs/i18n/fi/llm.txt
#	docs/i18n/fr/llm.txt
#	docs/i18n/ga/llm.txt
#	docs/i18n/gu/llm.txt
#	docs/i18n/ha/llm.txt
#	docs/i18n/he/llm.txt
#	docs/i18n/hi/llm.txt
#	docs/i18n/hr/llm.txt
#	docs/i18n/hu/llm.txt
#	docs/i18n/hy/llm.txt
#	docs/i18n/id/llm.txt
#	docs/i18n/ig/llm.txt
#	docs/i18n/it/llm.txt
#	docs/i18n/ja/llm.txt
#	docs/i18n/ka/llm.txt
#	docs/i18n/km/llm.txt
#	docs/i18n/kn/llm.txt
#	docs/i18n/ko/llm.txt
#	docs/i18n/lt/llm.txt
#	docs/i18n/lv/llm.txt
#	docs/i18n/ml/llm.txt
#	docs/i18n/mr/llm.txt
#	docs/i18n/ms/llm.txt
#	docs/i18n/mt/llm.txt
#	docs/i18n/my/llm.txt
#	docs/i18n/ne/llm.txt
#	docs/i18n/nl/llm.txt
#	docs/i18n/no/llm.txt
#	docs/i18n/or/llm.txt
#	docs/i18n/pa/llm.txt
#	docs/i18n/phi/llm.txt
#	docs/i18n/pl/llm.txt
#	docs/i18n/pt-BR/llm.txt
#	docs/i18n/pt/llm.txt
#	docs/i18n/ro/llm.txt
#	docs/i18n/ru/llm.txt
#	docs/i18n/si/llm.txt
#	docs/i18n/sk/llm.txt
#	docs/i18n/sl/llm.txt
#	docs/i18n/sr/llm.txt
#	docs/i18n/sv/llm.txt
#	docs/i18n/sw/llm.txt
#	docs/i18n/ta/llm.txt
#	docs/i18n/te/llm.txt
#	docs/i18n/th/llm.txt
#	docs/i18n/tr/llm.txt
#	docs/i18n/uk-UA/llm.txt
#	docs/i18n/ur/llm.txt
#	docs/i18n/uz/llm.txt
#	docs/i18n/vi/llm.txt
#	docs/i18n/yo/llm.txt
#	docs/i18n/zh-CN/llm.txt
#	docs/i18n/zh-TW/llm.txt
#	llm.txt
# Conflicts:
#	config/quality/file-size-baseline.json
@diegosouzapw
diegosouzapw merged commit d7be9fd into cheaper-inference:release/v3.8.51 Sep 22, 2026
9 of 16 checks passed
diegosouzapw added a commit that referenced this pull request Sep 23, 2026
…n from #14544) (#14599)

Hoists `let providerResponse` out of handleChatCore's prettier-ignore try block so persistFailureUsage (declared before that try) can read it. #14544 had made every upstream failure throw ReferenceError: providerResponse is not defined out of handleChatCore. Net-zero lines. Adds an end-to-end regression test (red on the tip, green here) and restores 2 failing tests in chatcore-codex-account-pool and 17 in chatcore-translation-paths. check:open-sse-typecheck no longer reports the chatCore.ts TS2304.

Refs #14544
josuerf pushed a commit to josuerf/OmniRoute that referenced this pull request Sep 23, 2026
`CLAUDEPROXY`-style env reads are `string | undefined`, so `options.host ??
externalHost` cannot satisfy the `host: string` the ready state declares and
`typecheck:core` fails. Falls back to the same loopback address the embedded
branch a few lines above already uses.

Inherited base-red: upstream d7be9fd (cheaper-inference#14544) introduced it earlier today and
it arrived with the sync merge, so it is not this fork's defect.
@RaviTharuma
RaviTharuma deleted the feat/cpa-trace-auth-index branch September 23, 2026 19:36
diegosouzapw added a commit that referenced this pull request Sep 24, 2026
…enumber migration to 186 (#13973)

The stagger added 45 min to the model-sync PERIOD (6h45m), so the two
schedulers only drifted and re-collided, and MODEL_SYNC_INTERVAL_HOURS was
silently overridden. Arm the recurring interval after a one-shot 45 min
phase timer instead, keeping effectiveIntervalMs unchanged, and cancel the
pending arm on stop.

Migration 185 collided with 185_usage_history_cpa_auth_index.sql on the
release tip (#14544), which aborts boot; renumber to 186.
diegosouzapw added a commit that referenced this pull request Sep 24, 2026
…n only the management key is set

#14544 built the probe URL from CLIPROXYAPI_HOST with no fallback, so a
key-only (local) setup probed http://undefined:8317 and showed the account as
unreachable; it was also the typecheck:core TS2322 on the release tip. Test
fails on the old code (actual http://undefined:8317/...).

Refs #14496
diegosouzapw added a commit that referenced this pull request Sep 24, 2026
…irement, extracted failure projection

- docs: migration count 182 -> 183 in README, AGENTS.md and llm.txt (+ the
  66 llm.txt mirrors), same shape as #14559; migration 185 landed with #14544.
- #14468 retired suno: APIKEY_PROVIDERS 242 -> 241 and the translate-path
  golden loses the suno entry (regenerated; that is the only diff).
- #14527 moved the retained provider-failure projection into
  chatCore/providerFailureRetention.ts; the public-error guard now follows the
  call and still requires sanitizeErrorMessage() at the projection.

Refs #14496
diegosouzapw added a commit that referenced this pull request Sep 24, 2026
Drains the base-red accumulated on release/v3.8.51 (#14496, #14547). Production fixes: auggie spawn typing, projectCombo type imports, Responses passthrough markers surviving the egress strip (#14252 regression), compression effective-pipeline preview following the runtime lossy policy (#14529 regression, #12063), CLIProxyAPI account-health host default (#14544 regression), DEEP_HEALTH_CHECK_ENABLED env contract. The remaining test guards were realigned to merged design changes, each traced to its commit; the subtitle-runtime fixtures moved to a per-run temp dir; documented file-size/stryker rebaselines absorb the 2026-09-23/24 merge-wave drift.
BenjaminAronsson added a commit to BenjaminAronsson/OmniRoute that referenced this pull request Oct 3, 2026
Rebase onto release/v3.8.51 surfaced three problems.

Migration 185 collided with 185_usage_history_cpa_auth_index from cheaper-inference#14544,
which the migration runner rejects outright. Renumbered to 186; no
retroactive isSchemaAlreadyApplied guard is needed because this migration
has never shipped under the old number.

The SSO branch claimed any RS256 JWT bearer even with SSO switched off,
so a client sending its own unrelated JWT — extractBearer already notes
VS Code Copilot does this — would hard-401 instead of degrading to
anonymous under REQUIRE_API_KEY=false. It is now gated on
isEntraSsoEnabled(), which answers false if the settings read throws so
an unreadable config falls through to the pre-SSO path rather than
500-ing auth. The new test is RED against the previous commit.

The migration count landed off by one: cheaper-inference#14559 had already moved the docs
to 181 and the base to 182, and the rebase merged both edits cleanly into
a number that no longer matched the 183 files on disk.
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.

feat(providers): correlate X-CPA-TRACE-ID auth_index with account health

2 participants