{"record":{"id":"c9c4d896be9a9fa3","repo":"Hmbown/CodeWhale","slug":"compaction-did-not-reduce-context-original-conversation-was","errorCode":null,"errorMessage":"Compaction did not reduce context; original conversation was preserved.","messagePattern":"Compaction did not reduce context; original conversation was preserved\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/compaction.rs","lineNumber":1226,"sourceCode":"            // invalidated the cached history prefix for the summary request.\n            messages,\n            config,\n            system_prompt,\n            prepared.tools.as_deref(),\n            &mut quality_retries,\n            invocation_usage,\n        )\n        .await\n        {\n            Ok((msgs, prompt, mut coverage)) => {\n                let kept = sanitize_retained_messages(msgs);\n                last_round::validate_last_round_coverage(messages, &kept)?;\n                if config.enabled\n                    && compaction_pressure_reached(messages, system_prompt, config)\n                    && estimate_input_tokens_for_pressure(&kept, system_prompt)\n                        >= estimate_input_tokens_for_pressure(messages, system_prompt)\n                {\n                    anyhow::bail!(\n                        \"Compaction did not reduce context; original conversation was preserved.\"\n                    );\n                }\n                let keep: CompactionKeep = inspect_compaction_keep(&kept);\n                coverage.last_round_messages = keep.last_round_messages;\n                coverage.last_round_tool_results = keep.last_round_tool_results;\n                coverage.last_round_assistant = keep.last_round_assistant;\n                if let (Some(session_id), Some(summary)) =\n                    (prepared.session_id.as_deref(), prompt.as_ref())\n                {\n                    let text = summary_prompt_text(summary);\n                    let redacted = codewhale_config::persistence::redact_json_secrets(\n                        &serde_json::Value::String(text),\n                    );\n                    crate::artifacts::write_session_relative_immutable(\n                        session_id,\n                        &std::path::PathBuf::from(\"artifacts\")\n                            .join(format!(\"context-transfer-{checkpoint_id}.md\")),","sourceCodeStart":1208,"sourceCodeEnd":1244,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/compaction.rs#L1208-L1244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Continue the session and let more turns accumulate so older content becomes compactable","Start a new session/fresh conversation to reset context","Check compaction configuration (thresholds/keep settings) if it over-protects recent messages","Retry compaction later — the original conversation was preserved, nothing is lost"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function compactionWillHelp(messages, kept, estimate) {\n  return estimate(kept) < estimate(messages);\n}","typeGuard":null,"tryCatchPattern":"match compaction::run(&messages).await {\n  Ok(summary) => apply(summary),\n  Err(e) if e.to_string().contains(\"did not reduce context\") => keep_original_conversation(),\n  Err(e) => return Err(e),\n}","preventionTips":["Expect this on short sessions where recent-message protection covers everything","Do not retry immediately; wait until more turns accumulate","Treat the error as informational — the original conversation is preserved","Review keep/threshold compaction settings if it recurs on long sessions"],"tags":["compaction","context-window","conversation"],"backgroundTag":"operation-not-supported","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}