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 OpenVINO/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "aipg-openvino-utils"
version = "1.0.0"
requires-python = ">=3.10"
requires-python = "==3.12.*"
dependencies = [
"openvino",
]
Expand Down
5 changes: 5 additions & 0 deletions WebUI/build/build-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"afterPack": "build/scripts/after-pack.cjs",
"copyright": "Copyright © Intel. All rights reserved",
"extraResources": [
{
"from": "../backend_shared",
"to": "backend_shared",
"filter": ["*.py"]
},
{
"from": "../service",
"to": "service",
Expand Down
10 changes: 0 additions & 10 deletions WebUI/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,16 +1247,6 @@ function initEventHandle() {
return pathsManager.scanAll()
})

ipcMain.handle('refreshLLMModles', (_event) => {
// Old ipexllm backend removed - return empty array
return []
})

ipcMain.handle('getDownloadedLLMs', (_event) => {
// Old ipexllm backend removed - return empty array
return []
})

ipcMain.handle('getDownloadedGGUFLLMs', (_event) => {
return pathsManager.scanGGUFLLMModels()
})
Expand Down
2 changes: 0 additions & 2 deletions WebUI/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
getInitSetting: () => ipcRenderer.invoke('getInitSetting'),
updateModelPaths: (modelPaths: ModelPaths) => ipcRenderer.invoke('updateModelPaths', modelPaths),
restorePathsSettings: () => ipcRenderer.invoke('restorePathsSettings'),
refreshLLMModles: () => ipcRenderer.invoke('refreshLLMModles'),
loadModels: () => ipcRenderer.invoke('loadModels'),
zoomIn: () => ipcRenderer.invoke('zoomIn'),
zoomOut: () => ipcRenderer.invoke('zoomOut'),
getDownloadedLLMs: () => ipcRenderer.invoke('getDownloadedLLMs'),
getDownloadedGGUFLLMs: () => ipcRenderer.invoke('getDownloadedGGUFLLMs'),
getDownloadedOpenVINOLLMModels: () => ipcRenderer.invoke('getDownloadedOpenVINOLLMModels'),
getDownloadedEmbeddingModels: () => ipcRenderer.invoke('getDownloadedEmbeddingModels'),
Expand Down
111 changes: 15 additions & 96 deletions WebUI/electron/subprocesses/llamaCppBackendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { app, net, type BrowserWindow } from 'electron'
import { appLoggerInstance } from '../logging/logger.ts'
import { packagedResourcesRoot } from '../aipgRoot.ts'
import { createEnhancedErrorDetails, type ApiService, type ErrorDetails } from './service.ts'
import { terminateProcessTree, waitForServerReadyOrThrow } from './processLifecycle.ts'
import {
vulkanDeviceSelectorEnv,
withSelectedDevice,
Expand Down Expand Up @@ -1341,28 +1342,10 @@ export class LlamaCppBackendService implements ApiService {
private async stopLlamaLlmServer(): Promise<void> {
if (this.llamaLlmProcess) {
this.appLogger.info(`Stopping LLM server for model: ${this.currentLlmModel}`, this.name)
this.llamaLlmProcess.process.kill('SIGTERM')

// Wait a bit for graceful shutdown, then force kill if needed
await new Promise<void>((resolve) => {
const currentProcess = this.llamaLlmProcess
const timeout = setTimeout(() => {
if (currentProcess) {
this.appLogger.warn(`Force killing LLM server process`, this.name)
currentProcess.process.kill('SIGKILL')
}
resolve()
}, 5000)

if (currentProcess) {
currentProcess.process.on('exit', () => {
clearTimeout(timeout)
resolve()
})
} else {
clearTimeout(timeout)
resolve()
}
await terminateProcessTree(this.llamaLlmProcess.process, {
name: this.name,
label: 'LLM',
appLogger: this.appLogger,
})

this.llamaLlmProcess = null
Expand All @@ -1377,28 +1360,10 @@ export class LlamaCppBackendService implements ApiService {
`Stopping embedding server for model: ${this.currentEmbeddingModel}`,
this.name,
)
this.llamaEmbeddingProcess.process.kill('SIGTERM')

// Wait a bit for graceful shutdown, then force kill if needed
await new Promise<void>((resolve) => {
const currentProcess = this.llamaEmbeddingProcess
const timeout = setTimeout(() => {
if (currentProcess) {
this.appLogger.warn(`Force killing embedding server process`, this.name)
currentProcess.process.kill('SIGKILL')
}
resolve()
}, 5000)

if (currentProcess) {
currentProcess.process.on('exit', () => {
clearTimeout(timeout)
resolve()
})
} else {
clearTimeout(timeout)
resolve()
}
await terminateProcessTree(this.llamaEmbeddingProcess.process, {
name: this.name,
label: 'embedding',
appLogger: this.appLogger,
})

this.llamaEmbeddingProcess = null
Expand Down Expand Up @@ -1441,58 +1406,12 @@ export class LlamaCppBackendService implements ApiService {
process: ChildProcess,
getStartupError?: () => string | null,
): Promise<void> {
const maxAttempts = this.llamaCppBuildVariant === 'ssd-offload' ? 500 : 120
const delayMs = 1000

for (let attempt = 0; attempt < maxAttempts; attempt++) {
// Abort early with an actionable message if the server has reported a
// fatal startup error (e.g. ran out of memory for the context size).
const startupError = getStartupError?.()
if (startupError) {
this.appLogger.error(startupError, this.name)
throw new Error(startupError)
}

// Check if process has exited before attempting health check
if (!process || process.killed) {
this.appLogger.warn(
`Process for ${this.name} is not alive, aborting health check`,
this.name,
)
throw new Error(`Process exited before server became ready`)
}

try {
const response = await fetch(healthUrl, {
method: 'GET',
signal: AbortSignal.timeout(1000),
})

if (response.ok) {
// Double-check process is still alive before accepting success
if (!process || process.killed) {
this.appLogger.warn(
`Process for ${this.name} exited after health check succeeded, marking as failed`,
this.name,
)
throw new Error(`Process exited after health check succeeded`)
}
this.appLogger.info(`Server ready at ${healthUrl}`, this.name)
return
}
} catch (_error) {
// Server not ready yet, continue waiting
// But check if process is still alive
if (!process || process.killed) {
this.appLogger.warn(`Process for ${this.name} exited during health check wait`, this.name)
throw new Error(`Process exited during server startup`)
}
}

await new Promise((resolve) => setTimeout(resolve, delayMs))
}

throw new Error(`Server failed to start within ${(maxAttempts * delayMs) / 1000} seconds`)
await waitForServerReadyOrThrow(healthUrl, process, {
name: this.name,
maxAttempts: this.llamaCppBuildVariant === 'ssd-offload' ? 500 : 120,
getStartupError,
appLogger: this.appLogger,
})
}

private async detectStorageTargets(): Promise<void> {
Expand Down
127 changes: 10 additions & 117 deletions WebUI/electron/subprocesses/openVINOBackendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import getPort, { portNumbers } from 'get-port'
import { ensureManagedPython, installBackend, uvPipInstallToTarget } from './uvBasedBackends/uv.ts'
import { binary, extract } from './tools.ts'
import { getBundledBackendVersionSync, resolveModels } from '../remoteUpdates.ts'
import {
terminateProcessTree as killProcessTree,
waitForServerReadyOrThrow,
} from './processLifecycle.ts'
import {
getMissingPackages,
hasAptGet,
Expand Down Expand Up @@ -2136,39 +2140,7 @@ export class OpenVINOBackendService implements ApiService {
* whole tree; we then wait for the OS to reap it and release the handles.
*/
private async terminateProcessTree(proc: ChildProcess, label: string): Promise<void> {
const waitForExit = (ms: number): Promise<boolean> =>
new Promise<boolean>((resolve) => {
if (proc.exitCode !== null || proc.signalCode !== null) {
resolve(true)
return
}
const timeout = setTimeout(() => resolve(false), ms)
proc.once('exit', () => {
clearTimeout(timeout)
resolve(true)
})
})

proc.kill('SIGTERM')
let exited = await waitForExit(2000)
if (exited) return

this.appLogger.warn(`Force killing OVMS ${label} process tree`, this.name)
if (process.platform === 'win32' && proc.pid !== undefined) {
try {
await execAsync(`taskkill /PID ${proc.pid} /T /F`)
} catch (e) {
// taskkill exits non-zero when the process is already gone — not fatal.
this.appLogger.warn(`taskkill for OVMS ${label} reported: ${e}`, this.name)
}
} else {
proc.kill('SIGKILL')
}

exited = await waitForExit(5000)
if (!exited) {
this.appLogger.warn(`OVMS ${label} not confirmed exited after force kill`, this.name)
}
await killProcessTree(proc, { name: this.name, label, appLogger: this.appLogger })
}

private async stopOvmsLlmServer(): Promise<void> {
Expand Down Expand Up @@ -2676,91 +2648,12 @@ export class OpenVINOBackendService implements ApiService {
childProcess: ChildProcess,
maxAttempts = 120,
): Promise<void> {
const delayMs = 1000

// Track whether the process has exited (process.killed only reflects
// signals sent by Node.js — not OS-level kills like OOM or SIGSEGV).
let processExited = false
let exitCode: number | null = null
let exitSignal: string | null = null
const stderrChunks: string[] = []

const onExit = (code: number | null, signal: string | null) => {
processExited = true
exitCode = code
exitSignal = signal
}
childProcess.on('exit', onExit)
childProcess.stderr?.on('data', (data: Buffer) => {
stderrChunks.push(data.toString())
// Keep only the last 20 lines of stderr for diagnostics
if (stderrChunks.length > 20) stderrChunks.shift()
await waitForServerReadyOrThrow(healthUrl, childProcess, {
name: this.name,
maxAttempts,
captureExitDiagnostics: true,
appLogger: this.appLogger,
})

const buildExitErrorMessage = (): string => {
const reason = exitSignal
? `killed by signal ${exitSignal}`
: exitCode !== null
? `exit code ${exitCode}`
: 'exit code null (killed by OS signal, possibly OOM)'
const lastStderr = stderrChunks.join('').trim()
const stderrSuffix = lastStderr ? `\nLast stderr output:\n${lastStderr.slice(-2000)}` : ''
return `OVMS process crashed during startup (${reason})${stderrSuffix}`
}

try {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
// Check if process has exited (covers OS kills, crashes, OOM, etc.)
if (processExited || childProcess.killed) {
const msg = buildExitErrorMessage()
this.appLogger.warn(
`Process for ${this.name} is not alive, aborting health check: ${msg}`,
this.name,
)
throw new Error(msg)
}

try {
const response = await fetch(healthUrl, {
method: 'GET',
signal: AbortSignal.timeout(1000),
})

if (response.ok) {
if (processExited || childProcess.killed) {
const msg = buildExitErrorMessage()
this.appLogger.warn(
`Process for ${this.name} exited after health check succeeded: ${msg}`,
this.name,
)
throw new Error(msg)
}
this.appLogger.info(`Server ready at ${healthUrl}`, this.name)
return
}
} catch (error) {
// Re-throw our own errors (from the process-exit check above)
if (error instanceof Error && error.message.startsWith('OVMS process crashed')) {
throw error
}
// Server not ready yet — check if the process died while we were waiting
if (processExited || childProcess.killed) {
const msg = buildExitErrorMessage()
this.appLogger.warn(
`Process for ${this.name} exited during health check wait: ${msg}`,
this.name,
)
throw new Error(msg)
}
}

await new Promise((resolve) => setTimeout(resolve, delayMs))
}

throw new Error(`Server failed to start within ${(maxAttempts * delayMs) / 1000} seconds`)
} finally {
childProcess.removeListener('exit', onExit)
}
}

// Error management methods for startup failures
Expand Down
Loading
Loading