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(deferred): race-safe pending injection + is_error semantic
xf gong2634e458411d
diff --git a/cubepi/deferred/_expand_tool.py b/cubepi/deferred/_expand_tool.pyindex 525fb5e..15401f3 100644--- a/cubepi/deferred/_expand_tool.py+++ b/cubepi/deferred/_expand_tool.py@@ -51,7 +51,7 @@ def _make_expand_tools(text = json.dumps(output.model_dump(), ensure_ascii=False)return AgentToolResult(content=[TextContent(text=text)],- is_error=bool(output.error),+ is_error=not output.expanded,)return AgentTool(diff --git a/cubepi/deferred/middleware.py b/cubepi/deferred/middleware.pyindex 7cc643c..f2d6e7f 100644--- a/cubepi/deferred/middleware.py+++ b/cubepi/deferred/middleware.py@@ -176,7 +176,7 @@ class DeferredToolsMiddleware(Middleware):self._expanded_schemas.append((group_id, new_schemas))# Stage newly expanded tools for injection by after_tool_call.- self._pending_injection = newly_expanded+ self._pending_injection.extend(newly_expanded)# Calculate remaining count.current_expanded = expanded_groups.get(group_id)@@ -207,8 +207,8 @@ class DeferredToolsMiddleware(Middleware):) -> ExpandToolsOutput:output = await self._expand_callback(group_id, tool_names)if output.expanded and self._pending_injection:- newly_expanded = self._pending_injection- self._pending_injection = []+ newly_expanded = list(self._pending_injection)+ self._pending_injection.clear()if context.tools is not None:existing_names = {t.name for t in context.tools}for tool in newly_expanded:@@ -233,8 +233,8 @@ class DeferredToolsMiddleware(Middleware):return Noneif self._pending_injection:- newly_expanded = self._pending_injection- self._pending_injection = []+ newly_expanded = list(self._pending_injection)+ self._pending_injection.clear()if ctx.context.tools is not None:existing_names = {t.name for t in ctx.context.tools}for tool in newly_expanded: