Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(mcp): make AvailabilityFacts hashable as its frozen dataclass promises (#2858)

Raghav Chamadiya2da57f27ccaa
diff --git a/packages/core/src/repowise/core/registry/tool_selection.py b/packages/core/src/repowise/core/registry/tool_selection.py
index 67dc3df2d..54d00adad 100644
--- a/packages/core/src/repowise/core/registry/tool_selection.py
+++ b/packages/core/src/repowise/core/registry/tool_selection.py
@@ -21,6 +21,7 @@ from __future__ import annotations
import logging
from collections.abc import Iterable, Mapping, Sequence
from dataclasses import dataclass, field
+from types import MappingProxyType
from .mcp_tool_registry import ToolEntry
@@ -57,6 +58,13 @@ class AvailabilityFacts:
counts: Mapping[str, int] = field(default_factory=dict)
+ def __post_init__(self) -> None:
+ # Snapshot into a read-only view so the hash below cannot drift.
+ object.__setattr__(self, "counts", MappingProxyType(dict(self.counts)))
+
+ def __hash__(self) -> int:
+ return hash(frozenset(self.counts.items()))
+
def normalize_override(override: str | Sequence[str] | None) -> list[str] | None:
"""Coerce a raw override (CLI/config) into a clean list of tokens.
diff --git a/tests/unit/registry/test_mcp_tool_selection.py b/tests/unit/registry/test_mcp_tool_selection.py
index b8d002593..4953ee8de 100644
--- a/tests/unit/registry/test_mcp_tool_selection.py
+++ b/tests/unit/registry/test_mcp_tool_selection.py
@@ -162,6 +162,18 @@ GATED = [
]
+def test_facts_are_hashable_and_snapshot_their_counts():
+ source = {"flows": 2}
+ facts = AvailabilityFacts(counts=source)
+ source["flows"] = 0
+
+ assert facts.counts["flows"] == 2
+ assert hash(facts) == hash(AvailabilityFacts(counts={"flows": 2}))
+ assert facts == AvailabilityFacts(counts={"flows": 2})
+ assert {facts, HAS_FLOWS} == {HAS_FLOWS}
+ assert hash(NO_FLOWS) == hash(AvailabilityFacts())
+
+
def test_predicate_true_keeps_the_default_tool():
assert "get_flow_map" in resolve_enabled_tools(GATED, is_workspace=False, facts=HAS_FLOWS)