Skip to content

Commit 692fdaf

Browse files
author
Eva
committed
fix(desktop): export/card resolves through the 30179 overlay; snapshot respond_to falls back to instance fields
Relay-hosted agents made two gaps in the export/card resolvers user-visible: - Gap B: a relay-only agent (30179 head, never started on this device) has no disk record, so materialize_snapshot_bytes / card_mint_key_status / mint_agent_card failed with "agent not found" until first START. - Gap A: a follower device exported the stale disk snapshot instead of the effective 30179 config it actually runs. Fold the private-config overlay onto the disk list at all three resolver sites — the identical resolution the agent list already uses (resolved_records: applies patches to disk records AND synthesizes relay-only entries). Card mint then also inherits the correct live kind:0 avatar for free, since its existing profile fetch runs after resolution. Also give build_snapshot's respond_to/allowlist the same instance fallback parallelism already has: an overlay-materialized record carries its enforced respond_to only on the instance fields, so without the fallback a relay-hosted agent exported respond_to=None while actually enforcing an allowlist — a shared agent that behaves differently than advertised. Mode and list travel together (definition mode -> definition list, instance fallback -> instance list, never mixed). Deferred as fidelity-not-function (tracked for the relay-hosted cutover): kind:0 avatar hydration for ordinary JSON/PNG manifests, name_pool. Verified: cargo test in desktop/src-tauri — 2283 passed, 0 failed; clippy --tests clean; fmt clean. Co-authored-by: Eva <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz> Signed-off-by: Eva <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz>
1 parent d945edf commit 692fdaf

5 files changed

Lines changed: 207 additions & 2 deletions

File tree

