Skip to content

Scheduler Fails to Cascade Delete When Placed Activities are Anchored to Each Other #1797

@Mythicaeda

Description

@Mythicaeda

This bug occurs when a procedural scheduling goal is set to delete activities it placed in a prior scheduling with the anchor resolution strategy set to Cascade. The scheduler deletes goals from a prior run by iterating over the activities placed by the goal and deleting them one-by-one, handling anchors as it deletes the anchoring activity. This means that if one of the later activities is anchored to an earlier one, when the earlier one is removed, the later one is deleted in that same iteration of the loop. When this deletion occurs, the "placed by previous run" iterator isn't updated and the scheduler will attempt to delete that later activity a second time, throwing an exception when it can't find the already-deleted activity.

The method Procedure#shouldDeletePastCreations needs to be updated to properly handle anchored activities.

Reproduction steps:
Run scheduling twice using the following procedural goal with the Bananation model:

@SchedulingProcedure
public record AnchorCascadeDeleteGoal() implements Goal {

  @Override
  public ActivityAutoDelete shouldDeletePastCreations(
      @NotNull final Plan plan,
      @Nullable final SimulationResults simResults) {
    // Delete activities created by previous runs of this goal, using Cascade to
    // handle anchored activities
    return new ActivityAutoDelete.AtBeginning(DeletedAnchorStrategy.Cascade, false);
  }

  @Override
  public void run(@NotNull final EditablePlan plan) {
    final var ids = new ActivityDirectiveId[3];

    ids[0] = plan.create(
        "BiteBanana",
        new DirectiveStart.Absolute(Duration.HOUR),
        Map.of("biteSize", SerializedValue.of(1))
    );
    ids[1] = plan.create(
        "BiteBanana",
        new DirectiveStart.Anchor(ids[0], Duration.HOUR, DirectiveStart.Anchor.AnchorPoint.End),
        Map.of("biteSize", SerializedValue.of(2))
    );
    ids[2] = plan.create(
        "BiteBanana",
        new DirectiveStart.Anchor(ids[1], Duration.HOUR, DirectiveStart.Anchor.AnchorPoint.Start),
        Map.of("biteSize", SerializedValue.of(3))
    );

    plan.commit();
  }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingschedulingAnything related to the scheduling domain

Type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions