@@ -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