86e603e7d6
The salvaged retention check compared the built-in memory snapshot before vs after the disk reload. That holds for a long-lived CLI agent, but on fresh-agent surfaces (gateway per-turn agents, TUI) the cached prompt is restored from the session DB and can predate mid-session memory writes that the fresh MemoryStore already absorbed at init: the snapshot is then identical on both sides of the reload while the prompt itself is stale, so compression would retain (and re-persist via update_system_prompt) a prompt missing the new memory for the life of the session. Replace the equality check with a containment check (_cached_prompt_reflects_builtin_memory): retain the cached prompt only when the freshly-reloaded rendered blocks appear verbatim inside it, and rebuild when a leftover block header remains for a target whose entries have since been emptied or disabled. Block headers are shared via MEMORY_BLOCK_HEADERS in tools/memory_tool.py so the check stays in lockstep with MemoryStore._render_block. Adds regression guards for the gateway stale-restore path and the emptied-memory leftover-block path; verified with a real-MemoryStore E2E matrix (9 scenarios) against a temp HERMES_HOME.