mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
refactor: improve OpenCode server restart logic with plugin awareness
- Add plugin detection to determine if server restart is required when config changes - Extend health check timeout to 120s when plugins are configured (from 30s) - Implement retry-once logic for plugin installations that may cause initial startup failure - Check agent, plugin, skills, and provider fields for restart decisions (previously only agents) - Improve frontend toast messages to distinguish between restart and apply scenarios - Set XDG_CACHE_HOME in Dockerfile for proper cache directory management
This commit is contained in:
1 parent
7a7090101c
commit
9c8811dbc7
4 files changed
+98
-25
No files matched your search
@@ -17,6 +17,7 @@ import {
|
||||
import { decryptSecret } from '../utils/crypto'
|
||||
import { SettingsService } from './settings'
|
||||
import { getWorkspacePath, getOpenCodeConfigFilePath, ENV } from '@opencode-manager/shared/config/env'
|
||||
import { parseJsonc } from '@opencode-manager/shared/utils'
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import { compareVersions } from '../utils/version-utils'
|
||||
import { patchOpenCodeConfig } from './proxy'
|
||||
@@ -121,7 +122,7 @@ class OpenCodeServerManager {
|
||||
OpenCodeServerManager.instance = null as unknown as OpenCodeServerManager
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
async start(retryAfterPluginInstall = true): Promise<void> {
|
||||
if (this.isHealthy) {
|
||||
logger.info('OpenCode server already running and healthy')
|
||||
return
|
||||
@@ -236,6 +237,7 @@ class OpenCodeServerManager {
|
||||
logger.info(`OpenCode server GIT_SSH_COMMAND: ${gitSshCommand}`)
|
||||
|
||||
await this.initializeOpencodeBinDirectory()
|
||||
const configuredPluginCount = await this.getConfiguredPluginCount(openCodeConfigPath)
|
||||
|
||||
let stderrOutput = ''
|
||||
|
||||
@@ -296,10 +298,18 @@ class OpenCodeServerManager {
|
||||
|
||||
logger.info(`OpenCode server started with PID ${this.serverPid}`)
|
||||
|
||||
const healthy = await this.waitForHealth(30000)
|
||||
const healthTimeoutMs = configuredPluginCount > 0 ? 120000 : 30000
|
||||
const healthy = await this.waitForHealth(healthTimeoutMs)
|
||||
if (!healthy) {
|
||||
const fallback = `Server failed to become healthy after 30s${stderrOutput ? `. Last error: ${stderrOutput.slice(-500)}` : ''}`
|
||||
const fallback = `Server failed to become healthy after ${Math.round(healthTimeoutMs / 1000)}s${stderrOutput ? `. Last error: ${stderrOutput.slice(-500)}` : ''}`
|
||||
this.lastStartupError = formatStartupError(stderrOutput, fallback)
|
||||
if (configuredPluginCount > 0 && retryAfterPluginInstall) {
|
||||
logger.warn(`OpenCode server did not become healthy after installing ${configuredPluginCount} configured plugin(s); restarting once`)
|
||||
await this.stop()
|
||||
await new Promise(r => setTimeout(r, 1000))
|
||||
await this.start(false)
|
||||
return
|
||||
}
|
||||
throw new Error('OpenCode server failed to become healthy')
|
||||
}
|
||||
|
||||
@@ -394,6 +404,16 @@ class OpenCodeServerManager {
|
||||
}
|
||||
}
|
||||
|
||||
private async getConfiguredPluginCount(configPath: string): Promise<number> {
|
||||
try {
|
||||
const content = await fs.readFile(configPath, 'utf-8')
|
||||
const config = parseJsonc(content) as { plugin?: unknown }
|
||||
return Array.isArray(config.plugin) ? config.plugin.length : 0
|
||||
} catch {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
async restart(): Promise<void> {
|
||||
logger.info('Restarting OpenCode server (full process restart)')
|
||||
await this.stop()
|
||||
|
||||
Reference in new issue
Block a user