Skip to content

fix(analytics): read auto routing usage from call logs - #10685

Merged
diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.50from
cryptiklemur:fix/auto-routing-analytics-usage-source
Aug 20, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.50from
cryptiklemur:fix/auto-routing-analytics-usage-source

Conversation

@cryptiklemur

@cryptiklemur cryptiklemur commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

CI note: Docs Gates currently inherits the release-base BOT_TOKEN / BOT_URL env-doc failure. the same base-red appears on unrelated #10780; this diff does not touch those variables.

The auto-routing analytics endpoint queried usage_logs, but the runtime does not create or write that table. the caught SQLite error made the endpoint return empty metrics.

call_logs.requested_model already records auto and auto-fast, along with the provider used for each call.

what changed

  • read auto-routing counts and provider totals from call_logs
  • use requested_model to separate auto from auto-fast
  • remove tests that created an application-owned schema that does not exist
  • test against the real core schema with different requested and resolved models
  • restore DATA_DIR after the database regression test

No migration is needed. the branch contains five changed files and does not carry the combo patch.

how to test

npx cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --max-old-space-size=4096 --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit --test-concurrency=1 tests/unit/auto-routing-analytics-db.test.ts tests/unit/db-logs-cache-3500.test.ts
npx eslint src/app/api/analytics/auto-routing/route.ts src/lib/db/usageLogs.ts src/lib/localDb.ts tests/unit/auto-routing-analytics-db.test.ts tests/unit/db-logs-cache-3500.test.ts

Both commands pass after rebasing onto the current release/v3.8.50 tip.

@diegosouzapw

Copy link
Copy Markdown
Owner

fix(analytics): read auto routing usage from call logs — looks correct, thanks for the clear premise. Verified: usage_logs is never written by the runtime (only the analytics code, the fabricated test table, and docs reference it), so the endpoint silently returned empty metrics; reading call_logs.requested_model is the right source and no migration is needed (column + idx_call_logs_requested_model already exist). The async-await fix in combo.ts is a real improvement too: getCachedProviderConnectionById is async but was being called synchronously, so the per-connection token limit was never applied to quota reservation — the new combo-quota test proving tokenLimit=5000 is applied is a good regression guard. All three touched test files pass locally. Two release-engine notes: (1) the PR is CONFLICTING vs release/v3.8.50 (single-file conflict in combo.ts) and (2) it depends on #10682 / #10693 — please merge the CI foundation (#10693) and the AI-Horde fix (#10682) first, then rebase this PR, before re-running the quality gates. Minor, optional: consider a separate PR for the combo.ts token-limit change next time so it stays reviewable under the analytics title, and restore process.env.DATA_DIR in auto-routing-analytics-db.test.ts like combo-quota-token-limit.test.ts does for cleaner test hygiene.

@cryptiklemur
cryptiklemur force-pushed the fix/auto-routing-analytics-usage-source branch from c6857b2 to c745328 Compare August 19, 2026 07:38
@cryptiklemur
cryptiklemur force-pushed the fix/auto-routing-analytics-usage-source branch from c745328 to 00420cc Compare August 20, 2026 04:28
@diegosouzapw
diegosouzapw merged commit 31031f9 into diegosouzapw:release/v3.8.50 Aug 20, 2026
5 checks passed
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
Merged — locally validated together with related cryptiklemur PRs (typecheck:core clean, gates green). Good catch on the phantom usage_logs table. Thanks!
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.

2 participants