Compare commits

...

1 Commits

Author SHA1 Message Date
Teknium
319141a0d1 fix(session_search): truncate TOOL rows with None tool_name
_format_conversation guarded truncation on `role == "TOOL" and tool_name`,
so TOOL rows where tool_name is None fell through to the generic branch
and rendered as untruncated `[TOOL]: <huge-blob>`, drowning out actual
conversation content during summarization. Truncate all TOOL rows and
render `[TOOL]` when tool_name is absent.

Credit to @toaiclaw-a11y for spotting this in PR #2579 (closed as
otherwise stale — rest of that PR's truncation logic has since been
superseded by _truncate_around_matches centering on query matches).

Co-authored-by: toaiclaw-a11y <264816063+toaiclaw-a11y@users.noreply.github.com>
2026-04-30 20:25:58 -07:00

View File

@@ -82,11 +82,15 @@ def _format_conversation(messages: List[Dict[str, Any]]) -> str:
content = msg.get("content") or "" content = msg.get("content") or ""
tool_name = msg.get("tool_name") tool_name = msg.get("tool_name")
if role == "TOOL" and tool_name: if role == "TOOL":
# Truncate long tool outputs # Truncate long tool outputs regardless of whether tool_name is set —
# stored sessions sometimes have tool_name=None, and without this
# guard those rows render as untruncated [TOOL]: <huge-blob>, drowning
# out actual conversation content during summarization.
if len(content) > 500: if len(content) > 500:
content = content[:250] + "\n...[truncated]...\n" + content[-250:] content = content[:250] + "\n...[truncated]...\n" + content[-250:]
parts.append(f"[TOOL:{tool_name}]: {content}") header = f"[TOOL:{tool_name}]" if tool_name else "[TOOL]"
parts.append(f"{header}: {content}")
elif role == "ASSISTANT": elif role == "ASSISTANT":
# Include tool call names if present # Include tool call names if present
tool_calls = msg.get("tool_calls") tool_calls = msg.get("tool_calls")