P2 Context Compaction Crashes with Jinja Template Error — Corrupts Session, Forces Restart (#55677)
Executive Summary
On the 2nd or 3rd auto-triggered compaction attempt, Hermes crashes with a Jinja template rendering error: "No user query found in messages." The message list assembled for the summarization prompt is empty or missing required fields, causing the compaction to fail. The session becomes corrupted — subsequent turns reference stale or incomplete context — and the user must start a new session. This is a data-loss class bug in the agent core context management. It is the 3rd distinct context compression/compaction bug we've tracked.
Reproduction & Root Cause
Steps to Reproduce
- Start conversation with LMStudio-hosted model (e.g., ornith-1.0-35b)
- Have several back-and-forth tool calls
- Let Hermes auto-trigger compaction when approaching context limits
- Error appears on 2nd or 3rd compaction attempt
The Error Chain
Root Cause Analysis
The message list assembled for the summarization prompt is empty or missing required fields on the 2nd/3rd compaction attempt. The Jinja template expects a "user query" field that isn't present in the assembled message list. This suggests a state management bug: after the first compaction, the message structure changes in a way the template doesn't handle. By the second or third compaction, the accumulated structural drift causes the template to fail.
Impact Assessment
| Dimension | Severity | Detail |
|---|---|---|
| Data Integrity | CRITICAL | Session state corruption — conversation continuity is lost. The compaction system that's supposed to preserve long-conversation coherence instead destroys it. |
| Session Recovery | HIGH | No recovery possible — user must start a new session. All conversation context from the corrupted session is lost. |
| Silent Failure | HIGH | Error may not be immediately obvious — subsequent turns reference stale or incomplete context, producing wrong answers with confidence. |
| Long-Conversation UX | CRITICAL | Compaction is the mechanism that enables long conversations. When it fails, long conversations become impossible — the agent's effective conversation length is capped at context window size. |
| Fix Complexity | HIGH | Jinja template + message assembly + state management across multiple compaction rounds — requires deep investigation into the compaction pipeline |
Context Management Bug History (3 Distinct Issues)
| Issue | Severity | Date | Description |
|---|---|---|---|
| #53008 | P2 | Jun 26 | Context Compression Infinite Loop — aux model too small triggers unbounded re-compression |
| #55626 | P2 | Jun 30 | mnemosyne_recall and cronjob list consistently return [Result unavailable] |
| #55677 | P2 | Jun 30 | Compaction crashes with Jinja error, corrupts session — forces restart |
⚠️ Pattern: Context management — the subsystem that's supposed to make Hermes reliable over long conversations — now has three independent failure modes: infinite loops (Jun 26), silent recall failures (Jun 30), and crash-on-compaction with session corruption (Jun 30). Two of these opened on the same day. The compaction pipeline needs systematic hardening — each fix addresses one failure mode while others remain.
Source Evidence
- GitHub Issue: #55677 — Context Compaction Crashes with Jinja Template Error
- Opened: June 30, 2026
- Reporter: @pawelgnatowski
- Labels: P2, bug, comp/agent, needs-repro, sweeper:risk-session-state, type/bug
- Hermes: v0.17.0 (fa3ab2f) | OS: Ubuntu 24.04 | Python: 3.11.15
- Debug report: paste.rs/sZXCf
- agent.log: paste.rs/dUC2c
- Reporter willing to submit PR: Yes
📋 https://hermes-agent.reviews/hermes-context-compaction-jinja-crash-55677.html
Tracked by hermes-agent.reviews — June 30, 2026