fix(main): re-evaluate chain per call to respect caller model override
All checks were successful
CI / Lint / Test / Vet (push) Successful in 1m8s
CI / Mirror to GitHub (push) Has been skipped

buildOrch now returns a closure instead of *Orchestrator. Each invocation
calls models.ChainFor(skill, req.Model) so a non-empty caller override
collapses to a single-entry chain (no escalation). The attempts slice is
also allocated fresh per call, preventing unbounded growth across requests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-04-20 11:34:09 +02:00
parent f1deedd39d
commit 6328766c7f

View File

@@ -92,14 +92,17 @@ func main() {
litellmExec := iexec.NewLiteLLM(cfg.LiteLLMBaseURL, cfg.LiteLLMAPIKey, 0) litellmExec := iexec.NewLiteLLM(cfg.LiteLLMBaseURL, cfg.LiteLLMAPIKey, 0)
verifier := iexec.NewVerifier("", models.Verifier(), 0) verifier := iexec.NewVerifier("", models.Verifier(), 0)
buildOrch := func(skill string) *iexec.Orchestrator { buildOrch := func(skill string) func(ctx context.Context, req iexec.Request) (iexec.Result, error) {
rawChain := models.ChainFor(skill, "") return func(ctx context.Context, req iexec.Request) (iexec.Result, error) {
chain := make([]iexec.ChainEntry, len(rawChain)) rawChain := models.ChainFor(skill, req.Model)
for i, m := range rawChain { chain := make([]iexec.ChainEntry, len(rawChain))
chain[i] = iexec.EntryFor(m) for i, m := range rawChain {
chain[i] = iexec.EntryFor(m)
}
attempts := make([]iexec.AttemptRecord, 0, len(chain))
orch := iexec.NewOrchestrator(chain, litellmExec.Run, claudeExec.Run, verifier, models.LlamaSwapURL(), &attempts)
return orch.Run(ctx, req)
} }
attempts := make([]iexec.AttemptRecord, 0, len(chain))
return iexec.NewOrchestrator(chain, litellmExec.Run, claudeExec.Run, verifier, models.LlamaSwapURL(), &attempts)
} }
tierFn := func(ctx context.Context) tier.Info { tierFn := func(ctx context.Context) tier.Info {
@@ -111,7 +114,7 @@ func main() {
SystemPrompt: string(systemPrompt), SystemPrompt: string(systemPrompt),
SkillPrompt: string(tddPrompt), SkillPrompt: string(tddPrompt),
DefaultModel: models.ChainFor("tdd", "")[0], DefaultModel: models.ChainFor("tdd", "")[0],
ExecutorFn: buildOrch("tdd").Run, ExecutorFn: buildOrch("tdd"),
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
})) }))
reg.Register(brain.New(brain.Config{ reg.Register(brain.New(brain.Config{
@@ -127,31 +130,31 @@ func main() {
SkillPrompt: string(retroPrompt), SkillPrompt: string(retroPrompt),
DefaultModel: models.ChainFor("retrospective", "")[0], DefaultModel: models.ChainFor("retrospective", "")[0],
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
ExecutorFn: buildOrch("retrospective").Run, ExecutorFn: buildOrch("retrospective"),
})) }))
reg.Register(review.New(review.Config{ reg.Register(review.New(review.Config{
SkillPrompt: string(reviewPrompt), SkillPrompt: string(reviewPrompt),
DefaultModel: models.ChainFor("review", "")[0], DefaultModel: models.ChainFor("review", "")[0],
ExecutorFn: buildOrch("review").Run, ExecutorFn: buildOrch("review"),
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
})) }))
reg.Register(skilldebug.New(skilldebug.Config{ reg.Register(skilldebug.New(skilldebug.Config{
SkillPrompt: string(debugPrompt), SkillPrompt: string(debugPrompt),
DefaultModel: models.ChainFor("debug", "")[0], DefaultModel: models.ChainFor("debug", "")[0],
ExecutorFn: buildOrch("debug").Run, ExecutorFn: buildOrch("debug"),
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
})) }))
reg.Register(spec.New(spec.Config{ reg.Register(spec.New(spec.Config{
SkillPrompt: string(specPrompt), SkillPrompt: string(specPrompt),
DefaultModel: models.ChainFor("spec", "")[0], DefaultModel: models.ChainFor("spec", "")[0],
ExecutorFn: buildOrch("spec").Run, ExecutorFn: buildOrch("spec"),
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
})) }))
reg.Register(trainer.New(trainer.Config{ reg.Register(trainer.New(trainer.Config{
ReaderPrompt: string(trainerReaderPrompt), ReaderPrompt: string(trainerReaderPrompt),
WriterPrompt: string(trainerWriterPrompt), WriterPrompt: string(trainerWriterPrompt),
DefaultModel: models.ChainFor("trainer", "")[0], DefaultModel: models.ChainFor("trainer", "")[0],
ExecutorFn: buildOrch("trainer").Run, ExecutorFn: buildOrch("trainer"),
SessionsDir: cfg.SessionsDir, SessionsDir: cfg.SessionsDir,
BrainDir: cfg.BrainDir, BrainDir: cfg.BrainDir,
})) }))