Files
llmgw/internal/agent/supervisor/state.go
T
ilkerandClaude Opus 5 6a13e3dddf Phase 2 (1/2): node discovery, engine adapters, process supervisor
Everything here works without GPUs and is covered by tests. The control plane
connection is not built yet, so llmgw agent itself is still a stub and the phase
exit criterion is not met.

- discovery: IB from /sys/class/infiniband, parsing the formats sysfs actually
  uses and telling native InfiniBand from RoCE; GPUs via nvidia-smi, the
  cgo-free path, with health flags for uncorrected ECC and memory already held
  by another process. A node without IB is not an error, it is a single-node
  island.
- engines: vLLM and SGLang command and environment construction, kept free of
  process handling so it stays testable. The NCCL environment is the part the
  plan marks critical: NCCL_IB_HCA lists only the chosen fabric's adapters,
  because leaving it open lets NCCL pick an adapter on a fabric where the peer
  is unreachable, and the job then hangs instead of failing.
- validation before launch: no mixed GPU types in a tensor-parallel group, the
  node/GPU/TP arithmetic has to add up, and fp8 is refused below compute
  capability 8.9 rather than silently falling back to a slower path.
- supervisor: process groups, because engines fork workers that hold GPU memory
  and outlive a signal sent only to the leader; a bounded log tail, since engine
  output is the only diagnosis when loading fails; Starting separate from
  Loading, because a 70B model legitimately takes minutes; and orphan adoption
  through pid files fingerprinted with the command line, since pids get reused
  and adopting an unrelated process is worse than leaking the original.
- readiness is two questions: /health says the process is up, /v1/models says
  the weights loaded. Routing on /health alone sends traffic into a loading model.
- llmgw agent inventory reports what the scheduler would see on a node.

One plan correction: GPU class sizes come from the driver in GiB, which does not
always match the marketing name. An L40S is sold as 48GB and reports 44.99 GiB,
so its class is l40s-45g, not l40s-48g. Consistency matters more than matching
the box, because that number decides whether a model fits. Plan §2 and §5.1
updated.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 02:01:59 +02:00

58 lines
1.5 KiB
Go

// Package supervisor runs and watches engine processes (plan §5.4).
package supervisor
import "fmt"
// State is where a shard is in its lifecycle.
//
// Loading is separate from Starting because model loading dominates startup:
// a 70B model takes minutes, and an operator watching a shard sit in one state
// for ten minutes needs to know whether that is normal.
type State int
const (
// Pending means the shard is known but not started.
Pending State = iota
// Starting means the process has been launched but has not opened its port.
Starting
// Loading means the port is open but the model is not ready.
Loading
// Ready means health checks pass and the model is served.
Ready
// Draining means no new work; existing requests finish.
Draining
// Stopped means the process exited as intended.
Stopped
// Failed means the process exited unexpectedly or never became ready.
Failed
)
func (s State) String() string {
switch s {
case Pending:
return "pending"
case Starting:
return "starting"
case Loading:
return "loading"
case Ready:
return "ready"
case Draining:
return "draining"
case Stopped:
return "stopped"
case Failed:
return "failed"
default:
return fmt.Sprintf("unknown(%d)", int(s))
}
}
// Terminal reports whether the shard has finished for good.
func (s State) Terminal() bool { return s == Stopped || s == Failed }
// Live reports whether a process should be running in this state.
func (s State) Live() bool {
return s == Starting || s == Loading || s == Ready || s == Draining
}