Validate providers and retain complete run debugging context

This commit is contained in:
2026-10-09 23:21:01 +01:00
parent f3d829bea5
commit 08b8647d5b
51 changed files with 1036 additions and 159 deletions
+16
View File
@@ -0,0 +1,16 @@
package pipeline
import (
"git.a-wan.net/alan/pipelines/internal/stage"
"strings"
)
// WithDefaultModel applies only to unpublished starter/example source. Never
// rewrite a persisted definition, retained draft, or pinned retry version.
func WithDefaultModel(source, model string) string {
provider, id, ok := strings.Cut(model, "/")
if !ok || !stage.ValidModel(provider, id) {
return source
}
return strings.NewReplacer("provider=opencode-go\n", "provider="+provider+"\n", "model="+stage.ModelID+"\n", "model="+id+"\n").Replace(source)
}
+18
View File
@@ -0,0 +1,18 @@
package pipeline
import (
"strings"
"testing"
)
func TestStarterUsesConfiguredProviderAndModel(t *testing.T) {
original := Template([]string{"worker"}, true)
source := WithDefaultModel(original, "openai/gpt-test")
graph, err := Parse(source)
if err != nil || graph.Stages[0].Configs["provider"] != "openai" || graph.Stages[0].Configs["model"] != "gpt-test" {
t.Fatal(err, graph)
}
if !strings.Contains(original, "provider=opencode-go") || WithDefaultModel(original, "bad\nvalue/model") != original {
t.Fatal("modified original or accepted invalid default")
}
}
+2 -3
View File
@@ -34,9 +34,8 @@ func TestValidation(t *testing.T) {
"duplicate outcome": strings.Replace(valid, "success -> reviewer", "success -> reviewer\nsuccess -> #", 1),
"unknown config": strings.Replace(valid, "retries=0", "oops=2", 1),
"duplicate config": strings.Replace(valid, "retries=0", "retries=0\nretries=1", 1),
"unknown provider": strings.Replace(valid, "provider=opencode-go", "provider=unknown", 1),
"unknown model": strings.Replace(valid, "model=deepseek-v4.1-flash", "model=unknown", 1),
"old model typo": strings.Replace(valid, "model=deepseek-v4.1-flash", "model=deepseek-v4.1-flask", 1),
"invalid provider": strings.Replace(valid, "provider=opencode-go", "provider=not valid", 1),
"invalid model": strings.Replace(valid, "model=deepseek-v4.1-flash", "model=not valid", 1),
"bad retries": strings.Replace(valid, "retries=0", "retries=-1", 1),
"multiple targets": strings.Replace(valid, "success -> reviewer", "success -> reviewer, implementer", 1),
"unreachable": Template([]string{"a", "b"}, false),
+6
View File
@@ -270,6 +270,12 @@ func (s *Store) RunSession(ctx context.Context, id int64, sequence int, session
type SessionOwner struct{ ID, Backend, Directory, Reference string }
func (s *Store) RunSessionOwner(ctx context.Context, id int64, sequence int) (SessionOwner, error) {
var owner SessionOwner
err := s.db.QueryRowContext(ctx, `SELECT s.session_id,COALESCE(o.backend,'v2'),r.workspace,COALESCE(o.reference,'') FROM run_steps s JOIN pipeline_runs r ON r.id=s.run_id LEFT JOIN run_session_owners o ON o.run_id=s.run_id AND o.sequence=s.sequence WHERE s.run_id=? AND s.sequence=?`, id, sequence).Scan(&owner.ID, &owner.Backend, &owner.Directory, &owner.Reference)
return owner, err
}
func (s *Store) ActiveSessionOwners(ctx context.Context) ([]SessionOwner, error) {
rows, err := s.db.QueryContext(ctx, `SELECT s.session_id,COALESCE(o.backend,'v2'),r.workspace,COALESCE(o.reference,'')
FROM run_steps s JOIN pipeline_runs r ON r.id=s.run_id LEFT JOIN run_session_owners o ON o.run_id=s.run_id AND o.sequence=s.sequence WHERE s.agent_active=1 AND s.session_id<>''`)