Skip to content

Replace several subnet-detail calls with the single windowed event-summary rollup on the subnet masthead #3486

Description

@JSONbored

Context

GET /api/v1/subnets/{netuid}/event-summary (handler handleSubnetEventSummary in workers/request-handlers/entities.mjs:2785) returns one windowed rollup card for a subnet: event_kinds[] and categories[] aggregates (counts, distinct hotkey_count/coldkey_count, amount_tao/alpha_amount sums, first/last block+timestamp bounds), plus total_events, kind_count, category_count, and a small newest-first recent_events[] evidence slice — over a window of 7d/30d/90d. This is consolidation, not new data: it's the dashboard-friendly companion to the raw per-event feed the Activity tab already renders. Today the subnet masthead (apps/ui/src/components/metagraphed/subnet-masthead.tsx) has no on-chain-activity tile at all — the stat spine covers identity, participants, endpoints, surfaces, uptime, latency, completeness, and evidence-link count, but nothing summarizing recent chain events.

Requirement

Add one stat tile to the subnet masthead's stat spine that renders the windowed event-summary rollup (total event count + a compact kind/category breakdown) using the single event-summary endpoint, in place of what would otherwise require stitching together several separate per-kind or per-category calls.

Backend

  • Endpoint: GET /api/v1/subnets/{netuid}/event-summary?window=7d|30d|90d&limit=<n> — confirmed live in workers/request-handlers/entities.mjs:2785, route pattern registered in workers/config.mjs:109, response schema SubnetEventSummaryArtifact documented in public/metagraph/types.d.ts:6168-6186 (mirrors packages/contract/index.d.ts:6169).
  • Query function: none exists. apps/ui/src/lib/metagraphed/queries.ts has no subnetEventSummaryQuery (confirmed by search — zero matches for event-summary/eventSummary/EventSummary in that file). This PR must add it, following the exact queryOptions/apiFetch/staleTime pattern already used by sibling subnet queries in the same file, e.g. subnetHealthPercentilesQuery (apps/ui/src/lib/metagraphed/queries.ts:2760-2775) and subnetTrajectoryQuery (:2829-2839):
    export const subnetEventSummaryQuery = (netuid: number, window = "7d") =>
      queryOptions({
        queryKey: k("subnet-event-summary", netuid, window),
        queryFn: async ({ signal }) => {
          const res = await apiFetch<Partial<SubnetEventSummary>>(
            `/api/v1/subnets/${netuid}/event-summary`,
            { params: { window }, signal },
          );
          return { data: res.data, meta: res.meta, url: res.url };
        },
        staleTime: STALE_SHORT,
      });
    Both the typed query function and the UI wiring must land in this one PR — a data-layer-only PR is exactly the failure mode this rewrite exists to prevent.

Deliverable

  • File(s) to change:
    • apps/ui/src/lib/metagraphed/queries.ts — add subnetEventSummaryQuery(netuid, window) (new function; confirmed no pre-existing one to extend).
    • apps/ui/src/components/metagraphed/subnet-masthead.tsx — add one new tile to the stat spine (confirmed current file: 557 lines, SubnetMasthead exported at line 147; stat spine grid at lines 403-554, currently 7 StatWithSpark tiles — Netuid, Participants, Endpoints, Surfaces, Uptime, Latency p50, Completeness, Evidence — inside <div className="mt-5 grid grid-cols-[repeat(auto-fit,minmax(150px,1fr))] divide-x divide-border rounded-xl border border-border bg-card overflow-hidden">).
  • Exact anchor: add const { data: summaryRes } = useQuery(subnetEventSummaryQuery(netuid)); alongside the existing useQuery calls at lines 167-170 (trajRes, uptimeRes, endpointsRes, pctRes), then append one more <StatWithSpark> tile immediately after the "Evidence" tile (currently the last, ending line 553) inside the same stat-spine grid.
  • What to render: label "Activity" (or "Events"), value={formatNumber(summaryRes?.data?.total_events)}, hint summarizing the top categories (e.g. join the top 2-3 categories[] entries by event_count as "<count> <category>", matching the existing hint={stackSegments.map(...).join(" · ")} idiom used on the Endpoints tile at lines 437-441), full="Windowed on-chain event rollup for this subnet (registrations, stake, serving, transfers, etc.)", updatedAt={summaryRes?.meta?.generated_at ?? generatedAt}, windowLabel={summaryRes?.data?.window ?? "7d"}, and a viz using the existing MiniStack primitive (apps/ui/src/components/metagraphed/charts/stat-with-spark.tsx:101, prop shape segments: Array<{ label; value; color }>) fed from categories[], mirroring how the Endpoints tile already builds stackSegments from per-kind counts (lines 212-216).
  • Coordination note: issue Add registration/deregistration event-volume counters to the subnet masthead #3483 ("Add registration/deregistration event-volume counters to the subnet masthead") also targets this exact same file (subnet-masthead.tsx) and stat-spine grid. If Add registration/deregistration event-volume counters to the subnet masthead #3483 lands first, this PR's new tile must slot in without duplicating the registration/deregistration counters it adds — the event-summary tile here is the aggregate rollup across all categories/kinds, not a registration-specific counter. Rebase against whichever of Add registration/deregistration event-volume counters to the subnet masthead #3483/Replace several subnet-detail calls with the single windowed event-summary rollup on the subnet masthead #3486 merges first to avoid a stat-spine merge conflict. This is also distinct from ActivityPanel/ActivityTableLoader (apps/ui/src/routes/subnets.$netuid.tsx:459-474, backed by subnetEventsQuery), which renders the raw per-event table in the Activity tab — this masthead tile is a compact rollup, not a duplicate of that table.

Acceptance criteria

  • Diff touches at least one file under apps/ui/src/routes/ or apps/ui/src/components/ (not just queries.ts/types.ts) — specifically apps/ui/src/components/metagraphed/subnet-masthead.tsx
  • subnet-masthead.tsx imports and calls the new subnetEventSummaryQuery function via useQuery (matching the existing useQuery(subnetTrajectoryQuery(netuid)) etc. pattern already in the same component)
  • The new tile renders total_events as its headline value and a kind/category breakdown (via MiniStack or equivalent) sourced from categories[] or event_kinds[] — not a hardcoded/placeholder value
  • Loading + empty + error states handled matching the masthead's existing convention: tiles render "—" while data is undefined/loading (see the latP50 != null ? ... : "—" and completenessPct != null ? ... : "—" patterns already in the file) and degrade gracefully to a dash/zero state when total_events is 0, with no unhandled query-error state bubbling past the page's existing QueryErrorBoundary

Non-goals

  • Does not add the raw registration/deregistration event-volume counters — that's Add registration/deregistration event-volume counters to the subnet masthead #3483, filed separately against the same masthead file.
  • Does not touch or duplicate the Activity tab's raw event table (ActivityPanel/subnetEventsQuery) — this issue is scoped to the masthead's compact summary tile only.
  • Does not add a dedicated "Activity" drill-down page or new route — the rollup card lives in the existing stat spine, nothing new to navigate to.

Size

Size: S — keep this PR small (aim for ≤10 files / ≤1000 LOC).

Part of #2542.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix or unsolicited PR — scores a 0.05x multiplier.

    Projects

    Status
    In progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions