
Steven MasleyandCoder Agents
1afc6d4fd0
feat: structured disconnect attribution for agent logs (#25191)
Implements
[PLAT-60](https://linear.app/codercom/issue/PLAT-60/enhance-disconnect-logs-with-structured-reason-attribution):
adds structured disconnect attribution to disconnect logs throughout the
agent and tailnet packages.
Every disconnect log site now carries structured slog fields. All
existing logs remain; existing messages are preserved with the fields
added alongside.
New fields on disconnect log lines:
- `connect_type` — which layer disconnected: `server_to_agent`,
`agent_to_client`, or `client_to_server`
- `disconnect_reason` — categorical reason: `graceful`, `network_error`,
`server_shutdown`, etc.
- `disconnect_expected` — whether the disconnect is normal operation
(`true`) or should be investigated (`false`)
- `disconnect_initiator` — who started it: `client`, `agent`, `server`,
or `network` (control-plane sites only)
- `disconnect_detail` — free-form supplemental info (where useful)
## What's covered
**Control plane (`server_to_agent`):** coordination RPC, DERP map
subscriber, agent runLoop, agent Close, `BasicCoordination.Close`,
`Controller.run`.
**Data plane (`agent_to_client`):** SSH sessions, reconnecting PTY,
JetBrains port-forwarding.
<details>
<summary>Control-plane sites</summary>
| Site | Reason | Initiator |
|---|---|---|
| `agent/agent.go` `runLoop` EOF | `network_error` | `network` |
| `agent/agent.go` `runCoordinator` deferred exit | `server_shutdown` /
`graceful` / `network_error` | `agent` / `server` / `network` |
| `agent/agent.go` `runDERPMapSubscriber` deferred exit | same (shared
`classifyCoordinatorRPCExit`) | same |
| `agent/agent.go` `Close` shutdown timeout | `server_shutdown` + detail
| `agent` |
| `agent/agent.go` `Close` clean coord disconnect | `server_shutdown` |
`agent` |
| `tailnet/controllers.go` `BasicCoordination.Close` | `graceful` or
`network_error` | `c.initiator` |
| `tailnet/controllers.go` `Controller.run` `net.ErrClosed` |
`network_error` | `network` |
</details>
<details>
<summary>Data-plane sites</summary>
| Site | Reason | Notes |
|---|---|---|
| `agent/agentssh/agentssh.go` SSH session closed | free-form
(`graceful`, `process exited with error status: N`, etc.) | Also sets
`closeCause("normal exit")` for clean exits so coderd's
`connection_log.DisconnectReason` is no longer empty |
| `agent/reconnectingpty/server.go` PTY closed | `server_shutdown`,
error string, or `graceful` | |
| `agent/agentssh/jetbrainstrack.go` channel closed | `normal close` or
error string | Previously passed empty reason |
</details>
<details>
<summary>Bug fix</summary>
The deferred `disconnected from coordination RPC` log no longer fires
when the initial `Coordinate()` RPC call fails before any connection is
established.
</details>
Refs PLAT-60.
---
_This PR was prepared by Coder Agents on behalf of @Emyrk._
**Manually QA'd a lot of common disconnects**
---------
Co-authored-by: Coder Agents <noreply@coder.com>
2026-05-19 09:47:03 -05:00
..
2026-05-05 10:36:26 +02:00
2025-06-20 13:16:55 -06:00
2026-03-10 18:46:01 +00:00
2026-05-18 08:33:29 -04:00
2026-05-16 15:33:43 +00:00
2026-01-08 15:24:11 +04:00
2026-05-14 15:54:37 -04:00
2026-05-18 11:10:30 +02:00
2026-05-18 11:10:30 +02:00
2026-05-18 15:06:30 +02:00
2025-10-23 20:22:51 +03:00
2026-03-03 16:34:33 +03:00
2025-10-09 14:53:08 +02:00
2025-10-09 14:53:08 +02:00
2026-05-18 22:32:05 +01:00
2026-04-27 22:51:01 +00:00
2026-05-18 15:17:20 -04:00
2026-05-18 12:30:30 -04:00
2026-05-18 12:30:30 -04:00
2025-06-24 13:06:02 +02:00
2026-01-08 15:24:11 +04:00
2026-04-16 12:46:52 -04:00
2026-04-07 07:24:53 -07:00
2025-07-30 13:42:39 -07:00
2025-08-29 10:41:32 +02:00
2026-03-13 14:09:39 +00:00
2026-04-01 13:05:14 +00:00
2026-05-12 10:48:36 -04:00
2026-05-18 22:32:05 +01:00
2026-05-19 09:47:03 -05:00
2026-05-19 09:47:03 -05:00
2025-12-15 17:41:47 +00:00
2026-03-20 12:43:03 -08:00
2025-08-19 10:41:33 +02:00
2026-03-04 12:54:39 +02:00
2026-03-27 05:51:51 +00:00
2026-05-12 08:54:53 -04:00
2025-06-20 13:16:55 -06:00
2026-01-09 15:40:26 -07:00
2026-03-06 10:48:58 +00:00
2026-04-10 12:49:22 +03:00
2026-02-23 12:18:44 +01:00
2026-03-26 10:36:40 +00:00
2025-06-20 13:16:55 -06:00
2026-05-06 09:27:24 -07:00
2026-05-10 11:04:55 -04:00
2025-07-28 15:02:26 +01:00
2026-05-07 15:01:58 +10:00
2026-05-18 22:32:05 +01:00
2026-03-31 10:07:21 +01:00
2025-06-20 13:16:55 -06:00
2026-02-03 14:10:49 -06:00
2025-10-27 17:14:16 -06:00
2025-09-26 11:43:32 +02:00
2026-05-11 12:43:52 -05:00
2026-01-08 15:24:11 +04:00
2026-04-23 06:20:35 +10:00
2025-06-20 13:16:55 -06:00
2026-05-14 14:25:07 +01:00
2026-04-09 12:12:55 -06:00
2026-04-14 12:44:55 -06:00
2026-04-14 12:44:55 -06:00
2026-02-06 15:52:54 +00:00
2026-04-29 12:24:26 -08:00
2025-09-10 11:01:54 -05:00
2026-03-27 08:52:13 -04:00
2025-06-20 13:16:55 -06:00
2026-01-08 15:24:11 +04:00
2026-04-27 12:58:26 +01:00
2026-05-13 14:20:02 -06:00
2026-03-23 13:18:49 -06:00