Skip to content

Commit 12245cf

Browse files
klopez4212Carl
andcommitted
Complete Pollen profile migration
Co-authored-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <[email protected]>
1 parent 6ac5049 commit 12245cf

6 files changed

Lines changed: 319 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,9 +1366,12 @@ use deploy::{ensure_remote_provider_supported, resolve_deploy_model_provider};
13661366

13671367
#[path = "agents_profile.rs"]
13681368
mod profile;
1369+
pub(crate) use profile::{
1370+
load_pending_profile_reconciliations, mark_profile_reconciled, reconcile_agent_profile,
1371+
ProfileReconcileData,
1372+
};
13691373
#[cfg(test)]
13701374
use profile::{profile_needs_sync, resolve_legacy_avatar};
1371-
pub(crate) use profile::{reconcile_agent_profile, ProfileReconcileData};
13721375

13731376
#[cfg(test)]
13741377
#[path = "agents_tests.rs"]

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

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//! guard). Owns the reconcile data carrier, the legacy-avatar backfill, and
33
//! the needs-sync predicate.
44
5-
use tauri::AppHandle;
5+
use std::collections::HashSet;
6+
use tauri::{AppHandle, Manager};
67

78
use crate::app_state::AppState;
89
use crate::managed_agents::managed_agent_avatar_url;
@@ -49,6 +50,78 @@ pub(super) fn resolve_legacy_avatar(
4950
.unwrap_or_default()
5051
}
5152

