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

  1. Start conversation with LMStudio-hosted model (e.g., ornith-1.0-35b)
  2. Have several back-and-forth tool calls
  3. Let Hermes auto-trigger compaction when approaching context limits
  4. Error appears on 2nd or 3rd compaction attempt

The Error Chain

Compaction Error
⚠️ API call failed (attempt 1/3): APIError 🔌 Provider: lmstudio Model: ornith-1.0-35b 📝 Error: Error rendering prompt with jinja template: "No user query found in messages."

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

DimensionSeverityDetail
Data IntegrityCRITICALSession state corruption — conversation continuity is lost. The compaction system that's supposed to preserve long-conversation coherence instead destroys it.
Session RecoveryHIGHNo recovery possible — user must start a new session. All conversation context from the corrupted session is lost.
Silent FailureHIGHError may not be immediately obvious — subsequent turns reference stale or incomplete context, producing wrong answers with confidence.
Long-Conversation UXCRITICALCompaction 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 ComplexityHIGHJinja template + message assembly + state management across multiple compaction rounds — requires deep investigation into the compaction pipeline

Context Management Bug History (3 Distinct Issues)

IssueSeverityDateDescription
#53008P2Jun 26Context Compression Infinite Loop — aux model too small triggers unbounded re-compression
#55626P2Jun 30mnemosyne_recall and cronjob list consistently return [Result unavailable]
#55677P2Jun 30Compaction 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

📋 https://hermes-agent.reviews/hermes-context-compaction-jinja-crash-55677.html
Tracked by hermes-agent.reviews — June 30, 2026