MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / load_state

Function load_state

uncommon_route/persistence.py:43–57  ·  view source on GitHub ↗
(directory: Path)

Source from the content-addressed store, hash-verified

41
42
43def load_state(directory: Path) -> LearnedState:
44 path = directory / STATE_FILENAME
45 if not path.exists():
46 return LearnedState()
47 try:
48 with open(path, encoding="utf-8") as f:
49 data = json.load(f)
50 if data.get("schema_version") != SCHEMA_VERSION:
51 logger.warning("Schema version mismatch, using defaults")
52 return LearnedState()
53 data.pop("schema_version", None)
54 return LearnedState(**{k: v for k, v in data.items() if k in LearnedState.__dataclass_fields__})
55 except (json.JSONDecodeError, KeyError, TypeError) as e:
56 logger.warning(f"Corrupt state file: {e}, using defaults")
57 return LearnedState()
58
59
60def reset_state(directory: Path) -> None:

Callers 5

test_save_load_roundtripFunction · 0.90
test_reset_stateFunction · 0.90
on_startupFunction · 0.90

Calls 5

LearnedStateClass · 0.85
openFunction · 0.85
popMethod · 0.80
loadMethod · 0.45
getMethod · 0.45

Tested by 4

test_save_load_roundtripFunction · 0.72
test_reset_stateFunction · 0.72