‎desktop/src-tauri/src/commands/personas/card.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,14 @@ pub fn card_mint_key_status(
493493
.lock()
494494
.map_err(|e| e.to_string())?;
495495

496+
// Overlay-fold (kind:30179) so the status reflects the agent's effective
497+
// config — including relay-only agents with no local record yet.
496498
let instances = load_managed_agents(&app)?;
499+
let instances = state
500+
.private_managed_agent_overlay
501+
.lock()
502+
.map_err(|e| e.to_string())?
503+
.resolved_records(&instances);
497504
let definitions = load_agent_definitions(&app)?;
498505
let (record, _) = resolve_from_lists(&id, &instances, &definitions)?;
499506

@@ -549,7 +556,15 @@ pub async fn mint_agent_card(
549556
.lock()
550557
.map_err(|e| e.to_string())?;
551558

559+
// Overlay-fold (kind:30179) — same resolution as snapshot export and
560+
// the agent list: mint sees effective config, and a relay-only agent
561+
// resolves before its first START on this device.
552562
let instances = load_managed_agents(&app)?;
563+
let instances = state
564+
.private_managed_agent_overlay
565+
.lock()
566+
.map_err(|e| e.to_string())?
567+
.resolved_records(&instances);
553568
let definitions = load_agent_definitions(&app)?;
554569
let (record, is_definition) =
555570
resolve_from_lists(&id, &instances, &definitions).map(|(r, d)| (r.clone(), d))?;

‎desktop/src-tauri/src/commands/personas/snapshot.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,17 @@ pub(crate) async fn materialize_snapshot_bytes(
245245
.lock()
246246
.map_err(|e| e.to_string())?;
247247

248+
// Fold the kind:30179 overlay onto the disk records (and synthesize
249+
// relay-only entries) so export sees the EFFECTIVE config — the same
250+
// resolution the agent list uses. Raw disk here would export stale
251+
// values on a follower device and fail with "agent not found" for a
252+
// relay-only agent that has never been started on this device.
248253
let instances = load_managed_agents(&app)?;
254+
let instances = state
255+
.private_managed_agent_overlay
256+
.lock()
257+
.map_err(|e| e.to_string())?
258+
.resolved_records(&instances);
249259
let definitions = load_agent_definitions(&app)?;
250260
let (def_record, is_definition) = resolve_from_lists(&id, &instances, &definitions)
251261
.map(|(r, is_def)| (r.clone(), is_def))?;

‎desktop/src-tauri/src/commands/personas/snapshot/tests.rs‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,120 @@ fn definition_slug_resolves_to_definition_and_linked_instance_is_valid_memory_so
161161

162162
// ── Resolver edge cases ───────────────────────────────────────────────────
163163

164+
// ── Overlay-fold resolution (kind:30179) ──────────────────────────────────
165+
//
166+
// Export resolves against `resolved_records(load_managed_agents(..))`, not
167+
// raw disk. These tests pin the two behaviors that fold buys export:
168+
// a relay-only agent resolves before its first START on this device, and a
169+
// follower exports the effective relay config instead of stale disk values.
170+
171+
#[cfg(not(target_os = "windows"))]
172+
mod overlay_fold {
173+
use super::*;
174+
use crate::managed_agents::private_config_overlay::PrivateConfigOverlay;
175+
use buzz_core_pkg::private_managed_agent::{
176+
Payload, PrivateConfig, PrivateIdentity, FORMAT, VERSION,
177+
};
178+
use serde_json::{json, Map};
179+
180+
fn relay_payload(pubkey: &str, name: &str, prompt: &str) -> Payload {
181+
Payload {
182+
format: FORMAT.into(),
183+
version: VERSION,
184+
agent_pubkey: pubkey.into(),
185+
owner_pubkey: "11".repeat(32),
186+
generation: 1,
187+
previous_event_id: None,
188+
updated_at: "2026-08-07T00:00:00Z".into(),
189+
identity: PrivateIdentity {
190+
private_key_nsec: "nsec-test".into(),
191+
auth_tag: None,
192+
},
193+
config: PrivateConfig {
194+
relay_url: "wss://relay.example".into(),
195+
name: name.into(),
196+
persona_id: None,
197+
runtime: Some("goose".into()),
198+
model: Some("relay-model".into()),
199+
provider: None,
200+
system_prompt: Some(prompt.into()),
201+
parallelism: None,
202+
respond_to: Some("allowlist".into()),
203+
respond_to_allowlist: vec!["ab".repeat(32)],
204+
agent_command_override: None,
205+
agent_args: vec![],
206+
idle_timeout_seconds: None,
207+
max_turn_duration_seconds: None,
208+
env_vars: BTreeMap::new(),
209+
backend: json!({"type":"local"}),
210+
backend_agent_id: None,
211+
team_id: None,
212+
persona_name_in_team: None,
213+
relay_mesh: None,
214+
extra: Map::new(),
215+
},
216+
extensions: BTreeMap::new(),
217+
extra: Map::new(),
218+
}
219+
}
220+
221+
/// Gap B: a relay-only agent (30179 head, no disk record — never started
222+
/// on this device) must resolve for export once the disk list is folded
223+
/// through the overlay. Raw disk alone returns "agent not found".
224+
#[test]
225+
fn relay_only_agent_resolves_for_export_after_overlay_fold() {
226+
let mut overlay = PrivateConfigOverlay::default();
227+
overlay
228+
.insert(relay_payload("relay-only-pk", "Relay Only", "relay prompt"))
229+
.unwrap();
230+
let disk: Vec<ManagedAgentRecord> = vec![];
231+
232+
// Raw disk: not found (the pre-fix behavior).
233+
assert!(resolve_from_lists("relay-only-pk", &disk, &[]).is_err());
234+
235+
// Folded: resolves, with the relay config as the effective record.
236+
let folded = overlay.resolved_records(&disk);
237+
let (record, is_def) = resolve_from_lists("relay-only-pk", &folded, &[]).unwrap();
238+
assert!(!is_def);
239+
assert_eq!(record.name, "Relay Only");
240+
assert_eq!(record.system_prompt.as_deref(), Some("relay prompt"));
241+
}
242+
243+
/// Gap A: a follower device with a stale disk record must export the
244+
/// effective 30179 values, not the disk snapshot — and the exported
245+
/// manifest must advertise the enforced respond_to via the instance
246+
/// fallback (the overlay patch only populates instance fields).
247+
#[test]
248+
fn follower_exports_effective_relay_values_not_stale_disk() {
249+
use crate::managed_agents::agent_snapshot::build_snapshot;
250+
251+
let mut overlay = PrivateConfigOverlay::default();
252+
overlay
253+
.insert(relay_payload("follower-pk", "Fresh Name", "fresh prompt"))
254+
.unwrap();
255+
let mut stale = make_instance("follower-pk", "some-persona");
256+
stale.name = "Stale Name".into();
257+
stale.system_prompt = Some("stale prompt".into());
258+
259+
let folded = overlay.resolved_records(std::slice::from_ref(&stale));
260+
let (record, _) = resolve_from_lists("follower-pk", &folded, &[]).unwrap();
261+
assert_eq!(record.name, "Fresh Name");
262+
assert_eq!(record.system_prompt.as_deref(), Some("fresh prompt"));
263+
assert_eq!(record.model.as_deref(), Some("relay-model"));
264+
265+
let snapshot = build_snapshot(record, MemoryLevel::None, vec![], None);
266+
assert_eq!(
267+
snapshot.definition.system_prompt.as_deref(),
268+
Some("fresh prompt")
269+
);
270+
assert_eq!(snapshot.definition.respond_to.as_deref(), Some("allowlist"));
271+
assert_eq!(
272+
snapshot.definition.respond_to_allowlist,
273+
vec!["ab".repeat(32)]
274+
);
275+
}
276+
}
277+
164278
#[test]
165279
fn resolve_by_pubkey_finds_keyed_instance() {
166280
let inst = make_instance("pubkey-xyz", "my-agent");

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ pub fn build_snapshot(
194194
// Use definition-level fields (respond_to, allowlist, parallelism) for
195195
// portability — instance-level equivalents are spawn-time snapshots and
196196
// would be stale.
197+
//
198+
// respond_to falls back to the instance fields when the definition-level
199+
// mode is unset — same rationale as the parallelism fallback below. A
200+
// record materialized from a kind:30179 relay head carries its effective
201+
// respond_to/allowlist ONLY on the instance fields (the overlay patch
202+
// never populates the definition ones), so without this fallback a
203+
// relay-hosted agent would export `respond_to: None` while actually
204+
// enforcing an allowlist. Mode and list travel together: a definition
205+
// mode uses the definition list, the instance fallback uses the instance
206+
// list — never a mix.
207+
let (respond_to, respond_to_allowlist) = match record.definition_respond_to.clone() {
208+
Some(mode) => (Some(mode), record.definition_respond_to_allowlist.clone()),
209+
None => (
210+
Some(record.respond_to.as_str().to_string()),
211+
record.respond_to_allowlist.clone(),
212+
),
213+
};
197214
let definition = AgentSnapshotDefinition {
198215
name: record
199216
.display_name
@@ -205,8 +222,8 @@ pub fn build_snapshot(
205222
model: record.model.clone(),
206223
provider: record.provider.clone(),
207224
parallelism: record.definition_parallelism.or(Some(record.parallelism)),
208-
respond_to: record.definition_respond_to.clone(),
209-
respond_to_allowlist: record.definition_respond_to_allowlist.clone(),
225+
respond_to,
226+
respond_to_allowlist,
210227
name_pool: record.name_pool.clone(),
211228
idle_timeout_seconds: record.idle_timeout_seconds,
212229
max_turn_duration_seconds: record.max_turn_duration_seconds,

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,55 @@ fn definition_fields_present_in_snapshot() {
540540
assert!(!snapshot.definition.respond_to_allowlist.is_empty());
541541
}
542542

543+
/// A definition-level mode must carry the DEFINITION list, never the
544+
/// instance list — mode and list travel together (`minimal_record` has
545+
/// distinct values on each level, so a mix-up is detectable).
546+
#[test]
547+
fn definition_respond_to_keeps_definition_list_not_instance_list() {
548+
let record = minimal_record();
549+
let snapshot = build_snapshot(&record, MemoryLevel::None, vec![], None);
550+
assert_eq!(snapshot.definition.respond_to.as_deref(), Some("allowlist"));
551+
assert_eq!(snapshot.definition.respond_to_allowlist, vec!["abc123def"]);
552+
}
553+
554+
/// A record materialized from a kind:30179 relay head carries its effective
555+
/// respond_to/allowlist only on the INSTANCE fields. Export must fall back
556+
/// to them (like parallelism already does) instead of advertising
557+
/// `respond_to: None` while the agent enforces an allowlist.
558+
#[test]
559+
fn respond_to_falls_back_to_instance_fields_when_definition_unset() {
560+
let mut record = minimal_record();
561+
record.definition_respond_to = None;
562+
record.definition_respond_to_allowlist = vec![];
563+
record.respond_to = RespondTo::Allowlist;
564+
record.respond_to_allowlist = vec!["ef".repeat(32)];
565+
566+
let snapshot = build_snapshot(&record, MemoryLevel::None, vec![], None);
567+
assert_eq!(snapshot.definition.respond_to.as_deref(), Some("allowlist"));
568+
assert_eq!(
569+
snapshot.definition.respond_to_allowlist,
570+
vec!["ef".repeat(32)]
571+
);
572+
}
573+
574+
/// The instance fallback exports the enforced default explicitly rather
575+
/// than `None` — an owner-only agent advertises owner-only.
576+
#[test]
577+
fn respond_to_fallback_exports_explicit_owner_only_default() {
578+
let mut record = minimal_record();
579+
record.definition_respond_to = None;
580+
record.definition_respond_to_allowlist = vec![];
581+
record.respond_to = RespondTo::default();
582+
record.respond_to_allowlist = vec![];
583+
584+
let snapshot = build_snapshot(&record, MemoryLevel::None, vec![], None);
585+
assert_eq!(
586+
snapshot.definition.respond_to.as_deref(),
587+
Some("owner-only")
588+
);
589+
assert!(snapshot.definition.respond_to_allowlist.is_empty());
590+
}
591+
543592
#[test]
544593
fn profile_fields_present_in_snapshot() {
545594
let record = minimal_record();

0 commit comments

Comments
 (0)