Skip to content

Self-improving AI Employees for everyone

fix(plugins): fingerprint node icon URLs so artwork changes reach browsers

trohitg99c858f77bfe
diff --git a/client/src/assets/icons/index.test.ts b/client/src/assets/icons/index.test.ts
index aa4fc11f..6b3aac69 100644
--- a/client/src/assets/icons/index.test.ts
+++ b/client/src/assets/icons/index.test.ts
@@ -65,9 +65,15 @@ describe('resolveLibraryIcon', () => {
*/
it('resolves every library icon declared in a plugin meta.json', () => {
const nodesDir = join(__dirname, '..', '..', '..', '..', 'server', 'nodes');
- const declared: Array<[string, string]> = [];
+ const metaFiles = pluginMetaFiles(nodesDir);
+ // Guards the guard: color-only meta.json files exist regardless of how
+ // many plugins currently use icon refs, so an empty list here means the
+ // discovery walk broke — not that the inventory shrank. (Zero *refs* is
+ // a legitimate state: brand-heavy plugins ship SVGs instead.)
+ expect(metaFiles.length).toBeGreaterThan(0);
- for (const file of pluginMetaFiles(nodesDir)) {
+ const declared: Array<[string, string]> = [];
+ for (const file of metaFiles) {
const meta = JSON.parse(readFileSync(file, 'utf-8')) as {
icon?: string;
icons?: Record<string, string>;
@@ -78,10 +84,6 @@ describe('resolveLibraryIcon', () => {
}
}
- // Guards the guard: if the discovery ever breaks, the loop below would
- // vacuously pass.
- expect(declared.length).toBeGreaterThan(0);
-
const unresolved = declared.filter(([, ref]) => resolveLibraryIcon(ref) === null);
expect(unresolved).toEqual([]);
});
diff --git a/server/services/plugin/base.py b/server/services/plugin/base.py
index 5e20cadd..996e0d4c 100644
--- a/server/services/plugin/base.py
+++ b/server/services/plugin/base.py
@@ -86,6 +86,22 @@ def _derive_auto_ui_hints(group: Sequence[str]) -> Dict[str, Any]:
return hints
+def _icon_fingerprint(path: Any) -> str:
+ """Short content hash used to version a plugin icon URL.
+
+ Content-based rather than mtime-based so a fresh checkout of the same
+ bytes keeps the same URL (and the same browser cache entry). Truncated
+ to 12 hex chars — cache-busting, not integrity. Unreadable files fall
+ back to a constant so registration never breaks over an icon.
+ """
+ import hashlib
+
+ try:
+ return hashlib.sha256(path.read_bytes()).hexdigest()[:12]
+ except OSError:
+ return "0"
+
+
class BaseNode:
"""Abstract plugin node. Do not instantiate directly — subclass
:class:`ActionNode`, :class:`TriggerNode`, or :class:`ToolNode`.
@@ -294,8 +310,17 @@ class BaseNode:
# reference), then the central visuals.json. Same shape as the
# color lookup below: plugin folder first, central registry as the
# legacy fallback.
- if get_plugin_icon_path(cls.type) is not None:
- icon = f"/api/schemas/nodes/{cls.type}/icon"
+ icon_path = get_plugin_icon_path(cls.type)
+ if icon_path is not None:
+ # Fingerprinted URL — standard asset-cache-busting. The icon
+ # route serves `Cache-Control: max-age=86400` on a URL that
+ # otherwise never changes, so replacing an SVG left every
+ # browser showing the old artwork for up to a day. A content
+ # hash in the URL makes the long cache correct instead of
+ # harmful: changed bytes mint a new URL, identical bytes keep
+ # the cached one. Computed once at registration, like every
+ # other field in this dict.
+ icon = f"/api/schemas/nodes/{cls.type}/icon?v={_icon_fingerprint(icon_path)}"
else:
icon = get_plugin_icon_ref(cls.type) or get_icon(cls.type)
color = get_plugin_meta(cls.type, "color") or get_color(cls.type)
diff --git a/server/tests/nodes/test_agent_context_node.py b/server/tests/nodes/test_agent_context_node.py
index d112ce76..1bbd3bcd 100644
--- a/server/tests/nodes/test_agent_context_node.py
+++ b/server/tests/nodes/test_agent_context_node.py
@@ -1,5 +1,7 @@
from __future__ import annotations
+import re
+
import pytest
from pydantic import ValidationError
@@ -52,10 +54,11 @@ def test_context_node_ships_backend_visual_assets():
assert icon_path.name == "icon.svg"
assert icon_path.parent.name == "context"
assert icon_path.is_file()
- assert (
- AgentContextNode._metadata_dict()["icon"]
- == "/api/schemas/nodes/context/icon"
- )
+ # Fingerprinted URL: `?v=<content-hash>` busts browser HTTP cache when
+ # the artwork changes (the route serves max-age=86400 on an otherwise
+ # stable URL). The hash varies with the file, so match shape, not value.
+ icon_url = AgentContextNode._metadata_dict()["icon"]
+ assert re.fullmatch(r"/api/schemas/nodes/context/icon\?v=[0-9a-f]{12}", icon_url), icon_url
assert get_plugin_meta("context", "color") == "#6272a4"