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

Skip to content

feat: report arbitrary workspace agent session types - #28338

Open
EhabY wants to merge 4 commits into
feat/session-family-usage-rollupfrom
feat/arbitrary-session-count-producers
Open

feat: report arbitrary workspace agent session types#28338
EhabY wants to merge 4 commits into
feat/session-family-usage-rollupfrom
feat/arbitrary-session-count-producers

Conversation

@EhabY

@EhabY EhabY commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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. Folded names are counted in coderd_agentstats_session_counts_folded_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.

Stacked on #29109; completes the producer portion of #27410. 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.

@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 force-pushed the feat/arbitrary-session-count-producers branch from a9cf035 to c7a121c Compare August 25, 2026 20:41
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from c7a121c to cb7257f Compare August 25, 2026 20:44
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch 3 times, most recently from 475165a to 46f985f Compare September 7, 2026 20:11
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 46f985f to b8bb260 Compare September 7, 2026 20:31
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from b8bb260 to 320f0b6 Compare September 8, 2026 16:42
@EhabY
EhabY changed the base branch from feat/session-count-family-attribution to feat/session-family-usage-rollup September 8, 2026 16:44
@EhabY
EhabY removed this pull request from stack #29110 September 9, 2026 14:34
@EhabY
EhabY force-pushed the feat/arbitrary-session-count-producers branch from 320f0b6 to b1ab129 Compare September 9, 2026 14:35
@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
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; whitespace-only
input is treated as no app name.

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.
Bound the agent-controlled session_counts map in the stats RPC handler
before normalization, folding the overflow into the unknown app so the
batcher's deterministic cap still applies and the rest of the report
survives. Count folded entries in a Prometheus counter and log the fold
at debug, since a misbehaving agent would repeat it on every report.

Log bounded scalars about the stats report instead of the payload, and
have NormalizeAppName strip every control character, not just null
bytes, so agent-chosen names cannot inject escape sequences.
Discard non-positive raw counts before folding overflow without reviving deprecated fields. Treat control-only usage app names as absent, matching normalization.

Generated by Coder Agents for @EhabY.
@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
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