Merge branch 'main' into turn-integration
# Conflicts: # internal/server/runner.go # internal/stage/model_prompt.go # internal/stage/model_run.go # internal/stage/model_test.go
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/turn"
|
||||
)
|
||||
|
||||
@@ -38,17 +37,6 @@ func harnessUnreachable(err error) error {
|
||||
}
|
||||
|
||||
func modelPrompt(def Definition, spec ModelSpec, input Values) (string, error) {
|
||||
return modelPromptForTarget(def, spec, input, nil)
|
||||
}
|
||||
|
||||
// modelPromptForTarget builds the file-based turn prompt. The model reads the
|
||||
// turn's input and memory, follows the stage's own instructions verbatim, and
|
||||
// returns the complete markdown for output.md. The outcome heading is the only
|
||||
// section the server interprets; every other section is free-form.
|
||||
//
|
||||
// The target comes only from the runner context; task input remains data and
|
||||
// cannot select or replace it.
|
||||
func modelPromptForTarget(def Definition, spec ModelSpec, input Values, target *protocol.ResourceTarget) (string, error) {
|
||||
outcomes := outcomesFor(def.Edges)
|
||||
if len(outcomes) == 0 {
|
||||
return "", fmt.Errorf("model stage %s: no declared outcomes", def.Key)
|
||||
@@ -113,13 +101,6 @@ func modelPromptForTarget(def Definition, spec ModelSpec, input Values, target *
|
||||
b.WriteString(preferredOutcome(outcomes))
|
||||
fmt.Fprintf(&b, "\n\nAllowed outcomes: %s.\n\nEverything else is free-form markdown for the next stage and the operator. The server does not parse or validate any other section. Return the complete output.md content as your final message; do not wrap it in a JSON envelope.\n", strings.Join(outcomes, ", "))
|
||||
fmt.Fprintf(&b, "\nExecution time: %s. Timezone: %s.\n", time.Now().Format(time.RFC3339), time.Local.String())
|
||||
if target != nil {
|
||||
b.WriteString("\nResource target granted by the server:\n")
|
||||
fmt.Fprintf(&b, "- member: %s\n", target.Member)
|
||||
for _, key := range sortedKeys(target.Metadata) {
|
||||
fmt.Fprintf(&b, "- %s: %s\n", key, target.Metadata[key])
|
||||
}
|
||||
}
|
||||
if def.Turn.Public != "" {
|
||||
fmt.Fprintf(&b, "\nShared artifacts go to %s; files there are visible to every later stage. Turn-local work goes to %s and is not handed to later stages.\n", def.Turn.Public, def.Turn.Private)
|
||||
}
|
||||
@@ -154,15 +135,6 @@ func serverChangedFiles(input Values) []string {
|
||||
return files
|
||||
}
|
||||
|
||||
func sortedKeys(values map[string]string) []string {
|
||||
keys := make([]string, 0, len(values))
|
||||
for key := range values {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func outcomesFor(edges map[string]string) []string {
|
||||
outcomes := make([]string, 0, len(edges))
|
||||
for name := range edges {
|
||||
|
||||
@@ -15,8 +15,7 @@ func (m ModelStage) Run(ctx context.Context, def Definition, input Values) (Resu
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
target, _ := ResourceTarget(ctx)
|
||||
prompt, err := modelPromptForTarget(def, spec, input, target)
|
||||
prompt, err := modelPrompt(def, spec, input)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func modelDefinition() Definition {
|
||||
@@ -205,33 +203,6 @@ func TestModelRunRejectsMissingOutcomeWithoutRepair(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelRunForwardsOnlyServerGrantedResourceTarget(t *testing.T) {
|
||||
target := &protocol.ResourceTarget{Member: "emulator", Metadata: map[string]string{"serial": "emu-5554", "type": "emulator"}}
|
||||
budget := NewBudget(0, 0)
|
||||
ctx := WithBudget(WithResourceTarget(context.Background(), target), budget)
|
||||
def := turnDefinition(t)
|
||||
|
||||
var received ModelConfig
|
||||
client := generatorFunc(func(_ context.Context, config ModelConfig, prompt string) (string, error) {
|
||||
received = config
|
||||
for _, want := range []string{"Resource target granted by the server:", "member: emulator", "serial: emu-5554"} {
|
||||
if !strings.Contains(prompt, want) {
|
||||
t.Fatalf("resource target missing %q: %s", want, prompt)
|
||||
}
|
||||
}
|
||||
if strings.Contains(prompt, "user-selected") {
|
||||
t.Fatalf("client-selected target leaked into prompt: %s", prompt)
|
||||
}
|
||||
return "# outcome\nsuccess\n", nil
|
||||
})
|
||||
if _, err := (ModelStage{Client: client}).Run(ctx, def, Values{"resource_target": map[string]any{"member": "user-selected"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if received.Budget != budget {
|
||||
t.Fatal("budget context was not preserved with resource target")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelRunCancellationStopsBeforeGeneration(t *testing.T) {
|
||||
def := turnDefinition(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -243,7 +243,7 @@ func (c *PiClient) Generate(ctx context.Context, config ModelConfig, prompt stri
|
||||
close(heartbeatDone)
|
||||
// agent_end/abort acknowledgement and the parent's exit alone do not
|
||||
// prove its shell descendants exited. A surviving process group retains
|
||||
// ownership rather than handing the resource to another stage.
|
||||
// ownership rather than handing it to another stage.
|
||||
quiet = quiet && errors.Is(syscall.Kill(-c.cmd.Process.Pid, 0), syscall.ESRCH)
|
||||
if quiet {
|
||||
_ = os.WriteFile(filepath.Join(c.Reference, "quiescent"), []byte("quiescent"), 0600)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestResourcePiReceiptRequiresProcessExit(t *testing.T) {
|
||||
func TestPiReceiptRequiresProcessExit(t *testing.T) {
|
||||
// A test-owned process only: no Pi provider, shell/ADB command or phone.
|
||||
cmd := exec.Command("sleep", "5")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
@@ -5,34 +5,8 @@ package stage
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type resourceTargetContextKey struct{}
|
||||
|
||||
// WithResourceTarget attaches the server-granted concrete target to a stage's
|
||||
// runtime context. It is deliberately separate from model input and contains
|
||||
// no capability or credential material.
|
||||
func WithResourceTarget(ctx context.Context, target *protocol.ResourceTarget) context.Context {
|
||||
if target == nil {
|
||||
return ctx
|
||||
}
|
||||
copy := &protocol.ResourceTarget{Member: target.Member}
|
||||
if target.Metadata != nil {
|
||||
copy.Metadata = map[string]string{}
|
||||
for key, value := range target.Metadata {
|
||||
copy.Metadata[key] = value
|
||||
}
|
||||
}
|
||||
return context.WithValue(ctx, resourceTargetContextKey{}, copy)
|
||||
}
|
||||
|
||||
func ResourceTarget(ctx context.Context) (*protocol.ResourceTarget, bool) {
|
||||
target, ok := ctx.Value(resourceTargetContextKey{}).(*protocol.ResourceTarget)
|
||||
return target, ok
|
||||
}
|
||||
|
||||
// Values are runtime data, not the prose output contract in a definition.
|
||||
type Values map[string]any
|
||||
|
||||
|
||||
Reference in New Issue
Block a user