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
3 changes: 3 additions & 0 deletions .cursor/rules/architecture.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ The binary inventory and launch ownership live in
`nvpair-engine-manager` owns lifecycle and model operations.

- Engine server ports and proxy ports are persisted by their backend owners.
- The engine manager identifies the installed version, selects the appropriate
release for each local engine, and applies managed updates. The desktop
schedules checks and presents the reported action.
- Desired engine state is restored by the backend.
- Leave shutdown ordering to the broker. Its shutdown stops the proxy, then the
engines through `engine:prepare-shutdown`, then the workers. Clients do not
Expand Down
6 changes: 4 additions & 2 deletions .cursor/rules/system-architecture.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ detail of either; a change to one is a change to both. Neither drives the other.
`nvpair-engine-manager` owns lifecycle, port, desired-state, and model
operations.

- Local lifecycle supports install, start, stop, uninstall, update, and port
changes.
- Local lifecycle supports install, start, stop, uninstall, and port changes.
The desktop checks each local engine through `engine:check-updates` and
sends `engine:update` for managed updates. An external update opens the
engine manager's vendor download URL for the detected installation.
- Remote lifecycle uses the engine manager's remote control methods where
available.
- `engine:prepare-shutdown` stops processes without clearing persisted desired
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ Each entry assumes the ones before it.
most users need. When you update, **[Release notes](docs/release-notes.mdx)**
lists what changed and the **[Upgrade guide](docs/upgrade-guide.mdx)** covers
any steps the update needs.
3. **[Managing engines](docs/engine-lifecycle.mdx)** — install, start, stop,
update, and uninstall engines; what PAIR restores after you quit or relaunch.
3. **[Managing engines](docs/engine-lifecycle.mdx)** — install, start, stop, and
uninstall engines, check for updates on this machine, and see what PAIR
restores on relaunch.
4. **[Engine settings](docs/engine-settings.mdx)** — change an engine's ports and
its launch command, on this machine or a paired one, and give a browser access
to your models.
Expand Down
37 changes: 37 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ binaries across the Windows, Linux, and macOS targets. First-party modules
| `github.com/rivo/uniseg` | v0.4.7 | MIT |
| `github.com/xo/terminfo` | v0.0.0-20220910002029-abceb7e1c41e | MIT |
| `github.com/yusufpapurcu/wmi` | v1.2.4 | MIT |
| `golang.org/x/mod` | v0.12.0 | BSD-3-Clause |
| `golang.org/x/net` | v0.58.0 | BSD-3-Clause |
| `golang.org/x/sys` | v0.47.0 | BSD-3-Clause |
| `golang.org/x/text` | v0.3.8 | BSD-3-Clause |
Expand Down Expand Up @@ -7212,6 +7213,42 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

### golang.org/x/mod v0.12.0

License: BSD-3-Clause

Repository: https://golang.org/x/mod

