[codex] Add native build usage chart#2050
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds native-version (version_build) tracking end-to-end: DB migration and RPC, typed schema updates, collection/read in Supabase & Cloudflare, public API and auth, frontend chart service and DevicesStats card, translation, and tests. ChangesNative Version Usage
Sequence Diagram(s)sequenceDiagram
participant Frontend
participant API as Statistics_API
participant Auth as Auth_Checker
participant Backend as Stats_Backend
participant DB as Database_Analytics
Frontend->>API: GET /statistics/app/:app/native_usage (app_id, date range)
API->>Auth: validate API key / subkey & RBAC
Auth-->>API: authorized
API->>Backend: readNativeVersionUsage(app_id, start, end)
Backend->>DB: query device_usage (group by date, platform, version_build) / or AE read
DB-->>Backend: rows (date, platform, version_build, devices)
Backend-->>API: aggregated labels, datasets, latestVersion
API-->>Frontend: { labels, datasets, latestVersion }
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
8fdf79c to
b0282c1
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
💡 Codex Reviewcapgo/src/services/chartDataService.ts Line 24 in b0282c1 Update the cache-key format and the app-scoped invalidation logic together. This key now starts with ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
b0282c1 to
de6c7ce
Compare
💡 Codex Reviewcapgo/supabase/functions/_backend/utils/supabase.ts Lines 1167 to 1169 in de6c7ce When ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
de6c7ce to
31d0d59
Compare
|
Addressed the Codex review feedback in |
31d0d59 to
f3c55c2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/statistics.test.ts`:
- Around line 148-170: The test is brittle because it relies on common
version_build labels ("1.0.0", "1.1.0") that other parallel tests may also seed;
update the seeded events (the array of objects you push before calling
.throwOnError()) to use per-test unique version_build values (e.g., incorporate
the test's prefix or a random/suffix token like `${prefix}-1.0.0` and
`${prefix}-1.1.0`) and then update the assertions that look up datasets
(variables version100 and version110) to search for those unique labels; this
ensures getNativeUsage / nativeUsageData.datasets are matched to the
test-specific version_build values and prevents cross-test collisions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6281fc1a-d819-4a47-81a7-1a67ebcda115
⛔ Files ignored due to path filters (2)
docs/pr-screenshots/native-version-usage-desktop.pngis excluded by!**/*.pngdocs/pr-screenshots/native-version-usage-mobile.pngis excluded by!**/*.png
📒 Files selected for processing (15)
messages/en.jsonsrc/components/dashboard/DevicesStats.vuesrc/pages/app/[app].vuesrc/services/chartDataService.tssrc/types/supabase.types.tssupabase/functions/_backend/plugins/stats.tssupabase/functions/_backend/public/statistics/index.tssupabase/functions/_backend/utils/cloudflare.tssupabase/functions/_backend/utils/stats.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/utils/supabase.types.tssupabase/functions/_backend/utils/types.tssupabase/functions/_backend/utils/update.tssupabase/migrations/20260506152006_native_version_usage_chart.sqltests/statistics.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
supabase/functions/_backend/public/statistics/index.ts (1)
711-720: ⚡ Quick winUse the existing stats retry wrapper for the native usage read.
This is the only new stats path here that goes straight from the backend read to a 500. A transient PostgREST/schema-cache failure will fail the native chart even though the other statistics handlers in this module already recover via
executeStatsQueryWithRetry(...).Suggested shape
async function getNativeVersionUsage(c: Context, appId: string, from: Date, to: Date) { const dates = generateDateLabels(from, to) const startDate = dayjs(from).utc().startOf('day').format('YYYY-MM-DD') const endDate = dayjs(to).utc().startOf('day').add(1, 'day').format('YYYY-MM-DD') - let nativeVersionUsage: NativeVersionUsageRow[] - try { - nativeVersionUsage = await readNativeVersionUsage(c, appId, startDate, endDate) as NativeVersionUsageRow[] - } - catch (error) { + const { data: nativeVersionUsage, error } = await executeStatsQueryWithRetry<NativeVersionUsageRow[]>( + c, + 'read_native_version_usage', + async () => { + try { + return { + data: await readNativeVersionUsage(c, appId, startDate, endDate) as NativeVersionUsageRow[], + error: null, + } + } + catch (error) { + return { data: null, error } + } + }, + ) + + if (error) { return { data: null, error } } + const seriesNames = [...new Set(nativeVersionUsage.map(getNativeVersionSeriesName))] const dailyCounts = buildNativeVersionCounts(nativeVersionUsage, dates, seriesNames)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@supabase/functions/_backend/public/statistics/index.ts` around lines 711 - 720, In getNativeVersionUsage, don't call readNativeVersionUsage directly; instead wrap it with the existing retry helper executeStatsQueryWithRetry so transient PostgREST/schema-cache failures are retried. Replace the direct await readNativeVersionUsage(c, appId, startDate, endDate) with a call to executeStatsQueryWithRetry(() => readNativeVersionUsage(c, appId, startDate, endDate), c) (or the module's executeStatsQueryWithRetry signature) and assign/return the resulting NativeVersionUsageRow[] so the rest of getNativeVersionUsage continues to use nativeVersionUsage as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/functions/_backend/utils/supabase.ts`:
- Around line 1165-1174: The helper readNativeVersionUsageSB currently uses the
service-role client supabaseAdmin(c) which bypasses RLS; change it to use the
authenticated Supabase client used by public endpoints (the same pattern as
other public stats handlers) by either adding a Supabase client parameter to
readNativeVersionUsageSB or by calling the context-bound user client (instead of
supabaseAdmin(c)), then call its rpc('read_native_version_usage', ...) and keep
the existing error logging/throw behavior; ensure callers of
readNativeVersionUsageSB (the /statistics/app/:app_id/native_usage path) are
updated to pass the authenticated client rather than relying on the service key.
---
Nitpick comments:
In `@supabase/functions/_backend/public/statistics/index.ts`:
- Around line 711-720: In getNativeVersionUsage, don't call
readNativeVersionUsage directly; instead wrap it with the existing retry helper
executeStatsQueryWithRetry so transient PostgREST/schema-cache failures are
retried. Replace the direct await readNativeVersionUsage(c, appId, startDate,
endDate) with a call to executeStatsQueryWithRetry(() =>
readNativeVersionUsage(c, appId, startDate, endDate), c) (or the module's
executeStatsQueryWithRetry signature) and assign/return the resulting
NativeVersionUsageRow[] so the rest of getNativeVersionUsage continues to use
nativeVersionUsage as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6451f53a-0cb1-4ce4-b917-622ccb1a1e66
📒 Files selected for processing (10)
messages/en.jsonsrc/types/supabase.types.tssupabase/functions/_backend/public/statistics/index.tssupabase/functions/_backend/utils/cloudflare.tssupabase/functions/_backend/utils/stats.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/utils/supabase.types.tssupabase/functions/_backend/utils/types.tssupabase/migrations/20260506152006_native_version_usage_chart.sqltests/statistics.test.ts
✅ Files skipped from review due to trivial changes (1)
- messages/en.json
🚧 Files skipped from review as they are similar to previous changes (4)
- supabase/functions/_backend/utils/types.ts
- tests/statistics.test.ts
- supabase/migrations/20260506152006_native_version_usage_chart.sql
- supabase/functions/_backend/utils/supabase.types.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
supabase/migrations/20260506152006_native_version_usage_chart.sql (1)
149-153: 💤 Low valueMinor: Function comment mentions "Authenticated" but function grants to
anonas well.The comment says "Authenticated aggregate" but the function is also granted to
anon. Consider updating the comment to reflect that both authenticated users and API keys (via anon role) can execute this function.COMMENT ON FUNCTION public.read_native_version_usage( character varying, timestamp without time zone, timestamp without time zone -) IS 'Authenticated aggregate for native version usage by platform.'; +) IS 'Aggregate for native version usage by platform (authenticated and API key access).';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@supabase/migrations/20260506152006_native_version_usage_chart.sql` around lines 149 - 153, The function comment for read_native_version_usage inaccurately calls it an "Authenticated aggregate" while the function is also granted to the anon role; update the COMMENT ON FUNCTION text to reflect that execution is allowed for both authenticated users and anon (API key) callers (or reword to "Accessible to authenticated users and anon/API key callers") so the comment matches the GRANT behavior for read_native_version_usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@supabase/migrations/20260506152006_native_version_usage_chart.sql`:
- Around line 149-153: The function comment for read_native_version_usage
inaccurately calls it an "Authenticated aggregate" while the function is also
granted to the anon role; update the COMMENT ON FUNCTION text to reflect that
execution is allowed for both authenticated users and anon (API key) callers (or
reword to "Accessible to authenticated users and anon/API key callers") so the
comment matches the GRANT behavior for read_native_version_usage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 05379371-2594-41bf-a823-5c61ed537e17
📒 Files selected for processing (5)
supabase/functions/_backend/public/statistics/index.tssupabase/functions/_backend/utils/stats.tssupabase/functions/_backend/utils/supabase.tssupabase/migrations/20260506152006_native_version_usage_chart.sqlsupabase/tests/26_test_rls_policies.sql
🚧 Files skipped from review as they are similar to previous changes (1)
- supabase/functions/_backend/utils/supabase.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/dashboard/DevicesStats.vue`:
- Around line 707-726: The early return in the watch callback prevents reacting
to usageKind changes when props.appId is empty; move extraction of old values
(oldPackageId and oldUsageKind) above the early return and change the guard to
only return when there is no packageId and the usageKind did not change (e.g. if
(!packageId && usageKind === oldUsageKind) return), so that usageKind changes
still trigger cache reset (cachedBillingData, cached30DayData), assignment to
appId, and loadData(true) as currently orchestrated by the existing
packageChanged check and loadData call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: da706adf-648f-4a9b-8dfc-c437eb2ed01c
⛔ Files ignored due to path filters (2)
docs/pr-screenshots/native-version-usage-desktop.pngis excluded by!**/*.pngdocs/pr-screenshots/native-version-usage-mobile.pngis excluded by!**/*.png
📒 Files selected for processing (1)
src/components/dashboard/DevicesStats.vue
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99e9d041ad
ℹ️ 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".
|



Summary (AI generated)
Native build by platformchart on the app dashboard second chart row.Motivation (AI generated)
Users need to see whether native app builds are still being used per platform, since iOS, Android, and Electron can each ship different native build versions.
Business Impact (AI generated)
This improves release observability for teams using Capgo, helping them reduce support risk and make native app rollout decisions with clearer usage evidence.
Screenshots (AI generated)
Desktop:
Mobile:
Test Plan (AI generated)
bun lintbun lint:backendbun typecheckbun run supabase:db:resetbun scripts/supabase-worktree.ts test db supabase/tests/26_test_rls_policies.sqlbun run supabase:with-env -- bunx vitest run tests/statistics.test.tsGenerated with AI
Summary by CodeRabbit