Skip to content

feat: normalize workspace agent session counts into a child table - #27952

Draft
EhabY wants to merge 1 commit into
mainfrom
feat/normalized-session-counts
Draft

feat: normalize workspace agent session counts into a child table#27952
EhabY wants to merge 1 commit into
mainfrom
feat/normalized-session-counts

Conversation

@EhabY

@EhabY EhabY commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Supersedes #27179 (same branch, squashed and rebased; the original PR had accumulated too much review noise).

Summary

Replaces the four fixed session_count_* columns on workspace_agent_stats with a normalized child table, workspace_agent_session_counts, keyed by app name, so any IDE or app can report session counts without schema or code changes.

Problem

Session counts were pinned to four hardcoded columns (vscode, jetbrains, reconnecting_pty, ssh). Every new IDE either mislabeled itself as one of the four or was dropped entirely, and supporting a new name meant a migration plus code changes at every layer.

Fix

  • New workspace_agent_session_counts table (PK (workspace_agent_stats_id, app_name), created_at copied from the parent for windowed pruning, BRIN index), backfilled from the current stats buffer so rollups see no gap during upgrade.
  • Agent API v2.11 adds a session_counts map to Stats, deprecating the fixed fields. Old agents' fixed fields are converted server-side.
  • coderd/idemetadata holds the shared vocabulary: Normalize canonicalizes client-supplied names at ingestion, and Family groups names into bounded families for metric labels.
  • Ingestion caps distinct app names at 64 per report; overflow aggregates under unknown and well-known names are never evicted. The agent applies a matching cap to concurrently active session types.
  • POST /workspaces/{workspace}/usage and coder ssh --usage-app now accept arbitrary app names; the allowlist is replaced by ingestion-time normalization.
  • Read-side queries (insights, deployment/agent stats) still pivot on the four well-known names. Family-based grouping at read time and richer client-reported names are follow-up work.

NOTE: The migration backfills the child table and rebuilds an index on workspace_agent_stats under lock. The stall is bounded by the stats retention window (~1 day of rows normally, up to 180 days on deployments where the purge never ran).

Mixed-version note: a new CLI passing a custom --usage-app value to an older coderd gets a 400, since old servers still validate against the fixed allowlist.

🤖 Generated with Claude Code

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant