Skip to content

The agent that grows with you

fix(tui): notify memory providers of /undo from the session's profile scope

unsupportedpastels28c85b1ad912
diff --git a/tests/tui_gateway/test_undo_command.py b/tests/tui_gateway/test_undo_command.py
index fc0e6aba3c8..cee9858a956 100644
--- a/tests/tui_gateway/test_undo_command.py
+++ b/tests/tui_gateway/test_undo_command.py
@@ -108,3 +108,17 @@ def test_undo_returns_prefill_with_target_text(server, session_with_history):
assert all("_row_id" in message for message in s["history"])
+def test_undo_notifies_memory_providers_from_the_session_profile(server, session_with_history):
+ # On a multiplexed process the memory manager refuses a hook whose caller names no profile, so a
+ # launch-profile session's /undo must enter the session's profile scope before notifying it.
+ from agent.memory_caller_scope import _explicit_caller_home
+ from agent.secret_scope import reset_multiplex_context, set_multiplex_context
+ sid, _session_key, _s, agent = session_with_history
+ callers = []
+ agent._memory_manager.on_session_switch.side_effect = lambda *a, **k: callers.append(_explicit_caller_home())
+ token = set_multiplex_context(True)
+ try:
+ assert _call(server, "command.dispatch", session_id=sid, name="undo", arg="")["result"]["type"] == "prefill"
+ finally:
+ reset_multiplex_context(token)
+ assert len(callers) == 1 and callers[0] is not None, callers
diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.py
index 2061e78d3e9..ecf60e0cf80 100644
--- a/tui_gateway/methods_tools.py
+++ b/tui_gateway/methods_tools.py
@@ -865,7 +865,8 @@ def _cmd_undo(rid, params, session, name, arg):
lambda: hasattr(agent, "_invalidate_system_prompt") and agent._invalidate_system_prompt(),
lambda: hasattr(agent, "_last_flushed_db_idx") and setattr(agent, "_last_flushed_db_idx", len(active)),
):
- with contextlib.suppress(Exception):
+ # The session's profile scope: a multiplexed manager refuses a hook naming no profile (#140058).
+ with contextlib.suppress(Exception), _session_profile_runtime_scope(session):
step()
_tui_model_friction("undo", session, turns_undone)
turn_word = "turn" if turns_undone == 1 else "turns"