fix: guard nil exitErr wrapping, document concurrency invariant

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Claude 2026-02-19 21:38:01 +00:00
parent 2c4966e652
commit c07f37afe9
No known key found for this signature in database
GPG key ID: AF404715446AEB41
2 changed files with 11 additions and 3 deletions

View file

@ -25,7 +25,11 @@ type rocmModel struct {
func (m *rocmModel) Generate(ctx context.Context, prompt string, opts ...inference.GenerateOption) iter.Seq[inference.Token] {
if !m.srv.alive() {
m.mu.Lock()
m.lastErr = fmt.Errorf("rocm: server has exited: %w", m.srv.exitErr)
if m.srv.exitErr != nil {
m.lastErr = fmt.Errorf("rocm: server has exited: %w", m.srv.exitErr)
} else {
m.lastErr = fmt.Errorf("rocm: server has exited unexpectedly")
}
m.mu.Unlock()
return func(yield func(inference.Token) bool) {}
}
@ -61,7 +65,11 @@ func (m *rocmModel) Generate(ctx context.Context, prompt string, opts ...inferen
func (m *rocmModel) Chat(ctx context.Context, messages []inference.Message, opts ...inference.GenerateOption) iter.Seq[inference.Token] {
if !m.srv.alive() {
m.mu.Lock()
m.lastErr = fmt.Errorf("rocm: server has exited: %w", m.srv.exitErr)
if m.srv.exitErr != nil {
m.lastErr = fmt.Errorf("rocm: server has exited: %w", m.srv.exitErr)
} else {
m.lastErr = fmt.Errorf("rocm: server has exited unexpectedly")
}
m.mu.Unlock()
return func(yield func(inference.Token) bool) {}
}

View file

@ -22,7 +22,7 @@ type server struct {
port int
client *llamacpp.Client
exited chan struct{}
exitErr error
exitErr error // safe to read only after <-exited
}
// alive reports whether the llama-server process is still running.