The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(achievements): read the deduped display history; drop the TypeError shim
teknium1cf86c141287f
diff --git a/plugins/hermes-achievements/dashboard/plugin_api.py b/plugins/hermes-achievements/dashboard/plugin_api.pyindex d17f09c7ff4..a4891c0a369 100644--- a/plugins/hermes-achievements/dashboard/plugin_api.py+++ b/plugins/hermes-achievements/dashboard/plugin_api.py@@ -139,9 +139,8 @@ ACHIEVEMENTS: List[Dict[str, Any]] = [SNAPSHOT_FILE = "scan_snapshot.json"CHECKPOINT_FILE = "scan_checkpoint.json"-# Checkpoint schema 2: stats were computed from the full (inactive+compacted, deduped)-# history so rewind/compaction never shrink lifetime sums. Version 1 caches (active-only-# window) are treated as stale and force a one-time rescan.+# Checkpoint schema 2: per-session stats read the compaction-archived display history, not just+# the active window. Version 1 caches were computed active-only and are rescanned once._CHECKPOINT_SCHEMA_VERSION = 2@@ -584,14 +583,10 @@ def scan_sessions(limit: Optional[int] = None, progress_callback: Optional[Any]stats = dict(cached["stats"])reused += 1else:- # Full history (inactive + compacted, deduped) so rewind/compaction never- # shrink lifetime sums. Dedup collapses compaction generations (#112273).- try:- messages = db.get_messages(sid, include_inactive=True, include_compacted=True)- except TypeError:- # Test fakes / older SessionDB builds without the flags.- messages = db.get_messages(sid)- stats = analyze_messages(sid, title or "Untitled", messages)+ # Compaction-archived display history too (deduped, no Undo/Rewind rows): the active+ # window shrinks after compaction, and stats read from it were never monotonic+ # (#112273). Rewound rows stay out — that work was undone.+ stats = analyze_messages(sid, title or "Untitled", db.get_messages(sid, include_compacted=True))rescanned += 1stats.update(session_id=sid, title=title or stats.get("title") or "Untitled", started_at=meta.get("started_at"), last_active=meta.get("last_active"), source=meta.get("source"))if meta.get("model"):@@ -727,17 +722,11 @@ def _compute_from_scan(scan: Dict[str, Any], *, is_partial: bool = False) -> Dicunlock_id = definition["id"]if not is_partial and result["unlocked"] and unlock_id not in unlocks:unlocks[unlock_id] = {"unlocked_at": now, "first_tier": result.get("tier"), "evidence": evidence_for(definition, scan.get("sessions", []))}- # Sticky unlocks: once recorded in state.json, an achievement stays unlocked even- # if a later scan's aggregate dips below threshold (rewind/compaction shrink, #112273).- was_unlocked = unlock_id in unlocks- if was_unlocked and not result["unlocked"]:- result = dict(result)- result["unlocked"] = True- result["discovered"] = True- result["state"] = "unlocked"- # Preserve a tier for display when the live aggregate no longer reaches one.- if result.get("tier") is None:- result["tier"] = unlocks[unlock_id].get("first_tier")+ # Sticky unlocks: state.json is a floor. A badge earned on evidence that rewind/compaction+ # later removed from the scan basis must not flicker back to locked (#112273).+ if unlock_id in unlocks and not result["unlocked"]:+ result.update(unlocked=True, discovered=True, state="unlocked",+ tier=result.get("tier") or unlocks[unlock_id].get("first_tier"))item = {**definition, **result}if result["unlocked"]:item["unlocked_at"] = unlocks.get(unlock_id, {}).get("unlocked_at")diff --git a/plugins/hermes-achievements/tests/test_achievement_engine.py b/plugins/hermes-achievements/tests/test_achievement_engine.pyindex bb9c7356256..44580595922 100644--- a/plugins/hermes-achievements/tests/test_achievement_engine.py+++ b/plugins/hermes-achievements/tests/test_achievement_engine.py@@ -188,3 +188,30 @@ class AchievementEngineTests(unittest.TestCase):if __name__ == "__main__":unittest.main()+++class CompactionScanTests(unittest.TestCase):+ def test_scan_stats_survive_compaction_and_v1_checkpoint_is_rescanned(self):+ """#112273: compaction archives the active rows (active=0, compacted=1); the scan must+ keep counting them, and a schema-1 (active-only) checkpoint must not be reused."""+ import hermes_state+ from hermes_state import SessionDB++ with TemporaryDirectory() as tmp, patch.object(plugin_api, "_data_dir", return_value=Path(tmp) / "data"):+ db = SessionDB(Path(tmp) / "state.db")+ try:+ db.create_session("s1", "cli", model="m")+ for i in range(20):+ db.append_message("s1", "assistant", tool_calls=[{"function": {"name": f"tool_{i}", "arguments": "{}"}}])+ db.append_message("s1", "tool", content="ok", tool_name=f"tool_{i}")+ db.archive_and_compact("s1", [{"role": "user", "content": "[summary]"}])+ finally:+ db.close()+ # A schema-1 (active-only) checkpoint for this session must be ignored, not reused.+ stale = {"fingerprint": None, "stats": {"tool_call_count": 0}}+ plugin_api._write_json(plugin_api.CHECKPOINT_FILE, {"schema_version": 1, "generated_at": 1, "sessions": {"s1": stale}})+ with patch.object(hermes_state, "SessionDB", lambda read_only=True: SessionDB(Path(tmp) / "state.db", read_only=read_only)):+ scan = plugin_api.scan_sessions()++ self.assertEqual(scan["aggregate"]["max_distinct_tools_in_session"], 20)+ self.assertEqual(scan["scan_meta"]["sessions_reused"], 0)