Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkgs/ro-shell/ro_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import tempfile
import threading

MAX_OUTPUT = 24_576
HEAD_BYTES = 12_288
TAIL_BYTES = 12_288
# 50 KB inline cap (25 KB head + 25 KB tail, matching goose shell's 50 KB knee).
# Widened from 24 KB after 48h telemetry showed 35.2% (25/71) spill re-read rate
# at 24 KB (44% in 24-32 KB, 41% in 32-40 KB) vs 7.1% (1/14) at 50 KB.
MAX_OUTPUT = 51_200
HEAD_BYTES = 25_600
TAIL_BYTES = 25_600
MAX_SPILL_BYTES = 10 * 1024 * 1024
DEFAULT_TIMEOUT = 300
# Goose extension timeout is 600s (gen_goose_roles.py ro_extensions).
Expand Down
19 changes: 11 additions & 8 deletions pkgs/ro-shell/test_ro_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,18 @@ def setUpClass(cls):
cls.ro_shell = mod

def test_small_output_passthrough_no_spill(self):
out = "hello world\nline 2\n"
res = self.ro_shell._truncate_and_spill(out)
self.assertEqual(res, out)
for out in ("hello world\nline 2\n", "X" * 40_000, "Y" * self.ro_shell.MAX_OUTPUT):
res = self.ro_shell._truncate_and_spill(out)
self.assertEqual(res, out)
# Exactly MAX_OUTPUT + 1 must spill
over = "Z" * (self.ro_shell.MAX_OUTPUT + 1)
self.assertIn("Full output saved to ", self.ro_shell._truncate_and_spill(over))

def test_large_output_head_tail_and_spill_file_matches_telemetry_regex(self):
import re
head_marker = "HEAD_START_MARKER\n"
tail_marker = "\nTAIL_END_MARKER"
body = head_marker + ("M" * 40_000) + tail_marker
body = head_marker + ("M" * (self.ro_shell.MAX_OUTPUT + 10_000)) + tail_marker
res = self.ro_shell._truncate_and_spill(body)

self.assertIn(head_marker, res)
Expand All @@ -581,8 +584,8 @@ def test_large_output_head_tail_and_spill_file_matches_telemetry_regex(self):
self.assertEqual(fh.read(), body)

def test_utf8_multibyte_boundary_safe(self):
# 4-byte emoji repeated so byte slice lands mid-codepoint
body = "\U0001f680" * 10_000 # 40,000 bytes
# 1-byte prefix shifts 4-byte emojis so HEAD_BYTES/TAIL_BYTES slices land mid-codepoint
body = "x" + ("\U0001f680" * ((self.ro_shell.MAX_OUTPUT // 4) + 2_500))
res = self.ro_shell._truncate_and_spill(body)
self.assertIn("Full output saved to ", res)
self.assertNotIn("\ufffd", res)
Expand All @@ -593,7 +596,7 @@ def test_spill_cleaned_up_on_server_exit(self):
prev = self.ro_shell._SCRATCH_DIR
self.ro_shell._SCRATCH_DIR = scratch
try:
res = self.ro_shell._truncate_and_spill("A" * 40_000)
res = self.ro_shell._truncate_and_spill("A" * (self.ro_shell.MAX_OUTPUT + 10_000))
m = re.search(r"Full output saved to:?\s+(/[^\s\]\)'\"`]+)", res)
self.assertIsNotNone(m)
spill_path = m.group(1).rstrip(".,;:")
Expand All @@ -612,7 +615,7 @@ def test_deleted_scratch_dir_is_recreated_with_private_mode(self):
prev = self.ro_shell._SCRATCH_DIR
self.ro_shell._SCRATCH_DIR = scratch
try:
res = self.ro_shell._truncate_and_spill("B" * 40_000)
res = self.ro_shell._truncate_and_spill("B" * (self.ro_shell.MAX_OUTPUT + 10_000))
m = re.search(r"Full output saved to:?\s+(/[^\s\]\)'\"`]+)", res)
self.assertIsNotNone(m)
spill_path = m.group(1).rstrip(".,;:")
Expand Down
Loading