Skip to content

fix: add hysteresis to message-count compaction - #582

Open
JiangYuxin-Jim wants to merge 1 commit into
shareAI-lab:mainfrom
JiangYuxin-Jim:fix/snip-compaction-hysteresis
Open

JiangYuxin-Jim wants to merge 1 commit into
shareAI-lab:mainfrom
JiangYuxin-Jim:fix/snip-compaction-hysteresis

Conversation

@JiangYuxin-Jim

Copy link
Copy Markdown

Closes #581.

When snip_compact trims a history back to the same 50-message threshold that triggers it, each subsequent exchange can cause another full transcript write before the next model call. Separate the trigger and target so normal compaction leaves room for new messages.

Changes

  • In S08 and S15, use trigger_messages=50 and target_messages=30; trigger when the history reaches 50 messages, including when a batch overshoots it.
  • Retain the first three messages, one archive marker, and normally the latest 26 messages. Keep the existing archive-before-trim and tool-call/result boundary protection; preserving a pair can slightly exceed the target.
  • Require 5 <= target_messages < trigger_messages so the target includes at least one recent message and leaves headroom.
  • Test the full preparation path: 49 messages cause no archive, 50 compact to 30, nine subsequent two-message additions create no new archives, and the tenth triggers the next archive. Also cover overshoot, invalid settings, complete transcript preservation, and both tool-pair boundaries.
  • Synchronize the S08/S15 English, Chinese, and Japanese READMEs, update the three S08 diagrams, and regenerate the website course data/assets with the repository script.

Tradeoffs

This keeps fewer recent messages directly in context (26 instead of 46), with older content available from the transcript. The defaults are a proposal for maintainer review. The existing active-request retention concern in #577 remains relevant when trimming more history; this PR does not attempt to solve that separate issue. Callers using the old max_messages keyword should now pass trigger_messages and target_messages; the in-repository call sites and tests are updated.

Validation

  • Python 3.11.16 in the contributor's existing py311 environment: python -m pytest tests -q — 485 passed, 112 subtests passed.
  • npx tsc --noEmit — passed.
  • npm run build — passed; 118 static pages generated.
  • git diff --check — passed.
  • Confirmed that the new hysteresis regression fails on both original implementations before the fix, and that the changed documentation code block is identical across all three languages.

AI assistance: OpenAI Codex assisted with the implementation, regression tests, documentation, verification, and PR preparation, based on the contributor's observation of repeated compaction at the message threshold.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s08/s15: separate snip_compact trigger and target to avoid repeated transcript writes

1 participant