Skip to content

feat: report the app that made a connection - #29675

Closed
EhabY wants to merge 5 commits into
ehab/client-640-connection-log-type-textfrom
ehab/client-640-agent-reports-app-name
Closed

EhabY wants to merge 5 commits into
ehab/client-640-connection-log-type-textfrom
ehab/client-640-agent-reports-app-name

Conversation

@EhabY

@EhabY EhabY commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #29674. Second half of phase 3 of the Scalable IDE Session Types RFC.

Problem

ReportConnection gets the app name from the SSH session, then maps it down to a family to fit the Connection_Type enum. A Cursor session reaches coderd as VSCODE, even though session counts already record cursor.

Fix

Add Connection.app_name to Agent API v2.12, which is unreleased. The agent sends the app it saw, and coderd stores it in app_name_or_port, normalized. Every agent connection is logged with source = agent.

type is deprecated in favor of app_name:

  • The agent still sends it for coderd releases without app_name. It stays frozen at its families, and apps outside them report SSH instead of TYPE_UNSPECIFIED, which those releases rejected, so their sessions are logged instead of dropped. The agent still dials Agent API v2.11, so it keeps connecting to those releases.
  • coderd reads it only from agents that send no app_name. Its family becomes the app name, so RECONNECTING_PTY logs as reconnecting_pty. A connection with neither is logged as app unknown.

An SSH client can't pose as the web terminal: a client-supplied reconnecting_pty is logged as unknown.

Rows then read "Cursor (VS Code Family) session". Per-IDE names reach users once clients send them (CLIENT-643).

Refs #27412

@linear-code

linear-code Bot commented Sep 21, 2026

Copy link
Copy Markdown

CLIENT-640

@EhabY
EhabY added this pull request to stack #29676 September 21, 2026 17:21
@EhabY EhabY changed the title feat(agent): report the app that made a connection feat: report the app that made a connection Sep 21, 2026
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from 18110e2 to e533793 Compare September 21, 2026 17:45
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 3 times, most recently from d384154 to 6abf0ba Compare September 23, 2026 10:25
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 2 times, most recently from c838427 to dd4555f Compare September 23, 2026 11:26
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 2 times, most recently from 8e25620 to 172de2e Compare September 23, 2026 13:00
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from 172de2e to e8bf7f0 Compare September 23, 2026 13:47
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 3 times, most recently from 52cf46d to e1576a7 Compare September 23, 2026 14:30
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from e1576a7 to 922055a Compare September 23, 2026 14:42
@EhabY
EhabY marked this pull request as ready for review September 23, 2026 15:27
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from 922055a to 35c72d3 Compare September 24, 2026 12:26
Comment thread tailnet/proto/version.go Resolved
Comment thread codersdk/agentsdk/convert.go Outdated
func AppFamilyFromProto(t proto.Connection_Type) (codersdk.AppFamilyName, error) {
name, ok := proto.Connection_Type_name[int32(t)]
if !ok || t == proto.Connection_TYPE_UNSPECIFIED {
return "", xerrors.Errorf("unknown connection type: %d", t)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it an error if we get TYPE_UNSPECIFIED when we have an "unknown" app family?

If you return an error here, then up the call stack in agentapi/connectionlog.go we'll fail to record the entire connection log if the app name is absent and the type is unspecified.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this so we have the following fallbacks:

  • app_name -> type (now called kind) -> unknown with kind ssh

@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from 35c72d3 to b920b48 Compare September 24, 2026 15:48
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 2 times, most recently from 098d7ce to 8d7e0b3 Compare September 24, 2026 16:17
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from 8d7e0b3 to f663788 Compare September 24, 2026 16:38
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch from f663788 to 43a483e Compare September 24, 2026 16:55
@EhabY
EhabY requested a review from spikecurtis September 24, 2026 17:36
Comment thread agent/proto/agent.proto Resolved
Comment thread agent/agent_internal_test.go Resolved
Comment thread coderd/database/db2sdk/db2sdk.go Resolved
Comment thread coderd/database/db2sdk/db2sdk.go Outdated
// ConnectionLogKindFromAgentProto returns the kind and app name of an agent
// connection. Without app_name, the family is the app name.
func ConnectionLogKindFromAgentProto(conn *agentproto.Connection) (database.ConnectionKind, string) {
kind := database.ConnectionKindSSH

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to default to SSH here. This is going to cause a lot of pain as many types of connections are assumed to be SSH when they are not.

Why are we even still trying to return a "kind"? The RFC says we're getting rid of the type enum.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer an issue with the new refactor of source text column

Comment thread coderd/database/db2sdk/db2sdk.go Resolved
@EhabY
EhabY force-pushed the ehab/client-640-agent-reports-app-name branch 2 times, most recently from 2cbbbae to 16171c4 Compare September 25, 2026 15:23
connection_logs.type mixed app names with connection types. Rename it to
kind, which records what observed the connection, and rename slug_or_port
to app_name_or_port: the app an agent reported, a workspace app slug, or a
port.

The API type is derived from the app registry on read, so a Cursor session
reads as type vscode with app_name cursor. type:vscode matches every app in
the family, type:unknown matches apps outside the registry, and the new app:
filter matches an agent app name or a workspace app slug. The site's type
labels are generated from the registry, and the family is labeled Visual
Studio Code.
Replace the kind enum with source, a text column with four known values:
agent, workspace_app, port_forwarding, and tunnel. Agent rows keep the app
in app_name_or_port, which tells SSH from the web terminal, so a new app or
agent feature needs no migration.

The migration converts old rows too: vscode, jetbrains, ssh, and
reconnecting_pty become source agent with that app name. Both columns
convert in one ALTER, so the table is rewritten once, about 1.7s per million
rows.

db2sdk maps a row's source and app to the API type, and sdk2db maps a type
filter back, so the two directions sit together and a test pins them. The
agent's connection type maps to an app name in sdk2db, and an unspecified
type logs as app unknown instead of being dropped.

The VS Code family is labeled VS Code Family, apart from the VS Code app.
Table the rows each migration direction converts, and use fixed SQL, which
also fixes the gosec G202 lint on the concatenated column list.
Add app_name to Connection in Agent API v2.12, which is unreleased. The
agent sends the app it saw, such as cursor, and coderd stores it
normalized. An agent without app_name sends only the type, whose family is
the app name, and a connection with neither logs as app unknown.

The agent still sets type for coderd releases that predate app_name. Apps
outside its frozen families map to SSH, so those releases log them instead
of dropping them.
Mark Connection.type deprecated. app_name supersedes it, and agents keep
sending the family only for coderd that predates app_name.

An SSH client can no longer claim to be the web terminal: a client-supplied
reconnecting_pty is logged as unknown, since only the reconnecting PTY
server is the web terminal. Drop the test case that pinned a quirk of
sshConnectionType.
@EhabY

EhabY commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by draft #30467, stacked on #30466, with a clean RFC-aligned implementation. This PR retains the earlier review history. Generated with Coder Agents on behalf of @EhabY.

@EhabY EhabY closed this Oct 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 7, 2026
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