agent icon: 404 when unconfigured, client-side fallback

hive_sh4re::assets::branding_svg() resolved a server-side default
icon at runtime from HIVE_ASSETS_DIR — the only consumer was
serve_icon(), which fell back to it whenever the agent had no
`hyperhive.icon` override. Removed both the fallback and the
function: serve_icon() now 404s when /etc/hyperhive/icon.svg is
absent, and the per-agent web UI (app.js) picks up the existing
dashboard swarm.js pattern — swap the <img> src to the
frontend-bundled /favicon.svg on load failure, guarded against
looping if the fallback itself 404s.

Updated the doc/comment claims that said the server always returns
an image (docs/web-ui/agent.md, nix/agent-modules/default.nix, the
hive-c0re/forge/users.rs comment referencing the old shared-asset
set). forge-avatar-sync and the matrix avatar sync are unaffected —
both are gated on hyperhive.icon != null and never depended on the
removed fallback.
This commit is contained in:
iris 2026-08-10 20:35:23 +02:00 committed by mara
commit e525dcb6d4
6 changed files with 49 additions and 38 deletions

View file

@ -11,20 +11,18 @@ use super::AppState;
/// This agent's icon. Serves the operator-configured SVG from
/// `/etc/hyperhive/icon.svg` (set via the `hyperhive.icon` agent.nix
/// option) when present, otherwise the bundled default hyperhive logo.
/// Always returns an image, so consumers (dashboard, favicon) can hit
/// `/icon` unconditionally without probing whether one is configured.
pub(super) async fn serve_icon() -> impl IntoResponse {
// Per-agent icon overrides go through `/etc/hyperhive/icon.svg`
// (set via the `hyperhive.icon` agent.nix option); the bundled
// default is resolved at runtime from
// `$HIVE_ASSETS_DIR/branding/hyperhive.svg`. If neither file can
// be read we serve an empty body — keeps the response a valid SVG
// content-type without a panic on a misconfigured container.
let body = std::fs::read_to_string("/etc/hyperhive/icon.svg").unwrap_or_else(|_| {
std::fs::read_to_string(hive_sh4re::assets::branding_svg()).unwrap_or_default()
});
([("content-type", "image/svg+xml")], body)
/// option) when present, otherwise **404** — there is no bundled
/// server-side default any more (that was `hive_sh4re::assets::
/// branding_svg`, now removed). Consumers fall back client-side: the
/// dashboard's `swarm.js` and this agent's own `app.js` both swap an
/// `/icon` load failure to the frontend-bundled `/favicon.svg` rather
/// than probing first, so a 404 here is the expected "unconfigured"
/// signal, not an error case to work around.
pub(super) async fn serve_icon() -> Response {
match std::fs::read_to_string("/etc/hyperhive/icon.svg") {
Ok(body) => ([("content-type", "image/svg+xml")], body).into_response(),
Err(_) => (StatusCode::NOT_FOUND, "no icon configured").into_response(),
}
}
/// WebSocket handler: upgrade then pump bytes between the WS client and