Commit Graph

8 Commits

Author SHA1 Message Date
Teknium
06f48b59e6 fix(caching): keep-alive accounting writes through the agent's storage handle
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.
2026-11-18 03:40:34 -08:00
Teknium
ebbaa5288e fix(compression): archive every pruned tool result to disk; never prune the running turn
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).
2026-11-18 03:40:34 -08:00
yoniebans
1bcda8c868 fix(storage): the shared rules' session source keeps the shared_session flag
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.
2026-11-17 17:49:48 +01:00
yoniebans
01b6f80004 feat(storage): rules and post-delete work the SQLite backend shares with callers
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.
2026-11-17 17:49:46 +01:00
yoniebans
d923fc1dc4 F20: session_rules comments describe behaviour, not its history
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
2026-11-17 14:09:23 +01:00
yoniebans
db427b05c9 fix(session_rules): never weld a passive group row into an addressed turn
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.
2026-11-17 13:01:56 +01:00
yoniebans
866436dc13 fix(session_rules): skill scaffold turns stop at the skill auto-load boundary
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.
2026-11-17 13:01:56 +01:00
yoniebans
5bf7658044 feat(session_rules): pure session rules shared by callers and backends 2026-11-17 13:01:55 +01:00