Main's persistence interface makes the agent's store a storage handle with no
queue_token_counts; the warmer's keep-alive accounting called it on
agent._session_db directly and silently lost every refresh's usage. It now goes
through turn_usage.queue_usage, which takes the handle's usage repository (and
the worker store otherwise) with the session id and surface the keep-alive
captured when it was scheduled.
Salvage of #136488 (kshitijk4poor), review findings from 100yenadmin and kvnloo.
- No information loss: before the proactive prune shortens a tool result, its
full original is written byte-verified to
$HERMES_HOME/cache/pruned/<session>_<UTC>_<tool>_<id>.<json|txt> and the stub
ends with " — full result: <path>", so read_file returns the exact output.
A result whose write fails stays whole and the reclaim gate is re-checked on
what is left (no commit -> the written files are removed).
- This also closes kvnloo's unflushed-original case without deferring the
prune: the original no longer depends on the store having seen the row.
- The running turn is never shortened: the post-tool site passes the turn's
user-row index (turn_start), and every row from it on is kept whole. Before,
the count-only tail let a long tool loop stub its own earlier calls.
- One sweeper: the spillover reference/retention machinery now covers
cache/pruned too (archive_refs_in_text / referenced_archive_refs; session
delete retires both). Pruned files follow sessions.retention_days and are
never deleted while state.db references them. cache/pruned is mounted for
sandboxed backends like cache/spillover, and the stub names the path the
backend sees.
- Cold-cache reading isolated in turn_proactive_prune.prompt_cache_is_cold so
the shared cache clock can replace it in one line.
- Two skill-safety fixtures pin the old 4096 reclaim gate (the shipped 64K
default made their ~7K-token transcripts no-ops).
SessionSource in session_rules.route_entries gains shared_session, written by to_dict only when set and read back by from_dict, and build_session_key keys a source with the flag on the chat's shared session even when it carries a sender id, as gateway.session does since main's Telegram observe-mode change. The copy is again main's SessionSource, and its build_session_key differs from main's only by the WhatsApp mapping it does not read.
New cases pin the round trip and the shared group key against main's own builder.
session_rules gains the turn-result, local-create retry and route-entry rules the store applies; persistence/core/keys.py names the profile a gateway session key belongs to; session_retention.py runs the post-commit work of the session delete, prune and archive verbs over the persistence contracts.
session_rules/turns.py and activity.py carried comments copied from main that retell history rather than behaviour: issue and PR numbers, "Pre-#NNNN" tags on the historical summary prefixes, a reviewer's name and review number, and a dated incident note on SUMMARY_PREFIX. Each now says what the code does, or the reference is dropped where the sentence already says it; the historical prefixes keep their byte-pinned text and each keeps a line naming what that wording lacks. Comments and docstrings only: the parse tree with docstrings blanked is identical before and after.
Reported-by: kshitijk4poor
The neutral copy of the restore-time repair takes main's boundary (agent_runtime_helpers._merge_consecutive_users): adjacent user rows merge only when both are passive (observed) or both addressed, so replay no longer folds an addressed turn into the group context. A row written before the flag existed counts as addressed. tests/neutral/test_turns_observed_merge.py covers the boundary and the same-class merges.
extract_user_instruction_from_skill_message now strips a gateway auto-load turn (complete header required) down to the typed text, and _describe_auto_loaded_skill_turn reads the same boundary through _auto_load_typed_text: the exact scaffold registered with register_auto_load_scaffold wins (longest match, bounded registry of 32 under a lock), and a turn built in another process falls back to the last payload footer and the trailing-block skip.
tests/neutral/test_turns_auto_load.py covers both functions on two-skill, bare, lookalike and registered-boundary turns, and the registry's cap and empty-scaffold guard.