feat(agent): escalate repeated transcript-sanitiser heals with a one-time user notice (#96870)
Builds the escalation layer on top of HexLab98's heal-log windowing (salvaged from PR #96916): - Per-session heal counters (heal events + messages healed) tracked by the repair path in agent_runtime_helpers.py, session totals preserved across 10-minute log windows. - Threshold escalation: after N heals in a session window (default 3, configurable via agent.sanitizer_heal_escalation_threshold in config.yaml, 0 = off) log ONE ERROR carrying session id + heal pattern (events/messages/window/threshold), then stay quiet. - ONE-TIME out-of-band user notice queued at the threshold and delivered by the conversation loop through _emit_warning (status callback -> gateway status message / CLI print). Never injected into conversation context or the wire copy: prompt caching, role alternation, and durable history are untouched. Never re-arms on a new window; scoped per session. - Counters visible in diagnostics: get_sanitizer_heal_stats() rendered in the /debug share // hermes debug report, and the config key surfaced in hermes dump overrides. errors.log carries the ERROR line for `hermes logs errors`.
This commit is contained in:
@@ -607,6 +607,26 @@ def collect_debug_report(
|
||||
if log_snapshots is None:
|
||||
log_snapshots = _capture_default_log_snapshots(log_lines)
|
||||
|
||||
# ── Sanitiser heal counters (#96870) ─────────────────────────────────
|
||||
# In-process, in-memory counters: populated when this report is built
|
||||
# inside a process that ran agent turns (gateway /debug share); empty
|
||||
# from a fresh CLI process, where the errors.log tail below carries the
|
||||
# same escalation lines instead.
|
||||
try:
|
||||
from agent.agent_runtime_helpers import get_sanitizer_heal_stats
|
||||
|
||||
heal_stats = get_sanitizer_heal_stats()
|
||||
if heal_stats:
|
||||
buf.write("\n\n--- transcript sanitiser heal counters ---\n")
|
||||
for sess, st in sorted(heal_stats.items()):
|
||||
buf.write(
|
||||
f"session {sess}: {st['heal_events']} heal events, "
|
||||
f"{st['messages_healed']} messages healed, "
|
||||
f"escalated={st['escalated']}\n"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ── Recent log tails (summary only) ──────────────────────────────────
|
||||
buf.write("\n\n")
|
||||
buf.write(f"--- agent.log (last {log_lines} lines) ---\n")
|
||||
|
||||
Reference in New Issue
Block a user