From 67be0414255a86e1f4b8f70f91e7de28773eacb9 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Sat, 25 Jul 2026 08:11:19 -0700 Subject: [PATCH] fix(data-api): widen accounts-summary route's statement_timeout to 10s Confirmed live: even with the ORDER BY/index fix (#8154), this route's two hotkey/coldkey scans still tripped the shared 3000ms default under real concurrent load. The sibling /accounts/:ss58/events route hit this same class of problem first and already widens its own budget -- same fix, ported here. --- tests/data-api.test.ts | 4 ++++ workers/data-api.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/data-api.test.ts b/tests/data-api.test.ts index a15f34161..843684e26 100644 --- a/tests/data-api.test.ts +++ b/tests/data-api.test.ts @@ -1341,6 +1341,7 @@ test("GET /api/v1/extrinsics/:ref skips the embedded-events query on an unresolv test("GET /api/v1/accounts/:ss58 shapes the cross-subnet summary from two merged, re-capped bounded scans", async () => { mockQueue.current = [ [], // SET + [], // SET LOCAL statement_timeout [ACCOUNT_EVENT_ROW], // hotkeyScanRows [{ ...ACCOUNT_EVENT_ROW, netuid: 5 }], // coldkeyScanRows [{ netuid: 4, uid: 1, stake_tao: "10", validator_permit: 1, active: 1 }], // regRows @@ -1375,6 +1376,7 @@ test("GET /api/v1/accounts/:ss58 shapes the cross-subnet summary from two merged test("GET /api/v1/accounts/:ss58 ignores null netuid events in subnet_count", async () => { mockQueue.current = [ [], // SET + [], // SET LOCAL statement_timeout [ACCOUNT_EVENT_ROW], // hotkeyScanRows [{ ...ACCOUNT_EVENT_ROW, netuid: null }], // coldkeyScanRows [], // regRows @@ -1423,6 +1425,7 @@ test("GET /api/v1/accounts/:ss58 merges, re-sorts, and re-caps events from BOTH }; mockQueue.current = [ [], // SET + [], // SET LOCAL statement_timeout [hotkeyRow], // hotkeyScanRows [coldkeyRowNewer, coldkeyRowOlder], // coldkeyScanRows [], // regRows @@ -1468,6 +1471,7 @@ test("GET /api/v1/accounts/:ss58 breaks a same-block tie between branches by eve }; mockQueue.current = [ [], // SET + [], // SET LOCAL statement_timeout [hotkeyRow], // hotkeyScanRows [coldkeyRow], // coldkeyScanRows [], // regRows diff --git a/workers/data-api.ts b/workers/data-api.ts index 4bebe07d8..89abac53c 100644 --- a/workers/data-api.ts +++ b/workers/data-api.ts @@ -5377,6 +5377,21 @@ async function dispatchDataApiRequest( // already re-derives the true block_number/event_index order // afterward, so which order SQL fetches the top CAP+1 rows in // doesn't change the final output (METAGRAPHED-6-class fix). + // + // Confirmed live 2026-07-25: even with that fix (no Sort node, + // idx_ae_hotkey_observed/idx_ae_coldkey_observed both used), this + // route still tripped the shared 3000ms default under real + // concurrent load -- two sequential 87-chunk scans per request, + // contending with this box's other concurrent readers/writers for + // buffer/CPU access, occasionally pushed total time past the + // blanket budget (pg_stat_activity + docker logs both showed + // `canceling statement due to statement timeout` still firing on + // this route's exact query text). The sibling + // /api/v1/accounts/:ss58/events route hit this same class of + // problem first and already widens its own budget below (10000ms) + // rather than raising the global default for every other, much + // lighter route in this dispatcher -- same fix, ported here. + await sql`SET LOCAL statement_timeout = '10000ms'`; const hotkeyScanRows = await sql` SELECT block_number, event_index, event_kind, hotkey, coldkey, netuid, uid, amount_tao, alpha_amount, observed_at, extrinsic_index FROM account_events WHERE hotkey = ${ss58}