Skip to content

Add missing indexes to call stack columns in EF Core migrations#7245

Closed
sfmskywalker with Copilot wants to merge 20 commits into
feat/activity-call-stackfrom
copilot/sub-pr-7204-again
Closed

Add missing indexes to call stack columns in EF Core migrations#7245
sfmskywalker with Copilot wants to merge 20 commits into
feat/activity-call-stackfrom
copilot/sub-pr-7204-again

Conversation

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

The V3_7 migrations added call stack tracking columns (SchedulingActivityExecutionId, SchedulingActivityId, SchedulingWorkflowInstanceId) but omitted the indexes required by the plan document. These columns are used in WHERE clauses and recursive chain traversal, causing table scans on unindexed columns.

Changes

  • Added indexes on all three call stack columns across all database providers (SQLite, PostgreSQL, Oracle, SQL Server, MySQL)
  • Fixed column types for indexability:
    • SQL Server: nvarchar(max)nvarchar(450) (matches other ID columns)
    • MySQL: longtextvarchar(255) (matches other ID columns)
    • Oracle/PostgreSQL/SQLite: No change needed (already indexable)
  • Added corresponding DropIndex calls in migration Down methods

Query Context

// ActivityExecutionRecordFilter.Apply() uses these in WHERE clauses
if (filter.SchedulingActivityExecutionId != null) 
    queryable = queryable.Where(x => x.SchedulingActivityExecutionId == filter.SchedulingActivityExecutionId);

// GetExecutionChainAsync() traverses the chain recursively
while (currentId != null && visited.Add(currentId))
{
    record = await store.FindAsync(new() { Id = currentId }, cancellationToken);
    currentId = record.SchedulingActivityExecutionId;  // Chain traversal
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

sfmskywalker and others added 19 commits January 22, 2026 20:16
Implements a call stack mechanism to track the execution chain, enabling visibility into the invocation hierarchy.

Introduces new fields to scheduling models and runtime contexts to store call stack information.

Includes EF Core migrations for various database providers to support new columns in `ActivityExecutionRecords`.

Provides an API to query and reconstruct the call stack for a given activity execution.
Simplifies scheduling logic by removing ambient scope mechanisms, refactoring scheduling context handling, and updating affected classes accordingly.
…ully and add `TryGetWorkflowGraphAsync` helper methods.
…ecution tracking

Introduce fields for aggregated fault count, scheduling context, workflow instance details, and call stack depth to enhance execution monitoring and debugging capabilities.
Introduced components and models to display a call stack for activity executions in the Workflow Instance Viewer. This includes UI elements for call stack rendering, error handling, and data integration with activity execution records.
Added cycle detection using a `HashSet` to prevent infinite loops when traversing activity execution chains in multiple storage implementations. Updated unit tests to validate correct handling of circular references and chain traversal.
Centralized the `GetExecutionChainAsync` method into an extension class to streamline and unify its implementation across stores. Removed redundant implementations from individual stores and updated interfaces to utilize the new extension method. This reduces code duplication and simplifies future maintenance.
Integrated the `CallStackDepth` property into `ActivityExecutionContext`, `ActivityExecutionContextState`, and related classes to track and manage the call stack depth of activity executions. Removed obsolete depth calculation logic to streamline the process.
- Add `WorkflowExecutionContextTests` to verify correct calculation of call stack depth during activity execution.
- Add `WorkflowStateExtractorTests` to ensure call stack depth is preserved during state extraction and application.
…utionMapper

- Recreated `DefaultActivityExecutionMapperTests` to fix compilation issues due to corrupted code.
- Restored unit test `MapAsync_SetsCallStackDepth_FromContext` ensuring proper handling of `CallStackDepth`.
- Deleted `DefaultActivityExecutionMapperTests_Fixed.cs` due to corruption.
- Updated project references to include `Elsa.Testing.Shared` for unit tests.
…tCallStack/Endpoint.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tCallStack/Endpoint.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Copilot AI changed the title [WIP] Update activity execution call stack support based on feedback Add missing indexes to call stack columns in EF Core migrations Feb 4, 2026
Copilot AI requested a review from sfmskywalker February 4, 2026 21:08
@sfmskywalker sfmskywalker force-pushed the feat/activity-call-stack branch from 212c69c to 7b9a27e Compare February 7, 2026 10:47
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