feat: implement isolated model worker with auto-restart and hot-reload
Introduce a supervised child process for capture, VAD, and recognition, enabling automatic restart on crash/hang and hot-reload via SIGHUP. Add `--model-auto-restart`, `--model-timeout`, and `--model-shutdown-timeout` options. Refactor `Run()` with lifecycle hooks for proper process group cleanup. Update README with new behavior and CLI flags.
This commit is contained in:
+22
-5
@@ -12,6 +12,8 @@ const (
|
||||
DefaultModelsDir = "models"
|
||||
DefaultOverlayFontFamily = "Sans"
|
||||
MinimumOverlayFinalLifetime = 3 * time.Second
|
||||
DefaultModelTimeout = 30 * time.Second
|
||||
DefaultModelShutdownTimeout = 2 * time.Second
|
||||
)
|
||||
|
||||
type Mode string
|
||||
@@ -22,11 +24,14 @@ const (
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
Mode Mode
|
||||
ChunkDuration time.Duration
|
||||
ModelsDir string
|
||||
Threads int
|
||||
PreviewThresholdDB float64
|
||||
Mode Mode
|
||||
ChunkDuration time.Duration
|
||||
ModelsDir string
|
||||
Threads int
|
||||
PreviewThresholdDB float64
|
||||
ModelAutoRestart bool
|
||||
ModelTimeout time.Duration
|
||||
ModelShutdownTimeout time.Duration
|
||||
}
|
||||
|
||||
func Parse() Settings {
|
||||
@@ -37,6 +42,9 @@ func Parse() Settings {
|
||||
flag.StringVar(&settings.ModelsDir, "models-dir", DefaultModelsDir, "directory containing downloaded Sherpa models")
|
||||
flag.IntVar(&settings.Threads, "threads", 2, "CPU threads used by recognition and VAD")
|
||||
flag.Float64Var(&settings.PreviewThresholdDB, "preview-threshold-dbfs", -45, "RMS dBFS threshold used to begin VAD previews")
|
||||
flag.BoolVar(&settings.ModelAutoRestart, "model-auto-restart", true, "restart the isolated model worker after a crash or timeout")
|
||||
flag.DurationVar(&settings.ModelTimeout, "model-timeout", DefaultModelTimeout, "maximum model startup or processing time; zero disables hang detection")
|
||||
flag.DurationVar(&settings.ModelShutdownTimeout, "model-shutdown-timeout", DefaultModelShutdownTimeout, "time allowed for model flush and cleanup before force-killing the worker")
|
||||
flag.Parse()
|
||||
settings.Mode = Mode(mode)
|
||||
return settings
|
||||
@@ -87,6 +95,9 @@ func ParseDesktop() DesktopSettings {
|
||||
flags.StringVar(&desktop.ModelsDir, "models-dir", DefaultModelsDir, "directory containing downloaded Sherpa models")
|
||||
flags.IntVar(&desktop.Threads, "threads", 2, "CPU threads used by recognition and VAD")
|
||||
flags.Float64Var(&desktop.PreviewThresholdDB, "preview-threshold-dbfs", -45, "RMS dBFS threshold used to begin VAD previews")
|
||||
flags.BoolVar(&desktop.ModelAutoRestart, "model-auto-restart", true, "restart the isolated model worker after a crash or timeout")
|
||||
flags.DurationVar(&desktop.ModelTimeout, "model-timeout", DefaultModelTimeout, "maximum model startup or processing time; zero disables hang detection")
|
||||
flags.DurationVar(&desktop.ModelShutdownTimeout, "model-shutdown-timeout", DefaultModelShutdownTimeout, "time allowed for model flush and cleanup before force-killing the worker")
|
||||
flags.StringVar(&output, "output", "", "caption output: terminal, overlay, or both (required)")
|
||||
flags.StringVar(&backend, "overlay-backend", "auto", "display backend: auto, wayland, or x11")
|
||||
flags.Float64Var(&desktop.Overlay.Opacity, "overlay-opacity", 0.90, "caption background opacity from 0 to 1")
|
||||
@@ -114,6 +125,12 @@ func (s Settings) Validate() error {
|
||||
if s.Threads <= 0 {
|
||||
return errors.New("--threads must be positive")
|
||||
}
|
||||
if s.ModelTimeout < 0 {
|
||||
return errors.New("--model-timeout cannot be negative")
|
||||
}
|
||||
if s.ModelShutdownTimeout <= 0 {
|
||||
return errors.New("--model-shutdown-timeout must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user