```text
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

### golang.org/x/net v0.58.0

License: BSD-3-Clause
Expand Down
5 changes: 5 additions & 0 deletions desktop/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ closed `EngineType` union and narrows external strings with `isEngineType()`.
`engineManagerName()` / `engineTypeFromManagerName()` are the one place that
translation to and from the engine manager's own spelling lives.

The desktop schedules release checks for each installed local engine. The engine manager
compares versions, determines installation ownership, and applies managed
updates. The bridge publishes availability through the existing engine snapshot
and `engines:state-changed` updates.

### Model downloads

A download is started with `engine:action{pull_model}`, or
Expand Down
4 changes: 3 additions & 1 deletion desktop/docs/frontend-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ They do not imply a WebSocket connection. Browser clients are not supported.

- `getInitialState()` returns engine statuses, models, active progress, and available
updates.
- `toggle`, `install`, `uninstall`, and `update` manage engine lifecycle.
- `toggle`, `install`, and `uninstall` manage engine lifecycle. `update` applies
an available release to a PAIR-managed engine on the local node. For an external
installation, the engine row links to the vendor's update instructions or release.
- `pullModel`, `cancelModelPull`, `loadModel`, `unloadModel`, `deleteModel`, and
`setModelExpiry` manage models.
- `searchHub(engineType, nodeId)` returns the curated model catalog for a
Expand Down
6 changes: 6 additions & 0 deletions desktop/docs/services-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
| `engine:action` | request (we call) | ✅ yes |
| `engine:cancel-pull` | request (we call) | ✅ yes |
| `engine:catalog` | request (we call) | ✅ yes |
| `engine:check-updates` | request (we call) | ✅ yes |
| `engine:configure-launch` | request (we call) | ⚠️ not called |
| `engine:configured-ports` | request (we call) | ⚠️ not called |
| `engine:describe` | request (we call) | ⚠️ not called |
Expand Down Expand Up @@ -127,6 +128,7 @@
| `engine:stop` | request (we call) | ✅ yes |
| `engine:uninstall` | request (we call) | ✅ yes |
| `engine:uninstall-managed` | request (we call) | ✅ yes |
| `engine:update` | request (we call) | ✅ yes |
| `error` | request (we call) | ✅ yes |
| `internal:set-reserved-port` | request (we call) | ⚠️ not called |

Expand Down Expand Up @@ -275,17 +277,21 @@
| `discovery:subscribe` | request (we call) | ✅ yes |
| `discovery:unsubscribe` | request (we call) | ⚠️ not called |
| `engine:apply-settings` | request (we call) | ✅ yes |
| `engine:check-updates` | request (we call) | ✅ yes |
| `engine:configure-launch` | request (we call) | ⚠️ not called |
| `engine:get-installed` | request (we call) | ✅ yes |
| `engine:get-settings` | request (we call) | ✅ yes |
| `engine:install` | request (we call) | ✅ yes |
| `engine:preview-settings` | request (we call) | ✅ yes |
| `engine:restart` | request (we call) | ⚠️ not called |
| `engine:set-port` | request (we call) | ⚠️ not called |
| `engine:set-reserved-port` | request (we call) | ⚠️ not called |
| `engine:start` | request (we call) | ✅ yes |
| `engine:status` | request (we call) | ✅ yes |
| `engine:stop` | request (we call) | ✅ yes |
| `engine:subscribe` | request (we call) | ✅ yes |
| `engine:unsubscribe` | request (we call) | ⚠️ not called |
| `engine:update` | request (we call) | ✅ yes |
| `errors:get-initial` | request (we call) | ✅ yes |
| `internal:set-reserved-port` | request (we call) | ⚠️ not called |
| `node/add` | request (we call) | ✅ yes |
Expand Down
8 changes: 6 additions & 2 deletions desktop/docs/services-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ one centralized pending-action layer so controls respond immediately while
waiting for authoritative state. Pending state clears on matching engine state,
progress, or error pushes.

Local engine operations include install, start, stop, uninstall, update, port
changes, and model actions. Remote cluster operations use the engine manager's
Local engine operations include install, start, stop, uninstall, port changes,
and model actions. The desktop calls `engine:check-updates` at startup and every
six hours for each installed local engine. A local start or stop also triggers
a background check for that engine. The bridge projects each successful result into
`updateAvailable` for the renderer. Selecting **Update** sends `engine:update`
for a managed installation. Remote cluster operations use the engine manager's
remote control surface where supported.

### Cancelling a download
Expand Down
12 changes: 6 additions & 6 deletions desktop/docs/services-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ history.
| Local engine lifecycle | Complete | Install, start, stop, uninstall, update, and port configuration |
| Remote engine lifecycle | Partial | Remote install, start, stop, status, and model pull are supported |
| Engine models | Partial | Core list, pull, load, unload, and supported delete actions are wired |
| Engine version metadata | Backend-limited | The backend status surface does not provide a complete version/install-owner/update contract |
| Engine version metadata | Local engines | The engine manager compares the installed version with the applicable platform release and distinguishes managed and external installs. |
| Errors | Complete | Broker-relayed registry with peer synchronization |
| Workloads | Complete after subscription | Local and peer workload events feed one Electron catalog |
| Cluster pairing | Complete | PIN pairing, identity, membership, leave, and removal |
Expand Down Expand Up @@ -279,11 +279,11 @@ genuinely foreign listener (with an actionable error). Personal AI Router treats
desired state as authoritative and surfaces a stop error as guidance, not as a
sign the OFF choice was discarded.

For ease of use, Personal AI Router issues starts in two additional cases and
keeps no auto-start list of its own: every install sends `engine:install` with
`start: true`, so a successful install (or managed update) starts the engine;
and on the first app open Personal AI Router starts every already-installed local
engine once. Both paths rely on the backend recording desired-enabled as a side
Every install sends `engine:install` with `start: true`, so a successful install
starts the engine. A managed engine update uses `engine:update` and preserves
the engine's running or stopped state. On the first app open Personal AI Router
starts every already-installed local engine once. Install and first-open starts
rely on the engine manager recording desired-enabled as a side
effect of start, so `nvpair-engine-manager` remains the single owner of
desired-state persistence and restoration.

Expand Down
6 changes: 6 additions & 0 deletions desktop/src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { macPrivilege } from '@/electron/services/mac-privilege-service'
import { registerAllIpc } from '@/electron/ipc'
import { destroyConnector, destroyConnectorSync, initializeConnector } from '@/electron/connector'
import { initializeUpdater } from '@/electron/updater'
import { subscribeEngineUpdateNotifications } from '@/electron/updater/engine-update-notification'
import { getModularBridgeState } from '@/electron/service-bridge/modular-state'
import { ensureNvpairOnPath } from '@/electron/nvpair-command'
import { isAppDataWipeScheduled } from '@/electron/app-data-wipe-orchestrator'
import { destroyInferenceDemoSync, stopInferenceDemo } from '@/electron/inference-demo'
Expand Down Expand Up @@ -162,6 +164,10 @@ if (!gotTheLock || exitRequested) {

registerAllIpc()
initializeUpdater()
const unsubscribeEngineUpdates = subscribeEngineUpdateNotifications(() =>
getModularBridgeState().getSelfId()
)
app.once('will-quit', unsubscribeEngineUpdates)

// Bound startup on broker `app:ready` before opening the normal Overview.
// Proxy readiness is not part of this gate — it is an asynchronous
Expand Down
47 changes: 25 additions & 22 deletions desktop/src/electron/service-bridge/empty-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,21 @@ function routeEngineManagerCommand(payload: WsInvokeRequest<'engine:command'>):
// Use the engine-manager's stable error key. If the manager already reported
// the operation failure, nvpair-errors upserts this fallback instead of showing
// a duplicate; admission/transport failures still get a visible error.
const failPendingOp = (action: string, operation: 'install' | 'uninstall') => {
const failPendingOp = (operation: 'install' | 'uninstall' | 'update') => {
return (error: string): void => {
state.clearPendingEngineOp(payload.engineType)
supervisor.reportError(`Failed to ${action} ${engine}: ${error}`, 'error', undefined, {
id: `engine-manager:${operation}-failed:${engine}`,
engineType: engine,
operation,
action: 'retry'
})
supervisor.reportError(
`Failed to ${operation} ${engine}: ${error}`,
'error',
undefined,
{
id: `engine-manager:${operation}-failed:${engine}`,
nodeId: payload.nodeId,
engineType: payload.engineType,
operation,
action: 'retry'
}
)
}
}
const failAction =
Expand All @@ -273,7 +279,7 @@ function routeEngineManagerCommand(payload: WsInvokeRequest<'engine:command'>):
'broker',
'engine:install',
{ engine, start: true },
failPendingOp('install', 'install'),
failPendingOp('install'),
true
)
break
Expand All @@ -283,28 +289,25 @@ function routeEngineManagerCommand(payload: WsInvokeRequest<'engine:command'>):
'broker',
'engine:uninstall',
{ engine },
failPendingOp('uninstall', 'uninstall'),
failPendingOp('uninstall'),
true
)
break
case 'update':
// The engine-manager serializes per-engine ops via its lifecycle
// lock, so the queued install waits for the uninstall to finish. The
// uninstall's engine:state-changed briefly clears this, then the
// install's progress re-establishes `installing`.
if (!payload.nodeId || payload.nodeId !== state.getSelfId()) {
supervisor.reportError(
'Engine updates are available on the local node.',
'warning',
'engine-cmd:update'
)
break
}
state.beginLocalEngineOp(payload.engineType, 'installing')
supervisor.sendProcess(
'broker',
'engine:uninstall',
'engine:update',
{ engine },
failPendingOp('update', 'uninstall'),
true
)
supervisor.sendProcess(
'broker',
'engine:install',
{ engine, start: true },
failPendingOp('update', 'install'),
failPendingOp('update'),
true
)
break
Expand Down
67 changes: 67 additions & 0 deletions desktop/src/electron/service-bridge/engine-update-checks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { createStructuredLogger } from '@/shared/utils/log'
import getErrorString from '@/shared/utils/get-error-string'
import type { EngineType } from '@/shared/types/engines'
import { EngineTypes } from '@/shared/constants/engines'
import type { JsonValue } from './json-rpc-subprocess'
import { getModularBridgeState } from './modular-state'

const log = createStructuredLogger('service-bridge')
const CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000

/** One timer per broker. Coalesce lifecycle changes independently for each engine. */
export function watchEngineUpdates(check: (engine: EngineType) => Promise<JsonValue | undefined>): {
refresh: (engine?: EngineType) => Promise<void>
stop: () => void
} {
const state = getModularBridgeState()
let active = true
const checking = new Set<EngineType>()
const requested = new Set<EngineType>()

async function checkEngine(engine: EngineType): Promise<void> {
requested.add(engine)
if (checking.has(engine)) return
checking.add(engine)
try {
while (active && requested.delete(engine)) {
const nodeId = state.getSelfId()
if (!nodeId || !state.supportsEngine(engine)) return
try {
const result = await check(engine)
if (active && !requested.has(engine)) {
state.applyEngineUpdateCheck(nodeId, engine, result)
}
} catch (error) {
log.verbose({
sublevel: 'engine-manager',
message: `${engine} update check unavailable: ${getErrorString(error)}`
})
}
}
} finally {
checking.delete(engine)
}
}

async function refresh(engine?: EngineType): Promise<void> {
if (engine) await checkEngine(engine)
else await Promise.all(EngineTypes.map(checkEngine))
}

const timer = setInterval(() => void refresh(), CHECK_INTERVAL_MS)
state.setEngineUpdateRefresher(refresh)
void refresh()
return {
refresh,
stop(): void {
if (!active) return
active = false
clearInterval(timer)
state.setEngineUpdateRefresher(undefined)
state.clearEngineUpdates()
}
}
}
Loading
Loading