← Back to Pull requests

[Dashboard] Share one /users/role lookup across components and plugins #11549

Open
unknown opened this pull request with 349 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 30, 2026 13:49 UTC
Author

Summary

Every dashboard component and plugin bundle fetched GET /users/role on its own — sidebar, config page, users page, workspaces, recipe hub, the jobs log download, and each plugin bundle — so a single page load sent the same request 6–9 times (up to 11 on a slow machine).

This adds one shared lookup:

  • client.js: new session-cached, promise-deduped getUserRole() (plus invalidateCurrentUserRole()); getCurrentUserInfo() now derives from it, and every internal caller routes through it (sidebar, config save-check, users, workspaces, recipe hub, jobs log download).

  • The lookup is exposed to plugin bundles through SkyDashboardPluginAPI.getContext().getUserRole() / invalidateUserRole(), so a plugin joins the page's single request instead of adding its own round trip (previously each bundle fetched independently — dashboardCache is keyed by function source, so a per-plugin fetch could never be shared).
  • Failure semantics: a transport failure or 5xx resolves the anonymous 'local' sentinel without caching it (the next caller retries); a 401/403 caches the sentinel like a success, so an unauthenticated session does not re-ask on every component mount. invalidateCurrentUserRole() drops both caches and is called after the users page changes a role (the viewer's own account may be the target).

    Test plan

    Unit tests — full dashboard jest suite passes (47 suites, 527 tests), including 5 new getUserRole tests covering concurrent-caller dedupe, invalidation, and the three failure modes:

    Test Suites: 47 passed, 47 total
    Tests:       527 passed, 527 total
    

    Before/after measurement — GET /users/role requests per full page load, counted in the browser (Playwright request listener around page.goto, waiting for the page to settle) on a local API server with plugin frontend bundles loaded, signed in as a non-admin user:

    | Page | Before | After |
    |---|---|---|
    | /dashboard/clusters | 10 | 1 |
    | /dashboard/jobs | 10 | 1 |
    | /dashboard/settings/config | 6 | 1 |
    | /dashboard/settings/audit-log | 7 | 1 |

    Functional checks in the browser after the change: non-admin correctly gated on the audit log and config pages, admin sees the config editor, jobs "Mine | All" toggle scopes correctly, users/service-account tables render, no new console errors.

    🤖 Generated with Claude Code
    <!-- devin-review-badge-begin -->

    ---

    <a href="https://app.devin.ai/review/skypilot-org/skypilot/pull/11549" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 349 lines (+261 / -88) across 4 files Reviewer: devin-ai-integration[bot] Review duration: 10m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 349 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.350
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #11549"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    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: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.6% · Safe to merge
    22.6%