Skip to content

Commit 59328d5

Browse files
salman1993Leo
andauthored
feat(desktop): add thread-scoped ACP session experiment (#6909)
## Why Thread-scoped ACP sessions from #6732 need an opt-in desktop rollout that preserves today’s channel policy by default. ## What - Add the default-off “Thread Scoped ACP Sessions” toggle under Settings → Experiments using the existing feature-override persistence. - Map the persisted setting to `BUZZ_ACP_SESSION_POLICY=channel|thread` for every local and provider-backed managed ACP launch. Changes apply when managed agents next start; DMs remain conversation-scoped by the backend. - Keep the desktop setting authoritative over descriptor environment and cover the UI, persistence, local spawn, provider payload, and existing Projects/Workflows experiments. ## Risk Assessment Low. The experiment defaults off and explicitly preserves `channel`; changes are limited to managed-agent launch configuration. Existing running agents are unchanged until their next start. ## Testing - `. ./bin/activate-hermit && just ci` — passed on the final restacked tree, including 5,674 desktop tests, 2,796 Tauri tests, and 1,860 mobile tests. - `cd desktop && pnpm build:e2e && pnpm exec playwright test tests/e2e/experimental-features.spec.ts --project=smoke` — 1 passed. - `. ./bin/activate-hermit && cargo test --manifest-path desktop/src-tauri/Cargo.toml session_policy --lib` — 4 passed. - `. ./bin/activate-hermit && cargo test --manifest-path desktop/src-tauri/Cargo.toml commands::agents::deploy::tests --lib` — 15 passed. - `. ./bin/activate-hermit && cargo test -p buzz-backend-kubernetes --test wire_fixtures` — 4 passed. ## Stack Info Stacked on #6732. This PR depends on #6732 and should merge after it. Generated with Codex --------- Signed-off-by: Salman Mohammed <[email protected]> Signed-off-by: Leo <5faf251baee50ee6bcde338aef6acdd70bb3e60115664c2cd490d94a55dfc488@buzz.block.builderlab.xyz> Co-authored-by: Leo <5faf251baee50ee6bcde338aef6acdd70bb3e60115664c2cd490d94a55dfc488@buzz.block.builderlab.xyz>
1 parent 571c190 commit 59328d5

45 files changed

Lines changed: 1575 additions & 122 deletions

Some content is hidden

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

‎crates/buzz-backend-kubernetes/tests/fixtures/provider-wire/deploy-full-launch.request.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"BUZZ_ACP_LAZY_POOL": "true",
2727
"BUZZ_ACP_MODEL": "gpt-5",
2828
"BUZZ_ACP_RELAY_OBSERVER": "true",
29+
"BUZZ_ACP_SESSION_POLICY": "channel",
2930
"BUZZ_ACP_SESSION_TITLE": "worker",
3031
"GOOSE_MODE": "auto"
3132
}

