Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: attribute session counts by app family - #28337

Merged
EhabY merged 1 commit into
mainfrom
feat/session-count-family-attribution
Sep 10, 2026
Merged

feat: attribute session counts by app family#28337
EhabY merged 1 commit into
mainfrom
feat/session-count-family-attribution

Conversation

@EhabY

@EhabY EhabY commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Groups app names into families on the read paths, so a session reported under a new name is counted rather than dropped.

  • codersdk gains the attribution registry: appNameFamilies maps each known app name to a family, and SessionCountAppFamiliesJSON() renders the attributed families as a single jsonb parameter. A session reported as cursor counts as VS Code in template insights, deployment stats, Prometheus, and telemetry.
  • The read queries take that one app_families parameter instead of four hardcoded name lists. Adding an alias to an existing family is one registry edit that flows everywhere. Adding a family is a registry edit plus one probe per reporting query, since sqlc output columns are static; validation and a pinning test turn a miss into a loud failure instead of a silently zeroed column.
  • dbauthz validates the registry structurally: exactly the probed families, each with a non-empty alias list. {}, null, a renamed family, or an extra family fail with the offending key named. It overrides the generated stubs through the scripts/dbgen external-method mechanism, covering every production store including rollup transactions.
  • The insights inclusion filter matches any session rather than the four known names, so an unrecognized app costs unattributed minutes instead of an idle user.
  • The per-agent sum sites decompose session_counts once per row, one jsonb_each_text with a filtered sum per family, instead of a correlated subplan per family. Insights only tests key presence and keeps the ?| probe, which is faster there.
  • TestEveryFamilyIsAttributed fails if a family is added with nowhere to report it. TestAttributedAppFamiliesMatchQueries pins the registry to the families the SQL probes. TestSessionCountsAttributeByFamily and TestUpsertTemplateUsageStatsAttributesSessionCountsByFamily pin the behavior end to end, including the rollup: cursor as VS Code, zed as SSH, an unknown name still marking the user active.

Measurements

PG 13, 1M rows, parallelism off, median of 3. The previous per-family correlated subplan against the shipped single-pass fold:

case per-family subplan single-pass fold
full scan, ungated sums 3711 ms 1126 ms
1 minute window 1.2-2.0 ms 0.5-0.6 ms
gated by the rn = 1 analogue 1947 ms 720 ms

The gating predicates ride inside the lateral as one-time filters, so the decompose is skipped for rows that are not counted, and a per-agent EXCEPT in both directions over 5000 agents returns zero rows. The insights sites invert this: ?| on the alias array measured 613 ms against 1500 ms for decomposing, so presence checks keep ?|.

Trade-offs

  • Family membership is a server-side alias list, so counting a new IDE under an existing family still needs a Coder release. A per-name breakdown is a later phase.
  • The insights filters test key presence, which equals a positive count only because writers strip non-positives. Testing the value there costs 2.4x, so this relies on the invariant that workspace_agent_stats.session_counts documents.
  • Attribution lives in one registry, but a new family still needs one probe expression per reporting query. The structural validation and the pinning test make that requirement fail loudly rather than silently.
  • Lands before the producers, so the alias plumbing sits unused until feat: report arbitrary workspace agent session types #28338. The other order would accept new names without counting them.

Depends on #28126. Phase 4 of #27410. Stacked on top: #29134 makes the count queries return per-app counts, and #29109 replaces the fixed per-family minute columns and the per-query probes.

Stack review decisions

Rebased onto main at 3ed8548e78; the attribution patch is unchanged.

Update generated by Coder Agents for @EhabY.

@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 2d19a27 to 9d808dd Compare August 20, 2026 12:29
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 9d808dd to 0dd464c Compare August 20, 2026 23:41
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 0dd464c to 8795832 Compare August 20, 2026 23:54
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 8795832 to aa690c5 Compare August 21, 2026 00:04
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from aa690c5 to d81e605 Compare August 21, 2026 00:15
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from d81e605 to d525a02 Compare August 23, 2026 14:09
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from d525a02 to 6bc11c5 Compare August 23, 2026 14:26
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 6bc11c5 to 48f8d80 Compare August 23, 2026 15:04
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 48f8d80 to 83ef550 Compare August 23, 2026 15:33
@EhabY EhabY changed the title feat(coderd): attribute session counts by app family feat: attribute session counts by app family Aug 23, 2026
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 83ef550 to 9939793 Compare August 23, 2026 15:50
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch 2 times, most recently from 318f669 to 1575f2f Compare August 25, 2026 14:15
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from 1575f2f to 2b8f6f3 Compare August 25, 2026 15:24
@EhabY
EhabY marked this pull request as ready for review August 25, 2026 15:43
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch 2 times, most recently from af88378 to 4b55fb5 Compare August 25, 2026 20:44
@EhabY
EhabY requested a review from code-asher September 1, 2026 22:45
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from c60c883 to c7002b2 Compare September 1, 2026 23:22

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadly looks good to me but what do you think about making the queries return the counts/minutes by app name, and we categorize into families at the point we need to.

That would allow for a richer dashboard for example, since it could get the individual names it could have a way to expand families and see the apps.

More importantly though I feel like it would make the code easier to reason about because we pass and store the same shape everywhere and transform it at the point it is displayed.

Comment thread coderd/database/dbauthz/dbauthz.go
Comment thread coderd/database/queries/insights.sql
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from c7002b2 to e757a01 Compare September 7, 2026 20:11
Base automatically changed from perf/workspace-agent-session-counts-jsonb to main September 7, 2026 20:31
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch 2 times, most recently from b447184 to c5bd9ae Compare September 8, 2026 16:34
@EhabY
EhabY removed this pull request from stack #29110 September 9, 2026 14:34
@EhabY
EhabY added this pull request to stack #29135 September 9, 2026 14:35
Groups app names into families on the read paths, so a session reported
under a new name is counted rather than dropped. The codersdk registry
maps each known app name to a family and renders the attributed families
as one jsonb parameter that every read query and rollup consumes.

dbauthz validates the registry structurally, so a missing or renamed
family fails loudly instead of silently zeroing a column. The per-agent
sum sites decompose session_counts once per row; insights keeps the key
presence probe, which is faster there.
@EhabY
EhabY force-pushed the feat/session-count-family-attribution branch from c5bd9ae to c955a42 Compare September 10, 2026 11:27
@EhabY
EhabY merged commit da45488 into main Sep 10, 2026
28 checks passed
@EhabY
EhabY deleted the feat/session-count-family-attribution branch September 10, 2026 11:54
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants