Skip to content

The agent that grows with you

fix(sessions): the low-disk notice clears only when answered and never re-asks

Teknium772d47df4239
diff --git a/gateway/run_housekeeping_disk.py b/gateway/run_housekeeping_disk.py
index 736d171b810..d37991e0cf0 100644
--- a/gateway/run_housekeeping_disk.py
+++ b/gateway/run_housekeeping_disk.py
@@ -95,11 +95,14 @@ async def publish_local_auto_prune_notice(authority, ref) -> None:
home = Path(authority.db.db_path).parent
if not prune_advisor.notice_due(home, _LOCAL_NOTIFIED):
return
- _LOCAL_NOTIFIED[str(home)] = time.time()
+ _LOCAL_NOTIFIED[str(home)] = time.time() # in-flight claim: one estimate per home at a time
advice = await asyncio.to_thread(prune_advisor.advise, home)
- if advice is None:
- return
- live.event_stream.publish(ref.session_id, prune_advisor.notice_payload(advice), event_type="notification.show")
+ # Answered (here or in another window) during the estimate: publishing would re-ask it.
+ delivered = (advice is not None and prune_advisor.should_ask(home) is not None
+ and live.event_stream.publish(ref.session_id, prune_advisor.notice_payload(advice),
+ event_type="notification.show"))
+ if not delivered:
+ _LOCAL_NOTIFIED.pop(str(home), None) # nobody saw it: the next window may ask
def clear_local_auto_prune_notice(runner, source) -> None:
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py
index 379a68cac8d..6e2a2a62099 100644
--- a/gateway/slash_commands.py
+++ b/gateway/slash_commands.py
@@ -597,8 +597,9 @@ class GatewaySlashCommandsMixin(
async def _handle_autoprune_command(self, event: MessageEvent) -> str:
"""Handle /autoprune — the low-disk auto-prune decision (same text as the CLI)."""
+ from hermes_cli.prune_advisor import answered
reply = _execute("autoprune", args=event.get_command_args()).text
- if event.get_command_args().strip().lower() in {"on", "off", "enable", "disable", "yes", "no", "later", "snooze"}:
+ if event.get_command_args().strip() and answered(): # a failed save or `status` keeps it
from gateway.run_housekeeping_disk import clear_local_auto_prune_notice
clear_local_auto_prune_notice(self, event.source)
return reply
diff --git a/hermes_cli/prune_advisor.py b/hermes_cli/prune_advisor.py
index 299fed2e668..87a1a4cd68c 100644
--- a/hermes_cli/prune_advisor.py
+++ b/hermes_cli/prune_advisor.py
@@ -229,6 +229,12 @@ def notice_payload(advice: Advice) -> dict:
"key": NOTICE_KEY, "id": NOTICE_KEY}
+def answered(home: Optional[Path] = None) -> bool:
+ """True once the question is settled for now (a saved on/off, or a live ``later`` snooze):
+ the only state in which a shown notice may be withdrawn."""
+ return not undecided(home) or snoozed(home)
+
+
def notice_due(home: Optional[Path], shown: dict) -> bool:
"""Per-process dedup that re-arms: a home already noticed is due again once the gate passes
and a full snooze window has gone by since (so ``later`` really asks again in a week)."""
diff --git a/tests/hermes_cli/test_prune_advisor.py b/tests/hermes_cli/test_prune_advisor.py
index 04b72d608d9..56cc1a45436 100644
--- a/tests/hermes_cli/test_prune_advisor.py
+++ b/tests/hermes_cli/test_prune_advisor.py
@@ -96,3 +96,43 @@ def test_later_re_arms_the_local_notice_after_the_snooze_window(home, monkeypatc
assert not prune_advisor.notice_due(home, shown) # same process, same window: once
shown[str(home)] = time.time() - prune_advisor.SNOOZE_SECONDS - 1
assert prune_advisor.notice_due(home, shown) # a week later it asks again
+
+
+def test_only_a_settled_question_may_withdraw_the_notice(home, monkeypatch):
+ """`status`, a typo or a failed save leave the question open; on/off/later settle it."""
+ _disk(monkeypatch, free_gb=1)
+ assert not prune_advisor.answered(home)
+ prune_advisor.run_command("status", home)
+ prune_advisor.run_command("bogus", home)
+ assert not prune_advisor.answered(home)
+ prune_advisor.run_command("later", home)
+ assert prune_advisor.answered(home)
+
+
+def test_local_notice_is_neither_re_asked_after_an_answer_nor_spent_on_nobody(home, monkeypatch):
+ """Desktop/Ink path: an answer given while the estimate runs suppresses the publish, and a
+ notice no viewer received releases its claim so the next window still asks."""
+ import asyncio
+ from types import SimpleNamespace
+ from gateway import run_housekeeping_disk as rhd
+ from gateway.config import Platform
+ from gateway.session_events import SessionEvents
+ monkeypatch.setattr("gateway.session_policy.policy_for_source", lambda *_: SimpleNamespace(source="gui"))
+ _disk(monkeypatch, free_gb=1)
+ events = SessionEvents() # no viewer attached: publish delivers to nobody
+ live = SimpleNamespace(source=SimpleNamespace(platform=Platform.LOCAL), event_stream=events)
+ authority = SimpleNamespace(sessions={"s1": live}, runner=None, db=SimpleNamespace(db_path=home / "state.db"))
+ ref = SimpleNamespace(session_id="s1")
+ rhd._LOCAL_NOTIFIED.clear()
+
+ asyncio.run(rhd.publish_local_auto_prune_notice(authority, ref))
+ assert events.sequence == 1 and str(home) not in rhd._LOCAL_NOTIFIED # undelivered: claim released
+
+ real_advise = prune_advisor.advise
+ def advise_then_answer(h):
+ advice = real_advise(h)
+ prune_advisor.run_command("off", h) # another window answers during the estimate
+ return advice
+ monkeypatch.setattr(prune_advisor, "advise", advise_then_answer)
+ asyncio.run(rhd.publish_local_auto_prune_notice(authority, ref))
+ assert events.sequence == 1 # nothing re-asked
diff --git a/tui_gateway/methods_slash.py b/tui_gateway/methods_slash.py
index 1836e8464e4..5b0bb0ad9fd 100644
--- a/tui_gateway/methods_slash.py
+++ b/tui_gateway/methods_slash.py
@@ -439,8 +439,12 @@ def _mirror_stop(sid, session, agent, arg) -> None:
# name → mirror(sid, session, agent, arg); a falsy return means "no warning".
def _mirror_autoprune(sid, session, agent, arg) -> str:
- """An answered low-disk question drops its sticky notice (``later`` too: it re-arms in a week)."""
- if arg:
+ """An answered low-disk question drops its sticky notice (``later`` too: it re-arms in a week);
+ ``status``, a typo or a failed save leave it up."""
+ from pathlib import Path
+ from hermes_cli.prune_advisor import answered
+ home = session.get("profile_home")
+ if arg and answered(Path(home) if home else None):
_emit("notification.clear", sid, {"key": "sessions.auto_prune"})
return ""
diff --git a/tui_gateway/session_registry.py b/tui_gateway/session_registry.py
index 17af1b94a3e..4d96df74c31 100644
--- a/tui_gateway/session_registry.py
+++ b/tui_gateway/session_registry.py
@@ -380,8 +380,10 @@ def _maybe_notify_auto_prune(sid: str, profile_home: str | None) -> None:
def _work() -> None:
advice = prune_advisor.advise(home)
- if advice is not None:
+ if advice is not None and prune_advisor.should_ask(home) is not None: # not answered meanwhile
_emit("notification.show", sid, prune_advisor.notice_payload(advice))
+ else:
+ _AUTO_PRUNE_NOTIFIED.pop(str(home), None)
from agent.memory_provider import spawn_context_thread
spawn_context_thread(_work, name="auto-prune-advice").start()