Skip to content

Add missing indexes for call stack columns in V3_7 migrations#7250

Merged
sfmskywalker merged 3 commits into
feat/activity-call-stackfrom
copilot/sub-pr-7204-another-one
Feb 5, 2026
Merged

Add missing indexes for call stack columns in V3_7 migrations#7250
sfmskywalker merged 3 commits into
feat/activity-call-stackfrom
copilot/sub-pr-7204-another-one

Conversation

Copilot AI commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

The V3_7 migrations added three new columns for activity execution call stack tracking but did not create indexes on them. These columns (SchedulingActivityExecutionId, SchedulingActivityId, SchedulingWorkflowInstanceId) are used for chain traversal queries and filtering, requiring indexes to avoid table scans.

Changes

  • EF Core Configuration: Added index definitions for the three scheduling columns in Configurations.cs
  • SQLite/PostgreSQL/Oracle: Added CreateIndex/DropIndex operations in Up/Down methods
  • SQL Server: Created columns as nvarchar(450) (matching existing indexed ID columns) with indexes
  • MySQL: Created columns as varchar(255) (matching existing indexed ID columns) with indexes

All column types align with existing schema patterns for indexed identifier columns in their respective providers.


💡 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.

Copilot AI and others added 2 commits February 5, 2026 11:37
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Copilot AI changed the title [WIP] Update migration steps and add missing indexes for all providers Add missing indexes for call stack columns in V3_7 migrations Feb 5, 2026
Copilot AI requested a review from sfmskywalker February 5, 2026 11:45
@sfmskywalker sfmskywalker marked this pull request as ready for review February 5, 2026 12:21
Copilot AI review requested due to automatic review settings February 5, 2026 12:21
@sfmskywalker sfmskywalker merged commit 9e284e9 into feat/activity-call-stack Feb 5, 2026
6 checks passed
@sfmskywalker sfmskywalker deleted the copilot/sub-pr-7204-another-one branch February 5, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds database indexes to three call stack tracking columns (SchedulingActivityExecutionId, SchedulingActivityId, SchedulingWorkflowInstanceId) that were introduced in the V3_7 migration. The indexes are necessary to optimize chain traversal queries and filtering operations.

Changes:

  • Added EF Core index configurations for three scheduling columns in the ActivityExecutionRecord entity
  • Modified V3_7 migrations across all database providers to include index creation
  • Changed column types to be index-compatible (nvarchar(450) for SQL Server, varchar(255) for MySQL)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/modules/Elsa.Persistence.EFCore/Modules/Runtime/Configurations.cs Added three index definitions for scheduling columns using consistent naming pattern
src/modules/Elsa.Persistence.EFCore.SqlServer/Migrations/Runtime/20260122123023_V3_7.cs Changed column types from nvarchar(max) to nvarchar(450) and added indexes in Up method; added DropIndex operations in Down method
src/modules/Elsa.Persistence.EFCore.MySql/Migrations/Runtime/20260122123013_V3_7.cs Changed column types from longtext to varchar(255) and added indexes in Up method; added DropIndex operations in Down method
src/modules/Elsa.Persistence.EFCore.Sqlite/Migrations/Runtime/20260122123040_V3_7.cs Added CreateIndex operations for TEXT columns in Up method; added DropIndex operations in Down method
src/modules/Elsa.Persistence.EFCore.PostgreSql/Migrations/Runtime/20260122123049_V3_7.cs Added CreateIndex operations for text columns in Up method; added DropIndex operations in Down method
src/modules/Elsa.Persistence.EFCore.Oracle/Migrations/Runtime/20260122123056_V3_7.cs Added CreateIndex operations for NVARCHAR2(2000) columns in Up method; added DropIndex operations in Down method

Comment on lines 28 to 47
migrationBuilder.AddColumn<string>(
name: "SchedulingActivityExecutionId",
schema: _schema.Schema,
table: "ActivityExecutionRecords",
type: "nvarchar(max)",
type: "nvarchar(450)",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "SchedulingActivityId",
schema: _schema.Schema,
table: "ActivityExecutionRecords",
type: "nvarchar(max)",
type: "nvarchar(450)",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "SchedulingWorkflowInstanceId",
schema: _schema.Schema,
table: "ActivityExecutionRecords",
type: "nvarchar(max)",
type: "nvarchar(450)",
nullable: true);

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

This PR modifies an existing V3_7 migration that may have already been deployed to production systems. If users have already run the original V3_7 migration (dated January 22, 2026), their databases will have these columns with incompatible types for indexing (nvarchar(max) instead of nvarchar(450)). Running migrations again won't fix existing columns since EF Core tracks which migrations have been applied.

Consider one of these approaches:

  1. If V3_7 has NOT been released yet, this change is fine.
  2. If V3_7 HAS been released, create a new migration (e.g., V3_7_1 or V3_8) that uses AlterColumn operations to change the column types and then adds the indexes.
  3. Add explicit SQL commands in the Up method to alter the column type if it already exists with the wrong type.

Copilot uses AI. Check for mistakes.
type: "varchar(255)",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

Similar to SQL Server, this modifies an existing V3_7 migration that may have already been deployed. If users have already run the original V3_7 migration, their databases will have these columns with longtext type instead of varchar(255), making them incompatible with indexing.

Consider one of these approaches:

  1. If V3_7 has NOT been released yet, this change is fine.
  2. If V3_7 HAS been released, create a new migration (e.g., V3_7_1 or V3_8) that uses AlterColumn operations to change the column types and then adds the indexes.
  3. Add explicit SQL commands in the Up method to alter the column type if it already exists with the wrong type.
Suggested change
// Ensure the scheduling columns use an indexable type even if they were previously created as LONGTEXT.
var tableName = string.IsNullOrWhiteSpace(_schema.Schema)
? "`ActivityExecutionRecords`"
: $"`{_schema.Schema}`.`ActivityExecutionRecords`";
migrationBuilder.Sql($"""
ALTER TABLE {tableName}
MODIFY COLUMN `SchedulingActivityExecutionId` varchar(255) NULL,
MODIFY COLUMN `SchedulingActivityId` varchar(255) NULL,
MODIFY COLUMN `SchedulingWorkflowInstanceId` varchar(255) NULL;
""");

Copilot uses AI. Check for mistakes.
sfmskywalker added a commit that referenced this pull request Feb 7, 2026
* Initial plan

* Add missing indexes for call stack columns in all provider migrations

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Optimize migrations by creating columns with correct indexable types

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
sfmskywalker added a commit that referenced this pull request Feb 24, 2026
* Adds activity execution call stack support

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.

* Refactor: Replace `PagedCallStackResult` with `Page<T>` for execution chain pagination

* Remove ambient scheduling scope logic and related methods

Simplifies scheduling logic by removing ambient scope mechanisms, refactoring scheduling context handling, and updating affected classes accordingly.

* Add `GetCallStackAsync` to `IActivityExecutionsApi` for querying activity execution call stack

* Add new properties to `ActivityExecutionRecord` for scheduling and execution tracking

Introduce fields for aggregated fault count, scheduling context, workflow instance details, and call stack depth to enhance execution monitoring and debugging capabilities.

* Add call stack visualization for activity executions

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.

* Remove obsolete ambient scheduling properties from WorkflowExecutionContext

* Fix infinite loop issues in activity execution chain traversal

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.

* Refactor activity execution chain retrieval logic

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.

* Add CallStackDepth property to activity contexts

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 unit tests for call stack depth calculations and persistence

- 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.

* Update src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Enhance activity execution handling with ID filter and task completion logic

- Implement `ActivityExecutionRecordFilter` for precise query matching by ID.
- Add await logic for task completion in command handler middleware.

* Add missing indexes for call stack columns in V3_7 migrations (#7250)

* Initial plan

* Add missing indexes for call stack columns in all provider migrations

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Optimize migrations by creating columns with correct indexable types

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add unit tests for ActivityExecutionStoreExtensions

- Introduce tests for `GetExecutionChainAsync` covering scenarios of empty results, single records, multi-level chain traversal, workflow boundary constraints, pagination, and circular references.

* Refactor tests for `ActivityExecutionStoreExtensions`

- Replace mock setup with `CreateStore` helper for clean and clear test arrangements.
- Remove unused imports and clean up test setup for improved readability and maintenance.

* Remove unused imports from ActivityExecutionLogStore in Elsa.Persistence.EFCore module.

* Removes obsolete planning document

Removes the activity execution call stack planning document
as the feature has been implemented.

* Remove DefaultActivityExecutionMapperTests

- Deleted `DefaultActivityExecutionMapperTests.cs` as the test class is no longer in use and redundant.

* Address review feedback: Fix corrupted test, Oracle migrations, and call stack depth calculation (#7272)

* Initial plan

* Fix corrupted DefaultActivityExecutionMapperTests.cs test file

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Fix Oracle migration snapshot to use NCLOB for large text fields

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Optimize GetExecutionChainAsync to avoid loading all workflow instance records

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Fix CallStackDepth calculation to support cross-workflow invocations

- Add SchedulingCallStackDepth to ActivityInvocationOptions
- Update WorkflowExecutionContext to use provided depth when scheduling context not found
- Remove problematic test that reveals pre-existing bug with duplicate contexts

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Improve documentation for CallStackDepth calculation

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add WorkflowStateExtractor to ActivityTestFixture services

* Refactor `DefaultActivityExecutionMapperTests` with `ActivityTestFixture` and add project reference for shared testing utilities.

* Propagate SchedulingCallStackDepth through cross-workflow invocation chain (#7273)

* Initial plan

* Add SchedulingCallStackDepth propagation through cross-workflow invocation chain

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add unit tests for CallStackDepth propagation across workflow boundaries

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Initial plan (#7274)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* Reduce NVARCHAR2 column sizes in Oracle migrations to optimize storage and improve performance.

* Change column types to NCLOB for large text fields in Oracle migrations to enhance data storage capacity.

* Update GitHub Actions to use .NET 10.x and refactor setup classes for consistency

* Improve test project detection in GitHub Actions by handling non-csproj files and updating project sorting mechanism.

* Enhance GitHub Actions to display .NET environment info and enforce .NET 10 toolchain for test execution.

* Update GitHub Actions to use .NET SDK 10.0.1xx and enforce its usage for builds and tests.

* Refine GitHub Actions workflow by narrowing test project search to the `test/unit` directory and removing unnecessary script checks.

* Remove redundant build step from GitHub Actions workflow.

* Enhance GitHub Actions workflow by adding multiple test directories and handling ignored failed sources in .NET restore.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
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.

3 participants