Skip to main content

Priority System

The priority system is the foundation of Smart Scheduling. It determines which items get scheduled first and which items can bump others.

Priority Levels

Smart Scheduling uses four priority levels:

Priority Inference

When an item doesn’t have an explicit priority set, the system infers it from the deadline:
Explicit priorities always override inferred priorities. If you set a task as “Low” priority, it stays low even if it’s overdue.

Priority Score Calculation

For more granular sorting, the system calculates a numeric priority score:
This scoring system ensures that:
  • Overdue items are scheduled first (score up to 9000)
  • Items due soon are prioritized even within the same priority level
  • Low priority items with urgent deadlines can outrank high priority items due later

Sorting Algorithm

Items are sorted using a multi-level comparison:
1

Primary: Priority

Higher priority items come first (critical > high > normal > low)
2

Secondary: Deadline

Among same priority, earlier deadlines come first
3

Tertiary: Creation Date

Among same priority and deadline, older items come first (FIFO)

Bumping Rules

Only critical priority items can bump other events:
Critical items cannot bump other critical items. This prevents infinite bumping loops and ensures all critical work gets done.

Bumping Process

When a critical task needs a time slot occupied by a lower-priority habit:
  1. The habit event is marked for rescheduling
  2. The task is scheduled in the freed slot
  3. The bumped habit is rescheduled to the next available slot
  4. If no suitable slot exists, a warning is generated

Implementation Details

The priority calculator is implemented in packages/ai/src/scheduling/priority-calculator.ts:

Testing

The priority system is thoroughly tested with a comprehensive suite (60 test cases as of this writing) covering:
  • Priority weight ordering
  • Explicit priority handling
  • Deadline-based inference
  • Priority comparison functions
  • Bumping rules
  • Multi-level sorting
  • Score calculation with urgency bonuses
Run tests with: