Skip to content

The agent that grows with you

fix(cron,tools): exact-id receipt reads fail closed on a non-dict JSON payload

teknium1e16fc212ec16
diff --git a/cron/bot_chat_delivery.py b/cron/bot_chat_delivery.py
index d743353a0ac..2e637983a8f 100644
--- a/cron/bot_chat_delivery.py
+++ b/cron/bot_chat_delivery.py
@@ -26,10 +26,14 @@ def _root() -> Path:
def read_pending(key: str) -> dict | None:
+ """Exact-id read: fails closed on anything but a JSON object, never licensing an overwrite."""
try:
- return json.loads((_root() / f"{key}.json").read_text(encoding="utf-8"))
+ record = json.loads((_root() / f"{key}.json").read_text(encoding="utf-8"))
except FileNotFoundError:
return None
+ if not isinstance(record, dict):
+ raise ValueError(f"deferred Bot Chat receipt {key} is not a JSON object ({type(record).__name__})")
+ return record
def _records(root: Path) -> list[tuple[Path, dict]]:
diff --git a/tools/bot_live_delivery.py b/tools/bot_live_delivery.py
index 104f03b4561..1668f2925d6 100644
--- a/tools/bot_live_delivery.py
+++ b/tools/bot_live_delivery.py
@@ -103,10 +103,14 @@ def _locked(home: Path | str):
def _read(path: Path) -> dict[str, Any] | None:
+ """Exact-id read: absent → None; unreadable or not a JSON object → raises (callers fail closed)."""
try:
- return json.loads(path.read_text(encoding="utf-8"))
+ record = json.loads(path.read_text(encoding="utf-8"))
except FileNotFoundError:
return None
+ if not isinstance(record, dict):
+ raise ValueError(f"ticket {path.name} is not a JSON object ({type(record).__name__})")
+ return record
# Tickets already reported unreadable by this process. The live poller rescans the