From 5e69d82c7804dacbd105ac40913337e8bd472244 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 21 Jul 2026 11:05:45 +0000 Subject: [PATCH] fix(dispatch): acquire agent mutex around main-loop agent_run The inbound ASAP HTTP path already calls agent_lock() before agent_run(), but the main channel loop did not, allowing concurrent session/memory access when gateway and channels are both active. Co-authored-by: esadrianno --- src/core/dispatch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/dispatch.c b/src/core/dispatch.c index 287cb91..8740004 100644 --- a/src/core/dispatch.c +++ b/src/core/dispatch.c @@ -38,9 +38,11 @@ int handle_message(const channel_t *ch, const channel_incoming_msg_t *msg) flat_tools[i].parameters_json = t->parameters_json; flat_tools[i].execute = t->execute; } + agent_lock(); int err = agent_run(bootstrap_get_cfg(), msg->session_id, text, bootstrap_get_provider(), flat_tools, tool_count, resp_buf, sizeof(resp_buf)); + agent_unlock(); if (err != 0 && resp_buf[0] == '\0') snprintf(resp_buf, sizeof(resp_buf), "Error: agent failed (code %d)", err); return ch->send(msg->session_id, resp_buf, NULL, 0);