Prevent runtime logos from replacing persona avatars

This commit is contained in:
klopez4212
2026-06-22 16:21:02 +01:00
parent 9c740c0dda
commit 8d28ee1ed6
7 changed files with 215 additions and 43 deletions

View File

@@ -6,12 +6,12 @@ use tauri::{AppHandle, State};
use crate::{
app_state::AppState,
managed_agents::{
build_managed_agent_summary, default_agent_workdir, find_managed_agent_mut,
known_acp_runtime, load_managed_agents, load_personas, managed_agent_avatar_url,
missing_command_message, normalize_agent_args, resolve_command,
AgentModelInfo, AgentModelsResponse, ManagedAgentRecord, UpdateManagedAgentRequest,
UpdateManagedAgentResponse, build_managed_agent_summary, default_agent_workdir,
find_managed_agent_mut, known_acp_runtime, load_managed_agents, load_personas,
managed_agent_avatar_url, missing_command_message, normalize_agent_args, resolve_command,
resolve_effective_prompt_model_provider, save_managed_agents, sync_managed_agent_processes,
try_regenerate_nest, AgentModelInfo, AgentModelsResponse, UpdateManagedAgentRequest,
UpdateManagedAgentResponse,
try_regenerate_nest,
},
relay::{relay_ws_url_with_override, sync_managed_agent_profile},
util::now_iso,
@@ -23,6 +23,27 @@ fn trim_optional(value: Option<String>) -> Option<String> {
.filter(|s| !s.is_empty())
}
fn is_persona_runtime_avatar(record: &ManagedAgentRecord, avatar_url: &str) -> bool {
record.persona_id.is_some()
&& managed_agent_avatar_url(&record.agent_command)
.as_deref()
.is_some_and(|runtime_avatar_url| runtime_avatar_url == avatar_url.trim())
}
fn profile_sync_avatar_url(record: &ManagedAgentRecord) -> Option<String> {
record
.avatar_url
.clone()
.filter(|avatar_url| !is_persona_runtime_avatar(record, avatar_url))
.or_else(|| {
if record.persona_id.is_none() {
managed_agent_avatar_url(&record.agent_command)
} else {
None
}
})
}
/// Query available models from an agent via `buzz-acp models --json`.
///
/// Spawns a short-lived subprocess (no relay connection needed). The subprocess
@@ -270,10 +291,7 @@ pub async fn update_managed_agent(
let avatar_url = if avatar_changed || record.avatar_url_cleared {
record.avatar_url.clone()
} else {
record
.avatar_url
.clone()
.or_else(|| managed_agent_avatar_url(&record.agent_command))
profile_sync_avatar_url(record)
};
let auth_tag = record.auth_tag.clone();
Some((agent_keys, relay_url, display_name, avatar_url, auth_tag))

View File

@@ -4,15 +4,15 @@ use tauri::{AppHandle, State};
use crate::{
app_state::AppState,
managed_agents::{
BackendKind, BackendProviderInfo, CreateManagedAgentRequest, CreateManagedAgentResponse,
DEFAULT_ACP_COMMAND, DEFAULT_AGENT_PARALLELISM, DEFAULT_AGENT_TURN_TIMEOUT_SECONDS,
ManagedAgentLogResponse, ManagedAgentRecord, ManagedAgentSummary, RelayMeshConfig,
build_managed_agent_summary, discover_provider_candidates, ensure_persona_is_active,
find_managed_agent_mut, invoke_provider, load_managed_agents, load_personas,
managed_agent_avatar_url, managed_agent_log_path, managed_agents_base_dir,
normalize_agent_args, provider_deploy, read_log_tail, resolve_provider_binary,
save_managed_agents, start_managed_agent_process, stop_managed_agent_process,
sync_managed_agent_processes, try_regenerate_nest, validate_provider_config, BackendKind,
BackendProviderInfo, CreateManagedAgentRequest, CreateManagedAgentResponse,
ManagedAgentLogResponse, ManagedAgentRecord, ManagedAgentSummary, RelayMeshConfig,
DEFAULT_ACP_COMMAND, DEFAULT_AGENT_PARALLELISM, DEFAULT_AGENT_TURN_TIMEOUT_SECONDS,
sync_managed_agent_processes, try_regenerate_nest, validate_provider_config,
},
relay::{relay_ws_url_with_override, sync_managed_agent_profile},
util::now_iso,
@@ -60,6 +60,7 @@ fn resolve_created_avatar_url(
requested_avatar_url: Option<&str>,
persona_avatar_url: Option<String>,
agent_command: &str,
use_command_fallback: bool,
) -> Option<String> {
requested_avatar_url
.and_then(trim_to_optional_string)
@@ -68,13 +69,30 @@ fn resolve_created_avatar_url(
.as_deref()
.and_then(trim_to_optional_string)
})
.or_else(|| managed_agent_avatar_url(agent_command))
.or_else(|| {
if use_command_fallback {
managed_agent_avatar_url(agent_command)
} else {
None
}
})
}
fn is_retired_fizz_data_url(persona_id: Option<&str>, avatar_url: &str) -> bool {
persona_id == Some("builtin:fizz") && avatar_url.trim_start().starts_with("data:image/")
}
fn is_command_avatar_for_persona(
persona_id: Option<&str>,
agent_command: &str,
avatar_url: &str,
) -> bool {
persona_id.is_some()
&& managed_agent_avatar_url(agent_command)
.as_deref()
.is_some_and(|command_avatar_url| command_avatar_url == avatar_url.trim())
}
fn filter_retired_fizz_avatar(
persona_id: Option<&str>,
avatar_url: Option<String>,
@@ -522,6 +540,7 @@ pub async fn create_managed_agent(
input.avatar_url.as_deref(),
persona_avatar_url,
&agent_command,
requested_persona_id.is_none(),
);
let record = crate::managed_agents::ManagedAgentRecord {
@@ -903,10 +922,17 @@ fn resolve_legacy_avatar(
persona_avatar: Option<String>,
relay_picture: Option<String>,
agent_command: &str,
use_command_fallback: bool,
) -> String {
persona_avatar
.or(relay_picture)
.or_else(|| managed_agent_avatar_url(agent_command))
.or_else(|| {
if use_command_fallback {
managed_agent_avatar_url(agent_command)
} else {
None
}
})
.unwrap_or_default()
}
@@ -924,15 +950,13 @@ fn should_skip_legacy_command_avatar(
/// Reconcile an agent's kind:0 profile on the relay.
///
/// Queries the relay for the agent's existing profile and re-publishes if missing
/// or stale (display_name or picture mismatch). This is fire-and-forget — errors
/// are returned to the caller for logging but never block agent startup.
/// or stale. This is fire-and-forget — errors are returned to the caller for
/// logging but never block agent startup.
///
/// For legacy records (pre-PR-921) where `avatar_url` is `None`, this function
/// backfills via `resolve_legacy_avatar` — preferring the persona record's avatar
/// over the relay's `picture`, since the old code may have corrupted the relay
/// profile — and persists the updated record. After backfill, normal
/// reconciliation proceeds.
///
/// Query and publish both target the agent's stored `relay_url` so that, under
/// an active workspace relay override, reconciliation reads and writes the same
/// relay the agent's profile actually lives on.
@@ -957,6 +981,12 @@ pub(crate) async fn reconcile_agent_profile(
.avatar_url
.as_deref()
.is_some_and(|url| is_retired_fizz_data_url(data.persona_id.as_deref(), url));
let stored_avatar_was_command_fallback = stored_avatar.as_deref().is_some_and(|url| {
is_command_avatar_for_persona(data.persona_id.as_deref(), &data.agent_command, url)
});
let stored_avatar = stored_avatar.filter(|url| {
!is_command_avatar_for_persona(data.persona_id.as_deref(), &data.agent_command, url)
});
let expected_avatar = if data.avatar_url_cleared && stored_avatar.is_none() {
None
} else {
@@ -982,6 +1012,21 @@ pub(crate) async fn reconcile_agent_profile(
.is_some_and(|url| is_retired_fizz_data_url(data.persona_id.as_deref(), url));
let relay_picture =
filter_retired_fizz_avatar(data.persona_id.as_deref(), relay_picture_raw);
let relay_picture_was_command_fallback =
relay_picture.as_deref().is_some_and(|url| {
is_command_avatar_for_persona(
data.persona_id.as_deref(),
&data.agent_command,
url,
)
});
let relay_picture = relay_picture.filter(|url| {
!is_command_avatar_for_persona(
data.persona_id.as_deref(),
&data.agent_command,
url,
)
});
let skip_command_fallback = should_skip_legacy_command_avatar(
stored_avatar_was_retired_fizz,
@@ -992,7 +1037,12 @@ pub(crate) async fn reconcile_agent_profile(
let backfilled = if skip_command_fallback {
String::new()
} else {
resolve_legacy_avatar(persona_avatar, relay_picture, &data.agent_command)
resolve_legacy_avatar(
persona_avatar,
relay_picture,
&data.agent_command,
data.persona_id.is_none(),
)
};
// Persist the backfilled avatar so this migration only runs once,
@@ -1000,6 +1050,8 @@ pub(crate) async fn reconcile_agent_profile(
// current profile image to backfill.
let should_persist_avatar = stored_avatar_was_retired_fizz
|| relay_picture_was_retired_fizz
|| stored_avatar_was_command_fallback
|| relay_picture_was_command_fallback
|| (!backfilled.is_empty()
&& data.avatar_url.as_deref() != Some(backfilled.as_str()));
if should_persist_avatar {

View File

@@ -48,6 +48,7 @@ fn created_avatar_prefers_explicit_input() {
Some(" https://x/input.png "),
Some("https://x/persona.png".to_string()),
"goose",
true,
);
assert_eq!(resolved.as_deref(), Some("https://x/input.png"));
@@ -55,8 +56,12 @@ fn created_avatar_prefers_explicit_input() {
#[test]
fn created_avatar_uses_persona_before_command_fallback() {
let resolved =
resolve_created_avatar_url(None, Some(" https://x/persona.png ".to_string()), "goose");
let resolved = resolve_created_avatar_url(
None,
Some(" https://x/persona.png ".to_string()),
"goose",
true,
);
assert_eq!(resolved.as_deref(), Some("https://x/persona.png"));
}
@@ -65,11 +70,18 @@ fn created_avatar_uses_persona_before_command_fallback() {
fn created_avatar_uses_command_fallback_without_input_or_persona() {
use crate::managed_agents::managed_agent_avatar_url;
let resolved = resolve_created_avatar_url(None, None, "goose");
let resolved = resolve_created_avatar_url(None, None, "goose", true);
assert_eq!(resolved, managed_agent_avatar_url("goose"));
}
#[test]
fn created_persona_avatar_does_not_use_command_fallback() {
let resolved = resolve_created_avatar_url(None, None, "goose", false);
assert_eq!(resolved, None);
}
#[test]
fn retired_fizz_data_url_is_treated_as_absent() {
assert_eq!(
@@ -169,6 +181,7 @@ fn legacy_avatar_prefers_persona_over_corrupted_relay_picture() {
Some("https://x/persona.png".to_string()),
Some("https://x/default-icon.png".to_string()),
"goose",
false,
);
assert_eq!(resolved, "https://x/persona.png");
@@ -176,7 +189,12 @@ fn legacy_avatar_prefers_persona_over_corrupted_relay_picture() {
#[test]
fn legacy_avatar_falls_back_to_relay_picture_without_persona() {
let resolved = resolve_legacy_avatar(None, Some("https://x/relay.png".to_string()), "goose");
let resolved = resolve_legacy_avatar(
None,
Some("https://x/relay.png".to_string()),
"goose",
false,
);
assert_eq!(resolved, "https://x/relay.png");
}
@@ -185,18 +203,47 @@ fn legacy_avatar_falls_back_to_relay_picture_without_persona() {
fn legacy_avatar_falls_back_to_command_icon_when_no_persona_or_relay() {
use crate::managed_agents::managed_agent_avatar_url;
let resolved = resolve_legacy_avatar(None, None, "goose");
let resolved = resolve_legacy_avatar(None, None, "goose", true);
assert_eq!(resolved, managed_agent_avatar_url("goose").unwrap());
}
#[test]
fn legacy_avatar_empty_when_nothing_resolves() {
let resolved = resolve_legacy_avatar(None, None, "totally-unknown-command");
let resolved = resolve_legacy_avatar(None, None, "totally-unknown-command", true);
assert!(resolved.is_empty());
}
#[test]
fn legacy_persona_avatar_does_not_use_command_fallback() {
let resolved = resolve_legacy_avatar(None, None, "goose", false);
assert!(resolved.is_empty());
}
#[test]
fn detects_command_avatar_for_persona_agents() {
let command_avatar = crate::managed_agents::managed_agent_avatar_url("goose")
.expect("goose avatar should resolve");
assert!(is_command_avatar_for_persona(
Some("builtin:fizz"),
"goose",
&command_avatar,
));
assert!(!is_command_avatar_for_persona(
None,
"goose",
&command_avatar,
));
assert!(!is_command_avatar_for_persona(
Some("builtin:fizz"),
"goose",
"https://x/fizz.png",
));
}
#[test]
fn legacy_avatar_skips_command_icon_for_retired_stored_fizz_avatar() {
assert!(should_skip_legacy_command_avatar(true, false, None, None));

View File

@@ -5,6 +5,7 @@ import { isManagedAgentActive } from "@/features/agents/lib/managedAgentControlA
import { useUserProfileQuery } from "@/features/profile/hooks";
import { useFeedbackToasts } from "@/shared/hooks/useToastEffect";
import { useFileImportZone } from "@/shared/hooks/useFileImportZone";
import { isKnownRuntimeAvatarUrl } from "@/shared/lib/runtimeAvatar";
import type { AgentPersona, ManagedAgent } from "@/shared/api/types";
import {
DropdownMenu,
@@ -253,8 +254,8 @@ function AgentPersonaCard({
const profileQuery = useUserProfileQuery(agent?.pubkey);
const avatarUrl = agent
? firstAvatarUrl(
profileQuery.data?.avatarUrl,
agent.avatarUrl,
withoutRuntimeAvatar(profileQuery.data?.avatarUrl),
withoutRuntimeAvatar(agent.avatarUrl),
persona.avatarUrl,
)
: persona.avatarUrl;
@@ -314,6 +315,14 @@ function firstAvatarUrl(
return null;
}
function withoutRuntimeAvatar(
avatarUrl: string | null | undefined,
): string | null {
const trimmed = avatarUrl?.trim();
if (!trimmed || isKnownRuntimeAvatarUrl(trimmed)) return null;
return trimmed;
}
function SectionHeader({
fileInputRef,
handleFileChange,

View File

@@ -68,16 +68,15 @@ import { useProfileFieldBuckets } from "@/features/profile/ui/UserProfilePanelFi
import { submitProfilePersonaDialog } from "@/features/profile/ui/UserProfilePanelPersonaSubmit";
import { UserProfilePersonaDialogs } from "@/features/profile/ui/UserProfilePersonaDialogs";
import {
buildPersonaDraftProfile,
deriveProfileChannels,
PROFILE_PANEL_VIEW_TITLES,
type ProfilePanelView,
resolveAgentInstruction,
resolveOwnerHandle,
resolvePanelProfile,
resolveProfileDisplayName,
type UserProfilePanelProps,
useRetainedPersona,
withProfileAvatarFallback,
} from "@/features/profile/ui/UserProfilePanelUtils";
import { useUserStatusQuery } from "@/features/user-status/hooks";
import { useAgentSession } from "@/shared/context/AgentSessionContext";
@@ -225,16 +224,11 @@ export function UserProfilePanel({
const unfollowMutation = useUnfollowMutation(currentPubkey);
const { onOpenAgentSession } = useAgentSession();
const { goChannel } = useAppNavigation();
const profile = React.useMemo(() => {
const baseProfile =
profileQuery.data ??
(resolvedPersona ? buildPersonaDraftProfile(resolvedPersona) : undefined);
return withProfileAvatarFallback(
baseProfile,
managedAgent?.avatarUrl,
resolvedPersona?.avatarUrl,
);
}, [managedAgent?.avatarUrl, profileQuery.data, resolvedPersona]);
const profile = resolvePanelProfile({
managedAgent,
persona: resolvedPersona,
profile: profileQuery.data,
});
const presenceStatus = pubkeyLower
? presenceQuery.data?.[pubkeyLower]
: undefined;

View File

@@ -9,6 +9,7 @@ import type {
UpdateManagedAgentInput,
} from "@/shared/api/types";
import { normalizePubkey } from "@/shared/lib/pubkey";
import { isKnownRuntimeAvatarUrl } from "@/shared/lib/runtimeAvatar";
export type ProfileChannelLink = {
id: string;
@@ -135,6 +136,24 @@ export function buildPersonaDraftProfile(persona: AgentPersona): Profile {
};
}
export function resolvePanelProfile({
managedAgent,
persona,
profile,
}: {
managedAgent: ManagedAgent | undefined;
persona: AgentPersona | undefined;
profile: Profile | undefined;
}): Profile | undefined {
const baseProfile =
profile ?? (persona ? buildPersonaDraftProfile(persona) : undefined);
return withProfileAvatarFallback(
baseProfile,
[managedAgent?.avatarUrl, persona?.avatarUrl],
{ ignoreRuntimeAvatars: Boolean(persona ?? managedAgent?.personaId) },
);
}
export function resolveProfileAvatarUrl(
...candidates: Array<string | null | undefined>
): string | null {
@@ -147,17 +166,37 @@ export function resolveProfileAvatarUrl(
export function withProfileAvatarFallback(
profile: Profile | undefined,
...fallbackAvatarUrls: Array<string | null | undefined>
fallbackAvatarUrls: Array<string | null | undefined>,
options: { ignoreRuntimeAvatars?: boolean } = {},
): Profile | undefined {
const avatarUrl = resolveProfileAvatarUrl(
const profileAvatarUrl = normalizeProfileFallbackAvatarUrl(
profile?.avatarUrl,
...fallbackAvatarUrls,
options.ignoreRuntimeAvatars,
);
const avatarUrl = resolveProfileAvatarUrl(
profileAvatarUrl,
...fallbackAvatarUrls.map((avatarUrl) =>
normalizeProfileFallbackAvatarUrl(
avatarUrl,
options.ignoreRuntimeAvatars,
),
),
);
return profile && avatarUrl !== profile.avatarUrl
? { ...profile, avatarUrl }
: profile;
}
function normalizeProfileFallbackAvatarUrl(
avatarUrl: string | null | undefined,
ignoreRuntimeAvatars = false,
): string | null {
const trimmed = avatarUrl?.trim();
if (!trimmed) return null;
if (ignoreRuntimeAvatars && isKnownRuntimeAvatarUrl(trimmed)) return null;
return trimmed;
}
export function resolveProfileDisplayName({
persona,
profile,

View File

@@ -0,0 +1,13 @@
const RUNTIME_AVATAR_URLS = new Set([
"https://goose-docs.ai/img/logo_dark.png",
"https://anthropic.gallerycdn.vsassets.io/extensions/anthropic/claude-code/2.1.77/1773707456892/Microsoft.VisualStudio.Services.Icons.Default",
"https://openai.gallerycdn.vsassets.io/extensions/openai/chatgpt/26.5313.41514/1773706730621/Microsoft.VisualStudio.Services.Icons.Default",
"https://raw.githubusercontent.com/block/buzz/refs/heads/main/crates/buzz-agent/buzz-agent.png",
]);
export function isKnownRuntimeAvatarUrl(
avatarUrl: string | null | undefined,
): boolean {
const trimmed = avatarUrl?.trim();
return trimmed ? RUNTIME_AVATAR_URLS.has(trimmed) : false;
}