mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-28 09:08:54 -04:00
fix(model): report backend crash diagnostics (#11532)
Unexpected runtime exits only reported an exit code, which hid the backend diagnostic. Include the final non-empty stderr line when one exists. Assisted-by: Codex:gpt-5 Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
This commit is contained in:
1 parent
ce8a04fe46
commit
342c3d0e17
2 files changed
+41
No files matched your search
@@ -350,6 +350,9 @@ func (ml *ModelLoader) startProcess(grpcProcess, id string, serverAddress string
|
||||
} else {
|
||||
// A stop we didn't initiate — a SIGSEGV from a missing shared
|
||||
// library, a Python ImportError, an OOM kill, an unexpected self-exit.
|
||||
if diagnostic := lastNonEmptyLine(grpcControlProcess.StderrPath(), startupStderrTailBytes); diagnostic != "" {
|
||||
fields = append(fields, "stderr", diagnostic)
|
||||
}
|
||||
xlog.Warn("Backend process exited unexpectedly", fields...)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mudler/LocalAI/pkg/system"
|
||||
"github.com/mudler/xlog"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("backend process exit diagnostics", func() {
|
||||
It("includes the exit code and final stderr line for an unexpected exit", func() {
|
||||
tmpDir := GinkgoT().TempDir()
|
||||
backendPath := filepath.Join(tmpDir, "failing-backend")
|
||||
Expect(os.WriteFile(backendPath, []byte("#!/bin/sh\necho 'first diagnostic' >&2\necho 'fatal metal pipeline error' >&2\nexit 42\n"), 0o700)).To(Succeed())
|
||||
|
||||
captured := &bytes.Buffer{}
|
||||
handler := slog.NewTextHandler(captured, &slog.HandlerOptions{Level: slog.LevelWarn})
|
||||
xlog.SetLogger(xlog.NewLoggerWithHandler(handler, xlog.LogLevelWarn))
|
||||
DeferCleanup(func() {
|
||||
xlog.SetLogger(xlog.NewLogger(xlog.LogLevel("info"), "text"))
|
||||
})
|
||||
|
||||
loader := NewModelLoader(&system.SystemState{Model: system.Model{ModelsPath: tmpDir}})
|
||||
process, err := loader.startProcess(backendPath, "test-model", "127.0.0.1:65535")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(process.Done()).Should(BeClosed())
|
||||
Eventually(captured.String).Should(And(
|
||||
ContainSubstring("Backend process exited unexpectedly"),
|
||||
ContainSubstring("exitCode=42"),
|
||||
ContainSubstring(`stderr="fatal metal pipeline error"`),
|
||||
))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user