Repository navigation
fix(coordinator): 503 from /v1/leaderboard when the ranking query fails - #1140
brandon-eigenlabs wants to merge 1 commit into
Conversation
|
@brandon-eigenlabs is attempting to deploy a commit to the EigenLabs Team on Vercel. A member of the Team first needs to authorize it. |
170950c to
4cf58c4
Compare
|
Rebased onto |
4cf58c4 to
c7e541e
Compare
c7e541e to
9029c68
Compare
store.Leaderboard swallowed every query error and returned nil, so a
timed-out ranking over provider_earnings reached the handler as an empty
slice, was served as 200 {"entries":[]} and cached for five minutes as if
no provider had earned anything. /v1/network/totals hitting the same 10 s
timeout on the same table already answers 503, so the two public endpoints
disagreed about the same outage.
Make Leaderboard return ([]LeaderboardRow, error) on both store backends,
fail on scan/iteration errors instead of silently dropping rows, and have
handleLeaderboard answer 503 service_unavailable without caching, matching
handleNetworkTotals and handleNetworkSeries. A genuinely empty window is
still a successful, cacheable 200.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
9029c68 to
c8ec752
Compare
|
Closing this PR as retired from d-inference: it changes the coordinator leaderboard API and store failure contract. Those now belong in https://github.com/Layr-Labs/darkbloom-platform; see merged #1408 and #1410. No exact successor was verified. Retirement here does not assert that the error-handling fix was merged, deployed or the defect resolved. |
Summary
store.Leaderboardswallowed every query error and returnednil, so a timed-out ranking overprovider_earningswas served as200 {"entries":[]}and cached for five minutes as if no provider had earned anything — while/v1/network/totalshitting the same 10 s timeout on the same table answered 503. This makesLeaderboardreturn([]LeaderboardRow, error)on both backends and hashandleLeaderboardanswer 503service_unavailablewithout caching, matchinghandleNetworkTotalsandhandleNetworkSeries. A genuinely empty window is still a successful, cacheable 200.Linked issue
Closes #1139
Test plan
Local, on this branch (
coordinator/):gofmt -l ./store ./api— cleango build ./...(root module) — okgo vet ./store/ ./api/— cleango test ./store/ -run 'Leaderboard|NetworkTotals|IsRewardLedgerType' -count=1— passgo test ./api/ -run 'Leaderboard|Totals|StatsRefresh|CacheRefresh' -count=1— pass (includes the two new regression tests below)go test $(go list ./... | grep -v /internal/api) -count=1— the pre-push set, passmake docs-check— 309 files OKmake docs-impact-check BASE=origin/master— see Documentation impactTestLeaderboardReturnsErrorWhenUnavailable(needsDATABASE_URL; skipped locally, no Postgres on this box)New tests:
coordinator/api/leaderboard_test.goTestLeaderboardStoreErrorIs503NotEmptyBoard— failing store → 503service_unavailable, nothing cached underleaderboard:earnings:24h:50; after recovery → 200 with the seeded row and the body is cached. Fails without the fix (previously 200 withentries: [], cached).TestLeaderboardEmptyWindowIs200— pins the contract that no earnings is a successful, cached empty board.coordinator/store/analytics_workmem_test.goTestLeaderboardReturnsErrorWhenUnavailable— Postgres closed-pool test mirroringTestNetworkTotalsReturnsErrorWhenUnavailable.coordinator/store/leaderboard_rewards_test.go— existing memory-store suite moved to the two-value signature via amustLeaderboardhelper; semantics unchanged.Components touched
Protocol / interface changes
No protocol/interface changes
Yes — described above and matching side updated
HTTP:
GET /v1/leaderboardgains a 503service_unavailableresponse (standard error envelope) on a store error after a cache miss. Success shape unchanged.console-ui/src/app/api/leaderboard/route.tsalready forwards non-2xx upstream statuses anduseLeaderboardalready surfaces!res.okas an error state, so the UI now shows its existing error state instead of an empty board — no UI change required.Go interface:
store.UsageStore.Leaderboard→([]LeaderboardRow, error). Both implementations (MemoryStore,PostgresStore) and the only caller updated. No WebSocket, config, CLI, schema or migration change; no version bump.Documentation impact
Canonical documentation updated
No documentation needed — reason:
docs/reference/api-contracts.md:/v1/leaderboardrow now states the 503 semantics (and drops the stale "1 min (recent window)" claim — the handler has always cached 5 min unconditionally); 503-envelope paragraph lists the leaderboard handler; freshness stamp refreshed.CHANGELOG.md: new Unreleased — leaderboard availability entry.make docs-impact-checkadditionally reports the storage schema rule forcoordinator/store/postgres.go→docs/architecture/storage.md. That mapping does not apply here: the change topostgres.gois theLeaderboardmethod's return type and error handling, not a table, index or migration, andstorage.mddocuments no per-method contract for it (its only mention is the genericUsageStorerow). Per the contributor skill I have not paddedstorage.mdto satisfy the gate — maintainer: please applydocs-not-needed(the label does not exist in the repo yet and needs creating).Notes for reviewers
Before / after — observable behavior
sequenceDiagram participant C as Client participant H as handleLeaderboard participant S as store.Leaderboard participant DB as provider_earnings Note over C,DB: BEFORE C->>H: GET /v1/leaderboard (cache miss) H->>S: Leaderboard(metric, since, limit) S->>DB: 3-CTE aggregate (10 s ctx) DB-->>S: context deadline exceeded S-->>H: nil (error swallowed) H->>H: readCache.Set(key, {"entries":[]}, 5 min) H-->>C: 200 {"entries":[]} Note over C: indistinguishable from "nobody earned anything" for 5 minsequenceDiagram participant C as Client participant H as handleLeaderboard participant S as store.Leaderboard participant DB as provider_earnings Note over C,DB: AFTER C->>H: GET /v1/leaderboard (cache miss) H->>S: Leaderboard(metric, since, limit) S->>DB: 3-CTE aggregate (10 s ctx) DB-->>S: context deadline exceeded S-->>H: nil, error H->>H: log warn + ddIncr cache.refresh_failed{key} H-->>C: 503 {"error":{"code":"service_unavailable",...}} Note over H: nothing cached — next request retriesBefore / after — code flow
flowchart TD subgraph BEFORE A1[pool.Query] -->|err| B1[return nil] A1 -->|ok| C1[rows.Scan] C1 -->|err| D1[continue — row dropped] C1 -->|ok| E1[append] B1 --> F1["handler: len(rows)==0"] E1 --> F1 F1 --> G1[json.Marshal → readCache.Set 5m → 200] endflowchart TD subgraph AFTER A2[pool.Query] -->|err| B2["return nil, err"] A2 -->|ok| C2[rows.Scan] C2 -->|err| B2 C2 -->|ok| E2[append] E2 --> R2[rows.Err] R2 -->|err| B2 R2 -->|ok| S2["return out, nil"] B2 --> H2["handler: 503 service_unavailable, no Set"] S2 --> G2[json.Marshal → readCache.Set 5m → 200] endMetric choice
The failure path reuses
cache.refresh_failedtaggedkey:leaderboard:<metric>:<window>:<limit>rather than adding a new metric, so it lands next to the existingnetwork_totals:*failures fromcache_refresher.goand any alert built on that name covers both.Scan-error semantics
Previously a
rows.Scanfailure silently dropped that row and published the rest as a complete board. It now fails the request; a partially-read ranking is as misleading as an empty one.Deliberately out of scope
This PR only makes the failure honest. The aggregate's cost is a separate problem: in production
provider_earningsis ~140M rows / 33 GB with nocreated_at-leading index, so 24h/7d windows plan as parallel seq scans andallas a full index scan, and the 10 s timeout is exceeded for cache misses. Candidate follow-ups (servewindow=allfrom the already-maintainedearnings_summarytable, acreated_atindex builtCONCURRENTLY, a time-bucketed rollup for 30d) each change semantics or schema and deserve their own issue/PR.Limitations
DATABASE_URL); it was not run locally. CI's Coordinator Tests ran it against the Postgres service and passed on the rebased head (c8ec7529d):DATABASE_URLwas set, andcoordinator/storetook 54 s there versus under 1 s locally, where these tests skip.v0.3.6/v0.4.0with zero open items and the coordinator is at 0.9.x — please assign if a release is targeted.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.