mirror of
https://github.com/run-llama/llama_deploy.git
synced 2026-08-24 21:01:26 -04:00
[PR #481] [CLOSED] Llama Deploy Race Condition #494
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/run-llama/llama_deploy/pull/481
Author: @eyao27
Created: 3/7/2025
Status: ❌ Closed
Base:
main← Head:bug_fix📝 Commits (3)
f19c48brace condition fixd39817fUpdate workflow.py05c094aMerge branch 'main' into bug_fix📊 Changes
1 file changed (+4 additions, -4 deletions)
View changed files
📝
llama_deploy/services/workflow.py(+4 -4)📄 Description
Problem
At our company, we use LlamaIndex Workflows for chat bot services. We are encountering a very subtle race condition bug where certain events in the Workflow's event stream are missing.
Root Cause
After some debugging, we've narrowed the root cause down to the
set_workflow_statefunction of the Workflow Service in Llama Deploy. This function is run when the workflow has completed. It's purpose is to update the state of the workflow on the control plane. However, a subtle bug can occur when the workflow is finished, yet there are still streaming messages that the control plane hasn't processed.Details
In the function
set_workflow_state, the variablesession_statecontains numerous keys, one for the session ID, but also many for the tasks, results and streams:For example, there could be keys for:
01d59890-f639-448b-984b-b97e113d0d41(session ID)504b8a6d-b846-4bbb-b684-a2b2051fcd81(task ID)stream_504b8a6d-b846-4bbb-b684-a2b2051fcd81result_504b8a6d-b846-4bbb-b684-a2b2051fcd81The current code works by:
session_state = await self.get_session_state(current_state.session_id)01d59890-f639-448b-984b-b97e113d0d41(i.e.,current_state.session_id).session_state[current_state.session_id] = workflow_state.model_dump_json()await self.update_session_state(current_state.session_id, session_state)This introduces a possible race condition where between steps 1 and 3, the value for other keys, namely the
stream_504b8a6d-b846-4bbb-b684-a2b2051fcd81can change. In particular, additional messages may have been received, but are not processed because they are replaced in step 3.Solution
The modified code works by only updating the value for the key
01d59890-f639-448b-984b-b97e113d0d41(the session ID), without changing the other values for the other keys.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.