fix(agent): reject invalid telemetry injection payloads

This commit is contained in:
Sylvester Kaczmarek
2026-08-16 10:00:28 +00:00
parent 0ec346495a
commit 74aab5611e
5 changed files with 150 additions and 59 deletions
+7
View File
@@ -121,6 +121,10 @@ def inject_layer_data(
if layer not in _INJECTABLE_LAYERS:
return {"ok": False, "detail": f"layer '{layer}' not injectable"}
mode = str(mode or "").strip().lower()
if mode not in {"append", "replace"}:
return {"ok": False, "detail": "mode must be 'append' or 'replace'"}
items = list(items or [])[:200]
if not items:
return {"ok": False, "detail": "no items provided"}
@@ -136,6 +140,9 @@ def inject_layer_data(
entry["_injected_at"] = now
tagged.append(entry)
if not tagged:
return {"ok": False, "detail": "no valid items provided"}
with _data_lock:
current = latest_data.get(layer)
existing = list(current) if isinstance(current, list) else []
+3 -1
View File
@@ -1362,7 +1362,9 @@ def _dispatch_command(cmd: str, args: dict[str, Any]) -> dict[str, Any]:
if not layer or not items:
return {"ok": False, "detail": "layer and items required"}
from services.ai_intel_store import inject_layer_data
result = inject_layer_data(layer, items)
result = inject_layer_data(layer, items, mode=args.get("mode", "append"))
if not result.get("ok"):
return result
return {"ok": True, "data": result}
if cmd == "create_layer":