Skip to content

fix: bound agent dial in coder support bundle so unreachable agents wont hang - #31697

Open
untra wants to merge 1 commit into
mainfrom
fix/CLI-59-coder-support-bundle-cannot-hang
Open

untra wants to merge 1 commit into
mainfrom
fix/CLI-59-coder-support-bundle-cannot-hang

Conversation

@untra

@untra untra commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

coder support bundle <workspace> hung indefinitely when the workspace agent had a record but was unreachable. DialAgent waits for the agent to become reachable using the caller's context, and the bundle passed its unbounded parent context, so the command blocked until Ctrl-C and wrote no bundle.

This command uploads a number of giagnostics from both the server and agent, including pprof. If the agent is unreachable, this should still be able to write out as much of the bundle as possible without timing out.

The agent dial now has a configurable time limit (Deps.AgentDialTimeout, default 30s). On timeout the bundle logs a warning, skips the sections that need a live agent connection (ping, peer diagnostics, magicsock, manifest, agent logs over tailnet, listening ports, workspace files, agent pprof), and still writes out the bundle. This includes agent logs fetched through the API. The CLI prints a warning and records it in cli_logs.txt; exit status stays 0.

Other changes:

  • Each request over an established agent connection has a 10s limit, and workspace file collection has a 60s limit, so an agent that drops mid-collection can't stall the bundle either.
  • Agent pprof is skipped when the first dial already failed, instead of waiting through a second dial. Server pprof collection is unchanged.
  • support.AgentInfo now takes the dial timeout and also reports whether the agent was reachable.
Verification and decision log

Reproduction. An end-to-end CLI test seeds a workspace whose build has an agent record but never starts an agent process, then runs coder support bundle <ws> --yes with a 90s outer deadline.

Tree Result
main Hung until the 90s deadline.
This branch Returned in 30.0s with exit 0 and wrote a 33-file zip. logs.txt contains agent unreachable, skipping agent-connected sections and cli_logs.txt contains could not connect to workspace agent.

TestRun/AgentUnreachable in support/support_test.go covers both --pprof off and on.

Decisions.

  • The hang was in DialAgent itself (workspacesdk.go, AwaitReachable(dialCtx)), not in Ping, so the time limit goes on the context passed to DialAgent. That function keeps the connection alive on a separate background context, so cancelling the dial context after a successful dial doesn't close the connection.
  • The regression test uses a real agent record with no agent process rather than the random agent ID the ticket suggested. A random ID fails fast during agent lookup and never reaches the code that hangs.
  • Limits follow the existing 10s and 45s timeouts used elsewhere in the bundle collector, plus the ticket's 30s dial target and its worst case of about 60s for an unreachable agent.

@linear-code

linear-code Bot commented Nov 3, 2026

Copy link
Copy Markdown

CLI-59

This branch has not been deployed

No deployments
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