diff --git a/bindu/server/endpoints/a2a_protocol.py b/bindu/server/endpoints/a2a_protocol.py index a5844952..96eb2b75 100644 --- a/bindu/server/endpoints/a2a_protocol.py +++ b/bindu/server/endpoints/a2a_protocol.py @@ -6,7 +6,7 @@ from typing import Any from starlette.requests import Request -from starlette.responses import Response +from starlette.responses import Response, StreamingResponse from bindu.common.protocol.types import ( InternalError, @@ -190,8 +190,8 @@ async def agent_run_endpoint(app: BinduApplication, request: Request) -> Respons logger.debug(f"A2A response to {client_ip}: method={method}, id={request_id}") - # Streaming handlers return a Starlette Response directly - if isinstance(jsonrpc_response, Response): + # FIX: Strictly check for StreamingResponse to prevent bypassing JSON-RPC + if isinstance(jsonrpc_response, StreamingResponse): if x402_is_requested(request): jsonrpc_response = x402_add_header(jsonrpc_response) return jsonrpc_response diff --git a/bindu/server/handlers/message_handlers.py b/bindu/server/handlers/message_handlers.py index 26d45297..fa4e0aba 100644 --- a/bindu/server/handlers/message_handlers.py +++ b/bindu/server/handlers/message_handlers.py @@ -289,7 +289,9 @@ async def stream_generator(): return return + # FIX: Exponential backoff to prevent DB hammering await anyio.sleep(poll_interval) + poll_interval = min(poll_interval * 1.5, 2.0) except cancelled_exc: logger.debug(f"Streaming client disconnected for task {task['id']}") return diff --git a/bindu/utils/task_telemetry.py b/bindu/utils/task_telemetry.py index 1d93df84..ea066c64 100644 --- a/bindu/utils/task_telemetry.py +++ b/bindu/utils/task_telemetry.py @@ -200,6 +200,10 @@ async def wrapper(self, request, *args, **kwargs): # Decrement active tasks for completion/cancellation operations if operation in ["cancel_task"]: active_tasks.add(-1, {"operation": "cancel"}) + + # FIX: Ensure creation operations decrement when the request cycle completes + elif operation in create_operations: + active_tasks.add(-1, {"operation": "completed"}) return result