Skip to content

fix(avatars): keep a template's shipped avatar instead of storing it as a default - #4754

Merged
vybe merged 4 commits into
devfrom
feature/4750-keep-shipped-avatar
Nov 24, 2026
Merged

vybe merged 4 commits into
devfrom
feature/4750-keep-shipped-avatar

Conversation

@vybe

@vybe vybe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Closes #4750. Closes #4609. Independent PR on dev. Draft until validated.

What

  • A template's shipped avatar is kept (src/backend/services/agent_service/crud.py). When a local: or github: template ships avatar.webp / avatar.png and the file is installed, the agent's avatar is stored the way a chosen image is, not as a default. "Generate Default Avatars" leaves it alone, and the Workspace card shows it (bug(workspace): a GitHub template's bundled avatar still shows as initials in the Workspace #4609).
  • Only a written file is stamped. Both installers now report whether they wrote the file; a prompt-only template, an oversized or corrupt image, a failed re-encode or a refused destination leaves the row as it was before (a default, or nothing).
  • No 0-byte file on a failed re-encode: both installers re-encode before opening the destination.
  • Docs: docs/memory/feature-flows/agent-avatars.md says a shipped image is kept, how an owner replaces it, and what happens to existing agents.

No schema change, no frontend change, no new endpoint.

Rulings carried (orchestrator, on the operator's behalf — plan file)

  • T1 close bug(workspace): a GitHub template's bundled avatar still shows as initials in the Workspace #4609 here. T3 no schema change (no avatar_source column).
  • T2 existing agents are left as they are: the database cannot tell a shipped image stored as a default from a generated one, and after one generation the shipped image is gone. Release-note line is in the flow doc.
  • T4 a local: template that ships an image without an avatar_prompt still installs nothing: a follow-up, not this PR.
  • The issue's "upload" wording was wrong: there is no avatar upload route in the core. An owner replaces a shipped image with Generate or Delete for that agent.

Review + security

/review (Opus 5.5, report-only, a run that did not build it): MERGEABLE. Only two places read the flag (default generation and the Workspace card); nothing that depends on variant or reference files is switched on by it. Fixed after review in 45b10b3b4 (the github: installer returns whether it wrote; no stamp on a refused path) and e84cb3954 (an end-to-end #4609 test through agent creation to the Workspace card, red with the crud.py change reverted). The enterprise module was grepped read-only: no reader breaks. Security: a manual pass over the diff, no finding; the full /cso skill was not run.

Tests

test_1484_create_agent_characterization.py 92, test_ent79_portal_exposure.py 75, test_1173_hub_display_avatar.py 13, test_ent1117_s8_path_barriers.py 196, each file in its own process on the engineer. Known and not from this change: test_portal_token_roundtrip_and_fence and test_signin_verify_happy_path fail on dev when the two changed files share a process (reproduced on the base, in file order and under seed 12345). Not run on the engineer: the full unit island and the repo-wide guard set; CI's run is the first full one.

Before merge

  • Not tested on a live stack. One look: create an agent from a template that ships an avatar, press Generate Default Avatars, confirm the image stays and the Workspace sidebar shows it.
  • Release notes: applies to agents created on this version or later; on existing installs default generation still replaces template images.

Handoffs

Three follow-ups, texts kept by the orchestrator, not filed: a local: template image without avatar_prompt installs nothing; Regenerate answers 404 for a shipped image (no reference file); the avatar write is not atomic (a failed write can leave a truncated file).

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 4 commits November 24, 2026 03:47
…as a default (#4750)

A template-shipped image was stamped `is_default_avatar=1`, so Generate
Default Avatars overwrote it and the Workspace showed initials (#4609).
Both install paths (`local:` and `github:`) now stamp a file that was
actually written with `set_avatar_identity` (=0), the writer the hub
avatar already uses for a chosen image. A `local:` template that declares
`avatar_prompt` but installs no file (none shipped, oversized, corrupt,
barrier refusal) keeps today's default seed.

`_install_bundled_avatar` now returns whether it wrote a file. Both
installers re-encode before opening the destination, so a failed
`optimize_avatar` no longer leaves a 0-byte `{name}.webp`.

Red on c62030c before the fix: test_4750_bundled_avatar_installed_as_kept,
test_4750_nonfatal_kept_stamp_failure, test_4570_github_bundled_avatar_is_stamped_as_kept,
test_4570_github_bundled_avatar_without_prompt_still_stamped, and both
test_4750_failed_reencode_leaves_no_empty_* (0-byte file present).
No schema change. Agents created before this keep their =1 rows.

Closes #4750
Closes #4609

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Flow doc: both install paths stamp a written file with set_avatar_identity,
the prompt-only seed stays a default, the replace path is Generate or Delete
(no upload; Regenerate 404s with no _ref.png), and agents created before the
fix are not migrated, with a release-note line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… was written (#4750)

`_install_bundled_avatar_bytes` now returns whether it wrote the file, like
its `local:` twin, and the `github:` caller stamps the avatar as kept only on
True. A destination the avatar store's path barrier refuses used to fall
through to the stamp with no file on disk, handing the Workspace card a URL
that 404s instead of showing initials (review note I2).

Red before the fix: test_4750_refused_github_avatar_path_is_not_stamped
(set_avatar_identity called once) and
test_4750_github_installer_reports_whether_it_wrote (returned None).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rkspace card (#4750)

test_4609_shipped_avatar_reaches_the_workspace_card drives
create_agent_internal with a `local:` template that ships avatar.png. The
harness's avatar writers are bound to the real facade over a tmp sqlite, so
crud's own choice of writer lands in a real agent_ownership row, and the real
portal roster then reads the card. The test never calls a writer itself
(review note I1: the ent79 test stamps through set_avatar_identity directly
and stays green with the fix reverted).

Mutation: with crud.py reverted to c62030c this test goes red
(`avatar_url` None: "shipped image shown as initials"); restored
byte-identical, green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trinity-ability

Copy link
Copy Markdown
Contributor

/validate-pr — APPROVE

Run BZQbA3yxFIo6TJWTcxOLbw (chain-ent1373-4750-validate). Head e84cb3954, lane B (service + tests + docs, no schema). I did not run the build, the fix or the review for this PR. Report only: no commits.

Check Result
Base / size / commits ✅ dev, 4 files, conventional commits
Closing keywords ✅ Closes #4750, Closes #4609 (same repo, both resolve, both type-bug P2)
Journey Impact ✅ check_journey_impact.py exit 0. No declaration is allowed for now; Journey Impact: none: <reason> would be better
Security greps, file modes, host paths ✅ clean
Config / build packaging ➖ no new env var or package
Audit rows (§4.11) ➖ no gated handler touched
Cross-surface drift (§5.5) ➖ nothing printed: no twin file, no router
Merge gate ✅ Tier 1 green on head (regression diff, pytest head seed 12345, schema-parity, verify-non-root, CodeQL ×2, gitleaks). dev-ci success
Structural review ✅ /review MERGEABLE (a separate run)
Product fit ✅ both issues approved (status-ready). Core avatar behaviour with no entitlement angle, and no doctrine line broken

Mutation sweep on crud.py (14 mutants)

Each mutant was run against test_1484, test_ent79 and test_1173 in one process. The two known test_ent79 failures from sharing a process appear in every run and are ignored.

  • Killed (10): always-kept or never-kept on local: · stamp kept on github: even when nothing was written · github: stamp back to set_default_avatar · an exception counted as installed (on both paths) · a missing or oversized file reported as written · re-encode moved back inside open() (on both paths) · a refused github: destination reported as written.
    • The cases you asked about: prompt-only, oversized and failed re-encode each have their own red test. A corrupt image is caught by the existing test_2693_corrupt_bundled_avatar_keeps_prompt_seed.
  • Survived (4):
    • ⚠️ On the local: path, a refused destination (avatar_path_or_none → None) and the template-root traversal refusal can both be flipped to return True with every test green. The code is correct and both paths are hard to reach: the agent name is validated and the template dir is already contained. But the "refused destination → no stamp" guarantee is pinned only on github: (test_4750_refused_github_avatar_path_is_not_stamped). A twin test for local: would be one function.
    • ➖ Both ephemeral guards (_register_agent and the github: install block) can be removed without a red test. These guards are older than this PR and this PR does not change them. It is a gap, not a finding against this PR.

What you asked me to look at

  • Closes #4609, both template types: holds. For local: it is proven end to end (test_4609_shipped_avatar_reaches_the_workspace_card, from create to the portal card). For github: it is proven in two halves: the stamp is now kept (test_4570_github_bundled_avatar_is_stamped_as_kept, killed by the M4 mutant), and a kept row produces a card URL (test_4750_shipped_avatar_is_kept_and_shown_in_the_workspace, against a real DB). The github: stamp runs after _register_agent, so a prompt-seeded default row is overwritten as kept. The order is right.
  • Agents with no shipped image: nothing an owner sees changes. The prompt-only and oversized branches still call set_default_avatar, and mutants M1 and M7 prove it. The one difference is that a failed re-encode no longer leaves a 0-byte file. That leaves the same state as a prompt-only template.
  • Readers of the flag: there are two, get_agents_without_custom_avatar and client_portal/service.py:951. No frontend or MCP code reads it. The enterprise member_agents/_avatar.py already stamps through set_avatar_identity.
  • Doc claims checked against routers/avatar.py: Generate calls set_avatar_identity (L516). Regenerate answers 404 without _ref.png (L537–539). Delete calls clear_avatar_identity (L601), so the agent rejoins the next Generate Default Avatars. All three match the doc.
  • The release-note claim about existing agents is true, with one imprecision. The doc says the shipped image of an agent made before bug(avatars): a template's shipped avatar is replaced when default avatars are generated #4750 "is still stored as is_default_avatar = 1". That is right for github: agents created between GitHub template bundled avatar is installed but never shown (avatar_url stays null) #4570 and now, and for local: agents. A github: agent created before GitHub template bundled avatar is installed but never shown (avatar_url stays null) #4570 has no stamp at all (avatar_updated_at NULL). The outcome is the same: Generate Default Avatars replaces it and the Workspace shows initials. Optional rewording.

Before merge

  • The PR is still Draft: mark it ready.
  • The live-stack check the PR body lists has not been run here: create from a template with an image, press Generate Default Avatars, confirm the image stays and the Workspace sidebar shows it.
  • Not run by me: the full unit island and /cso (lane B does not need /cso). CI's Tier 1 is the full-suite evidence.

APPROVE. The local: refused-destination test is a warning, not a blocker.

@trinity-ability trinity-ability left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/validate-pr: APPROVE at head e84cb39. Re-ran the changed test files at head (green) and reverted the fix in a scratch worktree (red). Tier 1 green, dev-ci green.

@vybe
vybe merged commit 22b674a into dev Nov 24, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants