Validate providers and retain complete run debugging context
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (r *runner) evidence(ctx context.Context, id int64) ([]protocol.SessionEvidence, error) {
|
||||
run, err := r.store.GetRun(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
var evidence []protocol.SessionEvidence
|
||||
for i := len(run.Steps) - 1; i >= 0 && len(evidence) < 3; i-- {
|
||||
step := run.Steps[i]
|
||||
if step.SessionID == "" {
|
||||
continue
|
||||
}
|
||||
item := protocol.SessionEvidence{Sequence: step.Sequence, SessionID: step.SessionID, Directory: run.Workspace}
|
||||
owner, err := r.store.RunSessionOwner(ctx, id, step.Sequence)
|
||||
if err == nil {
|
||||
item.Backend = owner.Backend
|
||||
item.Data, err = (stage.OpenCodeClient{Directory: owner.Directory, Backend: owner.Backend}).SessionEvidence(ctx, owner.ID)
|
||||
}
|
||||
if err != nil {
|
||||
item.Diagnostic = stage.RedactEvidence(err.Error())
|
||||
}
|
||||
evidence = append(evidence, item)
|
||||
}
|
||||
return evidence, nil
|
||||
}
|
||||
@@ -35,6 +35,8 @@ case "$3" in
|
||||
printf '{"data":{"id":"ses_fresh_%%s"}}' "$n" ;;
|
||||
/api/session/ses_fresh_1/generate) echo '{"_tag":"InvalidRequestError"}'; exit 1 ;;
|
||||
/api/session/ses_fresh_1/interrupt) echo '{}' ;;
|
||||
/api/session/ses_fresh_1) echo '{"data":{"id":"ses_fresh_1"}}' ;;
|
||||
/api/session/ses_fresh_1/message*) echo '{"data":[{"error":{"message":"provider rejected generation","token":"private-token"}}]}' ;;
|
||||
/api/session/ses_fresh_2/generate) echo '{"data":{"text":"{\"outcome\":\"success\",\"output\":{\"summary\":\"done\"}}"}}' ;;
|
||||
*) exit 99 ;;
|
||||
esac
|
||||
@@ -70,6 +72,13 @@ esac
|
||||
if err != nil || original.Status != "failed" || len(original.Steps) != 1 || original.Steps[0].SessionID != "ses_fresh_1" || original.Steps[0].AgentActive {
|
||||
t.Fatal("failed session not retained/stopped", original, err)
|
||||
}
|
||||
if !strings.Contains(original.Steps[0].Transcript, "opencode_failures") || !strings.Contains(original.Steps[0].Transcript, "InvalidRequestError") {
|
||||
t.Fatal("failure evidence not persisted", original.Steps[0].Transcript)
|
||||
}
|
||||
evidence, evidenceErr := r.evidence(ctx, original.ID)
|
||||
if evidenceErr != nil || len(evidence) != 1 || evidence[0].Diagnostic != "" || !strings.Contains(evidence[0].Data, "provider rejected generation") || strings.Contains(evidence[0].Data, "private-token") {
|
||||
t.Fatal(evidence, evidenceErr)
|
||||
}
|
||||
retry, err := r.retry(protocol.Message{RunID: original.ID, RequestKey: "second"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -296,7 +296,8 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
return
|
||||
}
|
||||
useAgent := stage.EffectiveType(def.Type) == stage.ModelType && (len(tools) > 0 || !explicitTools)
|
||||
client := &stage.AgentClient{OpenCodeClient: stage.OpenCodeClient{Directory: workspace}, WritePaths: request.WritePaths, Tools: tools}
|
||||
operations := &stage.OperationLog{}
|
||||
client := &stage.AgentClient{OpenCodeClient: stage.OpenCodeClient{Directory: workspace, Operations: operations}, WritePaths: request.WritePaths, Tools: tools}
|
||||
client.OnSession = func(session string, active bool) error {
|
||||
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@@ -309,7 +310,7 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
} else if useAgent {
|
||||
result, err = (stage.ModelStage{Client: client}).Run(ctx, def, input)
|
||||
} else if stage.EffectiveType(def.Type) == stage.ModelType {
|
||||
plain := &stage.OpenCodeClient{Directory: workspace}
|
||||
plain := &stage.OpenCodeClient{Directory: workspace, Operations: operations}
|
||||
plain.OnGenerationSession = func(session, backend, reference string, active bool) error {
|
||||
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
@@ -320,7 +321,7 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
} else {
|
||||
result, err = stage.DefaultRegistry().Run(ctx, def, input)
|
||||
}
|
||||
step := protocol.RunStep{Sequence: sequence, Stage: key, Status: "completed", Outcome: result.Outcome, Output: result.Output, Transcript: client.Transcript}
|
||||
step := protocol.RunStep{Sequence: sequence, Stage: key, Status: "completed", Outcome: result.Outcome, Output: result.Output, Transcript: operations.Transcript(client.Transcript)}
|
||||
if err != nil {
|
||||
step.Status = "failed"
|
||||
step.Diagnostic = err.Error()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
@@ -93,11 +94,22 @@ func systemStatus(r *http.Request, started time.Time, runErr error) *protocol.Sy
|
||||
s.Server.Candidates = candidateURLs(s.Addresses, scheme, port, "/connect")
|
||||
}
|
||||
}
|
||||
// Docker interface addresses are not the host's connection addresses. The
|
||||
// installer publishes the detected host LAN IP and actual mapped host port.
|
||||
if ip := net.ParseIP(os.Getenv("PIPELINES_HOST_IP")); ip != nil && !ip.IsLoopback() && !ip.IsUnspecified() {
|
||||
if port, err := strconv.Atoi(os.Getenv("PIPELINES_PUBLIC_PORT")); err == nil && port > 0 && port <= 65535 {
|
||||
s.Server.Port = strconv.Itoa(port)
|
||||
s.Server.URL = (&url.URL{Scheme: "ws", Host: net.JoinHostPort(ip.String(), s.Server.Port), Path: "/connect"}).String()
|
||||
s.Addresses = []protocol.NetworkAddress{{Interface: "LAN", IP: ip.String()}}
|
||||
s.Server.Candidates = []string{s.Server.URL}
|
||||
}
|
||||
}
|
||||
endpoints := notificationEndpoints()
|
||||
if len(endpoints) == 0 {
|
||||
return s
|
||||
}
|
||||
s.Topic = endpoints[0].Topic
|
||||
s.NtfyUser = os.Getenv("PIPELINES_NTFY_READER")
|
||||
s.Ntfy.Health = "not checked"
|
||||
// Only the validated public base is returned. Publishing URL and tokens
|
||||
// never leave the server, even on probe failure.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDockerStatusUsesPublishedHostAddressAndPort(t *testing.T) {
|
||||
t.Setenv("PIPELINES_HOST_IP", "192.0.2.25")
|
||||
t.Setenv("PIPELINES_PUBLIC_PORT", "18080")
|
||||
s := systemStatus(httptest.NewRequest("GET", "http://localhost:8080/connect", nil), time.Now(), nil)
|
||||
if s.Server.URL != "ws://192.0.2.25:18080/connect" || s.Server.Port != "18080" || len(s.Addresses) != 1 || s.Addresses[0].IP != "192.0.2.25" {
|
||||
t.Fatal(s)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -75,6 +76,9 @@ func Handler(ctx context.Context, stores ...*pipeline.Store) http.Handler {
|
||||
} else if request.Type == protocol.ListTemplates {
|
||||
response.Type = protocol.Templates
|
||||
response.Templates = examples.Catalog()
|
||||
for i := range response.Templates {
|
||||
response.Templates[i].Source = pipeline.WithDefaultModel(response.Templates[i].Source, os.Getenv("PIPELINES_DEFAULT_MODEL"))
|
||||
}
|
||||
} else if request.Type == protocol.Validate {
|
||||
graph, err := pipeline.Parse(request.Source)
|
||||
response.Type = protocol.Validated
|
||||
@@ -118,6 +122,7 @@ func Handler(ctx context.Context, stores ...*pipeline.Store) http.Handler {
|
||||
}
|
||||
} else if request.Type == protocol.List && len(stores) > 0 {
|
||||
response.Type = protocol.PipelineList
|
||||
response.DefaultModel = os.Getenv("PIPELINES_DEFAULT_MODEL")
|
||||
items, err := stores[0].List(ctx)
|
||||
if err != nil {
|
||||
response.Type = protocol.Error
|
||||
@@ -125,9 +130,12 @@ func Handler(ctx context.Context, stores ...*pipeline.Store) http.Handler {
|
||||
} else {
|
||||
response.Pipelines = items
|
||||
}
|
||||
} else if runs != nil && (request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.ListRuns || request.Type == protocol.GetRun || request.Type == protocol.CancelRun) {
|
||||
} else if runs != nil && (request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.ListRuns || request.Type == protocol.GetRun || request.Type == protocol.CancelRun || request.Type == protocol.GetRunEvidence) {
|
||||
var err error
|
||||
switch request.Type {
|
||||
case protocol.GetRunEvidence:
|
||||
response.Type = protocol.RunEvidence
|
||||
response.Evidence, err = runs.evidence(ctx, request.RunID)
|
||||
case protocol.RunPipeline:
|
||||
response.Type = protocol.RunStarted
|
||||
response.RunDetail, err = runs.start(request)
|
||||
|
||||
Reference in New Issue
Block a user