‎desktop/playwright.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default defineConfig({
4949
"**/channel-controls.spec.ts",
5050
"**/channel-activity-popover.spec.ts",
5151
"**/active-turn-resilience.spec.ts",
52+
"**/agent-control-regressions.spec.ts",
5253
"**/profile-active-turn.spec.ts",
5354
"**/config-bridge-screenshots.spec.ts",
5455
"**/observer-feed-screenshots.spec.ts",
@@ -147,6 +148,7 @@ export default defineConfig({
147148
"**/profile-backup-settings.spec.ts",
148149
"**/signout-confirmation.spec.ts",
149150
"**/settings-section-layout.spec.ts",
151+
"**/experimental-features.spec.ts",
150152
"**/agent-provider-dropdowns.spec.ts",
151153
"**/agent-lifecycle-feedback.spec.ts",
152154
"**/agent-access-warning.spec.ts",

‎desktop/src-tauri/src/app_state.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub struct AppState {
3636
pub workspace_apply_generation: AtomicU64,
3737
/// Defers managed-agent restore until `apply_workspace` installs relay and identity.
3838
pub managed_agent_restore_pending: AtomicBool,
39-
/// Disabled by agent-managed profiles so agent profile updates survive start/restore.
40-
pub managed_agent_profile_reconcile_enabled: AtomicBool,
39+
/// Experiment state applied to managed-agent starts and profile reconciliation.
40+
pub managed_agent_experiments: crate::managed_agents::ManagedAgentExperimentState,
4141
/// Shared shutdown signal checked by launch-time agent restoration.
4242
pub shutdown_started: AtomicBool,
4343
/// Serializes every managed-runtime transition that changes the protected
@@ -207,7 +207,7 @@ pub fn build_app_state() -> AppState {
207207
workspace_apply_lock: Arc::new(AsyncMutex::new(())),
208208
workspace_apply_generation: AtomicU64::new(0),
209209
managed_agent_restore_pending: AtomicBool::new(false),
210-
managed_agent_profile_reconcile_enabled: AtomicBool::new(true),
210+
managed_agent_experiments: crate::managed_agents::ManagedAgentExperimentState::default(),
211211
shutdown_started: AtomicBool::new(false),
212212
managed_agent_runtime_transition: Mutex::new(()),
213213
identity_mutation: Mutex::new(()),

‎desktop/src-tauri/src/commands/agent_settings.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ use crate::{
1313
#[tauri::command]
1414
pub fn set_agent_managed_profiles(enabled: bool, state: State<'_, AppState>) {
1515
state
16-
.managed_agent_profile_reconcile_enabled
16+
.managed_agent_profile_reconcile_enabled()
1717
.store(!enabled, Ordering::Release);
1818
}
1919

20+
#[tauri::command]
21+
pub fn set_thread_scoped_acp_sessions(enabled: bool, state: State<'_, AppState>) {
22+
state
23+
.thread_scoped_acp_sessions_enabled()
24+
.store(enabled, Ordering::Release);
25+
}
26+
2027
#[tauri::command]
2128
pub async fn set_managed_agent_start_on_app_launch(
2229
pubkey: String,

‎desktop/src-tauri/src/commands/agents.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ pub async fn start_managed_agent(
10121012
// with no persisted avatar, this also backfills the avatar from the relay.
10131013
if result.is_ok()
10141014
&& state
1015-
.managed_agent_profile_reconcile_enabled
1015+
.managed_agent_profile_reconcile_enabled()
10161016
.load(std::sync::atomic::Ordering::Acquire)
10171017
{
10181018
let reconcile_pubkey = pubkey.clone();

‎desktop/src-tauri/src/commands/agents_deploy.rs‎

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ pub(crate) fn resolve_deploy_model_provider(
4343

4444
/// Serialize the portable launch contract shared with provider-backed agents.
4545
///
46-
/// `descriptor.env` is the authoritative six-layer environment. Policy values
47-
/// are deliberately separate because providers apply them below that layered
48-
/// environment, preserving the local spawn's power-user override semantics.
49-
pub(super) fn build_launch_block(
46+
/// `descriptor.env` is the authoritative six-layer environment for ordinary
47+
/// values. Desktop-owned settings are reserved, stripped from that layer, and
48+
/// emitted through `policy_env` so local and provider launches agree.
49+
fn build_launch_block_for_policy(
5050
record: &ManagedAgentRecord,
5151
descriptor: &crate::managed_agents::readiness::EffectiveHarnessDescriptor,
5252
teams: &[crate::managed_agents::TeamRecord],
5353
effective_prompt: Option<&str>,
5454
effective_model: Option<&str>,
5555
owner_pubkey: &str,
56+
session_policy: crate::managed_agents::AcpSessionPolicy,
5657
) -> serde_json::Value {
5758
use crate::managed_agents::{
5859
known_acp_runtime, resolve_session_title, DISPLAY_NAME_ENV_VAR, SESSION_TITLE_ENV_VAR,
@@ -78,6 +79,7 @@ pub(super) fn build_launch_block(
7879
"BUZZ_ACP_AGENTS".into(),
7980
crate::managed_agents::acp_agents_value(&descriptor.command, record.parallelism),
8081
);
82+
crate::managed_agents::insert_acp_session_policy_env(&mut policy_env, session_policy);
8183

8284
if let Some(value) = effective_prompt {
8385
policy_env.insert("BUZZ_ACP_SYSTEM_PROMPT".into(), value.to_string());
@@ -138,7 +140,8 @@ pub(super) fn build_launch_block(
138140
// matching local, where `apply_claude_model_env(None)` removes both.
139141
let is_claude = runtime.map(|r| r.id == "claude").unwrap_or(false);
140142
let strip_key = |k: &str| {
141-
(record.effort_level.is_some() && k.eq_ignore_ascii_case("BUZZ_ACP_EFFORT_LEVEL"))
143+
k.eq_ignore_ascii_case(crate::managed_agents::ACP_SESSION_POLICY_ENV_VAR)
144+
|| (record.effort_level.is_some() && k.eq_ignore_ascii_case("BUZZ_ACP_EFFORT_LEVEL"))
142145
|| (is_claude
143146
&& (k.eq_ignore_ascii_case("BUZZ_ACP_MODEL")
144147
|| k.eq_ignore_ascii_case("ANTHROPIC_MODEL")))
@@ -159,6 +162,26 @@ pub(super) fn build_launch_block(
159162
})
160163
}
161164

165+
#[cfg(test)]
166+
pub(super) fn build_launch_block(
167+
record: &ManagedAgentRecord,
168+
descriptor: &crate::managed_agents::readiness::EffectiveHarnessDescriptor,
169+
teams: &[crate::managed_agents::TeamRecord],
170+
effective_prompt: Option<&str>,
171+
effective_model: Option<&str>,
172+
owner_pubkey: &str,
173+
) -> serde_json::Value {
174+
build_launch_block_for_policy(
175+
record,
176+
descriptor,
177+
teams,
178+
effective_prompt,
179+
effective_model,
180+
owner_pubkey,
181+
crate::managed_agents::AcpSessionPolicy::Channel,
182+
)
183+
}
184+
162185
pub(super) fn ensure_remote_provider_supported(provider: Option<&str>) -> Result<(), String> {
163186
if provider.map(str::trim) == Some(crate::managed_agents::RELAY_MESH_PROVIDER_ID) {
164187
return Err(
@@ -198,13 +221,14 @@ pub(crate) fn build_deploy_payload<R: tauri::Runtime>(
198221
crate::managed_agents::resolve_effective_harness_descriptor(record, &personas, &global)
199222
.map_err(|error| crate::managed_agents::user_facing_harness_error(&error))?;
200223
let owner_pubkey = super::workspace_owner_hex(state)?;
201-
let launch = build_launch_block(
224+
let launch = build_launch_block_for_policy(
202225
record,
203226
&descriptor,
204227
&teams,
205228
effective.system_prompt.value.as_deref(),
206229
effective.model.value.as_deref(),
207230
&owner_pubkey,
231+
crate::managed_agents::acp_session_policy(state),
208232
);
209233

210234
let effective_parallelism =
@@ -342,9 +366,40 @@ mod tests {
342366
assert_eq!(launch["policy_env"]["BUZZ_ACP_IDLE_TIMEOUT"], "17");
343367
assert_eq!(launch["policy_env"]["BUZZ_ACP_MAX_TURN_DURATION"], "23");
344368
assert_eq!(launch["policy_env"]["BUZZ_ACP_AGENTS"], "4");
369+
assert_eq!(launch["policy_env"]["BUZZ_ACP_SESSION_POLICY"], "channel");
345370
assert_eq!(launch["owner_pubkey"], "owner-hex");
346371
}
347372

373+
#[test]
374+
fn launch_block_thread_policy_is_authoritative_and_preserves_unrelated_env() {
375+
let record = record();
376+
let descriptor = EffectiveHarnessDescriptor {
377+
command: "goose".into(),
378+
args: vec![],
379+
env: BTreeMap::from([
380+
("BUZZ_ACP_SESSION_POLICY".to_string(), "channel".to_string()),
381+
("KEEP_ME".to_string(), "yes".to_string()),
382+
]),
383+
};
384+
385+
let launch = build_launch_block_for_policy(
386+
&record,
387+
&descriptor,
388+
&[],
389+
None,
390+
None,
391+
"owner-hex",
392+
crate::managed_agents::AcpSessionPolicy::Thread,
393+
);
394+
395+
assert_eq!(launch["policy_env"]["BUZZ_ACP_SESSION_POLICY"], "thread");
396+
assert!(
397+
launch["env"]["BUZZ_ACP_SESSION_POLICY"].is_null(),
398+
"desktop policy must not be shadowed by descriptor env"
399+
);
400+
assert_eq!(launch["env"]["KEEP_ME"], "yes");
401+
}
402+
348403
#[test]
349404
fn launch_block_claude_runtime_uses_anthropic_model_not_buzz_acp_model() {
350405
// B2: remote claude deploys must send ANTHROPIC_MODEL, not BUZZ_ACP_MODEL,

‎desktop/src-tauri/src/commands/agents_profile.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub(crate) async fn reconcile_agent_profile(
206206
);
207207

208208
if !state
209-
.managed_agent_profile_reconcile_enabled
209+
.managed_agent_profile_reconcile_enabled()
210210
.load(std::sync::atomic::Ordering::Acquire)
211211
{
212212
return Ok(ProfileReconcileOutcome::SkippedDisabled);
@@ -273,7 +273,7 @@ pub(crate) async fn reconcile_agent_profile(
273273
.map_err(|e| format!("failed to parse agent keys: {e}"))?;
274274

275275
if !state
276-
.managed_agent_profile_reconcile_enabled
276+
.managed_agent_profile_reconcile_enabled()
277277
.load(std::sync::atomic::Ordering::Acquire)
278278
{
279279
return Ok(ProfileReconcileOutcome::SkippedDisabled);

‎desktop/src-tauri/src/commands/workspace.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub async fn apply_workspace(
155155
nsec: Option<String>,
156156
repos_dir: Option<String>,
157157
agent_managed_profiles: Option<bool>,
158+
thread_scoped_acp_sessions: Option<bool>,
158159
app: AppHandle,
159160
) -> Result<(), String> {
160161
let state = app.state::<AppState>();
@@ -228,8 +229,15 @@ pub async fn apply_workspace(
228229
// experiment before launch-time restore can spawn any agents. Missing
229230
// means the stable behavior: desktop remains authoritative.
230231
state
231-
.managed_agent_profile_reconcile_enabled
232+
.managed_agent_profile_reconcile_enabled()
232233
.store(!agent_managed_profiles.unwrap_or(false), Ordering::Release);
234+
// Persisted frontend experiment state must land before launch-time
235+
// restore so every restored agent starts with the selected ACP policy.
236+
// Missing preserves the stable channel-scoped behavior.
237+
state.thread_scoped_acp_sessions_enabled().store(
238+
thread_scoped_acp_sessions.unwrap_or(false),
239+
Ordering::Release,
240+
);
233241

234242
// ── Filesystem side-effect (non-fatal) ────────────────────────────────
235243
// Persist the *effective* repos_dir (None when the candidate failed

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ pub fn run() {
700700
start_managed_agent,
701701
stop_managed_agent,
702702
set_agent_managed_profiles,
703+
set_thread_scoped_acp_sessions,
703704
set_managed_agent_start_on_app_launch,
704705
set_managed_agent_auto_restart,
705706
delete_managed_agent,

‎desktop/src-tauri/src/managed_agents/env_vars/tests.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ fn reserved_keys_include_remote_lifetime_policy() {
175175
}
176176
}
177177

178+
#[test]
179+
fn reserved_keys_include_desktop_acp_session_policy() {
180+
assert!(is_reserved_env_key("BUZZ_ACP_SESSION_POLICY"));
181+
let agent = map(&[("BUZZ_ACP_SESSION_POLICY", "thread")]);
182+
assert!(merged_user_env(&BTreeMap::new(), &agent).is_empty());
183+
}
184+
178185
#[test]
179186
fn reserved_keys_include_code_execution_surface() {
180187
// The agent/MCP command + args are what Buzz actually exec's.

0 commit comments

Comments
 (0)