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.
This commit is contained in:
Joey Yakimowich-Payne 2026-03-15 08:44:26 -06:00
commit 4a9182d4aa

View file

@ -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"