docs: align reactive_compact README guard with code

The reactive_compact README snippets (en/zh/ja) used a shortened tail
boundary check, while code.py guards with `tail_start > 0 and tail_start
< len(messages)` before reading messages[tail_start]. Match the snippets
to the actual code so the teaching example stays consistent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UJumwVeBXSGYh8nSzoVTF
This commit is contained in:
costajohnt
2026-06-21 16:47:09 -07:00
parent 49b3822247
commit 7659f28976
3 changed files with 9 additions and 3 deletions

View File

@@ -140,7 +140,9 @@ This triggers **reactive_compact**: more aggressive than compact_history, it ret
def reactive_compact(messages):
transcript = write_transcript(messages)
tail_start = max(0, len(messages) - 5)
if _is_tool_result_message(messages[tail_start]) and _message_has_tool_use(messages[tail_start - 1]):
if (tail_start > 0 and tail_start < len(messages)
and _is_tool_result_message(messages[tail_start])
and _message_has_tool_use(messages[tail_start - 1])):
tail_start -= 1
summary = summarize_history(messages[:tail_start])
return [{"role": "user",

View File

@@ -140,7 +140,9 @@ API がまだ `prompt_too_long`413を返すことがある。コンテキ
def reactive_compact(messages):
transcript = write_transcript(messages)
tail_start = max(0, len(messages) - 5)
if _is_tool_result_message(messages[tail_start]) and _message_has_tool_use(messages[tail_start - 1]):
if (tail_start > 0 and tail_start < len(messages)
and _is_tool_result_message(messages[tail_start])
and _message_has_tool_use(messages[tail_start - 1])):
tail_start -= 1
summary = summarize_history(messages[:tail_start])
return [{"role": "user",

View File

@@ -140,7 +140,9 @@ def compact_history(messages):
def reactive_compact(messages):
transcript = write_transcript(messages)
tail_start = max(0, len(messages) - 5)
if _is_tool_result_message(messages[tail_start]) and _message_has_tool_use(messages[tail_start - 1]):
if (tail_start > 0 and tail_start < len(messages)
and _is_tool_result_message(messages[tail_start])
and _message_has_tool_use(messages[tail_start - 1])):
tail_start -= 1
summary = summarize_history(messages[:tail_start])
return [{"role": "user",