Skip to content

feat: report arbitrary workspace agent session types - #28338

Merged
EhabY merged 4 commits into
mainfrom
feat/arbitrary-session-count-producers
Sep 18, 2026
Merged

EhabY merged 4 commits into
mainfrom
feat/arbitrary-session-count-producers

Conversation

@EhabY

@EhabY EhabY commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Enable arbitrary app-name reporting through the agent's Stats.session_counts map, coder ssh --usage-app, and the workspace usage API. Reconnecting PTY counts are added to the map without overwriting SSH-reported counts. Unrecognized names retain their identity and are attributed to the unknown family.

Normalize and merge names before applying the existing deterministic 64-name cap: known apps first, then count, then name. Overflow is summed into unknown. Non-positive counts cannot cancel valid activity. Control characters are stripped, whitespace/control-only HTTP app names are treated as absent, and SSH session-type extraction requires the exact environment-variable prefix. Overflow entries are counted in coderd_agentstats_session_counts_overflow_total; logs avoid raw payloads and repeated warnings.

Compatibility: new agents require a server supporting Agent API v2.11 and do not negotiate down. Older agents remain supported through the deprecated count fields. The usage API's app_name becomes a string; SDK types and API documentation are updated. No database migration is added.

Completes the producer portion of #27410, now that #29109 has merged. Dynamic API/metrics/UI projections (#27411), per-app insights (#27413), and arbitrary connection-log types (#27412) remain separate. Connection logs still use the existing enum until #27412 lands.

Design decisions and resource bounds
  • Keep a single normalize-then-cap path rather than an arbitrary raw cut or a second ranking algorithm. This preserves known-app priority and exact unknown-app ranking after aliases merge.
  • Stored reports contain at most 64 names plus unknown, but temporary processing scales with the input. The agent dRPC transport limits each message to 4 MiB. A local synthetic 200,000-name normalization-and-cap benchmark measured approximately 0.20 s and 25 MB allocated, excluding decoding.
  • Direct registry lookups avoid repeatedly normalizing names during sorting. A non-empty count map still takes precedence over deprecated fields even if all its values are non-positive.

Description updated by Coder Agents for @EhabY.

Closes CLIENT-644

@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from a9d73b0 to e77e137 Compare August 20, 2026 12:39
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from e77e137 to b47e46c Compare August 20, 2026 23:41
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from b47e46c to c2a30ad Compare August 20, 2026 23:54
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from c2a30ad to 7998d2e Compare August 21, 2026 00:04
EhabY added a commit that referenced this pull request Aug 21, 2026
Phase 2 of the Scalable Approach for Adding New IDE Session Types RFC,
tracked in #27410.

Adds a session_counts map to Stats on the Agent API, so an agent can report
a count per app name instead of the four fixed fields, which are now marked
deprecated. Bumps the API to v2.11.

- coderd normalizes names on ingest, caps distinct entries, and sums the
  overflow under unknown, so an arbitrary client name cannot blow up
  cardinality.
- Agents predating v2.11 set the fixed fields instead, never both, and the
  ingest path falls back to them.

Nothing sends session_counts yet. The agent starts populating it in #28338.
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 7998d2e to 13e915b Compare August 21, 2026 00:15
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch 2 times, most recently from 70d874b to fa9a7ff Compare August 23, 2026 14:26
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from fa9a7ff to b265c63 Compare August 23, 2026 15:04
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from b265c63 to 73b679d Compare August 23, 2026 15:33
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 73b679d to 7ff8185 Compare August 23, 2026 15:50
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 7ff8185 to ea0a9dc Compare August 23, 2026 18:00
aslilac pushed a commit that referenced this pull request Aug 24, 2026
Phase 2 of the Scalable Approach for Adding New IDE Session Types RFC,
tracked in #27410.

Adds a session_counts map to Stats on the Agent API, so an agent can report
a count per app name instead of the four fixed fields, which are now marked
deprecated. Bumps the API to v2.11.

- coderd normalizes names on ingest, caps distinct entries, and sums the
  overflow under unknown, so an arbitrary client name cannot blow up
  cardinality.
- Agents predating v2.11 set the fixed fields instead, never both, and the
  ingest path falls back to them.

Nothing sends session_counts yet. The agent starts populating it in #28338.
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from ea0a9dc to 6c8cec9 Compare August 25, 2026 14:15
@EhabY
EhabY added this pull request to stack #29135 September 9, 2026 14:35
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from b1ab129 to 1de03a9 Compare September 10, 2026 11:27
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 1de03a9 to adc653e Compare September 10, 2026 11:54
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from adc653e to ce685f3 Compare September 10, 2026 12:07
@EhabY
EhabY requested a review from code-asher September 10, 2026 16:35
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from ce685f3 to 37cb782 Compare September 14, 2026 18:10
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 37cb782 to b8fa392 Compare September 16, 2026 11:27
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch 2 times, most recently from e8b13d0 to e36be0a Compare September 16, 2026 12:37
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from e36be0a to 91a743d Compare September 16, 2026 12:42

@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.

Nice!!

Comment thread agent/agent.go Resolved
Comment thread coderd/agentapi/stats.go Resolved
Comment thread coderd/agentapi/stats_test.go Resolved
Comment thread coderd/agentapi/stats_test.go Resolved
Comment thread coderd/agentapi/stats_test.go Resolved
Comment thread coderd/workspacestats/batcher.go Resolved
Comment thread coderd/workspaces.go Resolved
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 91a743d to 7b4ea92 Compare September 17, 2026 08:55
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 7b4ea92 to f646fdc Compare September 17, 2026 14:16
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from f646fdc to 8371a0b Compare September 18, 2026 12:58
Base automatically changed from feat/session-family-usage-rollup to main September 18, 2026 13:26
The agent connects on Agent API 2.11 and reports Stats.session_counts
from its normalized map, so a new IDE needs no Coder change to show up
in usage reporting. coder ssh --usage-app and the workspace usage API
pass any app name through, normalized once at the edge.

Bound the agent-controlled map in the stats RPC handler, normalizing
names before the deterministic cap applies so aliases merge first, and
fold the overflow into the unknown app while counting the fold in a
Prometheus counter. Discard non-positive raw counts, and treat
whitespace-only and control-only app names as absent.

Agents at this revision require a coderd that serves v2.11, the same
coupling as the v2.10 bump. Older agents keep reporting the deprecated
fields, which the batcher still ingests.
The count comes from the capping function rather than a subtraction that
undercounts when unknown survives the cut, and folded becomes overflow
throughout, metric included. Also tables the session count subtests and drops
the benchmark.
Hoist the env prefix in extractAppName, switch getUsageAppName to a plain
string since any name is valid, use ContainsFunc for the nameless-app check,
and replace a select with testutil.RequireReceive.

Correct two comments that described the wrong condition: normalizeUsageAppName
returns empty only for whitespace and control characters, not wherever
NormalizeAppName reports the unknown family, and the batcher fold test asserts
a debug log and a counter rather than a warn throttle.
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