Skip to content

The agent that grows with you

fix: keep the carried pre-admission input across the waited lease reload

teknium1535878026496
diff --git a/agent/turn_facade_lease.py b/agent/turn_facade_lease.py
index 3323b6ad99e..5f60e934836 100644
--- a/agent/turn_facade_lease.py
+++ b/agent/turn_facade_lease.py
@@ -290,9 +290,18 @@ def admit_durable_turn_lease(
if latest_session_id:
agent.session_id = latest_session_id
task_context["session_id"] = latest_session_id
- admission.conversation_history = db.get_messages_as_conversation(
+ reloaded = db.get_messages_as_conversation(
agent.session_id, repair_alternation=True, include_row_ids=True
)
+ # A follow-up that aborted an earlier wait carries that turn's never-persisted input
+ # only in memory (see carry_unadmitted_user_message); the reload would drop it.
+ from agent.session_persistence import _PERSIST_AFTER_ADMISSION_INTERRUPT
+ reloaded.extend(
+ m for m in (conversation_history or [])
+ if isinstance(m, dict) and m.get(_PERSIST_AFTER_ADMISSION_INTERRUPT)
+ and "_row_id" not in m
+ )
+ admission.conversation_history = reloaded
lease.build_threads()
except BaseException:
# The façade never saw this lease; release here so an admitted row is not leaked.
diff --git a/tests/agent/test_cross_process_turn_lease.py b/tests/agent/test_cross_process_turn_lease.py
index fea169e08fa..3472bb545f4 100644
--- a/tests/agent/test_cross_process_turn_lease.py
+++ b/tests/agent/test_cross_process_turn_lease.py
@@ -357,6 +357,43 @@ def test_run_conversation_second_turn_after_lease_wait_abort(monkeypatch):
assert agent._interrupt_requested is False
+def test_carried_input_survives_waited_reload_on_follow_up_turn(monkeypatch):
+ db = _DB()
+ agent = _agent_with_db(db)
+ turns = {"n": 0}
+
+ def acquire_false_then_true_after_wait(session_id, holder, **kwargs):
+ db.events.append(("acquire", session_id, holder))
+ if turns["n"] == 0:
+ agent._interrupt_requested = True
+ agent._interrupt_message = "follow-up while waiting"
+ return False
+ kwargs["on_wait"](0.0) # the follow-up also has to wait before admission
+ return True
+
+ db.acquire_session_turn_lease = acquire_false_then_true_after_wait
+ observed = {}
+
+ def fake_run(_agent, _message, _system, history, *_args, **_kwargs):
+ observed["history"] = history
+ return {"final_response": "ok", "messages": history, "failed": False}
+
+ monkeypatch.setattr("agent.conversation_loop.run_conversation", fake_run)
+ first = AIAgent.run_conversation(
+ agent, "original", conversation_history=[{"role": "user", "content": "stale"}]
+ )
+ assert first.get("interrupted") is True
+ carried = first["messages"][-1]
+ assert carried["_persist_after_admission_interrupt"] is True
+ turns["n"] = 1
+ AIAgent.run_conversation(agent, "follow-up", conversation_history=first["messages"])
+
+ assert observed["history"] == [
+ {"role": "user", "content": "durable latest"},
+ carried,
+ ]
+
+
def test_run_conversation_interrupts_when_lease_refresh_lost(monkeypatch):
db = _DB()
agent = _agent_with_db(db)