sessionfile: defer backend/model overrides until after agent= in handleCfg
Ensures manual model/backend settings always win over agent.json defaults regardless of line order in ctl writes.
This commit is contained in:
parent
06b0775b66
commit
479ac1b9d4
|
|
@ -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")
|
||||
|
|
|
|||
Reference in New Issue