fix(accounts): take subnet_count from a GROUP BY subquery, not COUNT(DISTINCT) - #9283
fix(accounts): take subnet_count from a GROUP BY subquery, not COUNT(DISTINCT)#9283JSONbored wants to merge 1 commit into
Conversation
…DISTINCT) #9257 merged, deployed, and the account summary card still served zeros. Verified 33 minutes after merge with three sequential probes, over a window in which other deploys were landing normally -- /chain/weights/setters began serving data in the same period -- so this was not deploy lag. The aggregate read used `count(DISTINCT netuid)`, which R2 SQL rejects at this scale: `40015: scan budget exceeded: scanning too much data for count(DISTINCT) without GROUP BY`. That is the identical failure the #9251 correction found; I wrote this reader before that landed and reasoned the CTE's LIMIT 5000 made the DISTINCT cheap. It does not -- the planner still evaluates the DISTINCT against the underlying scan, so a capped CTE saves nothing. The rejected query returned null, the loader declined exactly as designed, and the handler fell through to the all-zero card. The decline path was right; the query should never have been sent. subnet_count now comes from its own GROUP BY subquery, the shape #9251 settled on. count(*) stays ungrouped: a plain row count carries no DISTINCT, so neither the budget rejection nor the wrong-question problem applies to it. Guarded by a test asserting no read in this loader uses COUNT(DISTINCT) at all, mirroring the one added alongside the #9251 fix, and confirmed to bite by reintroducing the original query. Worth recording: this class of failure is invisible to the fake-engine tests. The query typechecks, every local assertion passes, and it reads correctly -- only a production probe after deploy shows the engine refusing it. Closes #9281
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-data-api | e927140 | Aug 03 2026, 12:48 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-registry-sync-api | e927140 | Aug 03 2026, 12:48 PM |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Superseded by #9282, which landed the same fix on main — the distinct subnet count is now its own Verified in production for the address this was reported against: Three sessions independently found this same bug and wrote the same remedy today; #9287 was closed for the same reason. Nothing here is lost — the branch now conflicts against a main that already contains its change. One piece of fallout worth noting: #9282 and #9285 were each green against the main they branched from, but together the test stubs in #9285 kept matching on |
Summary
Verified 33 minutes post-merge, three sequential probes:
Not deploy lag —
/chain/weights/setters(#9251) began serving data over the same window.Cause
The aggregate read used
count(DISTINCT netuid). R2 SQL rejects an ungroupedcount(DISTINCT)at this scale:Identical to the failure the #9251 correction found. I wrote this reader before that landed and reasoned the CTE's
LIMIT 5000made the DISTINCT cheap. It does not — the planner still evaluates the DISTINCT against the underlying scan, so being inside a capped CTE saves nothing.The rejected query returned null, the loader declined exactly as designed, and the handler fell through to
buildAccountSummary(ss58, {}). The decline path was correct; the query should never have been sent.Fix
subnet_countnow comes from its ownGROUP BYsubquery — the shape #9251 settled on:count(*)stays ungrouped: a plain row count carries no DISTINCT, so neither the budget rejection nor the wrong-question problem applies to it.Guard
A test asserting no read in this loader uses
COUNT(DISTINCT)at all, mirroring the one added alongside the #9251 fix. Confirmed it bites by reintroducing the original query (1 failed | 8 passed).Worth recording
This class of failure is invisible to the fake-engine tests. The query typechecks, every local assertion passes, and it reads correctly — only a production probe after deploy shows the engine refusing it. Both instances of this bug (mine here, and #9251's) were found that way, not by CI.
Registry Safety
Closes #9281) — required.validate:contract-driftgreen.Validation
npm run typecheck·npm run lint·npm run format:checknpm run validate·npm run validate:contract-drift·npm run scan:public-safetynpm run worker:testnpx vitest run— 15,087 tests passing