Skip to content

fix: event ordering#4392

Merged
greysonlalonde merged 6 commits intomainfrom
gl/fix/event-ordering
Feb 6, 2026
Merged

fix: event ordering#4392
greysonlalonde merged 6 commits intomainfrom
gl/fix/event-ordering

Conversation

@greysonlalonde
Copy link
Contributor

@greysonlalonde greysonlalonde commented Feb 6, 2026

fix: thread-safe state proxies & native routing
add thread-safe state proxies and refactor native tool routing.

  • introduce LockedListProxy and LockedDictProxy in flow.py and update StateProxy to return them for list/dict attrs so mutations are protected by the flow lock.
  • update AgentExecutor to use StateProxy on flow init, guard the messages setter with the state lock, and return a StateProxy from the temp state accessor.
  • convert call_llm_native_tools into a listener (no direct routing return) an

expand the loop bridge listener to also trigger on tool completion events (tool_completed and native_tool_completed) so agent iteration resumes after tools finish. add a requests.post mock and response fixture in the liteagent test to simulate platform tool execution. refresh and sanitize vcr cassettes (updated model responses, timestamps, and header placeholders) to reflect tool-call flows and new recordings.

introduce a context var for the current task id in `crewai.context` to track task scope. update `Flow._execute_single_listener` to return `(result, event_id)` and adjust callers to unpack it and append `FlowMethodName(str(result))` to `router_results`. set/reset the current task id at the start/end of task execution (async + sync) with minor import and call-site tweaks.
call `crewai_event_bus.flush()` after crew kickoff. in `Flow`, await event handler futures instead of just collecting them: await pending `_event_futures` before finishing, await emitted futures immediately with try/except to log failures, then clear `_event_futures`. ensures handlers complete and errors surface.
expand the loop bridge listener to also trigger on tool completion events (`tool_completed` and `native_tool_completed`) so agent iteration resumes after tools finish. add a `requests.post` mock and response fixture in the liteagent test to simulate platform tool execution. refresh and sanitize vcr cassettes (updated model responses, timestamps, and header placeholders) to reflect tool-call flows and new recordings.
add thread-safe state proxies and refactor native tool routing.

* introduce `LockedListProxy` and `LockedDictProxy` in `flow.py` and update `StateProxy` to return them for list/dict attrs so mutations are protected by the flow lock.
* update `AgentExecutor` to use `StateProxy` on flow init, guard the messages setter with the state lock, and return a `StateProxy` from the temp state accessor.
* convert `call_llm_native_tools` into a listener (no direct routing return) and add `route_native_tool_result` to route based on state (pending tool calls, final answer, or context error).
* minor cleanup in `continue_iteration` to drop orphan listeners on init.
* update test cassettes for new native tool call responses, timestamps, and ids.

improves concurrency safety for shared state and makes native tool routing explicit.
@greysonlalonde greysonlalonde merged commit 7d498b2 into main Feb 6, 2026
44 checks passed
@greysonlalonde greysonlalonde deleted the gl/fix/event-ordering branch February 6, 2026 19:02
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.

2 participants