feat: normalize workspace agent session counts into a child table - #27952
Closed
EhabY wants to merge 2 commits into
Closed
feat: normalize workspace agent session counts into a child table#27952EhabY wants to merge 2 commits into
EhabY wants to merge 2 commits into
Conversation
EhabY
force-pushed
the
feat/normalized-session-counts
branch
3 times, most recently
from
August 11, 2026 13:32
ac127f6 to
ead98bf
Compare
EhabY
force-pushed
the
feat/normalized-session-counts
branch
from
August 11, 2026 13:52
ead98bf to
e8ce184
Compare
Replace the fixed session_count_* columns on workspace_agent_stats with a workspace_agent_session_counts child table keyed by app name, so any IDE can report session counts without schema changes. Agent API v2.11 adds a session_counts map to Stats, deprecating the fixed fields.
EhabY
force-pushed
the
feat/normalized-session-counts
branch
from
August 11, 2026 14:02
e8ce184 to
07b995b
Compare
EhabY
marked this pull request as ready for review
August 11, 2026 14:32
EhabY
requested review from
jdomeracki-coder,
johnstcn and
spikecurtis
as code owners
August 11, 2026 14:32
Contributor
Documentation CheckUpdates Needed
Automated review via Coder Agents |
3 tasks
spikecurtis
requested changes
Aug 13, 2026
spikecurtis
left a comment
Contributor
There was a problem hiding this comment.
@EhabY this needs to be split into smaller PRs. It's too big for any human to give a high quality review.
Contributor
Author
|
Closing this in favor of this stack: #28124 (first PR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #27179 (same branch, squashed and rebased).
Phase 1 of the Scalable Approach for Adding New IDE Session Types RFC, tracked in #27410.
Summary
Replaces the four fixed
session_count_*columns onworkspace_agent_statswith a sparsesession_countsJSONB object keyed by normalized app name. New IDEs can report session counts without schema changes, while existing APIs and metrics continue to expose the four well-known families.Problem
Session counts were pinned to four hardcoded columns (
vscode,jetbrains,reconnecting_pty, andssh). Every new IDE was mislabeled or dropped, and adding a name required changes across the schema and application.A normalized child-table implementation was benchmarked at up to 10 million rows and caused substantial read, write, storage, WAL, and migration regressions. Keeping the normalized object on the parent row avoids the extra relation and join overhead.
Fix
session_countsmap toStats, deprecating fields 8 to 11. The server converts the fixed fields only when the map is empty.coderd/idemetadataholds the shared vocabulary. App names are normalized at ingestion, reports are capped at 64 distinct names, and overflow is combined intounknown.workspace_agent_stats.session_countsstores one sparse JSONB object per stats row. Arbitrary keys are preserved, while existing read paths extract the four well-known names.POST /workspaces/{workspace}/usageandcoder ssh --usage-appaccept arbitrary app names.agentsdk.Stats, which has been unreachable since the HTTP stats endpoint was removed.Migration requirement
NOTE: Migration 569 takes an
ACCESS EXCLUSIVElock onworkspace_agent_stats, backfills the retained raw-stat window, rebuilds the template-insights covering index, and drops the four fixed columns.Deployments with retained rows containing positive session activity must have a
template_usage_statsrollup from within the previous 24 hours. If the watermark is missing or stale, the migration aborts before changing the schema. Run the previous Coder version until template usage stats roll up, then retry the upgrade. Check coderd logs forfailed to rollup dataif the watermark does not advance.Idle-only databases can upgrade without a watermark because their rows already match the
{}default. Databases containing only raw stats older than the 180-day retention fallback can also upgrade.With a healthy watermark, the 10 million-row benchmark converted approximately 333,000 rows in 4.44 seconds on PostgreSQL 17 tmpfs and 6.13 seconds on durable storage. Reads and writes remain blocked for most of the migration, and runtime scales with recent ingestion volume.
Mixed-version note: a new CLI passing a custom
--usage-appvalue to an older coderd gets a 400 because old servers still validate against the fixed allowlist.Follow-ups: #27411 (expose per-app counts in stats, Prometheus, UI), #27412 (
connection_logs.typeENUM to TEXT), #27413 (template_usage_stats*_minsto JSONB), coder/vscode-coder#1044 (report the real IDE from the extension).PR description updated by Coder Agents.