Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Added fix for large replies being truncated entirely leaving no response text

Alishahryar1593fb5595471
diff --git a/messaging/transcript.py b/messaging/transcript.py
index c85a43f6..82741007 100644
--- a/messaging/transcript.py
+++ b/messaging/transcript.py
@@ -571,14 +571,27 @@ class TranscriptBuffer:
# Use deque for O(1) popleft; list.pop(0) would be O(n) per iteration.
parts: deque[str] = deque(rendered)
dropped = False
+ last_part: str | None = None
while parts:
candidate = _join(parts, add_marker=True)
if len(candidate) <= limit_chars:
return candidate
- parts.popleft()
+ last_part = parts.popleft()
dropped = True
- # Nothing fits; return status only with marker if possible.
+ # Nothing fits - preserve tail of last segment instead of only marker+status.
+ if dropped and last_part:
+ budget = limit_chars - len(prefix_marker) - len(status_text)
+ if budget > 20:
+ if len(last_part) > budget:
+ tail = "..." + last_part[-(budget - 3) :]
+ else:
+ tail = last_part
+ candidate = prefix_marker + tail + status_text
+ if len(candidate) <= limit_chars:
+ return candidate
+
+ # Fallback: marker + status only.
if dropped:
minimal = prefix_marker + status_text.lstrip("\n")
if len(minimal) <= limit_chars:
diff --git a/tests/messaging/test_transcript.py b/tests/messaging/test_transcript.py
index 6a8ad063..65760ca1 100644
--- a/tests/messaging/test_transcript.py
+++ b/tests/messaging/test_transcript.py
@@ -326,3 +326,18 @@ def test_transcript_render_status_only_exceeds_limit():
long_status = "A" * 500
msg = t.render(_ctx(), limit_chars=100, status=long_status)
assert "... (truncated)" in msg or long_status in msg
+
+
+def test_transcript_truncation_preserves_last_segment_tail():
+ """When all segments exceed limit, preserve tail of last segment (not just marker+status)."""
+ t = TranscriptBuffer()
+ t.apply({"type": "thinking_chunk", "text": "Thinking..."})
+ t.apply(
+ {"type": "text_chunk", "text": "The actual output content here" + "x" * 500}
+ )
+
+ msg = t.render(_ctx(), limit_chars=100, status="✅ *Complete*")
+ # Must include actual content (tail of last segment), not only "... (truncated)\n✅ *Complete*"
+ assert escape_md_v2("... (truncated)") in msg
+ assert "✅ *Complete*" in msg
+ assert "actual output" in msg or "content" in msg or "x" in msg