Remove resource pools, leases and wait queues

Drop the resource allocation feature end to end: store tables and migration, runner scheduling and cleanup, protocol types and commands, CLI commands, TUI screens, tests and docs. Existing databases open cleanly and definitions carrying a retired resources block still validate.
This commit is contained in:
2026-10-19 22:27:27 +01:00
parent a676b30ff0
commit 72aecd8b1f
45 changed files with 282 additions and 3954 deletions
+9 -19
View File
@@ -8,8 +8,6 @@ import (
"sort"
"strings"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
var ErrInvalidModelResult = errors.New("invalid model stage result")
@@ -38,13 +36,6 @@ func harnessUnreachable(err error) error {
}
func modelPrompt(def Definition, spec ModelSpec, input Values) (string, error) {
return modelPromptForTarget(def, spec, input, nil)
}
// modelPromptForTarget carries a server-selected resource target separately from
// task input. 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 := make([]string, 0, len(def.Edges))
for name := range def.Edges {
outcomes = append(outcomes, name)
@@ -68,16 +59,15 @@ func modelPromptForTarget(def Definition, spec ModelSpec, input Values, target *
toolsLine = "This call has these stage tools: " + strings.Join(tools, ", ") + "."
}
data, err := json.Marshal(struct {
Key string `json:"stage"`
Instructions string `json:"instructions"`
OutputContract string `json:"output_contract"`
Outcomes []string `json:"allowed_outcomes"`
Input Values `json:"input"`
ResourceTarget *protocol.ResourceTarget `json:"resource_target,omitempty"`
ReportFileArtifacts bool `json:"report_file_artifacts"`
ExecutionTime string `json:"execution_time"`
Timezone string `json:"timezone"`
}{def.Key, spec.Prompt, spec.Output, outcomes, input, target, def.ReportFileArtifacts, time.Now().Format(time.RFC3339), time.Local.String()})
Key string `json:"stage"`
Instructions string `json:"instructions"`
OutputContract string `json:"output_contract"`
Outcomes []string `json:"allowed_outcomes"`
Input Values `json:"input"`
ReportFileArtifacts bool `json:"report_file_artifacts"`
ExecutionTime string `json:"execution_time"`
Timezone string `json:"timezone"`
}{def.Key, spec.Prompt, spec.Output, outcomes, input, def.ReportFileArtifacts, time.Now().Format(time.RFC3339), time.Local.String()})
if err != nil {
return "", fmt.Errorf("model stage input is not JSON-serializable: %w", err)
}
+1 -2
View File
@@ -16,8 +16,7 @@ func (m ModelStage) Run(ctx context.Context, def Definition, input Values) (Resu
return Result{}, err
}
spec.Config.ResultSchema = resultSchema(def.Edges)
target, _ := ResourceTarget(ctx)
prompt, err := modelPromptForTarget(def, spec, input, target)
prompt, err := modelPrompt(def, spec, input)
if err != nil {
return Result{}, err
}
-103
View File
@@ -9,8 +9,6 @@ import (
"strings"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func modelDefinition() Definition {
@@ -196,107 +194,6 @@ func TestModelRunUsesInstructionsAndStructuredOutput(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)
input := Values{"resource_target": map[string]any{"member": "user-selected"}, "prompt": "task"}
ctx := WithBudget(WithResourceTarget(context.Background(), target), budget)
var received ModelConfig
client := generatorFunc(func(_ context.Context, config ModelConfig, prompt string) (string, error) {
received = config
assertPromptResourceTarget(t, prompt, target, input)
return `{"outcome":"success","output":{}}`, nil
})
if _, err := (ModelStage{Client: client}).Run(ctx, modelDefinition(), input); err != nil {
t.Fatal(err)
}
if received.Budget != budget {
t.Fatal("budget context was not preserved with resource target")
}
}
func TestModelRunForwardsResourceTargetToNativeOpenCode(t *testing.T) {
target := &protocol.ResourceTarget{Member: "phone", Metadata: map[string]string{"serial": "phone-serial"}}
var prompt string
client := &OpenCodeClient{Directory: "/work/repo", command: func(_ context.Context, _ string, args ...string) ([]byte, error) {
switch args[2] {
case "/api/session":
return []byte(`{"data":{"id":"ses_target"}}`), nil
case "/api/session/ses_target/generate":
var body struct {
Prompt string `json:"prompt"`
}
if err := json.Unmarshal([]byte(args[4]), &body); err != nil {
t.Fatal(err)
}
prompt = body.Prompt
return []byte(`{"data":{"text":"{\"outcome\":\"success\",\"output\":{}}"}}`), nil
default:
t.Fatalf("unexpected fake OpenCode endpoint %q", args[2])
return nil, nil
}
}}
if _, err := (ModelStage{Client: client}).Run(WithResourceTarget(context.Background(), target), modelDefinition(), Values{"prompt": "task"}); err != nil {
t.Fatal(err)
}
assertPromptResourceTarget(t, prompt, target, Values{"prompt": "task"})
}
func TestModelPromptWithoutResourceTargetPreservesLegacyInput(t *testing.T) {
input := Values{"prompt": "task", "count": "1"}
spec, err := (ModelStage{}).Spec(modelDefinition())
if err != nil {
t.Fatal(err)
}
prompt, err := modelPrompt(modelDefinition(), spec, input)
if err != nil {
t.Fatal(err)
}
var payload struct {
Input Values `json:"input"`
ResourceTarget *protocol.ResourceTarget `json:"resource_target"`
}
if _, data, ok := strings.Cut(prompt, "Stage definition and runtime input:\n"); !ok || json.Unmarshal([]byte(data), &payload) != nil {
t.Fatal("could not decode legacy runtime payload")
}
if payload.ResourceTarget != nil || !reflect.DeepEqual(payload.Input, input) {
t.Fatalf("legacy runtime input changed: %#v", payload)
}
}
func assertPromptResourceTarget(t *testing.T, prompt string, want *protocol.ResourceTarget, wantInput Values) {
t.Helper()
_, data, ok := strings.Cut(prompt, "Stage definition and runtime input:\n")
if !ok {
t.Fatal("missing runtime payload")
}
var payload struct {
Input Values `json:"input"`
ResourceTarget *protocol.ResourceTarget `json:"resource_target"`
}
if err := json.Unmarshal([]byte(data), &payload); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(payload.ResourceTarget, want) {
t.Fatalf("resource target = %#v, want %#v", payload.ResourceTarget, want)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal([]byte(data), &fields); err != nil {
t.Fatal(err)
}
var targetFields map[string]json.RawMessage
if err := json.Unmarshal(fields["resource_target"], &targetFields); err != nil {
t.Fatal(err)
}
if len(targetFields) != 2 || targetFields["member"] == nil || targetFields["metadata"] == nil {
t.Fatalf("resource target leaked non-target fields: %s", fields["resource_target"])
}
if !reflect.DeepEqual(payload.Input, wantInput) {
t.Fatalf("input = %#v, want %#v", payload.Input, wantInput)
}
}
func TestModelResultValidationAndRetryBudget(t *testing.T) {
for _, text := range []string{
`not json`, `{"outcome":"missing","output":{}}`, `{"outcome":"success"}`,
+1 -1
View File
@@ -240,7 +240,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}
-26
View File
@@ -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