Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/nvpair-manual-nodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Emitted when a manually added node has been probed and its initial status determ
}
```

Each node is probed for both inference engines: Ollama on its default `:11434` (`GET /` + `/api/tags`) and LM Studio on its default `:1234` (`GET /v1/models`, which doubles as the liveness check and the model list). `lmstudio_up` / `lmstudio_port` / `lmstudio_models` mirror the `ollama_*` fields and let a supervising broker bridge the node into that engine's `nvpair-proxy` instance the same way it bridges Ollama into its own. A node can run either engine, both, or neither.
Unpaired nodes are probed for Ollama on its default `:11434` (`GET /` + `/api/tags`) and LM Studio on its default `:1234` (`GET /v1/models`). Once node-info authenticates a paired node, its per-engine model inventory is read from the engine-manager service over pinned mTLS and takes precedence over those direct probes. This lets a routed-subnet peer advertise its models without allowing plaintext model requests from the LAN. `lmstudio_up` / `lmstudio_port` / `lmstudio_models` mirror the `ollama_*` fields and let a supervising broker bridge the node into that engine's `nvpair-proxy` instance the same way it bridges Ollama into its own. A node can run either engine, both, or neither.

### `node/updated`

Expand Down
73 changes: 70 additions & 3 deletions services/nvpair-manual-nodes/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"nvpair-shared/applog"
"nvpair-shared/clustertrust"
"nvpair-shared/engines"
"nvpair-shared/errors"
"nvpair-shared/noderec"
)
Expand Down Expand Up @@ -70,7 +71,8 @@ type NodeInfoResponse struct {
// probes always use HTTPS with current cluster
// pins and our client certificate, regardless of TLSPort or MTLS. MTLS is an
// informational configuration flag echoed in status, not a transport switch.
// The separate Ollama and LM Studio engine probes use plain HTTP.
// Unpaired endpoints use plain HTTP engine probes; after a peer is
// authenticated, its model inventory is read over pinned mTLS.
type ManualEntry struct {
Address string `json:"address"`
Name string `json:"name"`
Expand Down Expand Up @@ -202,8 +204,9 @@ type Manager struct {
codec *Codec
cancel context.CancelFunc

// client probes Ollama and LM Studio over plain HTTP. Fresh connections
// let hostname entries recover after their remote address changes.
// client probes unpaired Ollama and LM Studio endpoints over plain HTTP.
// Fresh connections let hostname entries recover after their remote address
// changes.
client *http.Client

// mesh supplies current membership, our client certificate, and exact
Expand All @@ -223,13 +226,21 @@ type Manager struct {
// first port), so manual entries follow a --port-base shift; standalone
// runs keep the canonical 14318.
defaultNodeInfoPort int
// engineManagerPort is derived from the same service-block base and serves
// the peer's complete model inventory over pinned mTLS.
engineManagerPort int
}

func NewManager(codec *Codec, mesh *clustertrust.Mesh, defaultNodeInfoPort int) *Manager {
engineManagerPort, ok := noderec.ServicePort(defaultNodeInfoPort, noderec.ServiceEngineManager)
if !ok {
panic("engine-manager is not part of the PAIR service block")
}
return &Manager{
codec: codec,
mesh: mesh,
defaultNodeInfoPort: defaultNodeInfoPort,
engineManagerPort: engineManagerPort,
peerClients: clustertrust.NewPeerClientPool(mesh, probeTimeout),
client: &http.Client{
Timeout: probeTimeout,
Expand Down Expand Up @@ -482,6 +493,16 @@ func (m *Manager) probeNode(entry ManualEntry) {
}
nodeInfoUp, info = m.probeNodeInfo(client, addr, nodeInfoPort, localRecordID)
}
// Manual HTTP engine probes are useful for unpaired endpoints, but a paired
// peer restricts model inventory to its pinned mTLS surface. Once node-info
// has authenticated the endpoint, read that same peer inventory so a routed
// subnet does not need plaintext access to the inference ports.
if nodeInfoUp {
if models, ok := m.probePeerModels(addr, info.HostUUID); ok {
ollamaModels, ollamaUp = models[engines.NameOllama]
lmStudioModels, lmStudioUp = models[engines.NameLMStudio]
}
}
m.peerClients.DropUnpinned()

newStatus := ManualNodeStatus{
Expand Down Expand Up @@ -596,6 +617,52 @@ func (m *Manager) probeNode(entry ManualEntry) {
}
}

// probePeerModels reads the engine-manager inventory from a peer already
// authenticated by probeNodeInfo. The mTLS client and response certificate
// must still match the peer's current pin before the models are accepted.
func (m *Manager) probePeerModels(addr, hostUUID string) (map[string][]string, bool) {
m.mesh.Refresh()
client, ok := m.peerClients.Client(hostUUID)
if !ok {
return nil, false
}
url := "https://" + net.JoinHostPort(addr, strconv.Itoa(m.engineManagerPort)) + "/v1/models"
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, false
}
// Manual hostnames are resolved on every probe. Reusing a connection here
// could keep reading from the previous address after a DNS reassignment.
request.Close = true
resp, err := client.Do(request)
if err != nil {
slog.Debug("manual peer model inventory failed", "addr", addr, "host_uuid", hostUUID, "err", err)
return nil, false
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
slog.Debug("manual peer model inventory non-OK", "addr", addr, "host_uuid", hostUUID, "status", resp.StatusCode)
return nil, false
}
var result struct {
ModelsByEngine map[string][]string `json:"modelsByEngine"`
}
if err := json.NewDecoder(io.LimitReader(resp.Body, maxModelResponseBytes)).Decode(&result); err != nil {
slog.Debug("manual peer model inventory decode failed", "addr", addr, "host_uuid", hostUUID, "err", err)
return nil, false
}
if result.ModelsByEngine == nil {
// Older peers may only expose the flat union. Keep the explicitly
// configured HTTP probe results until both sides support per-engine data.
return nil, false
}
m.mesh.Refresh()
if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 || !m.mesh.VerifyPeerCertificate(hostUUID, resp.TLS.PeerCertificates[0]) {
return nil, false
}
return result.ModelsByEngine, true
}

// probeFailedID is the canonical ServiceError id for a manual node
// whose consecutive-failure counter has crossed the threshold. Single
// function so the report and clear can never drift (the dispatcher
Expand Down
40 changes: 39 additions & 1 deletion services/nvpair-manual-nodes/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ type manualPeerFixture struct {
frames *captureRW
entry ManualEntry
info NodeInfoResponse
modelsByEngine map[string][]string
server *httptest.Server
beforeResponse func()
respond func(http.ResponseWriter)
Expand Down Expand Up @@ -571,6 +572,10 @@ func newManualPeerFixture(t *testing.T) *manualPeerFixture {
http.Error(w, "forbidden", http.StatusForbidden)
return
}
if r.URL.Path == "/v1/models" {
assert.NoError(t, json.NewEncoder(w).Encode(map[string]any{"modelsByEngine": f.modelsByEngine}))
return
}
if f.beforeResponse != nil {
f.beforeResponse()
}
Expand All @@ -592,6 +597,7 @@ func newManualPeerFixture(t *testing.T) *manualPeerFixture {
Name: "manual-peer",
TLSPort: portNumber,
}
manager.engineManagerPort = portNumber
manager.nodes[nodeID(f.entry)] = &trackedNode{entry: f.entry}
return f
}
Expand Down Expand Up @@ -733,6 +739,37 @@ func TestProbeNode_AcceptsMeasurementsFromPinnedPeer(t *testing.T) {
assert.GreaterOrEqual(t, status[0].MSSince, int64(137))
}

func TestProbeNode_UsesPinnedPeerInventoryForManualModels(t *testing.T) {
f := newManualPeerFixture(t)
f.modelsByEngine = map[string][]string{
"ollama": {"llama3.2:latest"},
"lmstudio": {"qwen3-8b"},
}

f.manager.probeNode(f.entry)

status := f.manager.listNodes()
require.Len(t, status, 1)
assert.True(t, status[0].NodeInfoUp)
assert.True(t, status[0].OllamaUp)
assert.Equal(t, []string{"llama3.2:latest"}, status[0].OllamaModels)
assert.True(t, status[0].LMStudioUp)
assert.Equal(t, []string{"qwen3-8b"}, status[0].LMStudioModels)
}

func TestProbeNode_ReportsRunningEngineWithEmptyPinnedInventory(t *testing.T) {
f := newManualPeerFixture(t)
f.modelsByEngine = map[string][]string{"ollama": {}}

f.manager.probeNode(f.entry)

status := f.manager.listNodes()
require.Len(t, status, 1)
assert.True(t, status[0].OllamaUp, "a present empty inventory means the engine is running")
assert.Empty(t, status[0].OllamaModels)
assert.False(t, status[0].LMStudioUp, "a missing engine key means it is not serving")
}

func TestProbeNode_DiscardsOldIdentityAfterHostnameReassignment(t *testing.T) {
f := newManualPeerFixture(t)
f.manager.probeNode(f.entry)
Expand Down Expand Up @@ -790,7 +827,7 @@ func TestProbeNode_DiscardsOldIdentityAfterHostnameReassignment(t *testing.T) {
assert.Empty(t, status[0].GPUs)
assert.False(t, status[0].TelemetryValid)
targetMu.Lock()
assert.Equal(t, []string{f.server.Listener.Addr().String(), replacement.Listener.Addr().String()}, dialed)
assert.Equal(t, []string{f.server.Listener.Addr().String(), f.server.Listener.Addr().String(), replacement.Listener.Addr().String()}, dialed)
targetMu.Unlock()
}

Expand Down Expand Up @@ -915,6 +952,7 @@ func TestManager_DefaultNodeInfoPort_FlowsIntoStatusAndPreview(t *testing.T) {

status := m.addNode(ManualEntry{Address: "192.0.2.30", Name: "shifted"})
assert.Equal(t, shiftedPort, status.NodeInfoPort, "bare entry status port")
assert.Equal(t, shiftedPort+4, m.engineManagerPort, "engine-manager model port")
assert.False(t, status.TLSEnabled, "the default port is not a TLS hint")

t.Run("explicit tls_port still outranks the default", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions services/nvpair-manual-nodes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ Notifications emitted: `ready` with `{ "version": string }` (once, before the pr

### 7.2 Probe protocol and reachability

Each probe cycle performs up to four HTTP GETs against the entered address, each bounded by `probeTimeout` (3 s). Engine probes disable keep-alives so each cycle re-resolves the address. Hardware reads use the transport in §7.3:
Each probe cycle performs up to five HTTP GETs against the entered address, each bounded by `probeTimeout` (3 s). Direct engine probes disable keep-alives so each cycle re-resolves the address. Hardware and paired-peer inventory reads use the transports in §7.3:

- Ollama: `GET http://<address>:11434/` must return `200`; on success `GET http://<address>:11434/api/tags` supplies `ollama_models` from `models[].name`.
- LM Studio: `GET http://<address>:1234/v1/models` must return `200`; the same response supplies `lmstudio_models` from `data[].id`.
- node-info: `GET https://<address>:<port>/v1/node-info` must return `200`, fit within 64 KiB, and decode into `NodeInfoResponse`. Require an exact current pin, matching host and cluster response identities, and a remote identity distinct from this host.
- Paired-peer inventory: after node-info proves the host, `GET https://<address>:<engine-manager-port>/v1/models` must return `200`, fit within 16 MiB, and present the same pinned peer certificate. `modelsByEngine` is authoritative for `ollama` and `lmstudio`; a missing engine key means that engine is not serving a model inventory.

Ollama and LM Studio model-list JSON decoders read at most 16 MiB. A JSON value
that extends past this limit follows the existing model-parse failure path.
Hardware decoding requires the complete response body to fit within 64 KiB.

`node_info_port` defaults to the manager's `--node-info-port` (`14318` standalone; the broker hands it its resolved `ni` port) unless `tls_port > 0` overrides it. Service hardware reads always use pinned mTLS. Engine legs remain explicitly configured plain HTTP. `reachable` is `ollama_up || lmstudio_up || node_info_up`, independent of public previews. Publish changed status and every accepted hardware snapshot so stable values do not stop refreshing the scheduling cache.
`node_info_port` defaults to the manager's `--node-info-port` (`14318` standalone; the broker hands it its resolved `ni` port) unless `tls_port > 0` overrides it. The engine-manager port is derived from the same service-block base. Service hardware and authenticated model inventory reads use pinned mTLS. Direct engine probes remain available for unpaired manual endpoints; a valid per-engine inventory from a paired peer supersedes them. `reachable` is `ollama_up || lmstudio_up || node_info_up`, independent of public previews. Publish changed status and every accepted hardware snapshot so stable values do not stop refreshing the scheduling cache.

### 7.3 Probe transport and authenticated identity

Expand Down