Skip to content

fix(agents): show a GitHub template's bundled avatar (#4570) - #4574

Merged
webmixgamer merged 1 commit into
devfrom
fix/4570-github-template-avatar
Nov 14, 2026
Merged

webmixgamer merged 1 commit into
devfrom
fix/4570-github-template-avatar

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Fixes #4570

Problem

An agent created from a github: template that ships avatar.png (or avatar.webp) at its root got the file installed in the avatar store (GET /api/agents/{name}/avatar answers 200 with the right image, at the pinned ref) but avatar_url stayed null. The agent page, the dashboard tile and the Workspace all showed initials. Found in release testing of v1.0.5-rc2 (row B21 of Abilityai/trinity-enterprise#1189).

Cause

avatar_url is built only from an avatar identity row that has a non-empty prompt and a timestamp (db.get_avatar_identity returns nothing otherwise). The local: path writes that row with db.set_default_avatar(...) right after _install_bundled_avatar. The github: path from #4376 installs the bytes later via _install_bundled_avatar_bytes and never writes the row. The local: seed can't cover it either, because it reads avatar_prompt from template_data, which is {} on the github: path.

Fix

  • During template resolution, when the bundled file is found, keep the template's avatar_prompt from source_metadata (the template.yaml the create already reads for schedules, plugins and model).
  • After a successful install, _stamp_bundled_avatar records the file as a default avatar (set_default_avatar, is_default_avatar=1), seeded with that prompt, or with an AI agent named <name> when the template declares none. A non-empty prompt is required for avatar_url to resolve, and it is also what Regenerate starts from.
  • A failed install is not stamped, so a broken file falls back to initials instead of a broken image. Stamp errors are logged and the create continues, like every other post-registration step.

Tests

tests/unit/test_1484_create_agent_characterization.py drives a real github: create (@v1.2.0 ref) through the existing harness. Only the GitHub file fetch is stubbed; the install and the stamp run for real.

  • test_4570_github_bundled_avatar_is_stamped_as_default: the WebP is written and set_default_avatar is called with the template's prompt.
  • test_4570_github_bundled_avatar_without_prompt_still_stamped: no avatar_prompt → still stamped, with a non-empty prompt.
  • test_4570_failed_github_avatar_install_is_not_stamped: undecodable bytes → no file, no stamp, the create still completes.

Validation: pytest tests/unit/test_1484_create_agent_characterization.py tests/unit/test_1173_hub_display_avatar.py -p no:randomly → 92 passed.
Mutation: on dev the first two tests fail (set_default_avatar called 0 times) while the WebP assertion before them passes, which is the reported symptom. Separately, an empty fallback prompt, stamping after a failed install, and dropping the template's prompt each turn exactly one 4570 test red.

Unverified

Unverified: a live-stack run (re-tested on the next RC under row B21, by someone other than the author).

  • Not run on a live stack. Row B21's avatar step re-tests it on the next RC, by someone other than the author.
  • ruff check on crud.py reports one F841 (original_name unused in create_agent_internal) that is already on dev and untouched here.

Journey Impact

Journey Impact: none: restores what #4376 promised (a GitHub template's bundled avatar shows on the agent); no journey promise changes

A github: template that ships avatar.png/webp had the file installed but
never stamped as the agent's avatar, so avatar_url stayed null and every
surface showed initials. After a successful install, record it as a
default avatar seeded with the template's own avatar_prompt (from the
template.yaml the create already reads), or a generic prompt when it
declares none. A failed install is not stamped.
@AndriiPasternak31
AndriiPasternak31 marked this pull request as ready for review November 14, 2026 00:18
@webmixgamer

Copy link
Copy Markdown
Contributor

Review — APPROVE (head b013603ca)

/review + /validate-pr, lane B. Legend: PROVED = a command I ran, with its result. INFERRED = from reading only.

No blocking finding. One note the re-tester of row B21 needs before rc3 (note 1), three small ones.

Scope