53+
pub(crate) fn profile_reconcile_data(
54+
record: &crate::managed_agents::ManagedAgentRecord,
55+
personas: &[crate::managed_agents::AgentDefinition],
56+
) -> ProfileReconcileData {
57+
ProfileReconcileData {
58+
private_key_nsec: record.private_key_nsec.clone(),
59+
name: record.name.clone(),
60+
relay_url: record.relay_url.clone(),
61+
avatar_url: record.avatar_url.clone(),
62+
auth_tag: record.auth_tag.clone(),
63+
pubkey: record.pubkey.clone(),
64+
agent_command: crate::managed_agents::record_agent_command(record, personas),
65+
persona_id: record.persona_id.clone(),
66+
}
67+
}
68+
69+
pub(crate) fn load_pending_profile_reconciliations(
70+
app: &AppHandle,
71+
) -> Result<Vec<(String, ProfileReconcileData)>, String> {
72+
let state = app.state::<AppState>();
73+
let _store_guard = state
74+
.managed_agents_store_lock
75+
.lock()
76+
.map_err(|error| error.to_string())?;
77+
let store_path = crate::managed_agents::managed_agents_store_path(app)?;
78+
let queue_path = crate::migration::profile_reconcile_queue_path(&store_path);
79+
if !queue_path.exists() {
80+
return Ok(Vec::new());
81+
}
82+
83+
let pending: HashSet<String> = crate::migration::read_profile_reconcile_queue(&queue_path)?
84+
.into_iter()
85+
.collect();
86+
let records = crate::managed_agents::load_managed_agents(app)?;
87+
let personas = crate::managed_agents::load_personas(app).unwrap_or_default();
88+
let workspace_relay = relay_ws_url_with_override(&state);
89+
Ok(records
90+
.iter()
91+
// A queue write deliberately precedes the migrated agent-store write.
92+
// If the process dies between them, retain (but do not execute) the
93+
// stale item until the next boot finishes renaming the record.
94+
.filter(|record| {
95+
pending.contains(&record.pubkey)
96+
&& record.name == crate::managed_agents::POLLEN_DISPLAY_NAME
97+
})
98+
.map(|record| {
99+
let mut data = profile_reconcile_data(record, &personas);
100+
// Pin the effective relay while this workspace is active. Otherwise
101+
// a fast community switch could make a queued task for A run on B.
102+
data.relay_url =
103+
crate::relay::effective_agent_relay_url(&data.relay_url, &workspace_relay);
104+
(record.pubkey.clone(), data)
105+
})
106+
.collect())
107+
}
108+
109+
pub(crate) fn mark_profile_reconciled(app: &AppHandle, pubkey: &str) -> Result<(), String> {
110+
let state = app.state::<AppState>();
111+
let _store_guard = state
112+
.managed_agents_store_lock
113+
.lock()
114+
.map_err(|error| error.to_string())?;
115+
let store_path = crate::managed_agents::managed_agents_store_path(app)?;
116+
let queue_path = crate::migration::profile_reconcile_queue_path(&store_path);
117+
if !queue_path.exists() {
118+
return Ok(());
119+
}
120+
let mut pending = crate::migration::read_profile_reconcile_queue(&queue_path)?;
121+
pending.retain(|queued| queued != pubkey);
122+
crate::migration::write_profile_reconcile_queue(&queue_path, &pending)
123+
}
124+
52125
/// Reconcile an agent's kind:0 profile on the relay.
53126
///
54127
/// Queries the relay for the agent's existing profile and re-publishes if missing

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ pub async fn apply_workspace(
213213

214214
let state = restore_app.state::<AppState>();
215215
super::agents::provider_access::reconcile_on_workspace_apply(&restore_app, &state).await?;
216+
// The Bumble→Pollen migration may have renamed stopped agents. Reconcile
217+
// their relay profiles independently of runtime restore; successful writes
218+
// clear the durable queue, while failures retry on the next workspace apply.
219+
crate::managed_agents::spawn_pending_profile_reconciliations(&restore_app);
216220

217221
// Backfill this exact relay+owner scope only after the workspace has been
218222
// applied. Running at process boot would target the fallback relay and

‎desktop/src-tauri/src/managed_agents/restore.rs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,54 @@ pub async fn restore_managed_agents_on_launch(
472472
Ok(())
473473
}
474474

475+
pub(crate) fn spawn_pending_profile_reconciliations(app: &tauri::AppHandle) {
476+
let state = app.state::<AppState>();
477+
if !state
478+
.managed_agent_profile_reconcile_enabled
479+
.load(Ordering::Acquire)
480+
{
481+
return;
482+
}
483+
let items = match crate::commands::load_pending_profile_reconciliations(app) {
484+
Ok(items) => items,
485+
Err(error) => {
486+
eprintln!("buzz-desktop: failed to load pending profile reconciliations: {error}");
487+
return;
488+
}
489+
};
490+
491+
for (pubkey, data) in items {
492+
let reconcile_app = app.clone();
493+
tauri::async_runtime::spawn(async move {
494+
let state = reconcile_app.state::<AppState>();
495+
match crate::commands::reconcile_agent_profile(&state, &reconcile_app, &pubkey, &data)
496+
.await
497+
{
498+
Ok(())
499+
if state
500+
.managed_agent_profile_reconcile_enabled
501+
.load(Ordering::Acquire) =>
502+
{
503+
if let Err(error) =
504+
crate::commands::mark_profile_reconciled(&reconcile_app, &pubkey)
505+
{
506+
eprintln!(
507+
"buzz-desktop: failed to clear profile reconciliation for agent {pubkey}: {error}"
508+
);
509+
}
510+
}
511+
// Reconciliation can return Ok after the experiment is enabled
512+
// mid-flight; retain the queue item rather than treating that
513+
// intentional no-op as a successful relay write.
514+
Ok(()) => {}
515+
Err(error) => eprintln!(
516+
"buzz-desktop: profile reconciliation failed for agent {pubkey}: {error}"
517+
),
518+
}
519+
});
520+
}
521+
}
522+
475523
#[cfg(feature = "mesh-llm")]
476524
fn persist_restore_error(
477525
app: &tauri::AppHandle,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ pub use backfill::backfill_standalone_agents;
13751375
mod detach;
13761376
pub use detach::detach_directory_backed_teams;
13771377
mod pollen;
1378+
pub(crate) use pollen::{
1379+
profile_reconcile_queue_path, read_profile_reconcile_queue, write_profile_reconcile_queue,
1380+
};
13781381
mod team_suffix;
13791382
pub use team_suffix::strip_baked_team_instructions;
13801383

0 commit comments

Comments
 (0)