From 4a9182d4aa0d4f7ee04d30dbd27f544a01842fda Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 15 Mar 2026 08:44:26 -0600 Subject: [PATCH] fix: use auto-stub fallback for L1/L2 when LLM summary not available L1/L2 objects without LLM summaries kept full content as fallback, increasing context instead of reducing it. Now uses auto-stub (truncated preview) when no summary exists, ensuring degraded objects always produce smaller content. --- src/mnemosyne/gateway.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/mnemosyne/gateway.py b/src/mnemosyne/gateway.py index cb26ee4..20b1fe0 100644 --- a/src/mnemosyne/gateway.py +++ b/src/mnemosyne/gateway.py @@ -1383,24 +1383,27 @@ def _apply_fidelity(payload: dict, session: "Session") -> None: session._summary_cache.get((obj_id, int(FidelityLevel.L2))) or obj.summary_compact ) - if summary: - if block.get("type") == "tool_result": - block["content"] = summary - else: - block["text"] = summary - # else: keep full content as fallback + if not summary: + # No LLM summary yet — use auto-stub as fallback + summary = obj.stub or _auto_stub(text) + if block.get("type") == "tool_result": + block["content"] = summary + else: + block["text"] = summary elif obj.current_fidelity == FidelityLevel.L1: # L1: use detailed summary if available (from LLM or pre-set) summary = ( session._summary_cache.get((obj_id, int(FidelityLevel.L1))) or obj.summary_detailed ) - if summary: - if block.get("type") == "tool_result": - block["content"] = summary - else: - block["text"] = summary - # else: keep full content as fallback + if not summary: + # No LLM summary yet — use auto-stub as fallback + # so we still get compression instead of keeping full content + summary = obj.stub or _auto_stub(text) + if block.get("type") == "tool_result": + block["content"] = summary + else: + block["text"] = summary else: # New object — register it obj_type = "tool_result" if block.get("type") == "tool_result" else "file_context"