Files
coder/cli
Bobby Ho 5f90c2da69 fix: deflake config-ssh tests with per-invocation contexts (#28803)
Closes
[PLAT-563](https://linear.app/codercom/issue/PLAT-563/flake-testconfigssh-multiple-variants)

## Problem

`TestConfigSSH` and `TestConfigSSH_NoWildcard` both failed at
`cli/configssh.go:568` with `context deadline exceeded` in [this
run](https://github.com/coder/coder/actions/runs/33414383561/job/99561585574).

- Both commands made their API calls promptly, then went silent for
~18.4s, then printed `Updated ".../.ssh/config"` and failed the next
HTTP call.
- The only code in that window is `atomic.WriteFile`, which calls
`f.Sync()`. fsync takes no context and cannot be cancelled.
- Both gaps ended in the same millisecond while other goroutines in both
processes kept logging on schedule, so this was a shared filesystem
stall, not CPU starvation or a crashed server.
- `configssh.go:568` is the reporting site, not the fault site. The
fsync drained the context, so the next request failed before dialing.
- Both tests made this easier to hit by creating one `WaitMedium`
context before server, agent, and workspace setup, so the command ran on
whatever budget was left over.

## Fix

- One context per `config-ssh` invocation, created just before it runs,
so setup and prior runs cannot drain it.
- `WaitMedium` (15s) to `WaitLong` (25s), to cover a slow disk on top of
the HTTP calls.
- `TestConfigSSH` passes that context to the invocation, so
`StartWithWaiter` inherits it instead of injecting a second, independent
`WaitMedium` deadline.

Failed 20/20 under 4.8x CPU oversubscription before the change, 0/20
after.

This buys margin, it does not remove the failure mode: an uncancellable
fsync still sits inside a context-bounded command. The higher-leverage
follow-up is CI side (the Postgres container runs `log_statement=all` on
Docker's json-file driver, and `$RUNNER_TEMP` is not on tmpfs for
Linux). Filing that separately.
2026-09-01 16:09:02 -07:00
..
…