Clean. The issue asks for the default-avatar stamp after a successful install of a github: template's bundled file; the diff adds exactly that (crud.py:2896-2909, hand-off at crud.py:4153-4160), the template's own avatar_prompt carried through resolution (crud.py:2115-2117), three tests and one paragraph in the flow doc. Nothing unrelated.

Issue's fix direction, item by item:

  • Stamp after a successful _install_bundled_avatar_bytes: done, crud.py:4153-4160.
  • "A test that creates a github: agent with a bundled file and asserts avatar_url is non-null": changed — the tests assert the set_default_avatar call on the mocked DB, not avatar_url (note 3).

Execution coverage

changed symbol executed by live consumer verdict
_stamp_bundled_avatar all three test_4570_* (real function, mocked db) crud.py:4160 ✅ executed
the hand-off line in create_agent_internal (else: branch) the same three, through a real create_agent_internal — it is the consumer ✅ pinned (M2, M3)
_TemplateResolution.bundled_avatar_prompt + its capture in _resolve_template test_4570_github_bundled_avatar_is_stamped_as_default crud.py:4160 ✅ pinned (M4, M6)

No source-text assertions in the added tests (PROVED: grep for read_text(), inspect.getsource, .index().

Mutations (PROVED, scratch worktree at this head, pytest -p no:randomly unit/test_1484_create_agent_characterization.py -k 4570; unmutated: 3 passed):

mutation red tests
M1: crud.py reverted to the merge-base …_is_stamped_as_default, …_without_prompt_still_stamped
M2: only the hand-off line deleted the same two
M3: stamp even after a failed install (else: removed) …_failed_github_avatar_install_is_not_stamped
M4: hand-off passes None for the prompt …_is_stamped_as_default
M5: fallback prompt empty …_without_prompt_still_stamped
M6: resolution never captures avatar_prompt …_is_stamped_as_default

The author's mutation claims in the PR body match mine. M2 and M6 are mine.

Pinned guards (PROVED): the 305 guard files, with CI's flags and seed 12345, at this head and at the merge-base 8f0d07899. The red set is the same 98 test ids on both sides (real-app, route-census and pin-parity tests that my machine's environment cannot import), so nothing is red because of this PR; the head passes 3 more tests than the base (12 321 against 12 318), which are the three new ones. CI's regression diff passes on this head. The diff adds no route, protected path or registry entry.

Notes (none blocking)

1. The Workspace still shows initials for this agent after the fix. (confidence 9/10)

The stamp records a default avatar (is_default_avatar = 1), and the Workspace roster card drops the image for default avatars on purpose:

# src/backend/client_portal/service.py:945-951
# Only agents with a generated (non-default) avatar get an image URL;
# the UI renders an initials tile otherwise.
avatar_url = (
    f"/api/agents/{name}/avatar?v={updated}"
    if updated and not r.get("is_default_avatar")
    else None
)

That rule is pinned by tests/unit/test_ent79_portal_exposure.py::test_roster_avatar_url_rules ("default avatar → initials tile"; PROVED: passes at this head). So of the three surfaces the issue and the PR body name, the fix restores two:

surface source of avatar_url after this PR
agent page routers/agents.py:528-530 (identity row with a prompt) image
dashboard tile / agent list services/agent_service/helpers.py:332-336 (avatar_updated_at) image
Workspace roster, header, briefing client_portal/service.py:945-951 initials, as before

This is the same as a local: template's bundled avatar today, and it matches the issue's "Expected" (avatar_url set and the default flag on, like local:). PROVED on a local v1.0.5-rc2 stack with an agent in exactly the stamped state (default flag on, prompt, timestamp, from a local: template): GET /api/agents/{name} and the list both return avatar_url. INFERRED for the Workspace: from the code and the pinned test; I did not open the Workspace as that agent's person.

Nothing to change in the code for this PR. Two asks, both text:

  • Say it on the issue or in the PR body, so the rc3 re-test of B21 checks the agent page and the dashboard and does not go red on the Workspace tile.
  • Whether a template's bundled avatar should show in the Workspace is a product question for a follow-up; changing the roster rule here would also change every local: template agent.

