Repository navigation
feat: immersive network stats with geo analytics - #212
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
5310503 to
26a2485
Compare
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5310503c5b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for i := 0; i < b.Providers; i++ { | ||
| ra.providers[strings.Repeat("p", i+1)] = struct{}{} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| VALUES ($1, $2, $3, $4, $5, $6, $7)`, | ||
| providerID, h, model, promptTokens, completionTokens, requestID, costMicroUSD, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| consumerCity, consumerCountry string | ||
| providerCity, providerCountry string |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| if g.trustHeaders { | ||
| if loc := locationFromTrustedGeoHeaders(r); loc != nil { | ||
| return loc |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| // Build a provider location lookup from the live fleet. | ||
| providerLocs := make(map[string]*store.ProviderLocation) | ||
| s.registry.ForEachProvider(func(p *registry.Provider) { | ||
| if p.Location != nil { | ||
| cp := *p.Location | ||
| providerLocs[p.ID] = &cp | ||
| } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| allRecords := s.store.UsageRecords() | ||
| var totalInWindow int64 | ||
| for _, rec := range allRecords { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| for _, fa := range flows { | ||
| out = append(out, publicRequestFlowBucket{ | ||
| From: fa.from, | ||
| To: fa.to, | ||
| Requests: fa.requests, | ||
| }) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| if ip == nil { | ||
| return false | ||
| } | ||
| return ip.IsLoopback() || ip.IsPrivate() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
26a2485 to
011e434
Compare
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
|
@codex can you check? |
011e434 to
50a45a7
Compare
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50a45a7d49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (req.nextUrl.searchParams.get("mock") === "geo") { | ||
| return NextResponse.json(withMockGeography(data)); | ||
| } | ||
| return NextResponse.json(data); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| FROM usage | ||
| WHERE ($1::timestamptz IS NULL OR created_at >= $1) | ||
| GROUP BY city, region, region_code, country, country_code |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| if rec.Location != nil { | ||
| cp := *rec.Location | ||
| p.Location = &cp |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| func parseHeaderFloat(v string) float64 { | ||
| f, err := strconv.ParseFloat(strings.TrimSpace(v), 64) | ||
| if err != nil { | ||
| return 0 | ||
| } | ||
| return f |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| v = strings.Trim(v, "\"[]") | ||
| if host, _, err := net.SplitHostPort(v); err == nil { | ||
| v = host |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| ra = ®ionAgg{key: rk, lat: loc.Latitude, lng: loc.Longitude} | ||
| regions[rk] = ra |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
50a45a7 to
2e3df6c
Compare
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e3df6cd91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| provider.Mu().Lock() | ||
| provider.Location = loc | ||
| provider.Mu().Unlock() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| b = &agg{key: k, lat: loc.Latitude, lng: loc.Longitude, providers: make(map[string]struct{})} | ||
| buckets[k] = b |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| export async function GET(req: NextRequest) { | ||
| const res = await fetch(`${COORD_URL}/v1/stats`, { cache: "no-store" }); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| ra.requests += b.Requests | ||
| ra.promptTok += b.PromptTokens | ||
| ra.completeTok += b.CompletionTokens | ||
| ra.providers += b.Providers |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…e analytics/ service Coordinator changes: - Add GeoIP resolver (MaxMind DB + trusted reverse-proxy headers) for approximate provider and consumer location without storing raw IPs - Extend /v1/stats with provider_locations, provider_regions, request_locations, request_regions, and request_flows aggregations - Privacy floor: suppress city-level buckets below k-anonymity thresholds (min 2 providers per city, min 5 requests per city) - Add ProviderLocation to store interface, ProviderRecord, and Provider registry structs with Postgres JSONB persistence - Capture consumer request location on inference dispatch for flow visualization (stored as approximate geo, never raw IP) - Add provider attestation fields (attested, mda_verified, acme_verified, runtime_verified, certificate_available, challenge freshness) to stats Console-UI changes: - Rewrite /stats page with immersive network flow visualization: SVG world map with projected provider/consumer dots and animated request flow arcs - Add provider geography section with city/region breakdown tables - Add model inventory section with capacity, routability, and fleet mix - Add /api/stats proxy route with mock geo overlay (?mock=geo) for dev - Add /api/attestation proxy route - Add network-flow-ping CSS animation with prefers-reduced-motion support Cleanup: - Remove analytics/ standalone Go service (duplicate of coordinator /v1/stats, /v1/leaderboard, /v1/network/totals; never deployed)
2e3df6c to
1f9442e
Compare
Benchmark ResultsRunner: 1-provider-streaming1 providers, 1 users, 30 requests, concurrency=5, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-non-streaming1 providers, 1 users, 20 requests, concurrency=5, streaming=false
Latency Decomposition
Assertion Report: PASS
7-provider-multi-model7 providers, 5 users, 50 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-high-concurrency3 providers, 10 users, 60 requests, concurrency=20, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-queue-saturation1 providers, 10 users, 40 requests, concurrency=15, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-20-users3 providers, 20 users, 60 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
1-provider-scaling1 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-scaling3 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
5-provider-scaling5 providers, 5 users, 30 requests, concurrency=10, streaming=true
Latency Decomposition
Assertion Report: PASS
3-provider-heavy-100conc-10kb3 providers, 20 users, 100 requests, concurrency=100, streaming=true
Latency Decomposition
Assertion Report: FAIL
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c779b442af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| records := s.store.UsageRecordsSince(since) | ||
| for _, rec := range records { | ||
| consumerLoc := rec.RequestLocation | ||
| providerLoc := providerLocs[rec.ProviderID] |
There was a problem hiding this comment.
Store provider location at request time for flow accuracy
aggregateRequestFlows resolves providerLoc from the provider’s current/stored record (providerLocs[rec.ProviderID]) instead of from immutable per-request data, so any provider that reconnects from a different network/location within the 30-minute window will have earlier requests re-attributed to its latest location. This produces incorrect request_flows geography during normal mobility, restarts, or egress-IP changes, even when request-side locations are correct.
Useful? React with 👍 / 👎.
| routable, | ||
| }; | ||
| }) | ||
| : data.providers; |
There was a problem hiding this comment.
Return complete mock stats shape when upstream is down
In mock=geo mode, the offline fallback calls withMockGeography({}), but withMockGeography preserves data.providers/data.models when they are not arrays, leaving them undefined in the response. The stats page immediately does stats.providers.filter(...) and stats.models.map(...), so when the coordinator is unreachable this mock endpoint can still crash the page instead of providing a usable offline mock payload.
Useful? React with 👍 / 👎.
| provider.Mu().Lock() | ||
| provider.Location = loc | ||
| provider.Mu().Unlock() | ||
| s.registry.PersistProvider(provider) |
There was a problem hiding this comment.
Avoid racing stale provider persistence during registration
This new persistence call runs before attestation verification and PersistProvider is asynchronous, so two registration-time writes can race: an early snapshot without attestation/serial/account metadata may commit after the later verified snapshot and overwrite the provider row with stale fields. In that ordering, reconnect restoration and stats can intermittently lose verified trust/location linkage until another persist happens.
Useful? React with 👍 / 👎.
…dpoints) Master deleted the standalone analytics/ service in Layr-Labs#212 with the rationale "duplicate of coordinator endpoints, never deployed." Bring the liveness endpoints back as a single coordinator/api/liveness.go file, admin-gated via the existing requireAdminKey pattern. Reuses the coordinator's store.Store directly — no service layer, no separate types package, no pseudonym aliasing (matches existing /v1/stats which exposes raw provider IDs). Five endpoints: GET /v1/providers/{id}/liveness reliability summary GET /v1/providers/{id}/sessions recent session intervals GET /v1/providers/{id}/heartbeats recent heartbeat samples GET /v1/providers/reliability fleet shortlist by uptime bar GET /v1/network/availability distributional fleet stats Also repairs a stale interface docstring: GetReliabilityFeatures returns (nil, nil) on miss, not ErrNotFound. Both backends already returned (nil, nil); only the comment claimed otherwise. Includes httptest coverage for the admin gate, happy path, not-found, filter behavior, and small-N percentile correctness (math.Round so p90 separates from p50 at N=3). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dpoints) Master deleted analytics/ in Layr-Labs#212; this branch had been adding to it. Now that the liveness read endpoints live in coordinator/api/liveness.go, remove the duplicate tree (~1500 LOC across 17 files including the separate go.mod). Post-rebase, this conflict resolves cleanly because both sides delete the same files. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
codex/stats-network-analyticsworktree onto master with updated import paths (coordinator/internal/->coordinator/).analytics/Go service -- its endpoints (/v1/overview,/v1/leaderboard/earnings) are duplicates of the coordinator's/v1/stats,/v1/leaderboard, and/v1/network/totals. It was never deployed.Architecture: Before & After
Before
graph LR subgraph "Console UI /stats" A[Stats Page] end subgraph "Coordinator" B[GET /v1/stats] C[Registry<br/>in-memory providers] D[Store<br/>usage table] end subgraph "analytics/ service" E["GET /v1/overview<br/>GET /v1/leaderboard/earnings"] F[Postgres read replica] end A -->|"direct fetch<br/>every 10s"| B B --> C B --> D E --> F style E fill:#f9d6d6,stroke:#c00 style F fill:#f9d6d6,stroke:#c00 style A fill:#e8e8e8,stroke:#666 linkStyle 3 stroke:#c00,stroke-dasharray:5/v1/statsreturns flat provider list + usage totals + time seriesanalytics/service duplicates coordinator endpoints, never deployedAfter
graph LR subgraph "Console UI /stats" A["Stats Page<br/>(SVG world map,<br/>flow arcs, model inventory)"] end subgraph "Console UI API Routes" P["/api/stats proxy<br/>(?mock=geo for dev)"] Q["/api/attestation proxy"] end subgraph "Coordinator" B["GET /v1/stats<br/>(+ 10 geo fields)"] C["Registry<br/>Provider.Location"] D["Store<br/>usage.request_location JSONB<br/>providers.location JSONB"] G["GeoIP Resolver<br/>(MaxMind DB /<br/>CF+Vercel headers)"] end A --> P P --> B A --> Q Q -->|"/v1/providers/attestation"| B B --> C B --> D G -->|"provider connect"| C G -->|"consumer request"| D style A fill:#d4edda,stroke:#28a745 style G fill:#cce5ff,stroke:#004085 style P fill:#fff3cd,stroke:#856404 style Q fill:#fff3cd,stroke:#856404Data flow: geo capture to stats response
sequenceDiagram participant Provider as Provider (WS) participant Geo as GeoIP Resolver participant Reg as Registry participant Store as Store (Postgres) participant Stats as GET /v1/stats participant UI as Console UI Provider->>Geo: WebSocket connect Geo->>Geo: MaxMind lookup / trusted headers Geo->>Reg: attachProviderLocation(loc) Reg->>Store: UpsertProvider(location JSONB) Note over Provider,Store: Consumer inference request Geo->>Store: RecordUsageWithCostAndLocation(request_location) UI->>Stats: GET /v1/stats Stats->>Reg: ForEachProvider (live locations) Stats->>Store: UsageLocationBuckets (SQL GROUP BY) Stats->>Store: UsageRecordsSince (flow aggregation) Stats->>Store: ListProviderRecords (disconnected providers) Stats->>Stats: Privacy floor (k-anonymity) Stats->>UI: provider_locations, request_locations, request_flowsWhat changes
provider_geo.go-- MaxMind DB + trusted reverse-proxy header (CF/Vercel) resolver. Env:EIGENINFERENCE_GEOIP_DB,EIGENINFERENCE_TRUST_GEO_HEADERS. Validates proxy source before accepting headers. Rejects NaN/Inf coordinates./v1/statsprovider_locations,provider_regions,request_locations,request_regions,request_flows, plus privacy floor metadata. Provider entries gain attestation fields (attested,mda_verified,acme_verified,runtime_verified,certificate_available,last_challenge_verified,failed_challenges). All buckets includekey,scope, token counts.ProviderLocationstruct,RecordUsageWithCostAndLocation()+UsageLocationBuckets()+UsageRecordsSince()interface methods. Postgres:locationJSONB on providers +request_locationJSONB on usage, with schema migrations. NULL locations excluded from geo aggregation. Memory store implementations included.Locationfield onProvider,ConsumerLocationonPendingRequest.RestoreProviderStatepreserves fresh location on reconnect (does not overwrite). Deep-copy on persist/restore./stats/api/statsproxy (with?mock=geofor dev) and/api/attestationproxy.network-flow-pingkeyframe animation withprefers-reduced-motionsupport.analytics/standalone Go service (11 files, ~1,400 lines).Privacy
Verification
cd coordinator && go build ./...-- passescd coordinator && go test ./... -count=1 -timeout 180s-- all packages greengofmt -l coordinator/-- cleancd console-ui && npm run build-- passesDependencies
github.com/oschwald/geoip2-golang v1.13.0(MaxMind GeoIP2 reader)