Skip to content

Conversation

@adrianlyjak
Copy link
Contributor

Add idle workflow tracking

Implements tracking for when workflows become idle (waiting on external input via ctx.wait_for_event()).

Changes

  • New WorkflowIdleEvent: Emitted when a workflow transitions to idle state
  • Idle detection: Added _check_idle_state() helper to determine if all steps have no pending work but have active waiters
  • Server tracking: _WorkflowHandler and PersistentHandler now track idle_since timestamp
  • Resumption detection: idle_since is cleared when workflow resumes (receives StepStateChanged(RUNNING))

Definition of "Idle"

A workflow is idle when:

  1. The workflow is running (not completed/failed/cancelled)
  2. All steps have empty queues
  3. All steps have no in-progress workers
  4. At least one step has an active waiter

Future Work

This enables future implementation of:

  • Idle timeout configuration
  • Releasing idle workflows from memory while preserving state
  • Resume-on-event for released workflows

@adrianlyjak adrianlyjak added the enhancement New feature or request label Jan 6, 2026
@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2026

🦋 Changeset detected

Latest commit: 3fd5bae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
llama-index-workflows Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls
Copy link

coveralls commented Jan 6, 2026

Pull Request Test Coverage Report for Build 20801256245

Details

  • 12 of 13 (92.31%) changed or added relevant lines in 2 files are covered.
  • 72 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.1%) to 87.777%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/llama-index-workflows/src/workflows/runtime/control_loop.py 10 11 90.91%
Files with Coverage Reduction New Missed Lines %
src/workflows/server/abstract_workflow_store.py 1 97.83%
tests/runtime/test_control_loop.py 7 97.38%
src/workflows/runtime/control_loop.py 15 92.33%
src/workflows/server/server.py 49 83.91%
Totals Coverage Status
Change from base Build 20797436789: 0.1%
Covered Lines: 9163
Relevant Lines: 10439

💛 - Coveralls

@adrianlyjak adrianlyjak marked this pull request as ready for review January 6, 2026 20:20
commands.extend(subcommands)

# Check for idle transition at end of processing
was_idle = _check_idle_state(init)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does init ever change? We are checking this on every tick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's the initial state of the reducer function call, so its effectively the "last" state

Copy link
Collaborator

@logan-markewich logan-markewich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me

claude and others added 5 commits January 7, 2026 19:34
Add design document outlining the approach for tracking when workflows
are idle (waiting on external input) in the workflow-server. Covers
detection mechanisms, state tracking, and API changes needed to support
releasing idle workflows.
Refocus design on event-based approach that:
- Emits WorkflowIdleEvent/WorkflowResumedEvent on transitions
- Keeps events lightweight with no metadata
- Avoids depending on serialized context structure
- Works with different workflow backends (DBOS, Temporal, etc.)
- Only WorkflowIdleEvent needed (resumption uses existing StepStateChanged)
- Idle state computed from existing BrokerState fields, not stored
- No changes to context serialization required
@adrianlyjak adrianlyjak force-pushed the claude/idle-workflow-tracking-AHJQO branch from 7081baf to 3fd5bae Compare January 8, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants