# Engine Logic
URL: https://pro.rv-grid.com/guides/gantt/scheduling/engine/
Source: src/content/docs/guides/gantt/scheduling/engine.mdx
Description: Deep dive into the RevoGrid Gantt scheduling engine pipeline and conflict resolution.
The RevoGrid Gantt scheduling engine follows a deterministic pipeline to compute effective dates for all tasks. It processes data changes in five distinct phases to ensure dependency safety and constraint satisfaction.

## The 5-Step Pipeline

### 1. Topological Sort
The engine first builds a dependency graph and performs a topological sort. This ensures that tasks are ordered such that every predecessor is processed before its successors.
- Summary tasks are handled separately to ensure they can roll up dates from their children.
- Circular dependencies are detected and reported as `dependency-cycle` issues with the involved task and dependency IDs.

When the active dependency graph contains a cycle, the engine treats the project as structurally invalid schedule data. It does not try to calculate a dependency-valid order through the loop, and task drag/resize does not clamp against predecessor links until the cycle is resolved.

### 2. Forward Pass (ASAP)
In the default `scheduleFrom: 'project-start'` mode, the engine performs a forward pass:
- Root tasks (those without predecessors) are anchored to the `projectStartDate`.
- Successors are shifted forward to satisfy their incoming dependencies (FS, SS, FF, SF) plus any `lagDays`.
- The engine uses the successor's calendar to compute working-day offsets if `lagCalendar: 'working-days'` is enabled.

### 3. Constraint Application
Once the dependency-driven dates are known, the engine applies per-task constraints:
- **Soft Constraints**: SNET, SNLT, etc., refine the start date if the dependency date falls outside the constraint bound.
- **Hard Constraints**: `must-start-on` and `must-finish-on` override the forward pass results. If a hard constraint violates a dependency, a conflict is reported, but the constraint date wins.

### 4. Summary Rollup
After all leaf tasks have their dates resolved, the engine rolls up the schedule to summary (parent) tasks:
- A summary task's `startDate` is the minimum of its children's `startDate`.
- A summary task's `endDate` is the maximum of its children's `endDate`.
- Rollup is recursive, traversing the entire WBS (Work Breakdown Structure) tree.

### 5. Critical Path Analysis
The final phase computes the project's early and late dates using a backward pass from the project finish date:
- **Total Slack**: The number of days a task can be delayed without delaying the project finish.
- **Critical Path**: Tasks with zero total slack are marked as `isCritical`.
- This analysis helps planners identify the "chain" of tasks that determines the total project duration.

## Conflict Resolution

The engine prioritizes user intent and data integrity when scheduling rules collide:

| Priority | Rule | Outcome |
|---|---|---|
| **High** | Actuals | `actualStartDate` and `actualFinishDate` pin the task; the engine won't move them. |
| **High** | Hard Constraints | `MSO` / `MFO` dates win over dependencies; conflict reported. |
| **Medium** | Dependencies | Auto-tasks are clamped to satisfy predecessors. |
| **Medium** | Soft Constraints | Dates are adjusted to bounds where possible; conflict reported if windows are disjoint. |
| **Low** | Authored Dates | Used as the starting point for root tasks or manual tasks. |

  The scheduling engine runs synchronously on each render to provide immediate feedback during drag-and-drop or inline editing.
