Skip to content

Commit 64b8fea

Browse files
tlongwell-blocknpub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgytaTyler Longwellnpub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757
authored
Bug-bash round 2: table scroll, Goose instructions, workflow mention wake (#2034)
Signed-off-by: Tyler Longwell <[email protected]> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <[email protected]> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
1 parent 3e80b76 commit 64b8fea

6 files changed

Lines changed: 818 additions & 38 deletions

File tree

‎crates/buzz-acp/src/acp.rs‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,24 @@ impl AcpClient {
597597
.session_id)
598598
}
599599

600+
/// Send Goose's custom system-prompt request after `session/new`.
601+
pub async fn session_set_goose_system_prompt(
602+
&mut self,
603+
session_id: &str,
604+
text: &str,
605+
) -> Result<serde_json::Value, AcpError> {
606+
self.send_request(
607+
"_goose/unstable/session/system-prompt/set",
608+
serde_json::json!({
609+
"sessionId": session_id,
610+
"mode": "append",
611+
"key": "buzz",
612+
"text": text,
613+
}),
614+
)
615+
.await
616+
}
617+
600618
/// Send `session/set_config_option` (stable ACP path).
601619
pub async fn session_set_config_option(
602620
&mut self,
@@ -2889,6 +2907,61 @@ mod tests {
28892907
);
28902908
}
28912909

