Your gateway chat now gets summarized while you are away, not while you wait

You come back from lunch, open the Telegram thread you were debugging in, and type one short sentence: “so where did we land on the invoice format?” Then you watch the typing indicator for half a minute. Nothing is wrong — the agent is reading yesterday’s four hundred messages to remember what you already decided, and your one-line question is paying for all of it.
This is the gap Hermes v0.23.5 closes. Compaction of idle conversations existed, but it ran at the worst possible moment: when your next message arrived. The gateway now does it in the background, from the same housekeeping tick that already evicts cold agents, so the summary is ready before you are.
The bug was timing, not compression
Context compression itself is old news: when a conversation grows past a threshold, Hermes summarizes the older turns and keeps working on the summary. What was broken is when the idle trigger fired.
compression.idle_compact_after_seconds is an opt-in knob: if a session resumes after at least that many seconds of inactivity, compact it up front before the first reply. On paper, perfect. In practice the measured gap was always about zero, because both the durable turn lease and the gateway’s cached-agent initializer re-stamped the last-activity timestamp immediately before the check read it. A freshly rebuilt agent starts its clock at construction time, so every resumption looked like “just active”. In the gateway the idle timer never fired at all — issue #79357.
The fix changes the reference point: the gap is measured from the newest transcript row before this turn, and _last_activity_ts is only the fallback. The transcript survives an agent rebuild; the timestamp does not.
What the gateway does now
The housekeeping tick — the one that already runs every five minutes to evict idle agents — now also claims a cached chat whose idle policy has passed. It runs the existing cache-edge job: one job per key, the same semaphore, the chat’s profile scope and claim gate, the same manual-compression path with trigger="idle". No new worker, no new table, no new scheduler. That matters for reliability: compaction already had cooldowns, anti-thrash guards and a per-session lock, and the background path inherits all of them rather than growing a second, weaker copy.
Two details make it work on routes that used to be excluded. It does not depend on prompt-cache keep-alive, so local models and custom endpoints get it too. And the idle policy is checked before the cache edge’s offload claim — without that ordering, a tick just past the cache window was spent on a no-op offload and the compaction ran about five minutes late.
Turning it on
The global switch lives under compression:
compression:
threshold_tokens: 40000
target_ratio: 0.2
idle_compact_after_seconds: 1800 # 30 minutes idle; 0 = off (default)
0 is the default, so nothing changes until you ask for it. Pick a value that matches how you actually use the thread: 1800 seconds works for a chat you return to after meetings, a full day (86400) for a long-running project room, a few minutes if you are iterating quickly and want the context lean.
Per channel, the same key overrides the global value:
platforms:
telegram:
channel_overrides:
"-1001234567890":
idle_compact_after_seconds: 0 # never background-compact this room
The resolution walks chat, then thread, then parent, like model and system_prompt. A positive value compacts that channel’s idle chats; 0 turns it off there even when the global value is on; leaving it unset keeps the global value. It is a channel policy, so it also applies after /new. The global key is picked up by a cached agent on its next turn; a channel’s own value, like the other channel overrides, takes effect after a gateway restart.
Outside the gateway, the knob still means “compact up front when this session resumes after a long idle” — the same intent, executed synchronously because there is no housekeeping loop to lean on.
What it measured
The author verified it against real hermes gateway run processes, driving chats through the API server with a stable session id, on a custom (unpriced) endpoint with Claude Haiku 5.5. Config: idle_compact_after_seconds: 120, threshold_tokens: 40000, target_ratio: 0.2.
| Observation | Before | After |
|---|---|---|
| Idle window after the last turn | 3 ticks, no compaction log line at all | Background idle compaction … idle_after=120s result=Compressed: 16 → 8 messages, ~8,611 → ~3,665 tokens |
Rows in state.db before the next message |
unchanged, 7 messages | 17 active rows → 8, compacted rows written at 19:05:24 |
| Next message, 662 s idle | no idle compaction; prompt 28,310 tokens | prompt 5,865 tokens (was 12,047); the answer still knew the codename from before compaction |
Channel override set to 0 |
key ignored | that chat never compacted, the other one did |
The last row is the one worth keeping: compression did not lose the thread. The model still answered with a codename that had been stated in the part that got summarized.
The guardrails
Background work on someone’s live conversation needs restraint, so the job skips:
- a chat with a turn currently running;
- a chat with input that has not been dispatched yet — a pending adapter message, a text batch for the same session, an in-flight guard, or the runner’s overflow queue (re-checked immediately before summarizing, because a job can queue behind other summaries);
- a Codex app-server thread in
nativeoroffmode, which compacts itself.
It also runs at most once per idle stretch: a refused or failed attempt waits for new activity before trying again, and a success evicts the agent the way the cache-edge job already did. If the idle-TTL sweep gets to a chat first — the default agent cache TTL is one hour — the chat is compacted at release if it was due, otherwise when it resumes.
Everything is silent in the chat itself. Success and failure both go to the gateway log as Background idle compaction: session=… result=…. You will not get a “I summarized our conversation” message, which is the correct amount of ceremony for housekeeping.
What it does not do
It does not touch an agent that is mid-turn, it does not create a new messaging session, and it does not compact a chat that is already below the post-compression floor. It is also not a cost optimizer on its own: the summary itself costs a model call. What it buys is latency and context headroom on the next human message — which is why the numbers above matter more than the token count.
If you have ever watched a gateway reply start with a 30-second pause after a quiet night, this is the release that removes it. For the wider context of how Hermes decides when to compress, our compaction guide and the prompt-rebuild notes go deeper; the v0.23.5 rollup covers the rest of the window.