Skip to content

Commit 3b1772e

Browse files
authored
Carry per-root-Turn settings over the Runtime protocol (#918)
* Carry per-root-Turn settings over the Runtime protocol Add proto.TurnSettings (model, reasoning effort, service tier, review) to the prepare configuration, moved out of agent_options and ExecutionControls. The Executor identity ignores it; the Runtime hands each Turn's settings to StartTurn. harnessconfig gains Reviews and ValidateTurnSettings, and Prepare takes the model. Protocol version 0.24.0. No behavior change. * Keep Turn settings in the Executor identity until a Harness applies them A retained Executor that accepted a different turn would have run the prepared settings silently. Review support has no sender yet, so it waits for the change that sends it. * Check the Turn model in the none-device request test
1 parent d6c72ed commit 3b1772e

83 files changed

Lines changed: 314 additions & 257 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/daemon/internal/agent/claudesdk/cancellation_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func cancellationConfig(root, mode string) Config {
163163
}
164164

165165
func cancellationRequest() proto.PromptRequestPayload {
166-
return proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", AgentOptions: map[string]any{"model": "fake-model", "system_prompt": "instructions"}}
166+
return proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", Turn: proto.TurnSettings{Model: "fake-model"}, AgentOptions: map[string]any{"system_prompt": "instructions"}}
167167
}
168168

169169
func runCancellationHelper(request startRequest, mode string, scanner *bufio.Scanner, emit func(bridgeEvent)) {

‎apps/daemon/internal/agent/claudesdk/commands_session_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestWorkspaceCommandFramesKeepStartIdentityAndObservedOutput(t *testing.T)
3737
t.Fatal("preparation submitted a command")
3838
}
3939
out := make(chan proto.Envelope, 16)
40-
s, err := resource.StartTurn(t.Context(), "actual-command-run", proto.TextInput("hello"), out)
40+
s, err := resource.StartTurn(t.Context(), "actual-command-run", proto.TurnSettings{}, proto.TextInput("hello"), out)
4141
if err != nil {
4242
t.Fatal(err)
4343
}

‎apps/daemon/internal/agent/claudesdk/error_classification_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestClassifiedBridgeFailurePreservesTerminalEvidence(t *testing.T) {
2121
root := t.TempDir()
2222
t.Setenv("OAC_RUNTIME_HOME", root)
2323
config := Config{Node: os.Args[0], Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state"), Env: []string{"GO_CLAUDE_SDK_HELPER=1", "SDK_HELPER_MODE=classified-" + mode, "GORACE=atexit_sleep_ms=0"}}
24-
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", AgentOptions: map[string]any{"model": "fake-model", "system_prompt": "instructions"}}
24+
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", Turn: proto.TurnSettings{Model: "fake-model"}, AgentOptions: map[string]any{"system_prompt": "instructions"}}
2525
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
2626
defer cancel()
2727
out := make(chan proto.Envelope, 16)

‎apps/daemon/internal/agent/claudesdk/execution_controls_test.go‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestExecutionControlsPreserveNativeDefaultsAndInstructions(t *testing.T) {
1717
root := t.TempDir()
1818
t.Setenv("OAC_RUNTIME_HOME", root)
1919
config := Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
20-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), AgentSessionID: "native-session", AgentOptions: map[string]any{"model": "native-model", "system_prompt": "Keep these exact instructions.\nDo not replace them."}}
20+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), AgentSessionID: "native-session", Turn: proto.TurnSettings{Model: "native-model"}, AgentOptions: map[string]any{"system_prompt": "Keep these exact instructions.\nDo not replace them."}}
2121
ordinary, _, err := prepareConfiguration(config, request)
2222
if err != nil {
2323
t.Fatal(err)
@@ -49,7 +49,7 @@ func TestLiveWebSearchReachesTheBridgeOnEveryPlacement(t *testing.T) {
4949
root := t.TempDir()
5050
t.Setenv("OAC_RUNTIME_HOME", root)
5151
none, _, err := prepareConfiguration(Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}, proto.PromptRequestPayload{
52-
RunID: "run", Input: proto.TextInput("Search."), ExecutionControls: live, AgentOptions: map[string]any{"model": "native-model"}})
52+
RunID: "run", Input: proto.TextInput("Search."), ExecutionControls: live, Turn: proto.TurnSettings{Model: "native-model"}, AgentOptions: map[string]any{}})
5353
if err != nil || none.WebSearch != "live" {
5454
t.Fatal("live search on environment none did not reach the bridge", err)
5555
}
@@ -63,23 +63,24 @@ func TestLiveWebSearchReachesTheBridgeOnEveryPlacement(t *testing.T) {
6363

6464
func TestExecutionControlsRejectUnsupportedProfilesBeforeLaunch(t *testing.T) {
6565
enabled := true
66-
cases := map[string]proto.ExecutionControls{
67-
"cached-search": {WebSearch: &proto.WebSearchControl{Mode: "cached", ContextSize: "medium"}},
68-
"enabled-ptc": {ProgrammaticToolCalling: &enabled},
69-
"low-verbosity": {TextVerbosity: "low"},
70-
"high-verbosity": {TextVerbosity: "high"},
71-
"unknown-verbosity": {TextVerbosity: "invalid"},
72-
"no-effort": {ReasoningEffort: "none"},
73-
"minimal-effort": {ReasoningEffort: "minimal"},
74-
"summary": {ReasoningSummary: "concise"},
75-
"service-tier": {ServiceTier: "priority"},
76-
}
77-
for name, controls := range cases {
66+
model := proto.TurnSettings{Model: "native-model"}
67+
cases := map[string]proto.PromptRequestPayload{
68+
"cached-search": {Turn: model, ExecutionControls: &proto.ExecutionControls{WebSearch: &proto.WebSearchControl{Mode: "cached", ContextSize: "medium"}}},
69+
"enabled-ptc": {Turn: model, ExecutionControls: &proto.ExecutionControls{ProgrammaticToolCalling: &enabled}},
70+
"low-verbosity": {Turn: model, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "low"}},
71+
"high-verbosity": {Turn: model, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "high"}},
72+
"unknown-verbosity": {Turn: model, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "invalid"}},
73+
"summary": {Turn: model, ExecutionControls: &proto.ExecutionControls{ReasoningSummary: "concise"}},
74+
"no-effort": {Turn: proto.TurnSettings{Model: "native-model", ReasoningEffort: "none"}},
75+
"minimal-effort": {Turn: proto.TurnSettings{Model: "native-model", ReasoningEffort: "minimal"}},
76+
"service-tier": {Turn: proto.TurnSettings{Model: "native-model", ServiceTier: "priority"}},
77+
}
78+
for name, request := range cases {
7879
t.Run(name, func(t *testing.T) {
7980
root := t.TempDir()
8081
t.Setenv("OAC_RUNTIME_HOME", root)
8182
config := Config{Node: "must-not-run", Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
82-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), ExecutionControls: &controls, AgentOptions: map[string]any{"model": "native-model"}}
83+
request.RunID, request.Input = "run", proto.TextInput("Original input.")
8384
_, err := startSingleTurn(t.Context(), config, request, make(chan proto.Envelope, 1))
8485
if err == nil || !strings.Contains(err.Error(), "not supported by this Harness") {
8586
t.Fatal("unsupported controls did not fail at admission", err)
@@ -96,7 +97,7 @@ func TestReasoningEffortReachesNativeOptions(t *testing.T) {
9697
t.Setenv("OAC_RUNTIME_HOME", root)
9798
config := Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
9899
for _, effort := range []string{"low", "medium", "high", "xhigh", "max"} {
99-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium", ReasoningEffort: effort}, AgentOptions: map[string]any{"model": "native-model", "harness_config": map[string]any{"thinking": map[string]any{"type": "adaptive"}}}}
100+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium"}, Turn: proto.TurnSettings{Model: "native-model", ReasoningEffort: effort}, AgentOptions: map[string]any{"harness_config": map[string]any{"thinking": map[string]any{"type": "adaptive"}}}}
100101
start, _, err := prepareConfiguration(config, request)
101102
if err != nil {
102103
t.Fatal(effort, err)
@@ -127,7 +128,7 @@ func TestStructuredOutputConfigurationReachesNativeUnchanged(t *testing.T) {
127128
t.Setenv("OAC_RUNTIME_HOME", root)
128129
config := Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
129130
schema := json.RawMessage(`{"type":"object","properties":{"n":{"const":9007199254740992}}}`)
130-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), DisableSubagents: true, AgentOptions: map[string]any{"model": "model", "system_prompt": "Original instructions."}, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium", OutputFormat: &proto.OutputFormat{Type: "json_schema", Schema: schema}}}
131+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), DisableSubagents: true, Turn: proto.TurnSettings{Model: "model"}, AgentOptions: map[string]any{"system_prompt": "Original instructions."}, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium", OutputFormat: &proto.OutputFormat{Type: "json_schema", Schema: schema}}}
131132
start, _, err := prepareConfiguration(config, request)
132133
if err != nil {
133134
t.Fatal(err)
@@ -151,7 +152,7 @@ func TestToolDiscoveryPreservesFrozenFunctionsBesideOtherProfiles(t *testing.T)
151152
root := t.TempDir()
152153
t.Setenv("OAC_RUNTIME_HOME", root)
153154
config := Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
154-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), DisableSubagents: true, ToolSearch: true, AgentOptions: map[string]any{"model": "model"}, FunctionTools: []proto.FunctionTool{
155+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Original input."), DisableSubagents: true, ToolSearch: true, Turn: proto.TurnSettings{Model: "model"}, AgentOptions: map[string]any{}, FunctionTools: []proto.FunctionTool{
155156
{Name: "lookup", Description: "Lookup", Parameters: json.RawMessage(`{"type":"object","properties":{"ticket":{"const":"original"}}}`), DeferLoading: true},
156157
{Name: "clock", Description: "Clock", Parameters: json.RawMessage(`{"type":"object"}`)},
157158
}}
@@ -174,7 +175,7 @@ func TestReasoningSummaryReachesTheBridgeOnlyWhenRequested(t *testing.T) {
174175
root := t.TempDir()
175176
t.Setenv("OAC_RUNTIME_HOME", root)
176177
config := Config{Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state")}
177-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Input."), AgentOptions: map[string]any{"model": "native-model"}}
178+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("Input."), Turn: proto.TurnSettings{Model: "native-model"}, AgentOptions: map[string]any{}}
178179
for _, summary := range []string{"", "auto"} {
179180
request.ExecutionControls = &proto.ExecutionControls{TextVerbosity: "medium", ReasoningSummary: summary}
180181
start, _, err := prepareConfiguration(config, request)

‎apps/daemon/internal/agent/claudesdk/executor.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (e *executor) read() {
179179
close(e.done)
180180
}
181181

182-
func (e *executor) StartTurn(ctx context.Context, run string, input proto.MessageInput, out chan<- proto.Envelope) (agent.Turn, error) {
182+
func (e *executor) StartTurn(ctx context.Context, run string, _ proto.TurnSettings, input proto.MessageInput, out chan<- proto.Envelope) (agent.Turn, error) {
183183
if ctx == nil {
184184
ctx = context.Background()
185185
}

‎apps/daemon/internal/agent/claudesdk/executor_fixture_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func startSingleTurn(ctx context.Context, config Config, req proto.PromptRequest
2121
if err != nil {
2222
return nil, err
2323
}
24-
turn, err := resource.StartTurn(ctx, run, input, out)
24+
turn, err := resource.StartTurn(ctx, run, proto.TurnSettings{}, input, out)
2525
if turn == nil {
2626
_ = resource.Close(context.Background())
2727
return nil, err

‎apps/daemon/internal/agent/claudesdk/executor_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func persistentConfig(t *testing.T, mode string) (Config, proto.PromptRequestPay
2626
if err := os.WriteFile(entry, []byte("version-one"), 0600); err != nil {
2727
t.Fatal(err)
2828
}
29-
return Config{Node: os.Args[0], Entrypoint: entry, StateDir: filepath.Join(root, "state"), Env: []string{"GO_CLAUDE_EXECUTOR_HELPER=1", "SDK_EXECUTOR_DIR=" + root, "SDK_EXECUTOR_MODE=" + mode, "GORACE=atexit_sleep_ms=0"}}, proto.PromptRequestPayload{DisableExecutionEnvironment: true, AgentOptions: map[string]any{"model": "fixture"}}
29+
return Config{Node: os.Args[0], Entrypoint: entry, StateDir: filepath.Join(root, "state"), Env: []string{"GO_CLAUDE_EXECUTOR_HELPER=1", "SDK_EXECUTOR_DIR=" + root, "SDK_EXECUTOR_MODE=" + mode, "GORACE=atexit_sleep_ms=0"}}, proto.PromptRequestPayload{DisableExecutionEnvironment: true, Turn: proto.TurnSettings{Model: "fixture"}, AgentOptions: map[string]any{}}
3030
}
3131

3232
func runPersistentExecutorHelper() {
@@ -135,7 +135,7 @@ func runPersistentExecutorHelper() {
135135
func consumeExecutorTurn(t *testing.T, owner agent.Executor, id, input string) (agent.Turn, <-chan proto.Envelope) {
136136
t.Helper()
137137
out := make(chan proto.Envelope, 16)
138-
turn, err := owner.StartTurn(t.Context(), id, proto.TextInput(input), out)
138+
turn, err := owner.StartTurn(t.Context(), id, proto.TurnSettings{}, proto.TextInput(input), out)
139139
if err != nil || turn == nil {
140140
t.Fatalf("StartTurn: %v", err)
141141
}
@@ -215,7 +215,7 @@ func TestExecutorLateTurnEventInvalidatesWithoutRetargeting(t *testing.T) {
215215
t.Fatal("unknown native outcome marked settled")
216216
}
217217
next := make(chan proto.Envelope, 1)
218-
if turn, err := owner.StartTurn(t.Context(), "third", proto.TextInput("hello"), next); turn != nil || err == nil {
218+
if turn, err := owner.StartTurn(t.Context(), "third", proto.TurnSettings{}, proto.TextInput("hello"), next); turn != nil || err == nil {
219219
t.Fatal("invalid executor accepted input")
220220
}
221221
}
@@ -262,7 +262,7 @@ func TestExecutorSeparatesPreInputRejectionFromUnknownWrite(t *testing.T) {
262262
rejected := make(chan proto.Envelope, 1)
263263
cancelled, stop := context.WithCancel(t.Context())
264264
stop()
265-
if turn, err := owner.StartTurn(cancelled, "not-written", proto.TextInput("hello"), rejected); turn != nil || err == nil {
265+
if turn, err := owner.StartTurn(cancelled, "not-written", proto.TurnSettings{}, proto.TextInput("hello"), rejected); turn != nil || err == nil {
266266
t.Fatal("cancelled admission reached native input")
267267
}
268268
select {
@@ -275,7 +275,7 @@ func TestExecutorSeparatesPreInputRejectionFromUnknownWrite(t *testing.T) {
275275
t.Fatal(err)
276276
}
277277
out := make(chan proto.Envelope, 8)
278-
turn, err := owner.StartTurn(t.Context(), "unknown-write", proto.TextInput("hello"), out)
278+
turn, err := owner.StartTurn(t.Context(), "unknown-write", proto.TurnSettings{}, proto.TextInput("hello"), out)
279279
if turn == nil || err == nil {
280280
t.Fatalf("attempted write must preserve unknown Turn ownership: %T %v", turn, err)
281281
}

‎apps/daemon/internal/agent/claudesdk/functions_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestFunctionFactoryNativeReceipts(t *testing.T) {
2222
root := t.TempDir()
2323
t.Setenv("OAC_RUNTIME_HOME", root)
2424
config := Config{Node: os.Args[0], Entrypoint: filepath.Join(root, "worker"), StateDir: filepath.Join(root, "state"), Env: []string{"GO_CLAUDE_SDK_HELPER=1", "SDK_HELPER_MODE=" + mode, "GORACE=atexit_sleep_ms=0"}}
25-
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", AgentOptions: map[string]any{"model": "fake-model", "system_prompt": "instructions"}, FunctionTools: []proto.FunctionTool{{Name: "lookup", Description: "Lookup.", Parameters: json.RawMessage(`{"type":"object","properties":{"ids":{"type":"array","items":{"type":"string"}}}}`)}}}
25+
request := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), AgentSessionID: "native-session", Turn: proto.TurnSettings{Model: "fake-model"}, AgentOptions: map[string]any{"system_prompt": "instructions"}, FunctionTools: []proto.FunctionTool{{Name: "lookup", Description: "Lookup.", Parameters: json.RawMessage(`{"type":"object","properties":{"ids":{"type":"array","items":{"type":"string"}}}}`)}}}
2626
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
2727
defer cancel()
2828
out := make(chan proto.Envelope, 16)

‎apps/daemon/internal/agent/claudesdk/harness_config_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestHarnessConfigReachesBridgeAndOwnsSnapshot(t *testing.T) {
1313
t.Setenv("OAC_RUNTIME_HOME", root)
1414
config := Config{Entrypoint: filepath.Join(root, "main.js"), StateDir: filepath.Join(root, "state")}
1515
native := map[string]any{"thinking": map[string]any{"type": "enabled", "budgetTokens": 1024}}
16-
req := proto.PromptRequestPayload{AgentOptions: map[string]any{"model": "fixture", "harness_config": native}, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium", ReasoningEffort: "high"}}
16+
req := proto.PromptRequestPayload{Turn: proto.TurnSettings{Model: "fixture", ReasoningEffort: "high"}, AgentOptions: map[string]any{"harness_config": native}, ExecutionControls: &proto.ExecutionControls{TextVerbosity: "medium"}}
1717
start, _, err := prepareConfiguration(config, req)
1818
if err != nil {
1919
t.Fatal(err)

‎apps/daemon/internal/agent/claudesdk/mcp_bearer_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestMCPBearerUsesFreshOwnedEnvironmentReferences(t *testing.T) {
2222
{ConnectionOrigin: "service", ServerLabel: "second", ServerURL: "https://second.example/mcp", BearerToken: &tokens[1]},
2323
{ConnectionOrigin: "service", ServerLabel: "anonymous", ServerURL: "http://anonymous.example/mcp"},
2424
}
25-
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), DisableExecutionEnvironment: true, MCPHTTPServers: &servers, AgentOptions: map[string]any{"model": "fixture"}}
25+
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), DisableExecutionEnvironment: true, MCPHTTPServers: &servers, Turn: proto.TurnSettings{Model: "fixture"}, AgentOptions: map[string]any{}}
2626
seen := map[string]bool{}
2727
for range 2 {
2828
start, env, err := prepareConfiguration(config, req)
@@ -66,7 +66,7 @@ func TestMCPBearerRejectsInvalidCredentialBeforeStateCreation(t *testing.T) {
6666
t.Setenv("OAC_RUNTIME_HOME", root)
6767
config := Config{Entrypoint: filepath.Join(root, "main.js"), StateDir: filepath.Join(root, "state")}
6868
servers := []proto.MCPHTTPServer{{ConnectionOrigin: "service", ServerLabel: "fixture", ServerURL: "https://example.invalid/mcp", BearerToken: &token}}
69-
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), DisableExecutionEnvironment: true, MCPHTTPServers: &servers, AgentOptions: map[string]any{"model": "fixture"}}
69+
req := proto.PromptRequestPayload{RunID: "run", Input: proto.TextInput("hello"), DisableExecutionEnvironment: true, MCPHTTPServers: &servers, Turn: proto.TurnSettings{Model: "fixture"}, AgentOptions: map[string]any{}}
7070
if _, _, err := prepareConfiguration(config, req); err == nil || err.Error() != "claudesdk: unsupported HTTPS MCP bearer credential" {
7171
t.Fatal("invalid bearer accepted or unsafe error returned")
7272
}

0 commit comments

Comments
 (0)