Skip to content

fix: use step-internal context for debug breakpoints in llamaindex runtime#274

Merged
radu-mocanu merged 1 commit intomainfrom
fix/llamaindex-debug-breakpoint-context
Apr 9, 2026
Merged

fix: use step-internal context for debug breakpoints in llamaindex runtime#274
radu-mocanu merged 1 commit intomainfrom
fix/llamaindex-debug-breakpoint-context

Conversation

@radu-mocanu
Copy link
Copy Markdown
Collaborator

@radu-mocanu radu-mocanu commented Apr 9, 2026

Summary

  • regression fix: uipath debug with llamaindex workflows fails with ContextStateError
  • uipath run is unaffected (breakpoint injection is skipped)

the error

WorkflowFailedEvent
├── exception_type: workflows.errors.ContextStateError
├── exception_message: wait_for_event is only available from within step functions.

root cause

the breakpoint wrapper calls ctx.wait_for_event() to pause a step before execution. this requires a Context in InternalContext state (the per-step context the framework creates).

the old code read self.context from the workflow instance, which was the ExternalContext set by the runtime at _run_workflow() time:

# old (broken)
ctx: Context | None = getattr(self, "context", None)
await ctx.wait_for_event(...)  # ExternalContext -> ContextStateError

the fix

create an InternalContext via Context._create_internal(workflow=self) inside the wrapper. this works because the wrapper executes inside the step worker where StepWorkerStateContextVar is already set:

# new
ctx = Context._create_internal(workflow=self)
await ctx.wait_for_event(...)  # InternalContext -> works

note: _create_internal is a private API on the workflows library. there is currently no public way to obtain an InternalContext from within a step wrapper that doesn't declare ctx: Context in its signature. this is a workaround until [llama-index/llama_index_workflows#TBD] provides a public API. see the issue linked below.

other changes

  • removed DebuggableWorkflow protocol and the runtime code that set debug_workflow.context (no longer needed)
  • bumped uipath-llamaindex to 0.5.9
  • added pexpect-based integration test (testcases/debug-breakpoints) covering single/multiple breakpoints, step mode, and quit

Why

breakpoints are a core part of the uipath debug experience. this regression made debug mode unusable for all llamaindex workflow agents.

Llamaindex opened issue: run-llama/llama-agents#505

@radu-mocanu radu-mocanu force-pushed the fix/llamaindex-debug-breakpoint-context branch 3 times, most recently from e96336f to 30d9b31 Compare April 9, 2026 14:14
the breakpoint wrapper was calling wait_for_event on the workflow-level
ExternalContext instead of a per-step InternalContext. this caused
ContextStateError on every uipath debug run (uipath run was unaffected
because it skips breakpoint injection).

fix: create an InternalContext via Context._create_internal(workflow)
inside the wrapper, which runs within the step worker where the
framework has already set up the required context variables.

also adds a pexpect-based integration test (testcases/debug-breakpoints)
that exercises single/multiple breakpoints, step mode, and quit against
the debug-agent sample.
@radu-mocanu radu-mocanu force-pushed the fix/llamaindex-debug-breakpoint-context branch from 30d9b31 to 24a0d2b Compare April 9, 2026 14:15
@radu-mocanu radu-mocanu merged commit 1e0dfb2 into main Apr 9, 2026
64 checks passed
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