Repository navigation
Description
Complete the per-app template insights API and UI on top of the already-landed session usage storage. Originally Phase 4 of the Scalable Approach for Adding New IDE Session Types RFC; the remaining work follows the Completing Scalable IDE Session Tracking RFC.
Already landed
- feat: store session usage per app and family in template usage stats #29109:
UpsertTemplateUsageStatsstores per-app session minutes intemplate_usage_stats_session_appsand drops the fixed*_minscolumns. A child table replaced the original JSONB proposal, keeping session app names separate from workspace web-app slugs and avoiding collisions. - Migration
000596backfills the historical family totals under their canonical family app names. Family-level history is preserved; per-IDE detail before this migration cannot be recovered from those totals. - fix: deduplicate template insights family metrics #30497: Prometheus family usage counts distinct user-minutes from raw agent stats, avoiding double-counting overlapping apps in one family. This does not change the per-app HTTP/UI path.
Delivered: #29796 (merged 2026-10-19)
- Read per-app session usage from
template_usage_stats_session_appsand buildreport.apps_usagedynamically: one row per used built-in app, with registry display names and icons and no family; unused built-ins are omitted. - Report new app names without a schema change. List registered apps and the 64 busiest unregistered names; fold the remainder into
overflow("Other apps"), withunknownfor usage reported without an app name. - Add
report.usage_total_seconds(each user's active minute counts once) andapps_usage[].seconds_is_upper_boundfor folded usage whose overlap cannot be recovered from the rollup. - Update the Insights page to use active time as the percentage denominator, explain that overlapping app shares can exceed 100%, and show placeholder icons and accounting-row tooltips, including "Up to…" for upper bounds.
- Update SDK/generated API artifacts and regression coverage for the new response shape.
- Use distinct UI row keys (
method/slug) for session apps and workspace apps with the same slug.
Compatibility
This is a breaking change for GET /api/v2/insights/templates: the fixed five built-in family rows become per-app rows, unused apps disappear, and Web Terminal's slug changes from reconnecting-pty to reconnecting_pty. Consumers that rely on fixed slugs/display names must adapt. Workspace web-app usage is unchanged apart from method: workspace_app; GetTemplateAppInsights remains separate. The PR also removes the unused Go SDK UnionByFamily helper.
Separate follow-ups
- CLIENT-998: normalize workspace web-app storage out of
app_usage_mins. Per-app web usage already reaches the API; this storage change is not required to complete this issue. - Record the connection method for session app usage #31012 / refactor: share the session app fold rule and method derivation #31028: store the connection method of each session app.
- Export per-app usage time per template to Prometheus #29940, CLIENT-1036 / feat!: label the VS Code family and report built-in app usage per app #29906, stacked on refactor: share the session app fold rule and method derivation #31028: per-app built-in usage in Prometheus and the "VS Code Family" label.
Storage depends on the completed #27410 work.
Updated by Coder Agents on behalf of @EhabY.
Activity
linear-code commentedon Jul 22, 2026
ENG-3077
[-]Merge template_usage_stats *_mins into app_usage_mins JSONB (IDE session types phase 4)[/-][+]Merge template_usage_stats *_mins into app_usage_mins JSONB[/+]EhabY commentedon Aug 19, 2026
Two decisions and one measurement from implementing phase 1 (#28124 → #28127).
Per-IDE history starts with this phase.
DeleteOldWorkspaceAgentStatspurgesworkspace_agent_statsabout a day past the rollup watermark, and #28127 has the rollup store family minutes rather than per-app minutes. No backfill can recover per-IDE detail for any period before this phase ships. Family-level history stays correct throughout, so nothing the current surfaces expose is lost.Use a new
session_mins jsonbcolumn, notapp_usage_mins. The scope note asks to confirm how the insights queries tell the two key kinds apart, and as specified they cannot:app_usage_minsis keyed byworkspace_apps.slug, joined viaAND tus.app_usage_mins ? apps.slugand read as(tus.app_usage_mins -> apps.slug)::smallint(insights.sql:266and:254). An IDE key namedvscodewould be attributed to any template with a web app sluggedvscode, double-counting it inGetTemplateAppInsights.zedalready appears as an app slug in this repo's tests. A separate column removes the ambiguity and leavesGetTemplateAppInsightsuntouched.Backfill cost. On a synthetic 8M-row
template_usage_stats(1301 MB, PG13), the backfillUPDATEtakes about 67s holdingACCESS EXCLUSIVE, roughly 8s per million rows and scaling with retained history. Dropping the five*_minscolumns is metadata-only, about 2ms. That argues for a separate migration rather than folding this into 000569, which completes in a few seconds.Not required for correctness. With read-side family grouping in #28127, a new IDE already counts in its family with no schema change. This phase adds per-IDE granularity, so it can be scheduled on its own merits.
[-]Merge template_usage_stats *_mins into app_usage_mins JSONB[/-][+]Report template insights session usage per app[/+]