Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/experts): keep an owner-set avatar across roster seeds (#14803)

Reinier van der Leera8594ab150fd
diff --git a/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py b/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
index 7e6c8ab895..1209b1135b 100644
--- a/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
+++ b/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
@@ -4534,9 +4534,10 @@ async def test_seed_backfills_presentation_fields_onto_hired_copies(
assert hired.expert.avatar_url is None
assert hired.expert.bio is None
assert hired.expert.skills == []
- # The owner's own skill edit after hire, which no re-seed may touch.
+ # The owner's own edits after hire, which no re-seed may touch.
await prisma.models.Expert.prisma().update(
- where={"id": hired.expert.id}, data={"skills": ["Customer interviews"]}
+ where={"id": hired.expert.id},
+ data={"skills": ["Customer interviews"], "avatarUrl": "/avatars/mine.svg"},
)
entry: seed.RosterEntry = {
@@ -4562,19 +4563,72 @@ async def test_seed_backfills_presentation_fields_onto_hired_copies(
refreshed = await experts_db.get_expert(test_user.id, hired.expert.id)
assert refreshed is not None
- assert refreshed.avatar_url == "/experts/maria.svg"
assert refreshed.job_title == "Marketing Manager"
assert refreshed.tagline == "Refreshed tagline"
assert refreshed.bio == "Maria is a senior marketing strategist."
assert refreshed.categories == ["marketing"]
- # A user's rename and skill list survive the refresh: the template's
- # skills neither replace the owner's nor get merged back into them.
+ # A user's rename, skill list and avatar survive the refresh: the
+ # template's skills neither replace the owner's nor get merged back into
+ # them, and its avatar never reaches a hire at all.
assert refreshed.skills == ["Customer interviews"]
+ assert refreshed.avatar_url == "/avatars/mine.svg"
assert refreshed.name == "My Maria"
# Day one stays on the template; the backfill must not copy it onto hires.
assert refreshed.day_one == []
[email protected](loop_scope="session")
+async def test_seed_roster_keeps_an_owner_set_avatar(
+ server: SpinTestServer, test_user, monkeypatch
+):
+ """An owner picks their hire's avatar, and no re-seed may take it back.
+
+ Driven through ``seed_roster`` rather than the helper, so a later pass
+ that pushes avatars separately fails here rather than silently resetting
+ every hire that ever set one."""
+ entry: seed.RosterEntry = {
+ "name": f"Maria {uuid.uuid4().hex[:8]}",
+ "role": "Marketing",
+ "job_title": "Marketing Generalist",
+ "tagline": "Does all of marketing.",
+ "avatar_url": "/experts/maria.svg",
+ "bio": "Maria is a generalist marketer.",
+ "bundled_skills": [],
+ "categories": ["marketing"],
+ "identity": "You are Maria, a generalist.",
+ "voice_preferences": "Clear and confident.",
+ "voice_samples": [],
+ "boundaries": "Never invent customer evidence.",
+ "day_one": [],
+ "preloads": [],
+ "routines": [],
+ }
+ monkeypatch.setattr(seed, "ROSTER", [entry])
+ (template_id,) = await seed.seed_roster()
+ _seeded_template_ids.append(template_id)
+ hired = await experts_db.hire_expert(test_user.id, template_id, None)
+ assert hired.expert.avatar_url == entry["avatar_url"]
+ await experts_db.update_avatar(test_user.id, hired.expert.id, "/avatars/mine.svg")
+
+ monkeypatch.setattr(
+ seed,
+ "ROSTER",
+ [
+ {
+ **entry,
+ "avatar_url": "/experts/maria-refreshed.svg",
+ "tagline": "Takes a keyword from brief to article.",
+ }
+ ],
+ )
+ assert await seed.seed_roster() == [template_id]
+
+ refreshed = await experts_db.get_expert(test_user.id, hired.expert.id)
+ assert refreshed is not None
+ assert refreshed.avatar_url == "/avatars/mine.svg"
+ assert refreshed.tagline == "Takes a keyword from brief to article."
+
+
# ─── Pods ──────────────────────────────────────────────────────────────
diff --git a/autogpt_platform/backend/backend/api/features/experts/seed.py b/autogpt_platform/backend/backend/api/features/experts/seed.py
index 7b31717c0f..918542a78d 100644
--- a/autogpt_platform/backend/backend/api/features/experts/seed.py
+++ b/autogpt_platform/backend/backend/api/features/experts/seed.py
@@ -11,7 +11,7 @@ from listing slugs and
all are validated before any template is mutated, so
``backend.api.features.store.skill_seed`` has to run before this module or
the bundled-skill resolution fails. Each upsert also refreshes the
-presentation fields (avatar, job title, tagline, bio, categories) on experts already
+presentation fields (job title, tagline, bio, categories) on experts already
hired from that template, so roster changes reach existing users and not just
new hires.
"""
@@ -2497,10 +2497,10 @@ async def _backfill_hired_copies(template: prisma.models.Expert) -> int:
A hire copies the template row, so roster updates would otherwise only
ever reach new hires and everyone who hired earlier would keep a blank
- avatar/job title/tagline/bio/categories forever. ``name`` is deliberately excluded —
+ job title/tagline/bio/categories forever. ``name`` is deliberately excluded —
users may have renamed their hire — as are ``role``/``identity``, which
- drive live persona behaviour, and ``skills``, which the owner edits after
- hire.
+ drive live persona behaviour, and ``skills`` and ``avatarUrl``, which the
+ owner edits after hire (``update_avatar``).
A rescoped template (see ``RESCOPED_TEMPLATES``) is the exception: there
the persona moves with the presentation, in one write, so a hire can never
@@ -2515,7 +2515,6 @@ async def _backfill_hired_copies(template: prisma.models.Expert) -> int:
"isTemplate": False,
}
data: prisma.types.ExpertUpdateManyMutationInput = {
- "avatarUrl": template.avatarUrl,
"jobTitle": template.jobTitle,
"tagline": template.tagline,
"bio": template.bio,