fix(coderd): add role param to agent RPC to prevent false connectivity by kacpersaw · Pull Request #22052 · coder/coder

@kacpersaw

…connectivity updates

coder-logstream-kube and other tools that use the agent token to connect
to the RPC endpoint were incorrectly triggering connection monitoring,
causing false connected/disconnected timestamps on the agent. This led
to VSCode/JetBrains disconnections and incorrect dashboard status.

Add a 'role' query parameter to /api/v2/workspaceagents/me/rpc:
- role=agent: triggers connection monitoring (default for the agent SDK)
- any other value: skips connection monitoring (for logstream-kube, etc.)
- omitted: triggers monitoring for backward compatibility with older agents

The agent SDK now sends role=agent by default. A new Role field on the
agentsdk.Client allows non-agent callers to specify a different role.

Fixes #21625

@kacpersaw

@kacpersaw kacpersaw changed the title fix: add role query parameter to agent RPC endpoint to prevent false connectivity updates fix(codcerd): add role query parameter to agent RPC endpoint to prevent false connectivity updates

Feb 12, 2026

@kacpersaw kacpersaw changed the title fix(codcerd): add role query parameter to agent RPC endpoint to prevent false connectivity updates fix(coderd): add role query parameter to agent RPC endpoint to prevent false connectivity updates

Feb 13, 2026

@kacpersaw

@kacpersaw kacpersaw changed the title fix(coderd): add role query parameter to agent RPC endpoint to prevent false connectivity updates fix(coderd): add role param to agent RPC to prevent false connectivity

Feb 13, 2026

spikecurtis

@kacpersaw

Address review feedback:
- Remove exported Role field from agentsdk.Client (race condition risk)
- Add role parameter to internal connectRPCVersion()
- Add ConnectRPCWithRole() and ConnectRPC28WithRole() public methods
- SDK defaults to not sending role (new callers don't trigger monitoring)
- Workspace agent explicitly sends role=agent via ConnectRPC28WithRole
- Update agent Client interface and agenttest mock

spikecurtis

@kacpersaw kacpersaw deleted the kacpersaw/add-role-to-agent-rpc branch

February 18, 2026 08:44