fix(backend): revert argMaxIf to argMax in readDevicesCF query#1625
Conversation
argMaxIf is not supported by Cloudflare Analytics Engine SQL API, causing the entire device list query to fail silently and return []. This broke /private/devices for all apps since 5a4828b.
📝 WalkthroughWalkthroughA SQL query modification in the Cloudflare utilities file changes the custom_id extraction logic from a conditional aggregate ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|



Summary (AI generated)
argMaxIf(blob5, timestamp, blob5 != '')back toargMax(blob5, timestamp)in thereadDevicesCFquery (cloudflare.ts:602)Motivation (AI generated)
Commit
5a4828b97("Gate device custom_id from /stats", #1615) introducedargMaxIfin the device list query to preserve the last non-emptycustom_idwhen newer/statspings write''to blob5. However,argMaxIfis not a supported function in Cloudflare Analytics Engine SQL API. The query fails with"unknown function call: ARGMAXIF", the error is silently caught, and an empty[]is returned to the client.This broke
POST /private/devicesfor all apps, all users — the console device list has been returning empty since #1615 was merged.Beyond the missing function, the
argMaxIfapproach was also logically flawed:custom_id— empty values were always ignored in favor of older non-empty ones, regardless of theallow_device_custom_idsetting.custom_idto''whenallow_device_custom_idisfalse.argMax(blob5, timestamp)is correct: last write wins. If the write side clearscustom_id, the read side should reflect that.Business Impact (AI generated)
Critical / P0. The device list in the Capgo console has been completely broken for all customers since #1615 was merged. No user can see their devices. This is a core feature of the dashboard and directly impacts customer experience and trust.
Test Plan (AI generated)
argMaxIffails in CF Analytics Engine SQL Studio:"Error: Input was invalid: unknown function call: ARGMAXIF"argMaxquery returns correct results in CF Analytics Engine SQL Studio (11 rows forcom.shelf.app)device_infodataset has 338M+ records with active writes (latest: 2026-02-11 14:32:15)bun run deploy:cloudflare:api:preprod) and testedPOST https://api.preprod.capgo.app/private/devices— returns non-empty resultsGenerated with AI
Summary by CodeRabbit