From e0628f4273194b249aeffd1ed82e762e281c4323 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 27 Jul 2026 11:10:37 +0000 Subject: [PATCH] fix(asap): acquire agent mutex around inbound mcp.tool_call dispatch handle_mcp_tool_call executed tools without agent_lock while task.request already held the mutex, allowing concurrent tool/session access from HTTP threads during an active agent_run. Co-authored-by: esadrianno --- src/asap/server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/asap/server.c b/src/asap/server.c index d681f9b..fa39b0c 100644 --- a/src/asap/server.c +++ b/src/asap/server.c @@ -282,11 +282,14 @@ static int handle_mcp_tool_call(const asap_envelope_t *in, asap_envelope_t *out, return -32603; } result_buf[0] = '\0'; + /* Same mutex discipline as task.request: tools touch shared session/memory. */ + agent_lock(); if (ctx->tool_call_hook) { int hr = ctx->tool_call_hook(ctx, tool_name, args_json, result_buf, RESULT_CAP); exec_rc = hr == 0 ? 0 : 2; } else exec_rc = dispatch_tool_by_name(ctx, tool_name, args_json, result_buf, RESULT_CAP); + agent_unlock(); free(args_json); if (exec_rc == 1) { free(result_buf);