2910+
#[tokio::test]
2911+
async fn goose_system_prompt_request_uses_append_contract() {
2912+
let script = r#"
2913+
read -t 2 REQ
2914+
echo '{"jsonrpc":"2.0","id":0,"result":{"_receivedRequest":'"$REQ"'}}'
2915+
sleep 1
2916+
"#;
2917+
let mut client = spawn_script(script).await;
2918+
let result = client
2919+
.session_set_goose_system_prompt("ses_goose", "Be terse")
2920+
.await
2921+
.expect("custom request succeeds");
2922+
let received = &result["_receivedRequest"];
2923+
assert_eq!(
2924+
received["method"],
2925+
"_goose/unstable/session/system-prompt/set"
2926+
);
2927+
assert_eq!(received["params"]["sessionId"], "ses_goose");
2928+
assert_eq!(received["params"]["mode"], "append");
2929+
assert_eq!(received["params"]["key"], "buzz");
2930+
assert_eq!(received["params"]["text"], "Be terse");
2931+
}
2932+
2933+
#[tokio::test]
2934+
async fn goose_system_prompt_preserves_method_not_found_for_fallback() {
2935+
let script = r#"
2936+
read -t 2 _REQ
2937+
echo '{"jsonrpc":"2.0","id":0,"error":{"code":-32601,"message":"Method not found"}}'
2938+
sleep 1
2939+
"#;
2940+
let mut client = spawn_script(script).await;
2941+
assert!(matches!(
2942+
client
2943+
.session_set_goose_system_prompt("ses_goose", "Be terse")
2944+
.await,
2945+
Err(AcpError::AgentError { code: -32601, .. })
2946+
));
2947+
}
2948+
2949+
#[tokio::test]
2950+
async fn goose_system_prompt_preserves_invalid_params_as_error() {
2951+
let script = r#"
2952+
read -t 2 _REQ
2953+
echo '{"jsonrpc":"2.0","id":0,"error":{"code":-32602,"message":"Invalid params"}}'
2954+
sleep 1
2955+
"#;
2956+
let mut client = spawn_script(script).await;
2957+
assert!(matches!(
2958+
client
2959+
.session_set_goose_system_prompt("ses_goose", "Be terse")
2960+
.await,
2961+
Err(AcpError::AgentError { code: -32602, .. })
2962+
));
2963+
}
2964+
28922965
#[tokio::test]
28932966
async fn session_new_full_omits_system_prompt_when_none() {
28942967
// When system_prompt is None, the field should not appear in params.

‎crates/buzz-acp/src/lib.rs‎

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ struct RespawnResult {
984984
/// Tuple: (initialized client, protocol version, supports_goose_steer).
985985
/// The third element is always `true` — the supervisor uses
986986
/// try-and-tolerate for the steer extension.
987-
result: Result<(AcpClient, u32, bool)>,
987+
result: Result<(AcpClient, u32, String)>,
988988
}
989989

990990
/// Outcome of a non-cancelling steer attempt, forwarded from a per-attempt
@@ -1028,7 +1028,7 @@ impl RespawnGuard {
10281028
/// Send the result and disarm the guard. Uses `try_send` (sync) so there
10291029
/// is no await boundary between marking `sent` and actually enqueueing —
10301030
/// cancellation cannot slip between the two.
1031-
fn send(mut self, result: Result<(AcpClient, u32, bool)>) {
1031+
fn send(mut self, result: Result<(AcpClient, u32, String)>) {
10321032
// Invariant: try_send succeeds because the channel capacity equals the
10331033
// slot count, and respawn_in_flight guarantees at most one outstanding
10341034
// result per slot. If this ever fails, the channel sizing or the
@@ -1198,13 +1198,16 @@ async fn tokio_main() -> Result<()> {
11981198
"initializeResult": init_result,
11991199
}),
12001200
);
1201+
let agent_name = normalized_agent_name(&init_result);
12011202
agent_slots.push(Some(OwnedAgent {
12021203
index: i,
12031204
acp,
12041205
state: SessionState::default(),
12051206
model_capabilities: None,
12061207
desired_model: config.model.clone(),
12071208
model_overridden: false,
1209+
agent_name,
1210+
goose_system_prompt_supported: None,
12081211
protocol_version,
12091212
}));
12101213
}
@@ -1640,14 +1643,16 @@ async fn tokio_main() -> Result<()> {
16401643
while let Ok(rr) = respawn_rx.try_recv() {
16411644
crash_history[rr.index].respawn_in_flight = false;
16421645
match rr.result {
1643-
Ok((acp, protocol_version, _)) => {
1646+
Ok((acp, protocol_version, agent_name)) => {
16441647
let agent = OwnedAgent {
16451648
index: rr.index,
16461649
acp,
16471650
state: SessionState::default(),
16481651
model_capabilities: None,
16491652
desired_model: config.model.clone(),
16501653
model_overridden: false,
1654+
agent_name,
1655+
goose_system_prompt_supported: None,
16511656
protocol_version,
16521657
};
16531658
pool.return_agent(agent);
@@ -3199,10 +3204,6 @@ fn dispatch_heartbeat(
31993204
.heartbeat_prompt
32003205
.clone()
32013206
.unwrap_or_else(default_heartbeat_prompt);
3202-
// For legacy agents (protocol_version < 2), prepend base_prompt to the
3203-
// heartbeat user message since they don't receive it via session/new.
3204-
let prompt_text =
3205-
pool::prepend_base_for_legacy(agent.protocol_version, ctx.base_prompt, &prompt_text);
32063207
let result_tx = pool.result_tx();
32073208
let ctx_clone = Arc::clone(ctx);
32083209
let agent_index = agent.index;
@@ -3315,6 +3316,17 @@ fn spawn_respawn_task(
33153316
true
33163317
}
33173318

3319+
fn normalized_agent_name(init_result: &serde_json::Value) -> String {
3320+
init_result
3321+
.get("agentInfo")
3322+
.or_else(|| init_result.get("serverInfo"))
3323+
.and_then(|info| info.get("name"))
3324+
.and_then(|value| value.as_str())
3325+
.unwrap_or("unknown")
3326+
.trim()
3327+
.to_ascii_lowercase()
3328+
}
3329+
33183330
// ── spawn_and_init ────────────────────────────────────────────────────────────
33193331
/// Spawn an agent subprocess and run the MCP `initialize` handshake.
33203332
///
@@ -3327,7 +3339,7 @@ async fn spawn_and_init(
33273339
has_generated_codex_config: bool,
33283340
agent_index: usize,
33293341
observer: Option<observer::ObserverHandle>,
3330-
) -> Result<(AcpClient, u32, bool)> {
3342+
) -> Result<(AcpClient, u32, String)> {
33313343
let mut acp = AcpClient::spawn(command, args, extra_env, has_generated_codex_config)
33323344
.await
33333345
.map_err(|e| anyhow::anyhow!("failed to spawn agent: {e}"))?;
@@ -3344,7 +3356,8 @@ async fn spawn_and_init(
33443356
"initializeResult": init_result,
33453357
}),
33463358
);
3347-
Ok((acp, protocol_version, true))
3359+
let agent_name = normalized_agent_name(&init_result);
3360+
Ok((acp, protocol_version, agent_name))
33483361
}
33493362
Err(e) => {
33503363
// Explicitly shut down the spawned child to prevent zombie/leak.
@@ -4287,6 +4300,22 @@ mod error_outcome_emission_tests {
42874300
}
42884301
}
42894302

4303+
#[test]
4304+
fn normalizes_agent_name_from_initialize_result() {
4305+
assert_eq!(
4306+
normalized_agent_name(&serde_json::json!({
4307+
"agentInfo": { "name": " Goose ", "version": "1.43.0" }
4308+
})),
4309+
"goose"
4310+
);
4311+
assert_eq!(
4312+
normalized_agent_name(&serde_json::json!({
4313+
"serverInfo": { "name": "buzz-agent" }
4314+
})),
4315+
"buzz-agent"
4316+
);
4317+
}
4318+
42904319
/// Spawn a real but inert agent subprocess (`cat`) so the error paths have
42914320
/// an `OwnedAgent` to move into respawn or return to the pool. The error
42924321
/// branches never talk to the subprocess.
@@ -4300,6 +4329,8 @@ mod error_outcome_emission_tests {
43004329
model_capabilities: None,
43014330
desired_model: None,
43024331
model_overridden: false,
4332+
agent_name: "unknown".into(),
4333+
goose_system_prompt_supported: None,
43034334
// Error branches under test never read this; 1 is the legacy
43044335
// non-systemPrompt path, the simplest valid value.
43054336
protocol_version: 1,

0 commit comments

Comments
 (0)