From 5017deb3db50ccb0e3d4ab63e9e9606a24a6664b Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 3 Aug 2026 17:24:25 +0530 Subject: [PATCH] refactor(insights): strip INDEXED BY pins via an attribute loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify-pass fold: the four copy-pasted .replace blocks meant a\nfifth pinned statement could forget its strip line — a hard 'no such\nindex' crash on read-only DBs, the exact bug the fallback prevents.\nLoop over the attribute names instead. --- agent/insights.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/agent/insights.py b/agent/insights.py index 1f5b9493046f3..fd4083b1b724e 100644 --- a/agent/insights.py +++ b/agent/insights.py @@ -114,14 +114,16 @@ class InsightsEngine: self._has_assistant_calls_index = False if not self._has_assistant_calls_index: _strip = f" INDEXED BY {self._MESSAGES_ASSISTANT_CALLS_INDEX}" - self._GET_TOOL_CALLS_WITH_SOURCE = ( - self._GET_TOOL_CALLS_WITH_SOURCE.replace(_strip, "") - ) - self._GET_TOOL_CALLS_ALL = self._GET_TOOL_CALLS_ALL.replace(_strip, "") - self._GET_SKILL_CALLS_WITH_SOURCE = ( - self._GET_SKILL_CALLS_WITH_SOURCE.replace(_strip, "") - ) - self._GET_SKILL_CALLS_ALL = self._GET_SKILL_CALLS_ALL.replace(_strip, "") + # Loop over every pinned statement so adding a new one can't + # forget its strip line (which would be a hard `no such index` + # crash on read-only DBs — the exact bug this fallback prevents). + for _attr in ( + "_GET_TOOL_CALLS_WITH_SOURCE", + "_GET_TOOL_CALLS_ALL", + "_GET_SKILL_CALLS_WITH_SOURCE", + "_GET_SKILL_CALLS_ALL", + ): + setattr(self, _attr, getattr(self, _attr).replace(_strip, "")) def generate(self, days: int = 30, source: str = None) -> Dict[str, Any]: """