The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): steer/redirect releases a blocking process_manage wait (port of MoonshotAI/kimi-code#3697)
Tekniumcbd4492f1fc3
diff --git a/tests/tools/test_process_wait_clarity.py b/tests/tools/test_process_wait_clarity.pyindex d5a61ed1076..fd3dd0646b1 100644--- a/tests/tools/test_process_wait_clarity.py+++ b/tests/tools/test_process_wait_clarity.py@@ -62,3 +62,46 @@ class TestWaitTimeoutClarity:r = registry.wait(session.id, timeout=10)assert r["status"] == "exited"assert "process_running" not in r+++class TestWaitYieldRelease:+ """A mid-turn steer/redirect (request_yield on the tool-worker tid) releases a+ process wait instead of parking the user's message behind it (kimi-code#3697 class)."""++ def test_yield_releases_wait_and_keeps_process_running(self, registry):+ import threading+ import time++ from tools.interrupt import request_yield++ sid = _spawn_sleeper(registry)+ try:+ result = {}++ def waiter():+ result["r"] = registry.wait(sid, timeout=15)++ t = threading.Thread(target=waiter)+ t.start()+ time.sleep(0.3)+ request_yield(t.ident)+ t.join(5)+ assert not t.is_alive(), "wait did not release within 5s of the yield request"+ r = result["r"]+ assert r["status"] == "interrupted"+ assert r["process_running"] is True+ assert "still running" in r["note"]+ # The process was not killed and the yield bit was consumed.+ assert registry.poll(sid)["status"] == "running"+ from tools.interrupt import is_thread_yield_requested+ assert not is_thread_yield_requested(t.ident)+ finally:+ registry.kill_process(sid)++ def test_wait_without_yield_still_times_out(self, registry):+ sid = _spawn_sleeper(registry)+ try:+ r = registry.wait(sid, timeout=1)+ assert r["status"] == "timeout"+ finally:+ registry.kill_process(sid)diff --git a/tools/process_registry.py b/tools/process_registry.pyindex 19d5c23e7d0..ebacbfaa581 100644--- a/tools/process_registry.py+++ b/tools/process_registry.py@@ -1673,10 +1673,11 @@ class ProcessRegistry(ProcessCheckpointMixin):return resultdef wait(self, session_id: str, timeout: int = None) -> dict:- """Block until the process exits, the timeout elapses, or the user interrupts.+ """Block until the process exits, the timeout elapses, the user interrupts, or a+ mid-turn user message (steer/redirect → ``request_yield``) releases the wait.``timeout`` defaults to (and is clamped by) TERMINAL_TIMEOUT. Returns a dictwith status exited|timeout|interrupted|not_found|error and an output snapshot."""- from tools.interrupt import is_interrupted as _is_interrupted+ from tools.interrupt import consume_yield as _consume_yield, is_interrupted as _is_interruptedtry:max_timeout = int(os.getenv("TERMINAL_TIMEOUT", "180"))@@ -1708,6 +1709,16 @@ class ProcessRegistry(ProcessCheckpointMixin):result = {"status": "interrupted", "command": session.command, "output": _output_tail(session, 1000),"note": "User sent a new message -- wait interrupted"}+ elif _consume_yield(threading.current_thread().ident):+ # A steer/redirect landed mid-turn: redirect() asks tool workers to YIELD so+ # the user's message is delivered instead of parked behind this wait. The+ # process is untouched and still notify-tracked; the model should read the+ # steer text and respond, not re-issue the wait (kimi-code#3697 class).+ result = {+ "status": "interrupted", "command": session.command, "output": _output_tail(session, 1000),+ "process_running": True,+ "note": ("User sent a new message -- wait released; the process is still "+ "running and you will be notified on exit. Respond to the user now.")}if result is not None:if timeout_note:result["timeout_note"] = timeout_note