← Back to Pull requests

refactor(analytics): migrate gen-ai tracking to shared analytics context API #10763

Closed
unknown closed this pull request without merging on Nov 26, 2026 12:52 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 13:52 UTC
Author

Fixes: https://redhat.atlassian.net/browse/RHAI-21479
Fixes: https://redhat.atlassian.net/browse/RHAI-21480
Fixes: https://redhat.atlassian.net/browse/RHAI-21481
Fixes: https://redhat.atlassian.net/browse/RHAI-21482

Problem

GenAI sends feature events through dashboard-internal analytics helpers. This couples reusable asset, playground, document/media/MCP, and response-service code to the dashboard's delivery implementation instead of the tracking callback supplied by its host.

Solution

  • Route GenAI feature events through the shared analytics provider. Inject a plain TrackEvent callback into clipboard, document, and response helpers so they remain usable outside React. Preserve event names, payloads, emission conditions, and the public response-request interface.

  • Wire standalone GenAI through createStandaloneAnalytics using module-owned build metadata. Federated and embedded consumers inherit their parent's provider; host policy continues to control delivery.

  • Extend the shared tracking contract to accept existing null and readonly-array properties, and remove the document helpers' double casts while retaining their strict property schemas.

  • Adapt existing tests to real provider wrappers, remove the obsolete legacy analytics mock, and enable feature analytics import guards with a bootstrap-only ESLint exception.
  • Evidence

    | Area | Validation |
    | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
    | GenAI | Lint, public-type checks, TypeScript checks, all 2,136 unit tests, and the production build pass. |
    | Shared analytics | Lint, TypeScript checks, and all 42 unit tests pass. |
    | MaaS Portal | All 72 unit/configuration tests, application and Cypress type-checks, the production build, and all 37 mocked browser tests across six specs pass. |
    | AutoRAG embedding | All 16 focused provider-wiring and playground-embedding tests pass. |
    | Shared infrastructure | Federation checks and git diff --check pass. |

    Focused coverage verifies clipboard success/rejection, null/array forwarding, standalone and embedded provider wiring, profile callback replacement, and guardrail errors/refusals through normal SSE lines and trailing buffers. Added asynchronous cases use explicitly resolved promises or completed streams without wall-clock sleeps. The caller audit confirms no remaining legacy analytics imports in GenAI and unchanged event names and payload expressions across 132 migrated calls.

    MaaS Portal's GenAI routes inherit its existing NoopAnalyticsTrackingProvider, preserving intentionally disabled analytics. MaaS Portal browser tests exercise model endpoints, model access, API keys, subscriptions, observability, and the user dropdown. Opening endpoint details exercises a migrated tracking call. No MaaS Portal code changes are required.

    Production builds report bundle-size warnings.

    <details>
    <summary>Validation commands</summary>

    Run from the repository root:

    pnpm -C packages/gen-ai/frontend run test:lint
    pnpm -C packages/gen-ai/frontend run test:type-check
    pnpm -C packages/gen-ai/frontend run test:unit --runInBand
    pnpm -C packages/gen-ai/frontend run build:prod
    pnpm -C packages/analytics run lint
    pnpm -C packages/analytics run type-check
    pnpm -C packages/analytics run test-unit --runInBand
    pnpm -C distributions/maas-portal run test-unit --runInBand
    pnpm -C distributions/maas-portal run type-check
    pnpm -C distributions/maas-portal run test:cypress-ci
    pnpm -C packages/autorag/frontend run test:unit --runInBand bootstrap PlaygroundDrawerPanel
    pnpm -C packages/app-config run test-unit --runInBand shared-subpath-runtime
    git diff --check
    

    </details>

    Diff: 534 lines (+400 / -134) across 6 files Reviewer: ikeola13 Review duration: 12899m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.71) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.71 · 534 lines diff across 6 files
    0.71
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.071
    Real PR Conversation Timeline
    1 comments
    "Review active on #10763"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.1% (HIGH) · Higher = larger blast radius
    71.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.1% · Safe to merge
    28.1%