Skip to content

fix: re-add HOW_TO_COMPRESS_RULES to nudge injection - #245

Merged
ranxianglei merged 1 commit into
masterfrom
2026-07-30_how-to-compress-investigation
Jul 30, 2026
Merged

fix: re-add HOW_TO_COMPRESS_RULES to nudge injection#245
ranxianglei merged 1 commit into
masterfrom
2026-07-30_how-to-compress-investigation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

v1.14.7 (PR #228) removed HOW_TO_COMPRESS_RULES from nudge templates to save ~2.4K tokens/turn. Rules kept in system prompt only.

But in 8700+ message sessions, the system prompt (12K chars) is buried at the START of a 1M+ token context. The model's attention to rules at the beginning degrades — the "lost in the middle" effect. When the nudge fires and the model needs to write summaries, the detailed rules (KEEP VERBATIM, DROP, PRIORITY) are not at high attention.

The nudge message IS at the END of context (high attention). Before v1.14.7 it contained the rules. Now it only has COMPRESS_PHILOSOPHY (889 chars, high-level) — missing the detailed 4936-char rules for HOW to write good summaries.

Evidence: session ses_0b89319b floor 8683 — nudge shows "Compression Philosophy" but NOT "HOW TO COMPRESS" rules.

Fix

Re-add HOW_TO_COMPRESS_RULES to nudge text in two places:

  1. Non-maxLimit path (inject.ts:534): Before compressible ranges list, after COMPRESS_PHILOSOPHY
  2. MaxLimit path (inject.ts:545): In strong alert tipsText, before JSON example

Tradeoff

+5K chars when a nudge fires (gated by nudgeGrowthTokens — NOT every turn). Better summaries = fewer recompressions needed = net token savings.

Verification

  • typecheck: clean
  • 934 tests pass (0 failures)

…on summary guidance

v1.14.7 removed HOW_TO_COMPRESS_RULES from nudge to save ~2.4K tokens/turn,
keeping it in system prompt only. But in 8700+ message sessions, the system
prompt is 12K chars buried at the START of 1M+ token context — the model's
attention to the rules degrades ('lost in the middle' effect). When the nudge
fires and the model needs to write summaries, the detailed rules (KEEP VERBATIM,
DROP, PRIORITY) are not at high attention.

Re-add HOW_TO_COMPRESS_RULES to nudge text: non-maxLimit path (before ranges
list) and maxLimit path (in strong alert). +5K chars per nudge, but nudges
are gated by nudgeGrowthTokens — not every turn. Better summaries = fewer
recompressions = net token savings.
@ranxianglei
ranxianglei merged commit 33e4a2f into master Jul 30, 2026
5 checks passed
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.

1 participant