fix: add lock in workflow run update, refactor _handle_stasis_start

This commit is contained in:
Sabiha Khan 2026-02-17 18:58:16 +05:30
parent f3b4de9eb6
commit fe80c11ae5
2 changed files with 14 additions and 15 deletions

View file

@ -321,8 +321,11 @@ class WorkflowRunClient(BaseDBClient):
state: str | None = None,
) -> WorkflowRunModel:
async with self.async_session() as session:
# Use SELECT FOR UPDATE to lock the row during the update
result = await session.execute(
select(WorkflowRunModel).where(WorkflowRunModel.id == run_id)
select(WorkflowRunModel)
.where(WorkflowRunModel.id == run_id)
.with_for_update()
)
run = result.scalars().first()
if not run: