From c04c7a8f6209c4be5fc632763b9bffc483f2411b Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 Mar 2026 15:52:38 +0700 Subject: [PATCH] Fix: new_candidate wird nicht mehr durch Duplikat-Ergebnis ueberschrieben --- homelab-ai-bot/context.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/homelab-ai-bot/context.py b/homelab-ai-bot/context.py index cb1339e1..32b037e7 100644 --- a/homelab-ai-bot/context.py +++ b/homelab-ai-bot/context.py @@ -304,7 +304,6 @@ def _tool_memory_suggest(scope, kind, content, memory_type="temporary", expires_ import memory_client from datetime import datetime global last_suggest_result - last_suggest_result = {"type": None, "candidate_id": None} _log.info("memory_suggest aufgerufen: scope=%s kind=%s type=%s content=%s", scope, kind, memory_type, content[:80]) if memory_type not in ("temporary", "permanent"): @@ -331,6 +330,8 @@ def _tool_memory_suggest(scope, kind, content, memory_type="temporary", expires_ data["expires_at"] = exp_epoch result = memory_client._post("/memory", data) + prev_type = last_suggest_result.get("type") + if result and result.get("duplicate"): ex_status = result.get("existing_status", "?") ex_type = result.get("existing_memory_type", "") @@ -338,22 +339,27 @@ def _tool_memory_suggest(scope, kind, content, memory_type="temporary", expires_ ex_id = result.get("existing_id") if ex_status == "candidate": - last_suggest_result = {"type": "existing_candidate", "candidate_id": ex_id} - _log.info("Duplikat: bestehender Kandidat ID=%s", ex_id) + if prev_type != "new_candidate": + last_suggest_result = {"type": "existing_candidate", "candidate_id": ex_id} + _log.info("Duplikat: bestehender Kandidat ID=%s (prev=%s)", ex_id, prev_type) return "Noch nicht bestaetigt — zeige Auswahl erneut." elif ex_status == "active": if ex_type == "temporary" and ex_exp: exp_str = datetime.fromtimestamp(ex_exp).strftime("%d.%m.%Y") - last_suggest_result = {"type": "active_temporary", "candidate_id": None} + if prev_type != "new_candidate": + last_suggest_result = {"type": "active_temporary", "candidate_id": None} return f"Schon temporaer gespeichert bis {exp_str}." elif ex_type == "permanent": - last_suggest_result = {"type": "active_permanent", "candidate_id": None} + if prev_type != "new_candidate": + last_suggest_result = {"type": "active_permanent", "candidate_id": None} return "Schon dauerhaft gespeichert." else: - last_suggest_result = {"type": "active_other", "candidate_id": None} + if prev_type != "new_candidate": + last_suggest_result = {"type": "active_other", "candidate_id": None} return "Bereits aktiv gespeichert." elif ex_status == "archived": - last_suggest_result = {"type": "existing_candidate", "candidate_id": ex_id} + if prev_type != "new_candidate": + last_suggest_result = {"type": "existing_candidate", "candidate_id": ex_id} memory_client._patch(f"/memory/{ex_id}", {"status": "candidate"}) return "War archiviert — erneut als Kandidat vorgeschlagen." else: