fix(ai-usage): record embeddings + self-host vision, fix advisory-routed model attribution - #5247
Conversation
…ry-routed model attribution Embeddings (src/review/rag.ts's inference calls) and self-host vision analysis (runVisualVisionForAdvisory/runScreenshotTableVisionForAdvisory's AI_VISION branches) were never recorded in ai_usage_events at all, leaving two whole AI features invisible to any usage dashboard. Also, advisory-routed calls (slop/e2e-test-gen/linked-issue- satisfaction/summaries routed through AI_ADVISORY) always recorded a stale hardcoded model label instead of the real model the provider reported, understating self-host Ollama usage and misattributing it to a legacy Workers-AI id. Fixes the root cause once in createOpenAiCompatibleAi (src/selfhost/ai.ts) so every caller gets real provider/model attribution for free, then updates each of the four affected features plus the new embeddings/vision recording call sites.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5247 +/- ##
=======================================
Coverage 94.34% 94.35%
=======================================
Files 473 473
Lines 39982 40017 +35
Branches 14576 14590 +14
=======================================
+ Hits 37722 37757 +35
Misses 1585 1585
Partials 675 675
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Caution 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥 🛑 Gittensory review result - fixes requiredReview updated: 2026-07-12 11:39:14 UTC
🛑 Suggested Action - Manual Review
Review summary Blockers
Nits — 5 non-blocking
Why this is blocked
CI checks failing
Review context
Contributor next steps
Signal definitions
[BETA] Chat with GittensoryAsk Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
…sage patch adapters.ts's new embedding-error handler never exercised its non-Error-thrown branch, and buildAiUsage's model/costUsd/effort branches are structurally unreachable through its 3 real call sites (none ever pass costUsd/effort, and model is always defined) -- add a direct unit test via a new __selfHostAiInternals export, matching this repo's existing internals-export convention for testing private helpers.
…vider (#5259) createOpenAiCompatibleAi's usage.provider fix (#5247) never took effect in production because src/server.ts's 3 call sites that construct the AI_EMBED/AI_VISION/AI_ADVISORY bindings never passed providerName at all -- confirmed live via a real RAG-indexing pass on edge-nl-01, which recorded correct model attribution (bge-m3:latest) but every row's provider column was still blank. These bindings accept any openai-compatible endpoint with no explicit provider selector, so classify the configured base URL's hostname into the existing ollama/openai/openai-compatible provider-name set instead of guessing or hardcoding one.
Summary
Phase B1 of the Grafana/AI-usage observability audit: the underlying
ai_usage_eventsdata had real gaps that a dashboard consolidation (Phase B2, follow-up PR) would just
have visualized incorrectly otherwise.
src/review/rag.ts's inference calls(via
src/review/adapters.ts'sreviewInferenceAdapter) had zeroai_usage_eventsrows. Now every embedding call records under
feature: "embeddings", using the realreported provider/model when available and falling back to the requested model id
otherwise (e.g. the Workers AI binding, which reports no usage).
runVisualVisionForAdvisoryandrunScreenshotTableVisionForAdvisoryonly recorded their BYOK branches; theenv.AI_VISIONself-host branches recorded nothing. Both now record undervisual_vision/screenshot_table_visionwith a nullableproviderKeydistinguishingBYOK (
byok:<provider>) from self-host (real reported model, or a static fallbacklabel when the provider reports none).
modellabel. Whenai-slop,ai-e2e-test-gen,linked-issue-satisfaction, and the twoai-summariespaths routethrough
settings.advisoryAiRoutingtoenv.AI_ADVISORY, the recordedmodelcolumnwas a hardcoded legacy Workers-AI id (or, for
ai-summaries, always an empty string)instead of the real serving model. Fixed at the root in
createOpenAiCompatibleAi(
src/selfhost/ai.ts, from a prior commit already on this branch) so every caller nowgets correct provider/model attribution; this PR updates the 4 consumer call sites to
prefer that real value over their hardcoded fallback.
Test plan
npm run typecheck— cleannpm run test:ci— full local gate green (742+ test files / 14.7k+ tests, engine,workers, MCP, UI suites all pass)
npm audit --audit-level=moderate— 0 vulnerabilitiesattribution vs. fallback-label, BYOK vs. self-host, success vs. no-usable-output,
and a thrown-error/rethrow path for the new embeddings recording wrapper.