
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-08 13:25:30 +10:00
2026-05-05 10:36:26 +02:00
2026-05-16 15:33:43 +00:00
2025-03-17 11:10:14 +02:00
2026-05-11 17:28:12 +00:00
2026-05-15 17:37:08 +10:00
2026-05-08 13:25:30 +10:00
2025-03-26 01:56:39 -05:00
2026-03-20 11:34:06 -04:00
2026-03-04 21:18:17 +04:00
2026-05-19 09:47:03 -05:00
2026-05-05 10:36:26 +02:00
2026-03-03 12:42:34 -07:00
2026-03-23 23:19:23 +02:00
2026-01-23 08:20:13 +01:00
2026-05-05 10:36:26 +02:00
2026-03-14 21:15:47 +01:00
2026-05-19 09:47:03 -05:00
2025-11-28 08:33:50 +02:00
2025-03-17 11:10:14 +02:00
2026-05-15 17:37:08 +10:00
2026-05-19 09:47:03 -05:00
2026-05-13 10:22:51 +01:00
2026-05-19 09:47:03 -05:00
2026-05-08 13:25:30 +10:00
2025-05-27 16:05:03 +04:00
2026-01-08 15:24:11 +04:00
2026-03-18 17:02:38 +00:00
2026-01-08 15:24:11 +04:00
2026-01-08 10:29:41 +04:00
2026-01-08 15:24:11 +04:00
2025-11-25 14:25:24 +04:00
2025-11-25 14:25:24 +04:00
2025-11-25 14:25:24 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-04-17 16:55:24 -06:00