@@ -1018,9 +1018,7 @@ async fn create_session_and_apply_model(
10181018 // advertises the requested mode in session/new. Agents that don't support
10191019 // the mode (e.g., goose crashes on unrecognized set_config_option values)
10201020 // are safely skipped — the harness auto-approves via handle_permission_request.
1021- if !ctx. permission_mode . is_default ( )
1022- && agent_supports_mode ( & resp. raw , ctx. permission_mode . as_wire_str ( ) )
1023- {
1021+ if should_apply_permission_mode ( & resp. raw , & ctx. permission_mode ) {
10241022 apply_permission_mode ( & mut agent. acp , & resp. session_id , & ctx. permission_mode ) . await ?;
10251023 }
10261024
@@ -1130,10 +1128,6 @@ async fn apply_model_switch(
11301128 Ok ( ( ) )
11311129}
11321130
1133- /// Set the session permission mode via `session/set_config_option`.
1134- ///
1135- /// Non-fatal for most errors: logs and proceeds. The agent falls back
1136- /// to its default permission mode (`"default"`), which still works via
11371131/// Check if the agent's `session/new` response advertises a given mode ID
11381132/// in `result.modes.availableModes[].id`. Returns `false` if the modes
11391133/// field is absent or the mode isn't listed.
@@ -1150,7 +1144,20 @@ fn agent_supports_mode(session_new_result: &serde_json::Value, mode_wire: &str)
11501144 . unwrap_or ( false )
11511145}
11521146
1153- /// per-tool auto-approval in `handle_permission_request`.
1147+ /// Decide whether Buzz should override the adapter's session permission mode.
1148+ /// The default deliberately leaves the adapter untouched so its individual
1149+ /// permission requests reach the harness.
1150+ fn should_apply_permission_mode (
1151+ session_new_result : & serde_json:: Value ,
1152+ mode : & PermissionMode ,
1153+ ) -> bool {
1154+ !mode. is_default ( ) && agent_supports_mode ( session_new_result, mode. as_wire_str ( ) )
1155+ }
1156+
1157+ /// Set the session permission mode via `session/set_config_option`.
1158+ ///
1159+ /// Non-fatal for application-level errors: the agent remains in its default
1160+ /// mode and the harness handles its per-tool permission requests.
11541161///
11551162/// **Fatal exception:** if the agent process exits (e.g., goose crashes on
11561163/// unrecognized methods), returns `Err(AgentExited)` so the caller can respawn.
@@ -4039,6 +4046,31 @@ mod tests {
40394046 }
40404047 }
40414048
4049+ #[ test]
4050+ fn default_permission_mode_never_sends_a_session_override ( ) {
4051+ let session = json ! ( {
4052+ "modes" : {
4053+ "availableModes" : [
4054+ { "id" : "default" } ,
4055+ { "id" : "bypassPermissions" }
4056+ ]
4057+ }
4058+ } ) ;
4059+
4060+ assert ! ( !should_apply_permission_mode(
4061+ & session,
4062+ & PermissionMode :: Default
4063+ ) ) ;
4064+ assert ! ( should_apply_permission_mode(
4065+ & session,
4066+ & PermissionMode :: BypassPermissions
4067+ ) ) ;
4068+ assert ! ( !should_apply_permission_mode(
4069+ & json!( { } ) ,
4070+ & PermissionMode :: BypassPermissions
4071+ ) ) ;
4072+ }
4073+
40424074 #[ test]
40434075 fn public_session_forwards_channel_origin_to_mcp ( ) {
40444076 let channel_id = Uuid :: new_v4 ( ) ;
0 commit comments