Skip to content

Commit 5da2220

Browse files
committed
acp: settings/set drops recipe retry and sub_recipes and renders a stored template when no recipe is sent
1 parent 6901a17 commit 5da2220

4 files changed

Lines changed: 39 additions & 16 deletions

File tree

‎crates/goose-sdk-types/src/custom_requests/session_settings.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use super::{EmptyResponse, RecipeDto};
77

88
/// Pin a session's prompt-cache TTL and recipe, persisted on the session row.
99
///
10-
/// Only the recipe's `instructions` and `response` take effect; its `settings`,
11-
/// `extensions`, `prompt` and `parameters` are ignored, and the session keeps
12-
/// its model.
10+
/// The recipe is stored on the session and read every turn: its `title`,
11+
/// `instructions` and `response` take effect. Its `settings`, `extensions`,
12+
/// `prompt` and `parameters` are ignored, `retry` and `sub_recipes` are
13+
/// dropped, and the session keeps its model.
1314
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema, JsonRpcRequest)]
1415
#[request(
1516
method = "_goose/unstable/session/settings/set",

‎crates/goose/acp-schema.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@
837837
"required": [
838838
"sessionId"
839839
],
840-
"description": "Pin a session's prompt-cache TTL and recipe, persisted on the session row.\n\nOnly the recipe's `instructions` and `response` take effect; its `settings`,\n`extensions`, `prompt` and `parameters` are ignored, and the session keeps\nits model.",
840+
"description": "Pin a session's prompt-cache TTL and recipe, persisted on the session row.\n\nThe recipe is stored on the session and read every turn: its `title`,\n`instructions` and `response` take effect. Its `settings`, `extensions`,\n`prompt` and `parameters` are ignored, `retry` and `sub_recipes` are\ndropped, and the session keeps its model.",
841841
"x-side": "agent",
842842
"x-method": "_goose/unstable/session/settings/set"
843843
},

‎crates/goose/src/acp/server/session_settings.rs‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ fn normalized_cache_ttl(ttl: &str) -> Result<String, agent_client_protocol::Erro
3030

3131
/// The recipe as the session row stores it: rendered with the session's
3232
/// parameter values, except for scheduled sessions, which keep the template.
33-
fn recipe_to_store(raw: Recipe, session: &Session) -> Result<Recipe, agent_client_protocol::Error> {
33+
/// `retry` and `sub_recipes` are dropped: the state machine reads the stored
34+
/// recipe every turn, and a retry block would let a failed check truncate a
35+
/// long-lived session back to its kickoff message.
36+
fn recipe_to_store(
37+
mut raw: Recipe,
38+
session: &Session,
39+
) -> Result<Recipe, agent_client_protocol::Error> {
40+
raw.retry = None;
41+
raw.sub_recipes = None;
3442
if raw.check_for_security_warnings() {
3543
return Err(invalid_recipe(
3644
"contains hidden characters that could be malicious",
@@ -108,7 +116,7 @@ impl AcpConnection {
108116
.map(normalized_cache_ttl)
109117
.transpose()?;
110118

111-
let session = self
119+
let mut session = self
112120
.services
113121
.session_manager
114122
.get_session(session_id, false)
@@ -153,15 +161,17 @@ impl AcpConnection {
153161
}
154162
}
155163

156-
if let Some(recipe) = recipe {
157-
self.services
158-
.session_manager
159-
.update(session_id)
160-
.recipe(Some(recipe))
161-
.apply()
162-
.await
163-
.internal_err_ctx("Failed to persist recipe to session")?;
164-
}
164+
let Some(recipe) = recipe else {
165+
self.render_stored_recipe_template(&mut session).await?;
166+
return Ok(EmptyResponse {});
167+
};
168+
self.services
169+
.session_manager
170+
.update(session_id)
171+
.recipe(Some(recipe))
172+
.apply()
173+
.await
174+
.internal_err_ctx("Failed to persist recipe to session")?;
165175

166176
Ok(EmptyResponse {})
167177
}

‎crates/goose/tests/acp_session_settings_test.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,20 @@ fn test_session_settings_set_persists_and_survives_reload() {
174174
let session_id = session.session_id().0.to_string();
175175
let session_manager = SessionManager::new(temp_data.path().to_path_buf());
176176

177+
let mut recipe = summary_recipe();
178+
recipe["retry"] = serde_json::json!({
179+
"max_retries": 1,
180+
"checks": [{ "type": "shell", "command": "false" }]
181+
});
182+
recipe["sub_recipes"] = serde_json::json!([{ "name": "child", "path": "child.yaml" }]);
177183
for _ in 0..2 {
178184
let res = send_custom(
179185
conn.cx(),
180186
SETTINGS_SET,
181187
serde_json::json!({
182188
"sessionId": session_id,
183189
"cacheTtl": "1h",
184-
"recipe": summary_recipe(),
190+
"recipe": recipe,
185191
}),
186192
)
187193
.await
@@ -197,6 +203,12 @@ fn test_session_settings_set_persists_and_survives_reload() {
197203
stored.model_config.as_ref().and_then(|mc| mc.cache_ttl()),
198204
Some("1h".to_string())
199205
);
206+
let stored_recipe = stored.recipe.expect("recipe stored");
207+
assert!(stored_recipe.retry.is_none(), "retry must not be stored");
208+
assert!(
209+
stored_recipe.sub_recipes.is_none(),
210+
"sub_recipes must not be stored"
211+
);
200212
let out = session
201213
.prompt("Hello with recipe", PermissionDecision::AllowOnce)
202214
.await

0 commit comments

Comments
 (0)