Skip to content

fix(dispatch): acquire agent mutex around main-loop agent_run - #54

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-0bbd
Draft

fix(dispatch): acquire agent mutex around main-loop agent_run#54
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-0bbd

Conversation

@cursor

@cursor cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Bug and impact

When the gateway is enabled alongside Telegram/Discord/WebChat channels, the main loop and inbound ASAP HTTP threads can call agent_run() concurrently. The HTTP path already uses agent_lock(), but the channel dispatch path did not, causing session/memory races and lost conversation turns.

Root cause

Asymmetric mutex usage: only non-main threads acquired agent_lock() while the main loop called agent_run() without holding the same mutex.

Fix and validation

  • Wrap agent_run() in handle_message() with agent_lock() / agent_unlock().
  • Matches the thread-safety guidance in README.md.

Validation

  • Code review against existing ASAP server locking pattern in src/asap/server.c.
  • ShellClaw unit tests could not run in this environment (missing libcurl headers).
Open in Web View Automation 

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 <esadrianno@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant