fix: stop shrinking conversations behind the user's back — both automatic context guards ship off
Nightly Build / build (push) Successful in 7m35s

The shipped default combined a sliding history window with no compaction, which
is the worse of the two available trades in both directions it is measured on.

`max_history_messages: 30` is a sliding tail window (`projection::window` —
`drain(..len - max)`). Past 30 messages it drops from the head on *every* turn,
so the prompt prefix changes on every single request and every provider that
caches one (Anthropic breakpoints, OpenAI automatic prefix caching) misses every
time. It also drops those messages with no summary standing in for them: silent
amnesia, not just a cold cache. Compaction rewrites the prefix once per
compaction and leaves a summary behind — yet it was the half that was commented
out, while the window's own doc-comment already said the two were exclusive.

Both are now `Option` and both ship unset, so nothing shrinks a conversation
unless a human types `/compact`.

Which surfaced the real bug: `/compact` did not work either. The compactor was
`Option<Arc<ContextCompactor>>` keyed on the config section existing, so
commenting out `compaction:` disabled the manual command too — `force_compact`
returned `Ok(false)` and the chat answered "compaction disabled". Manual
compaction is a command a user types; it cannot depend on an admin having filled
in a token threshold. The compactor is now built unconditionally and
`threshold_tokens: Option<u32>` arms only the automatic pass; `try_compact`
early-returns without it, `force_compact` deliberately never consults it.

The projection accordingly yields to the *automatic* pass rather than to the
compactor's existence (`LoopConfig.auto_compaction_enabled`), so a configured
message cap is not silently voided by `/compact` merely being available.
`CompactionConfig::Default` is hand-written for the same reason `RoleAttrs`'s is:
a derived one gives `keep_recent: 0`, which would compact away every recent
message on any box omitting the section — now the default.

Also fixes two documentation bugs in the same file: `event_triage` was documented
nested under `llm:`, where it parses fine and is then silently ignored (it is a
top-level field), and `datetime` was documented twice with conflicting examples.

A new test asserts the shipped default actually deserializes and that both guards
are off — a field the default omits must be genuinely optional, or a brand-new
install fails to boot.

Automatic compaction returns later, triggered off the resolved model's own
context window instead of a hand-tuned token count that cannot know which model
is answering.
This commit is contained in:
2026-08-02 21:21:14 +01:00
parent d4b34e6130
commit baf68878e4
16 changed files with 227 additions and 105 deletions
+24
View File
@@ -99,3 +99,27 @@ impl Config {
pub fn resolved_log_dir() -> std::path::PathBuf {
std::path::PathBuf::from("logs")
}
#[cfg(test)]
mod tests {
use super::*;
/// The shipped default is copied verbatim to `config.yml` on first run, so a
/// field it omits must be genuinely optional — a required one would fail the
/// boot of a brand-new install, where nobody has a config to compare against.
#[test]
fn shipped_default_config_parses() {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(DEFAULT_CONFIG);
let content = std::fs::read_to_string(&path)
.unwrap_or_else(|e| panic!("cannot read {}: {e}", path.display()));
let cfg: Config = serde_yaml::from_str(&content).expect("default.config.yaml does not parse");
// Both automatic context reducers ship off: only `/compact` shrinks a
// conversation, so the prompt prefix (and the provider's cache of it)
// stays stable. See the context-size section in CLAUDE.md.
assert_eq!(cfg.llm.max_history_messages, None, "the history window must ship disabled");
assert_eq!(cfg.llm.compaction.threshold_tokens, None, "automatic compaction must ship disabled");
// ...while manual compaction still has usable settings behind it.
assert_eq!(cfg.llm.compaction.keep_recent, 6);
}
}
+1 -1
View File
@@ -277,7 +277,7 @@ async fn handle_socket(mut socket: WebSocket, skald: Arc<Skald>, source: String,
let _ = socket.send(to_msg(&ServerEvent::Done {
message_id: 0,
stack_id: 0,
content: "⏩ Compaction skipped (no messages to summarize or compaction disabled).".to_string(),
content: "⏩ Compaction skipped (nothing to summarize).".to_string(),
input_tokens: None,
output_tokens: None,
reasoning_content: None,