diff --git a/store/sessionfile.go b/store/sessionfile.go index 7f6cad1..cce821e 100644 --- a/store/sessionfile.go +++ b/store/sessionfile.go @@ -328,6 +328,7 @@ func (h *sessionHelper) cfgContent() string { func (h *sessionHelper) handleCfg(input string) error { p := h.sess.Core.GenerationParams() hasParams := false + var deferredBackend, deferredModel string for _, line := range strings.Split(input, "\n") { line = strings.TrimSpace(line) if line == "" { @@ -339,14 +340,28 @@ func (h *sessionHelper) handleCfg(input string) error { } k, v = strings.TrimSpace(k), strings.TrimSpace(v) switch k { - case "backend", "model", "agent": + case "agent": if v == "" { continue } if h.sess.Core.IsRunning() { return fmt.Errorf("cannot switch %s while agent is running", k) } - h.sess.Core.Submit(h.sess.Ctx, "/"+k+" "+v, h.makePublish()) + h.sess.Core.Submit(h.sess.Ctx, "/agent "+v, h.makePublish()) + case "backend", "model": + if v == "" { + continue + } + if h.sess.Core.IsRunning() { + return fmt.Errorf("cannot switch %s while agent is running", k) + } + // Defer backend/model until after the loop so they override + // any values set by agent=. + if k == "backend" { + deferredBackend = v + } else { + deferredModel = v + } case "cwd": if v == "" { continue @@ -458,6 +473,13 @@ func (h *sessionHelper) handleCfg(input string) error { // state → read-only, silently ignored } } + // Apply backend/model after agent= so manual overrides win. + if deferredBackend != "" { + h.sess.Core.Submit(h.sess.Ctx, "/backend "+deferredBackend, h.makePublish()) + } + if deferredModel != "" { + h.sess.Core.Submit(h.sess.Ctx, "/model "+deferredModel, h.makePublish()) + } if hasParams { if h.sess.Core.IsRunning() { return fmt.Errorf("cannot change params while agent is running")