docs: compaction tuning guide with per-tier presets and cache economics#308
docs: compaction tuning guide with per-tier presets and cache economics#308100yenadmin wants to merge 8 commits into
Conversation
New comprehensive guide for operators tuning LCM compaction behavior: - docs/compaction-tuning.md (356 lines): TLDR, per-tier model presets (Opus, Sonnet, Haiku, GPT-4o-mini, Gemini Flash), cache economics break-even formula, debugging checklist, orchestration scenarios - docs/architecture.md: cache-aware guards section with Mermaid flowchart - docs/configuration.md: new settings reference, model comparison table - skills references: config field updates Split from Martian-Engineering#289 (Part 3 of 3). Independent of Martian-Engineering#306 and Martian-Engineering#307.
There was a problem hiding this comment.
Pull request overview
Adds operator-facing documentation for tuning Lossless Claw compaction behavior, including a new compaction tuning guide and updates to existing docs/reference materials.
Changes:
- Add new
docs/compaction-tuning.mdguide with presets, cache economics, and troubleshooting. - Update
docs/configuration.mdanddocs/architecture.mdwith new compaction tuning/guard explanations. - Update skill config reference with new compaction-related fields.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
docs/compaction-tuning.md |
New tuning guide describing cache-aware compaction behavior, presets, and economics. |
docs/configuration.md |
Updates defaults and adds a new “cache-aware compaction tuning” section. |
docs/architecture.md |
Adds an architecture section describing cache-aware compaction guard ordering with a Mermaid diagram. |
skills/lossless-claw/references/config.md |
Documents new config fields related to cache-aware compaction skipping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Change "Never use your main model" to "Avoid using your main model when it's expensive or slow" — consistent with later recommending Haiku/Sonnet which may be someone's main model - Add clarifying note that quick-start snippet values are recommended overrides, not defaults (freshTailCount=32 vs default 64)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- TLDR example: "Sonnet" → "Haiku" to match the copy-paste config - Debug section: make log line guidance more resilient to wording changes - Architecture flowchart: "raw tokens" → "raw tokens outside fresh tail"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add LCM_LEAF_MIN_FANOUT, LCM_CONDENSED_MIN_FANOUT, and LCM_CONDENSED_MIN_FANOUT_HARD to the settings table - Replace hard-coded "5%" in flowcharts with "leafSkipReductionThreshold (default 5%)" in both compaction-tuning.md and architecture.md
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…n comparison table - README env var table: LCM_LEAF_TARGET_TOKENS default was 1200, config resolver uses 2400. Fixed to match code. - Model comparison table: add note that names are marketing names, use provider-qualified IDs for config.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adversarial audit findings: - Remove unverifiable "$4 for 200-turn session" claim, replace with paper-backed reduction ranges (20-39% avg, up to 86%) - Fix gpt-4.1-mini pricing: $0.40/$1.60 → $0.20/$0.80 - Fix mistral-small pricing: $0.15/$0.60 → $0.20/$0.60 - Add gpt-4.1-nano ($0.10/$0.40) — cheapest available option - Add config IDs next to marketing names in model table - Remove MiniMax-Text-01 (unverifiable pricing) - Add cache write premium note to break-even formula (1.25x for 5-min TTL adds ~0.7 turns to break-even) - Sort table by cost/call ascending for easier comparison
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This is pure gold, thank you. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | Model | Cost/call | Context | Notes | | ||
| |-------|-----------|---------|-------| | ||
| | `gpt-4o-mini` | ~$0.004 | 128K | Cheapest, auto caching | | ||
| | `mistral-small-4` | ~$0.004 | 256K | Same price, bigger context | |
| ~2400 tokens ~2400 tokens ├── fresh tail ──┤ | ||
|
|
||
| After condensation (depth 1): | ||
| [condensed₁: leafs 1-3] [leaf₄] [leaf₅] [msg₄₁] ... [msg₅₀] |
| When compaction runs on the main agent session, it stalls all connected sessions sharing that thread. To prevent this: | ||
|
|
||
| 1. **Isolate sub-agent sessions** — Configure `ignoreSessionPatterns` or `statelessSessionPatterns` to prevent sub-agents from triggering compaction | ||
| 2. **Use shorter timeouts** — Set `summaryTimeoutMs` to 30000 (30s) so failed compaction releases quickly | ||
| 3. **Choose fast models** — A 0.5s Haiku call is invisible even without isolation | ||
|
|
||
| ```json | ||
| { | ||
| "summaryModel": "claude-haiku-4-5", | ||
| "summaryProvider": "anthropic", | ||
| "summaryTimeoutMs": 30000, | ||
| "ignoreSessionPatterns": ["agent:*:cron:**"], | ||
| "statelessSessionPatterns": ["agent:*:subagent:**"] |
| **Fix:** Set `expansionModel` to a cheaper model: | ||
|
|
||
| ```json | ||
| { | ||
| "expansionModel": "claude-haiku-4-5", | ||
| "expansionProvider": "anthropic" | ||
| } |
| 2. Receives ~600-2400 output tokens (the summary) | ||
| 3. Blocks until complete (full sweep is synchronous) | ||
|
|
||
| **Compaction model comparison** (cost per call = 20K input + 2.4K output). Model names below are marketing names — use the provider-qualified config ID (e.g., `gpt-4o-mini`, `claude-haiku-4-5`) when setting `summaryModel`: |
Summary
Comprehensive operator-facing documentation for tuning LCM compaction behavior — model selection, cache economics, per-tier presets, debugging, and the full guard evaluation flow. No code changes.
Part 3 of 3 from #289 split. Merge after #306 and #307.
Why This Documentation Matters
Compaction tuning is the highest-leverage configuration in LCM. The wrong settings cost real money:
lcm_expand_queryspawns a 3-8 turn sub-agent. On Opus, that's $0.15-0.50 per call. SettingexpansionModelto Haiku drops it to $0.03-0.10.None of this is discoverable from the code alone.
New Content
docs/compaction-tuning.md(356 lines, NEW)The main guide, structured for both quick-start and deep understanding:
TLDR section — Copy-paste configs for 4 common scenarios:
How it works — Full lifecycle with Mermaid diagrams:
Cache economics — Concrete cost tables:
Model selection — Comparison table of 10 compaction model options:
Guard evaluation flow — Mermaid flowchart showing:
Debugging checklist — Three common problems:
References — Links to the LCM paper, arXiv research, Anthropic/OpenAI caching docs.
Updated docs
docs/architecture.mddocs/configuration.mdskills/lossless-claw/references/config.mdleafSkipReductionThresholdandleafBudgetHeadroomFactorwith defaults, ranges, and env var names.