Reuse loaded AI config when restarting stopped service

This commit is contained in:
rcourtman 2026-03-28 10:00:37 +00:00
parent ba3cdca961
commit 716340dcd6
2 changed files with 7 additions and 3 deletions

View file

@ -311,6 +311,10 @@ type AIStateProvider interface {
func (h *AIHandler) Start(ctx context.Context, stateProvider AIStateProvider) error {
log.Info().Msg("AIHandler.Start called")
aiCfg := h.loadAIConfig(ctx)
return h.startWithConfig(ctx, stateProvider, aiCfg)
}
func (h *AIHandler) startWithConfig(ctx context.Context, stateProvider AIStateProvider, aiCfg *config.AIConfig) error {
if aiCfg == nil {
log.Info().Msg("AI config is nil, AI is disabled")
return nil
@ -396,7 +400,7 @@ func (h *AIHandler) Restart(ctx context.Context) error {
}
h.stateProvidersMu.RUnlock()
return h.Start(ctx, sp)
return h.startWithConfig(ctx, sp, newCfg)
}
return nil
}

View file

@ -307,7 +307,7 @@ func TestRestart_StartsStoppedServiceWithSavedStateProvider(t *testing.T) {
assert.Equal(t, "data", capturedCfg.DataDir)
}
func TestStart_AllowsEmptyPersistenceDataDir(t *testing.T) {
func TestStart_DefaultsEmptyPersistenceDataDir(t *testing.T) {
oldNewService := newChatService
defer func() { newChatService = oldNewService }()
@ -327,7 +327,7 @@ func TestStart_AllowsEmptyPersistenceDataDir(t *testing.T) {
err := h.Start(context.Background(), mockState)
assert.NoError(t, err)
assert.Equal(t, "", capturedCfg.DataDir)
assert.Equal(t, "data", capturedCfg.DataDir)
assert.Same(t, mockState, capturedCfg.StateProvider)
}