Skip to content

feat: add workspace agent session count protocol - #28125

Draft
EhabY wants to merge 1 commit into
refactor/normalize-agent-session-metadatafrom
feat/agent-session-counts-protocol
Draft

feat: add workspace agent session count protocol#28125
EhabY wants to merge 1 commit into
refactor/normalize-agent-session-metadatafrom
feat/agent-session-counts-protocol

Conversation

@EhabY

@EhabY EhabY commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Defines Agent API 2.11: a session count per app instead of four fixed counters.

  • Adds Stats.session_counts, a map<string, int64>, as field 13, and marks fields 8 through 11 deprecated without removing them.
  • Adds DRPCAgentClient211, ConnectRPC211, and ConnectRPC211WithRole alongside the existing 2.9 and 2.10 constructors, and bumps CurrentMinor so coderd accepts 2.11.
  • normalizedSessionCounts reads the map, normalizes names, drops non-positive counts, and falls back to the deprecated fields only when the map yields nothing, so one ingestion path serves old and new agents.
  • capSessionCounts bounds a report at 64 names, keeping the known families and then the busiest, and sums the remainder into unknown so no count is lost.
  • HasSessionCounts and ClearSessionCounts replace the two places that spelled the four fields out by hand.

The agent still connects on 2.10 and the helpers are not on the write path yet, so a 2.11 report would be accepted here but its map not stored. That only matters if coderd is rolled back to this commit while a newer agent is running, and it costs the per-app counts and nothing else: reporter.go already gates workspace activity on HasSessionCounts, which reads the map, so such a report still bumps activity and the workspace is not treated as idle.

The bump belongs ahead of the agent rather than alongside it. Validate rejects a requested minor above the server's, and the agent does not negotiate down, so a coderd advertising 2.10 refuses a 2.11 agent outright. Advertising first keeps the skew in the safe direction.

The version bump lives here so the whole version story, the field, the client constructors, and the advertised version, reads in one diff.

Depends on #28124.

agent/proto/agent.pb.go is generated from agent.proto by make gen and is nearly all of the line count; the .gitattributes entry marks agent/proto/*.pb.go generated so GitHub collapses it. Worth a close read: agent/proto/agent.proto and coderd/workspacestats/sessioncounts.go.

@EhabY
EhabY force-pushed the feat/agent-session-counts-protocol branch from 11e05b6 to f2663f1 Compare August 13, 2026 16:29
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