Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

Merge remote-tracking branch 'upstream/main' into pr3702

Daniel Hiltgen920a4b0794d9
diff --cc llm/server.go
index 02780c2e6,78106ea06..b452434ee
--- a/llm/server.go
+++ b/llm/server.go
@@@ -416,44 -481,61 +481,56 @@@ func (s *llmServer) Ping(ctx context.Co
return nil
}
- func (s *LlamaServer) WaitUntilRunning() error {
+ func (s *llmServer) WaitUntilRunning(ctx context.Context) error {
start := time.Now()
- // TODO we need to wire up a better way to detect hangs during model load and startup of the server
expiresAt := time.Now().Add(10 * time.Minute) // be generous with timeout, large models can take a while to load
- ticker := time.NewTicker(50 * time.Millisecond)
- defer ticker.Stop()
slog.Info("waiting for llama runner to start responding")
- var lastStatus ServerStatus = -1
+
for {
+ select {
+ case <-ctx.Done():
+ slog.Info("context expired before server started")
+ return fmt.Errorf("timed out waiting for llama runner to start: %w", ctx.Err())
+ case err := <-s.done:
+ msg := ""
+ if s.status != nil && s.status.LastErrMsg != "" {
+ msg = s.status.LastErrMsg
+ }
+ return fmt.Errorf("llama runner process has terminated: %v %s", err, msg)
- case <-ticker.C:
- if time.Now().After(expiresAt) {
- // timeout
- msg := ""
- if s.status != nil && s.status.LastErrMsg != "" {
- msg = s.status.LastErrMsg
- }
- return fmt.Errorf("timed out waiting for llama runner to start: %s", msg)
- }
- if s.cmd.ProcessState != nil {
- msg := ""
- if s.status != nil && s.status.LastErrMsg != "" {
- msg = s.status.LastErrMsg
- }
- return fmt.Errorf("llama runner process no longer running: %d %s", s.cmd.ProcessState.ExitCode(), msg)
- }
-
- c, cancel := context.WithTimeout(ctx, 200*time.Millisecond)
- defer cancel()
- status, err := s.getServerStatus(c)
- if err != nil && lastStatus != status {
- slog.Debug("server not yet available", "error", err)
- lastStatus = status
- continue
++ default:
++ }
+ ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
+ defer cancel()
+ status, err := s.getServerStatus(ctx)
+ if err != nil {
+ slog.Debug("server not yet available", "error", err)
+ }
+ if time.Now().After(expiresAt) {
+ // timeout
+ msg := ""
+ if s.status != nil && s.status.LastErrMsg != "" {
+ msg = s.status.LastErrMsg
}
-
- switch status {
- case ServerStatusLoadingModel:
- // TODO - this state never seems to happen with the current server.cpp code (bug?)
- // it doesn't respond to the health endpoint until after the model is loaded
- slog.Debug("loading model")
- case ServerStatusReady:
- slog.Debug(fmt.Sprintf("llama runner started in %f seconds", time.Since(start).Seconds()))
- return nil
+ return fmt.Errorf("timed out waiting for llama runner to start: %s", msg)
+ }
+ if s.cmd.ProcessState != nil {
+ msg := ""
+ if s.status != nil && s.status.LastErrMsg != "" {
+ msg = s.status.LastErrMsg
}
+ return fmt.Errorf("llama runner process no longer running: %d %s", s.cmd.ProcessState.ExitCode(), msg)
+ }
+ switch status {
+ case ServerStatusLoadingModel:
+ time.Sleep(time.Millisecond * 250)
+ slog.Debug("loading model")
+ case ServerStatusReady:
+ slog.Info(fmt.Sprintf("llama runner started in %0.2f seconds", time.Since(start).Seconds()))
+ return nil
+ default:
+ time.Sleep(time.Millisecond * 250)
+ continue
}
}
}