feat(stage): honor per-stage reasoning effort across native harnesses
This commit is contained in:
@@ -97,8 +97,15 @@ func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt s
|
||||
}
|
||||
}
|
||||
rules := c.permissionRules()
|
||||
data, err := c.call(ctx, "post", "/api/session", map[string]any{"title": "Pipeline audited agent stage", "agent": "build", "location": map[string]string{"directory": c.Directory}, "model": map[string]string{"providerID": config.Provider, "id": config.Model}, "permissions": rules})
|
||||
model, err := openCodeModelSelection(config, c.Backend)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
data, err := c.call(ctx, "post", "/api/session", map[string]any{"title": "Pipeline audited agent stage", "agent": "build", "location": map[string]string{"directory": c.Directory}, "model": model, "permissions": rules})
|
||||
if err != nil {
|
||||
if variant := model["variant"]; variant != "" {
|
||||
err = fmt.Errorf("OpenCode model selection for reasoning_effort=%s (variant %q) failed: %w", variant, variant, err)
|
||||
}
|
||||
// No prompt or tool call was admitted: a request failure here is a
|
||||
// reachable retry rather than a reason to end the run.
|
||||
return "", harnessUnreachable(err)
|
||||
|
||||
@@ -98,9 +98,6 @@ func (ModelStage) Spec(def Definition) (ModelSpec, error) {
|
||||
if err != nil {
|
||||
return ModelSpec{}, err
|
||||
}
|
||||
if backend == "pi" && effort == "max" {
|
||||
return ModelSpec{}, fmt.Errorf("reasoning_effort=max is not supported by pi; use a supported thinking level up to xhigh")
|
||||
}
|
||||
if delivery := def.Configs["delivery"]; delivery != "" && delivery != "true" {
|
||||
return ModelSpec{}, fmt.Errorf("delivery must be true when set")
|
||||
}
|
||||
|
||||
@@ -309,13 +309,20 @@ func (c *OpenCodeClient) Generate(ctx context.Context, config ModelConfig, promp
|
||||
if len(encoded) > maxModelRequest {
|
||||
return "", fmt.Errorf("OpenCode request exceeds 64 KiB limit")
|
||||
}
|
||||
model, err := openCodeModelSelection(config, c.Backend)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
created, err := c.call(ctx, "post", "/api/session", map[string]any{
|
||||
"title": "Pipeline stage generation",
|
||||
"location": map[string]string{"directory": directory},
|
||||
"model": map[string]string{"providerID": config.Provider, "id": config.Model},
|
||||
"model": model,
|
||||
"permissions": []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}},
|
||||
})
|
||||
if err != nil {
|
||||
if variant := model["variant"]; variant != "" {
|
||||
err = fmt.Errorf("OpenCode model selection for reasoning_effort=%s (variant %q) failed: %w", variant, variant, err)
|
||||
}
|
||||
// No prompt or tool call was admitted: a request failure here is a
|
||||
// reachable retry rather than a reason to end the run.
|
||||
return "", harnessUnreachable(err)
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestOpenCodeEffortReachesAgentAndTextSession(t *testing.T) {
|
||||
for _, agent := range []bool{false, true} {
|
||||
for _, effort := range []string{"", "default", "none", "off", "minimal", "low", "medium", "high", "xhigh", "max"} {
|
||||
t.Run(effort+map[bool]string{true: "/agent", false: "/text"}[agent], func(t *testing.T) {
|
||||
prompts := 0
|
||||
created := false
|
||||
client := OpenCodeClient{Backend: "v2", Directory: t.TempDir(), sessionPollInterval: time.Millisecond}
|
||||
client.command = func(_ context.Context, _ string, args ...string) ([]byte, error) {
|
||||
switch {
|
||||
case args[2] == "/api/session":
|
||||
var body struct {
|
||||
Model map[string]string `json:"model"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(args[4]), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := effort
|
||||
if effort == "default" {
|
||||
want = ""
|
||||
}
|
||||
if effort == "off" {
|
||||
want = "none"
|
||||
}
|
||||
if body.Model["providerID"] != "fixture" || body.Model["id"] != "model" || body.Model["variant"] != want {
|
||||
t.Fatalf("wrong native selection: %+v", body.Model)
|
||||
}
|
||||
if want == "" {
|
||||
if _, ok := body.Model["variant"]; ok {
|
||||
t.Fatal("default unexpectedly overrides native variant")
|
||||
}
|
||||
}
|
||||
created = true
|
||||
return []byte(`{"data":{"id":"ses_effort"}}`), nil
|
||||
case args[2] == "/api/session/ses_effort/prompt":
|
||||
if !created {
|
||||
t.Fatal("prompt before session selection")
|
||||
}
|
||||
prompts++
|
||||
var body map[string]any
|
||||
if err := json.Unmarshal([]byte(args[4]), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := body["model"]; ok {
|
||||
t.Fatal("prompt replaced the selected native model variant")
|
||||
}
|
||||
return []byte(`{}`), nil
|
||||
case args[2] == "/api/session/active":
|
||||
return []byte(`{"data":{}}`), nil
|
||||
case strings.HasPrefix(args[2], "/api/session/ses_effort/message"):
|
||||
return []byte(`{"data":[{"id":"msg_result","type":"assistant","finish":"stop","content":[{"type":"text","text":"# outcome\nsuccess"}]}]}`), nil
|
||||
case args[2] == "/api/session/ses_effort":
|
||||
return usageResponse("ses_effort", 0, 1), nil
|
||||
default:
|
||||
t.Fatalf("unexpected call: %v", args)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
config := ModelConfig{Provider: "fixture", Model: "model", ReasoningEffort: effort}
|
||||
var result string
|
||||
var err error
|
||||
if agent {
|
||||
result, err = (&AgentClient{OpenCodeClient: client, Tools: []string{"read"}}).Generate(context.Background(), config, "task")
|
||||
} else {
|
||||
result, err = client.Generate(context.Background(), config, "task")
|
||||
}
|
||||
if err != nil || result != "# outcome\nsuccess" || prompts != 1 {
|
||||
t.Fatalf("result=%q err=%v prompts=%d", result, err, prompts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenCodeRejectedEffortNeverAdmitsWork(t *testing.T) {
|
||||
for _, agent := range []bool{false, true} {
|
||||
client := OpenCodeClient{Backend: "v2", Directory: t.TempDir()}
|
||||
calls := 0
|
||||
client.command = func(_ context.Context, _ string, args ...string) ([]byte, error) {
|
||||
calls++
|
||||
if args[2] != "/api/session" {
|
||||
t.Fatalf("work admitted after invalid native variant: %v", args)
|
||||
}
|
||||
return nil, errors.New("unknown model variant high")
|
||||
}
|
||||
config := ModelConfig{Provider: "fixture", Model: "no-reasoning", ReasoningEffort: "high"}
|
||||
var err error
|
||||
if agent {
|
||||
_, err = (&AgentClient{OpenCodeClient: client}).Generate(context.Background(), config, "task")
|
||||
} else {
|
||||
_, err = client.Generate(context.Background(), config, "task")
|
||||
}
|
||||
if err == nil || calls != 1 || !strings.Contains(err.Error(), "reasoning_effort=high") {
|
||||
t.Fatalf("unsupported effort was ignored: %v %d", err, calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,9 +111,6 @@ func (c *PiClient) Generate(ctx context.Context, config ModelConfig, prompt stri
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if effort == "max" {
|
||||
return "", fmt.Errorf("reasoning_effort=max is not supported by pi; use a supported thinking level up to xhigh")
|
||||
}
|
||||
thinking := effort
|
||||
if thinking == "none" {
|
||||
thinking = "off"
|
||||
|
||||
@@ -85,6 +85,8 @@ func TestPiReasoningEffort(t *testing.T) {
|
||||
{name: "medium", effort: "medium", flag: "medium"},
|
||||
{name: "high", effort: "high", flag: "high"},
|
||||
{name: "xhigh", effort: "xhigh", flag: "xhigh"},
|
||||
{name: "max", effort: "max", flag: "max"},
|
||||
{name: "max-clamped", effort: "max", flag: "max", fixture: "clamped", wantErr: `effective "high"`},
|
||||
{name: "clamped", effort: "xhigh", flag: "xhigh", fixture: "clamped", wantErr: `effective "high"`},
|
||||
{name: "off-clamped", effort: "off", flag: "off", fixture: "clamped", wantErr: `effective "high"`},
|
||||
{name: "nonreasoning", effort: "high", flag: "high", fixture: "no-reasoning", wantErr: "cannot confirm reasoning support"},
|
||||
@@ -174,7 +176,7 @@ func TestPiReasoningEffort(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPiInvalidReasoningEffortBeforeProcess(t *testing.T) {
|
||||
for _, effort := range []string{"max", "invalid", "HIGH", " high "} {
|
||||
for _, effort := range []string{"invalid", "HIGH", " high "} {
|
||||
t.Run(effort, func(t *testing.T) {
|
||||
client := &PiClient{Executable: "/does-not-exist", WorkStarted: true}
|
||||
_, err := client.Generate(context.Background(), ModelConfig{ReasoningEffort: effort}, "task")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -31,11 +30,7 @@ func TestReasoningEffortConfig(t *testing.T) {
|
||||
}
|
||||
def.Configs["harness"] = "pi"
|
||||
_, err = (ModelStage{}).Spec(def)
|
||||
if value == "max" {
|
||||
if err == nil || !strings.Contains(err.Error(), "pi") {
|
||||
t.Fatal("unsupported Pi effort accepted")
|
||||
}
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user