hermes - 💡(How to fix) Fix [Feature]: Pre-compression task state preservation hook [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11753Fetched 2026-04-18 05:59:04
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Root Cause

When Hermes Agent's context compression fires (triggered by context_engine: compressor), it destroys context without any pre-hook to preserve task state. This caused a catastrophic data loss: 249 conversation turns were wiped because the compression API call (Google Gemini, no key configured) failed silently.

Fix Action

Fix / Workaround

  • Periodic checkpoint cron (workaround): Running session_checkpoint.py every N minutes reduces blast radius but doesn't guarantee preservation before compression fires.
  • Changing compression provider: Switching from Google to another provider fixes the API key issue but doesn't solve the fundamental race condition — compression can still fail, and context is still destroyed without warning.
  • Relying on Hindsight/MemPalace: These are excellent secondary memory systems, but they're async/backups, not part of the compression lifecycle. They can't block compression.

Code Example

# Before attempting compression summary
hook_result = self.trigger_hook("precompact", session_state)
if hook_result.decision == "block":
    # Wait for memories to be saved externally, then retry
    return {"status": "deferred", "reason": "pending_memory_save"}

---

sessionRetention:
  enabled: true
  checkpoint_before_compress: true
  min_checkpoint_interval: 5  # exchanges
RAW_BUFFERClick to expand / collapse

Problem or Use Case

When Hermes Agent's context compression fires (triggered by context_engine: compressor), it destroys context without any pre-hook to preserve task state. This caused a catastrophic data loss: 249 conversation turns were wiped because the compression API call (Google Gemini, no key configured) failed silently.

The existing memory_hook.py has a precompact trigger designed precisely for this — it returns {"decision": "block"} to pause compression until memories are saved. However, nothing in the Hermes runtime actually invokes this hook before initiating compression.

The result: users lose entire conversation histories with no recovery mechanism, even when backup systems like Hindsight/MemPalace are running.

Proposed Solution

Two-part fix:

1. Wire precompact into the compression cycle

In context_compressor.py (or equivalent), add a hook call before call_llm for summarization:

# Before attempting compression summary
hook_result = self.trigger_hook("precompact", session_state)
if hook_result.decision == "block":
    # Wait for memories to be saved externally, then retry
    return {"status": "deferred", "reason": "pending_memory_save"}

This mirrors how memory_hook.py was already designed to work.

2. Add sessionRetention as a first-class config option

sessionRetention:
  enabled: true
  checkpoint_before_compress: true
  min_checkpoint_interval: 5  # exchanges

This gives users explicit control over session persistence behavior, separate from record_sessions.

Alternatives Considered

  • Periodic checkpoint cron (workaround): Running session_checkpoint.py every N minutes reduces blast radius but doesn't guarantee preservation before compression fires.
  • Changing compression provider: Switching from Google to another provider fixes the API key issue but doesn't solve the fundamental race condition — compression can still fail, and context is still destroyed without warning.
  • Relying on Hindsight/MemPalace: These are excellent secondary memory systems, but they're async/backups, not part of the compression lifecycle. They can't block compression.

Feature Type

  • Performance / reliability (data loss prevention)
  • Configuration option (new sessionRetention config block)

Scope

  • Medium — requires modifying compression engine lifecycle + adding config schema
  • Likely 2-3 files: context_compressor.py, config schema, and documentation

Debug context: Confirmed on Hermes Agent v0.9.0 (2026.4.13). The precompact trigger in memory_hook.py exists but has no caller in the compression pipeline.

extent analysis

TL;DR

Implement a precompact hook in the compression cycle to pause compression until task state is preserved, and introduce a sessionRetention config option for explicit control over session persistence.

Guidance

  • Modify context_compressor.py to invoke the precompact hook before initiating compression, allowing the hook to block compression if necessary.
  • Add a sessionRetention config block to provide users with control over session persistence behavior, including the ability to checkpoint sessions before compression.
  • Verify that the precompact hook is correctly blocking compression when necessary by testing the memory_hook.py functionality.
  • Consider implementing a periodic checkpoint cron as a temporary workaround to reduce the risk of data loss until the full fix is implemented.

Example

# Example of how to invoke the precompact hook in context_compressor.py
hook_result = self.trigger_hook("precompact", session_state)
if hook_result.decision == "block":
    # Wait for memories to be saved externally, then retry
    return {"status": "deferred", "reason": "pending_memory_save"}

Notes

The proposed solution requires modifying the compression engine lifecycle and adding a new config schema, which may have implications for existing configurations and workflows. Additionally, the effectiveness of the sessionRetention config option will depend on the specific use case and requirements of the users.

Recommendation

Apply the proposed two-part fix, including wiring the precompact hook into the compression cycle and introducing the sessionRetention config option, to prevent data loss and provide users with explicit control over session persistence behavior. This approach addresses the root cause of the issue and provides a more robust solution than relying on workarounds or alternative compression providers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING