Skip to content

Commit

Permalink
[bug fix] Ensure that StopEvent gets cleared from `Context._in_prog…
Browse files Browse the repository at this point in the history
…ress["_done"]` after a Workflow run (#17300)

* remove StopEvent from in progress

* add new and update stepwise test
  • Loading branch information
nerdai authored Dec 17, 2024
1 parent ea589c0 commit d6b0f70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llama-index-core/llama_index/core/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ async def _task(
new_ev = await instrumented_step(**kwargs)
break # exit the retrying loop
except WorkflowDone:
await ctx.remove_from_in_progress(name=name, ev=ev)
raise
except Exception as e:
if config.retry_policy is None:
Expand Down Expand Up @@ -277,6 +278,7 @@ async def _task(
None, run_task
)
except WorkflowDone:
await ctx.remove_from_in_progress(name=name, ev=ev)
raise
except Exception as e:
raise WorkflowRuntimeError(
Expand Down
10 changes: 10 additions & 0 deletions llama-index-core/tests/workflow/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ async def test_deprecated_params(ctx):
DeprecationWarning, match="`make_private` is deprecated and will be ignored"
):
await ctx.set("foo", 42, make_private=True)


@pytest.mark.asyncio()
async def test_empty_inprogress_when_workflow_done(workflow):
h = workflow.run()
_ = await h

# there shouldn't be any in progress events
for inprogress_list in h.ctx._in_progress.values():
assert len(inprogress_list) == 0
3 changes: 3 additions & 0 deletions llama-index-core/tests/workflow/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ async def test_workflow_run_step(workflow):
result = await handler
assert handler.is_done()
assert result == "Workflow completed"
# there shouldn't be any in progress events
for inprogress_list in handler.ctx._in_progress.values():
assert len(inprogress_list) == 0


@pytest.mark.asyncio()
Expand Down

0 comments on commit d6b0f70

Please sign in to comment.