CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
fix(todo): invalidate background waits after HITL answers
xf gong4742512464cf
diff --git a/cubeloop/middleware/todo.py b/cubeloop/middleware/todo.pyindex cad0c21..2e4a496 100644--- a/cubeloop/middleware/todo.py+++ b/cubeloop/middleware/todo.py@@ -48,6 +48,7 @@ from cubeloop.providers.base import (Message,TextContent,ToolCall,+ ToolResultMessage,UserMessage,is_synthetic_message,)@@ -311,6 +312,11 @@ def _input_boundary(ctx: AgentContext) -> str:for message in ctx.messagesif (isinstance(message, UserMessage) and not is_synthetic_message(message))or isinstance(message.metadata.get("input_id"), str)+ or (+ isinstance(message, ToolResultMessage)+ and isinstance(message.details, dict)+ and "hitl" in message.details+ )]return hashlib.sha256(json.dumps(diff --git a/dev/specs/2026-09-21-todo-task-wait.md b/dev/specs/2026-09-21-todo-task-wait.mdindex 9356ddf..7d316a2 100644--- a/dev/specs/2026-09-21-todo-task-wait.md+++ b/dev/specs/2026-09-21-todo-task-wait.md@@ -14,6 +14,8 @@ Extra must be saved at completed tool-turn boundaries before the next model callBefore the existing unfinished-Todo pure-text guard forces another model call, revalidate the declaration. `valid` allows natural completion while leaving unfinished items unchanged. `cancelled` does the same only for an existing, still-bound successful declaration, and stores the user's cancellation reason. It never permits creation of a new declaration. Invalid IDs, missing authority, validation failures, changed input, or an unconfigured validator retain the normal guard.+HITL answers are new input too. Their structured tool-result evidence invalidates an earlier wait even when resuming the same run; the model must handle the answer before declaring a new wait.+This exemption cannot bypass malformed Todo input, parallel write restrictions, explicit stop, HITL, or another middleware's stop decision. It emits no notification, starts no run, and does not modify historical messages or a dynamic system prompt prefix.## Evidence requireddiff --git a/tests/middleware/test_todo_task_wait.py b/tests/middleware/test_todo_task_wait.pyindex 4fcb5e8..654c9d1 100644--- a/tests/middleware/test_todo_task_wait.py+++ b/tests/middleware/test_todo_task_wait.py@@ -27,7 +27,11 @@ from cubeloop.providers.base import (synthetic_user_message,)from cubeloop.providers.faux import FauxProvider, faux_assistant_message, faux_tool_call-from cubeloop.session import InputEnvelope, PromptExecutionRequest+from cubeloop.session import (+ InputEnvelope,+ PromptExecutionRequest,+ RespondExecutionRequest,+)TODOS = [{"content": "Wait for build result", "status": "in_progress"}]@@ -517,6 +521,27 @@ async def test_valid_task_wait_does_not_complete_a_pending_hitl_request(assert checkpoint is not None and checkpoint.extra["todos"] == TODOSassert checkpoint.extra["todo_task_wait_outcome"] is Noneassert await storage.load_pending("task-wait") is not None+ provider.set_responses(+ [+ faux_assistant_message(+ "The answer needs to be handled before waiting again."+ ),+ complete_call(),+ faux_assistant_message("Done."),+ ]+ )+ resumed = await agent.session.execute(+ RespondExecutionRequest(+ run_id="run-a",+ attempt_id="attempt-b",+ question_id=result.pending_request.question_id,+ answer={"continue": "yes"},+ )+ )+ assert resumed.outcome == "completed"+ checkpoint = await storage.load("task-wait")+ assert checkpoint is not None and checkpoint.extra["todo_task_wait"] is None+ assert checkpoint.extra["todos"][0]["status"] == "completed"async def test_wait_binding_is_checkpointed_before_the_next_model_call() -> None:diff --git a/website/docs/guides/middleware/todo.md b/website/docs/guides/middleware/todo.mdindex c0dc176..4ecf689 100644--- a/website/docs/guides/middleware/todo.md+++ b/website/docs/guides/middleware/todo.md@@ -117,7 +117,7 @@ input boundary. Before forcing a finalization correction, CubeLoop asks thehost again. A valid wait lets the run end naturally without completing unfinishedTodos or making another model call. An ordinary Todo update without task IDsclears the declaration. New user or internal input, including a new run's initial-message, invalidates it. A changed or unprovable boundary after compaction also+message or a HITL answer, invalidates it. A changed or unprovable boundary after compaction alsorequires a new declaration.If the user cancels previously validated work, the callback may returndiff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/middleware/todo.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/middleware/todo.mdindex 197c0cc..913a8c5 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/middleware/todo.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/middleware/todo.md@@ -97,7 +97,7 @@ scope、发起者权限、取消状态,以及任务是否仍有可观察、待成功的声明绑定任务 ID、Todo 快照、run 和当前输入边界。纯文本收尾触发未完成守卫前,CubeLoop 再次调用宿主校验;仍有效则正常结束当前 run,不勾选未完成 Todo,也不强制追加模型调用。不带任务 ID 的普通 Todo 更新会清除声明。新的用户或内部输入、新 run-的初始消息都会使旧声明失效;压缩上下文后无法确认原输入边界时也需重新声明。+的初始消息或 HITL 答复都会使旧声明失效;压缩上下文后无法确认原输入边界时也需重新声明。用户后来取消已验证的工作时,宿主证明取消发生在原校验之后,可返回`status="cancelled"` 和非空 `reason`,允许自然收尾并保留未完成列表和取消原因。