Supervisor manages the lifecycle of a single connection: initial connect, watcher goroutine, restart with backoff, graceful Stop. It is the shared implementation for MCP (stdio + remote) and LSP transports; per-transport behaviour is captured in the Connector. Supervisor is safe for concurrent use.
| 153 | // |
| 154 | // Supervisor is safe for concurrent use. |
| 155 | type Supervisor struct { |
| 156 | name string |
| 157 | connector Connector |
| 158 | policy Policy |
| 159 | tracker *Tracker |
| 160 | |
| 161 | // startMu serializes Start so two concurrent first-callers don't both |
| 162 | // invoke Connector.Connect. |
| 163 | startMu sync.Mutex |
| 164 | |
| 165 | // mu guards the rest of the fields. |
| 166 | mu sync.Mutex |
| 167 | session Session |
| 168 | stopping bool |
| 169 | watcherAlive bool |
| 170 | forceRestart bool // set by RestartAndWait so the watcher reconnects |
| 171 | restarted chan struct{} // closed and replaced on each successful restart |
| 172 | // done is closed when the supervisor enters a terminal state (Stopped |
| 173 | // or Failed) so RestartAndWait can wake up promptly. Replaced with a |
| 174 | // fresh channel by Start when transitioning out of a terminal state. |
| 175 | done chan struct{} |
| 176 | |
| 177 | // watchDone is closed by the current watcher goroutine. Stop waits on it |
| 178 | // after closing the session so no transport goroutines are left behind. |
| 179 | watchDone chan struct{} |
| 180 | |
| 181 | // inflightConnect holds a connector.Connect that a startup timeout left |
| 182 | // running (see connect). At most one exists at a time; the next Start |
| 183 | // adopts it and Stop reaps it, so overlapping Connects never race on the |
| 184 | // shared MCP session. |
| 185 | inflightConnect *pendingConnect |
| 186 | |
| 187 | // randFloat is the jitter source; tests may override. |
| 188 | randFloat func() float64 |
| 189 | } |
| 190 | |
| 191 | // New returns a Supervisor that drives connector with policy. The name is |
| 192 | // used in lifecycle log messages and should uniquely identify the toolset. |
nothing calls this directly
no outgoing calls
no test coverage detected