diff --git a/pkgs/ro-shell/ro_shell.py b/pkgs/ro-shell/ro_shell.py index 5b17cff1..5f084997 100755 --- a/pkgs/ro-shell/ro_shell.py +++ b/pkgs/ro-shell/ro_shell.py @@ -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). diff --git a/pkgs/ro-shell/test_ro_shell.py b/pkgs/ro-shell/test_ro_shell.py index e7f7b997..57bd3ec5 100644 --- a/pkgs/ro-shell/test_ro_shell.py +++ b/pkgs/ro-shell/test_ro_shell.py @@ -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) @@ -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) @@ -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(".,;:") @@ -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(".,;:")