2. A skipped install is still stamped. (confidence 8/10 on the mechanism, low impact)

_install_bundled_avatar_bytes returns without writing when the avatar store refuses the path:

# crud.py:2924-2926
dest = avatar_paths.avatar_path_or_none(agent_name, ".webp")
if dest is None:
    return

No exception, so the else: at crud.py:4153 runs and the row points at a file that was never written — the case the comment there says cannot happen. PROVED with a probe at this head (avatar_path_or_none patched to return None): file written False, set_default_avatar called once. Reach is small: agent names are sanitized to [a-z0-9_.-], so only a name long enough to exceed the 255-byte component limit gets there. Cheapest fix: let the install return whether it wrote, and stamp on that. Fine as a follow-up.

3. The tests stop at the mocked DB. They prove the stamp is called with the right name and prompt; the step from that row to a non-null avatar_url (db/agent_settings/avatar.py:46, routers/agents.py:528-530) rests on unchanged code. I checked that step on a live stack (note 1), so this is a suggestion only: one assertion through the real AvatarMixin on the test DB would close the loop the issue asked for.

4. The generic fallback prompt pre-empts the generator's own. For a template with no avatar_prompt, the stamp stores an AI agent named <name>. Generate Default Avatars takes a stored prompt first (routers/avatar.py:195-197), so it never reaches its per-agent style fallback (routers/avatar.py:205-206) for these agents. Cosmetic: a later generated default is plainer than it would have been. Optional.

Low confidence, for the record: set_default_avatar returns False when no row matched and _stamp_bundled_avatar logs "Stamped" either way. The local: seed does the same (crud.py:3038-3039).

Clean categories

  • SQL and data safety: no SQL in the diff; the write is the existing parameterized set_default_avatar.
  • Auth: no route, dependency or gate touched. Audit-row check: no gated write handler touched.
  • Credentials and disclosure: no secret, address or host path in the diff (PROVED: the key, email, IP, file-mode and host-path scans, and the enterprise-docs pattern over the added doc lines).
  • Concurrency: the stamp runs after _register_agent in the same create, on the new agent's own row.
  • Ephemeral agents: skipped (crud.py:4148), as before.
  • Cross-surface: no router changed; crud.py has no agent-server mirror (PROVED: git ls-files, git grep).
  • Config and packaging: no new env var, directory, Dockerfile or compose change.
  • Timestamp format: datetime.now(timezone.utc).isoformat(), the same call the local: seed and the generator use.

Process (/validate-pr)

check result
Base branch, size ✅ dev, 3 files (+96 / −0)
Commit message ✅ fix(agents): …(#4570)
Closing keyword ✅ Fixes #4570; the issue is type-bug, priority-p2
Journey Impact ✅ PROVED: scripts/ci/check_journey_impact.py exits 0 on this body and these SHAs
Docs ✅ bug fix; the flow doc agent-avatars.md gains one paragraph, accurate against the code
Security scans ✅
Test adequacy ✅ a named regression test that goes red without the fix (M1), plus the failure path
Merge gate, Tier 1 ✅ on b013603ca: 20 pass, 5 skipped, none failed or pending; pytest (head, seed 12345) and regression diff pass
dev before merge ✅ dev-ci success on the dev tip 8479a1d6f; no open dev-ci red issue
Conflicts ✅ mergeable; dev has not touched the three files since the merge-base
Product fit ➖ no route, tool, setting or view touched

Not checked

  • A real github: create on a live stack with this branch. Row B21 re-tests it on rc3; see note 1 for what to look at.
  • The Workspace as the agent's person (note 1 is from the code and its pinned test).

@webmixgamer webmixgamer 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.

Approved at head b013603ca. Full report in the comment above: no blocking finding; the fix is pinned by six mutations and regression diff passes on this head. One note for the rc3 re-test of row B21: the Workspace keeps showing initials for this agent, because the roster drops default avatars by rule (note 1).

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