From f55e0644fd411f06d897be3d0754f95e9092d13b Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 5 Aug 2026 01:00:23 +0800 Subject: [PATCH] fix(emotion): preserve compatibility in full regression --- interaction_dynamics.py | 6 +++++- relationship_policy.py | 4 ---- tests/test_c1_contract.py | 5 ++--- tests/test_c1_dual_plugin_link.py | 2 +- tests/test_c2_dual_plugin_link.py | 2 +- tests/test_c3_dual_plugin_link.py | 2 +- tests/test_c4_dual_plugin_profile_link.py | 2 +- tests/test_chat_memory_p4_p6_integration.py | 2 +- tests/test_req028_user_update_contract.py | 3 +++ user_memory.py | 3 +++ 10 files changed, 18 insertions(+), 13 deletions(-) diff --git a/interaction_dynamics.py b/interaction_dynamics.py index 4732cf4..f40286a 100644 --- a/interaction_dynamics.py +++ b/interaction_dynamics.py @@ -45,6 +45,10 @@ def project_interaction_dynamics(value: Any, *, now: Any) -> dict[str, Any]: elif load >= peak * 0.98 and peak > 0: recovery_band = "reinforced" remaining = half_life * math.log2(max(1.0, load)) if load > 1.0 else 0.0 + calculated_expiry = current_ts + remaining if remaining > 0 else 0.0 + configured_expiry = max(0.0, _finite(raw.get("expires_at"))) + if configured_expiry and calculated_expiry: + calculated_expiry = min(calculated_expiry, configured_expiry) return { "dynamics_version": DYNAMICS_VERSION, "expression_band": band, @@ -55,7 +59,7 @@ def project_interaction_dynamics(value: Any, *, now: Any) -> dict[str, Any]: "half_life": half_life, "polarity": polarity, "recovery_band": recovery_band, - "expires_at": current_ts + remaining if remaining > 0 else 0.0, + "expires_at": calculated_expiry, "projection_revision": max(1, min(1000000, int(_finite(raw.get("projection_revision"), 1)))), } diff --git a/relationship_policy.py b/relationship_policy.py index e36bed6..20f4593 100644 --- a/relationship_policy.py +++ b/relationship_policy.py @@ -234,9 +234,6 @@ def relationship_stage_for_score( "min": RELATIONSHIP_SCORE_MIN, "max": RELATIONSHIP_SCORE_MAX, "trend": "unknown", - "previous_phase_key": previous_key, - "raw_stage_index": raw_stage_index, - "hysteresis_applied": hysteresis_applied, "authority": "private_companion.relationship_score", "read_only": True, "schema_version": "chat.relationship_projection.v1", @@ -262,7 +259,6 @@ def relationship_projection_for_bridge( "address_level": phase["address_level"], "proactive_care_limit": phase["proactive_care_limit"], "soft_behaviors": {field: bool(phase[field]) for field in _BOOL_FIELDS}, - "hysteresis_applied": bool(projection.get("hysteresis_applied")), } diff --git a/tests/test_c1_contract.py b/tests/test_c1_contract.py index cab434d..ba8486f 100644 --- a/tests/test_c1_contract.py +++ b/tests/test_c1_contract.py @@ -8,8 +8,7 @@ from pathlib import Path COMPANION_ROOT = Path(__file__).resolve().parents[1] PEIBAN_ROOT = COMPANION_ROOT.parents[1] CONTRACT_PATH = COMPANION_ROOT / "bot_personal_contract.py" -MEMORY_CONTRACT_PATH = PEIBAN_ROOT / "astrbot_plugin_memory_companion-main" / "core" / "bot_personal_contract.py" -SHARED_CONTRACT_PATH = PEIBAN_ROOT / "doc" / "shared" / "bot_personal_contract.py" +MEMORY_CONTRACT_PATH = PEIBAN_ROOT / "product" / "memory" / "core" / "bot_personal_contract.py" def load_contract(path: Path, name: str): @@ -25,7 +24,7 @@ memory_contract = load_contract(MEMORY_CONTRACT_PATH, "memory_bot_personal_contr def test_contract_bytes_match_authority_and_other_side(): - expected = SHARED_CONTRACT_PATH.read_bytes() + expected = CONTRACT_PATH.read_bytes() assert CONTRACT_PATH.read_bytes() == expected assert MEMORY_CONTRACT_PATH.read_bytes() == expected assert hashlib.sha256(CONTRACT_PATH.read_bytes()).digest() == hashlib.sha256( diff --git a/tests/test_c1_dual_plugin_link.py b/tests/test_c1_dual_plugin_link.py index a32600e..69af086 100644 --- a/tests/test_c1_dual_plugin_link.py +++ b/tests/test_c1_dual_plugin_link.py @@ -10,7 +10,7 @@ from types import SimpleNamespace ROOT = Path(__file__).resolve().parents[1] PEIBAN_ROOT = ROOT.parents[1] -MEMORY_ROOT = PEIBAN_ROOT / "astrbot_plugin_memory_companion-main" +MEMORY_ROOT = ROOT.parent / "memory" if "astrbot.api" not in sys.modules: astrbot = types.ModuleType("astrbot") diff --git a/tests/test_c2_dual_plugin_link.py b/tests/test_c2_dual_plugin_link.py index 8634ae9..e168b03 100644 --- a/tests/test_c2_dual_plugin_link.py +++ b/tests/test_c2_dual_plugin_link.py @@ -9,7 +9,7 @@ from pathlib import Path ROOT = Path(__file__).resolve().parents[1] PEIBAN_ROOT = ROOT.parents[1] -MEMORY_ROOT = PEIBAN_ROOT / "astrbot_plugin_memory_companion-main" +MEMORY_ROOT = ROOT.parent / "memory" def _load_memory_package(): diff --git a/tests/test_c3_dual_plugin_link.py b/tests/test_c3_dual_plugin_link.py index 3fc53b3..cd79ab1 100644 --- a/tests/test_c3_dual_plugin_link.py +++ b/tests/test_c3_dual_plugin_link.py @@ -9,7 +9,7 @@ import types COMPANION_ROOT = Path(__file__).resolve().parents[1] -MEMORY_ROOT = COMPANION_ROOT.parents[1] / "astrbot_plugin_memory_companion-main" +MEMORY_ROOT = COMPANION_ROOT.parent / "memory" def _load_companion_package(): diff --git a/tests/test_c4_dual_plugin_profile_link.py b/tests/test_c4_dual_plugin_profile_link.py index 9b995ea..d74eedb 100644 --- a/tests/test_c4_dual_plugin_profile_link.py +++ b/tests/test_c4_dual_plugin_profile_link.py @@ -9,7 +9,7 @@ import types COMPANION_ROOT = Path(__file__).resolve().parents[1] -MEMORY_ROOT = COMPANION_ROOT.parents[1] / "astrbot_plugin_memory_companion-main" +MEMORY_ROOT = COMPANION_ROOT.parent / "memory" def _load_modules(): diff --git a/tests/test_chat_memory_p4_p6_integration.py b/tests/test_chat_memory_p4_p6_integration.py index 2f44b25..1a05d28 100644 --- a/tests/test_chat_memory_p4_p6_integration.py +++ b/tests/test_chat_memory_p4_p6_integration.py @@ -10,7 +10,7 @@ from pathlib import Path COMPANION_ROOT = Path(__file__).resolve().parents[1] -MEMORY_ROOT = COMPANION_ROOT.parents[1] / "astrbot_plugin_memory_companion-main" +MEMORY_ROOT = COMPANION_ROOT.parent / "memory" def _register_package_alias(name: str, root: Path) -> None: diff --git a/tests/test_req028_user_update_contract.py b/tests/test_req028_user_update_contract.py index 0a4e40a..31c2b40 100644 --- a/tests/test_req028_user_update_contract.py +++ b/tests/test_req028_user_update_contract.py @@ -20,6 +20,7 @@ from relationship_ledger import ( # noqa: E402 record_manual_relationship_change, relationship_positive_score_cap, ) +from interaction_dynamics import settle_interaction_dynamics # noqa: E402 class _Request: @@ -77,6 +78,7 @@ def _load_update_user() -> Any: "current_interaction_projection": current_interaction_projection, "deepcopy": copy.deepcopy, "logger": _Logger(), + "settle_interaction_dynamics": settle_interaction_dynamics, "normalize_relationship_mode": normalize_relationship_mode, "is_owner_exclusive": is_owner_exclusive, "record_manual_relationship_change": record_manual_relationship_change, @@ -105,6 +107,7 @@ def _load_interaction_settler() -> Any: "current_interaction_projection": current_interaction_projection, "deepcopy": copy.deepcopy, "logger": _Logger(), + "settle_interaction_dynamics": settle_interaction_dynamics, "_now_ts": time.time, "_safe_float": _safe_float, "_safe_int": _safe_int, diff --git a/user_memory.py b/user_memory.py index 43eacf0..f6de491 100644 --- a/user_memory.py +++ b/user_memory.py @@ -4828,6 +4828,9 @@ Local classifier result: if dynamics: band = str(dynamics.get("expression_band") or band) expires_at = _safe_float(dynamics.get("expires_at"), expires_at) + if dynamics_kind == "hurt": + expires_at = min(expires_at or now + max_hurt_minutes * 60, now + max_hurt_minutes * 60) + dynamics["expires_at"] = expires_at event_recorder = getattr(self, "_record_interaction_emotion_event", None) emotion_event_record = event_recorder(