Hmbown/CodeWhale · error

Compaction did not reduce context; original conversation…

Error message

Compaction did not reduce context; original conversation was preserved.

What it means

After building a compacted message list, the compaction pipeline compares estimated input tokens of the kept messages against the original conversation. If compaction pressure was reached but the compacted result is not smaller than the original, it bails and keeps the original conversation intact, refusing to replace history with a no-op or larger compaction.

Solutions

  1. Continue the session and let more turns accumulate so older content becomes compactable
  2. Start a new session/fresh conversation to reset context
  3. Check compaction configuration (thresholds/keep settings) if it over-protects recent messages
  4. Retry compaction later — the original conversation was preserved, nothing is lost
Defensive patterns

Strategy: try-catch

Validate before calling

function compactionWillHelp(messages, kept, estimate) {
  return estimate(kept) < estimate(messages);
}

Try / catch

match compaction::run(&messages).await {
  Ok(summary) => apply(summary),
  Err(e) if e.to_string().contains("did not reduce context") => keep_original_conversation(),
  Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: The kept-message selection after last_round validation is the same size or larger than the original messages — e.g. nearly all messages are in the last round so nothing can be dropped, or token estimates of kept content equal/exceed the original.

Common situations: Very short conversations where everything is protected as recent history; tool-heavy sessions where results cannot be elided; compaction invoked repeatedly after context already shrank.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/c9c4d896be9a9fa3. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/compaction.rs:1226

            // invalidated the cached history prefix for the summary request.
            messages,
            config,
            system_prompt,
            prepared.tools.as_deref(),
            &mut quality_retries,
            invocation_usage,
        )
        .await
        {
            Ok((msgs, prompt, mut coverage)) => {
                let kept = sanitize_retained_messages(msgs);
                last_round::validate_last_round_coverage(messages, &kept)?;
                if config.enabled
                    && compaction_pressure_reached(messages, system_prompt, config)
                    && estimate_input_tokens_for_pressure(&kept, system_prompt)
                        >= estimate_input_tokens_for_pressure(messages, system_prompt)
                {
                    anyhow::bail!(
                        "Compaction did not reduce context; original conversation was preserved."
                    );
                }
                let keep: CompactionKeep = inspect_compaction_keep(&kept);
                coverage.last_round_messages = keep.last_round_messages;
                coverage.last_round_tool_results = keep.last_round_tool_results;
                coverage.last_round_assistant = keep.last_round_assistant;
                if let (Some(session_id), Some(summary)) =
                    (prepared.session_id.as_deref(), prompt.as_ref())
                {
                    let text = summary_prompt_text(summary);
                    let redacted = codewhale_config::persistence::redact_json_secrets(
                        &serde_json::Value::String(text),
                    );
                    crate::artifacts::write_session_relative_immutable(
                        session_id,
                        &std::path::PathBuf::from("artifacts")
                            .join(format!("context-transfer-{checkpoint_id}.md")),

View on GitHub (pinned to 73e0f67d83)