Skip to content
Merged
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
270 changes: 220 additions & 50 deletions backend/src/services/opencode-single-server.ts

Large diffs are not rendered by default.

45 changes: 7 additions & 38 deletions backend/src/services/opencode-supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,12 @@ import { ENV } from '@opencode-manager/shared/config/env'
import { archiveBrokenOpenCodeConfigFile, writeHealthWatchArtifact } from './opencode-config-file'
import { restoreLastKnownGoodOpenCodeConfig, seedOpenCodeConfigFile } from './opencode-config-apply'
import type { OpenCodeServerManager } from './opencode-single-server'

export const OPENCODE_LIFECYCLE_STATES = [
'idle',
'starting',
'healthy',
'unhealthy',
'recovering',
'failed',
'stopping',
'stopped',
] as const

export type OpenCodeLifecycleState = (typeof OPENCODE_LIFECYCLE_STATES)[number]

export const OPENCODE_RECOVERY_ACTIONS = [
'restart',
'debug_capture',
'rollback_last_known_good',
'seed_default_config',
] as const

export type OpenCodeRecoveryAction = (typeof OPENCODE_RECOVERY_ACTIONS)[number]
import {
OPENCODE_RECOVERY_ACTIONS,
type OpenCodeLifecycleState,
type OpenCodeLifecycleStatus,
type OpenCodeRecoveryAction,
} from '@opencode-manager/shared/opencode'

const MAX_QUEUED_LIFECYCLE_OPERATIONS = 2

Expand All @@ -36,22 +20,6 @@ export type OpenCodeOperationReason =
| 'settings_reload'
| 'manual'

export interface OpenCodeLifecycleStatus {
state: OpenCodeLifecycleState
healthy: boolean
port: number
version: string | null
minVersion: string
versionSupported: boolean
lastError: string | null
activeRecoveryAction: OpenCodeRecoveryAction | null
attemptedRecoveryActions: OpenCodeRecoveryAction[]
nextRecoveryAction: OpenCodeRecoveryAction | null
failureCount: number
watching: boolean
updatedAt: string
}

interface OpenCodeSupervisorOptions {
pollIntervalMs?: number
failureThreshold?: number
Expand Down Expand Up @@ -267,6 +235,7 @@ export class OpenCodeSupervisor {
}

this.activeRecoveryAction = null
logger.error(`OpenCode server failed after recovery actions [${this.attemptedRecoveryActions.join(', ')}]: ${this.lastError ?? 'unknown error'}`)
this.setState('failed')
this.openCodeServerManager.setLifecycleInitialized(false)
return this.getStatus()
Expand Down
Loading