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
reactive_compact summarized the full message history before slicing off
the recent tail, so the kept tail was summarized and then re-attached
verbatim, and the emergency prompt-too-long path re-summarized the whole
oversized context. Move the summarize_history call below the tail
computation (including the tool_use/tool_result pair adjustment) and
summarize only messages[:tail_start], so the summary covers older history
while the recent tail stays verbatim.
Applied to the duplicated function in s08, s09, and s20, with the s08
README snippets (en/zh/ja) updated to match. Adds tests covering the
normal path and the case where a tool pair straddles the tail boundary.
Fixes#350