feat(opencode): surface server startup and recovery failures in-app

This commit is contained in:
Chris Scott committed 2026-10-01 16:13:11 -04:00
1 parent 53a70d8545
commit 7e9afc3da4
19 files changed
+454 -181

No files matched your search

@@ -0,0 +1,42 @@
import { useEffect, useRef } from 'react'
import { showToast } from '@/lib/toast'
import { getOpenCodeServerIssue, useServerHealth } from '@/hooks/useServerHealth'
import { useSettingsDialog } from '@/hooks/useSettingsDialog'
export const OPENCODE_FAILURE_TOAST_ID = 'opencode-server-failure'
/**
* Raises one persistent error toast per distinct terminal OpenCode server
* failure (startup failure or exhausted recovery), offering to open the Logs
* settings tab or restart the server, and announces when the server recovers.
*/
export function useOpenCodeFailureToast(enabled: boolean, onRestart: () => void) {
const { data: health } = useServerHealth(enabled)
const { setActiveTab } = useSettingsDialog()
const notifiedFailureRef = useRef<string | null>(null)
const issue = getOpenCodeServerIssue(health)
const failureMessage = issue?.state === 'failed' ? issue.message : null
const isHealthy = health?.opencodeLifecycle ? health.opencodeLifecycle.healthy : health?.opencode === 'healthy'
useEffect(() => {
if (failureMessage !== null) {
if (notifiedFailureRef.current === failureMessage) return
notifiedFailureRef.current = failureMessage
showToast.error('OpenCode server failed', {
id: OPENCODE_FAILURE_TOAST_ID,
duration: Infinity,
description: failureMessage,
action: { label: 'View logs', onClick: () => setActiveTab('logs') },
cancel: { label: 'Restart', onClick: onRestart },
})
return
}
if (isHealthy && notifiedFailureRef.current !== null) {
notifiedFailureRef.current = null
showToast.dismiss(OPENCODE_FAILURE_TOAST_ID)
showToast.success('OpenCode server is back online')
}
}, [failureMessage, isHealthy, setActiveTab, onRestart])
}