fix(planning): replan a plan once when reconsiderations race
Retracting a plan's assumption replanned it and withdrew its pending approval. An executor tick holding the old plan then saw the withdrawn approval, treated it as expired and replanned a second time. Entering replanning is now a compare-and-set, so only the first reconsideration replans and a stale one does nothing. A regression test fails with three plans without the guard.
This commit is contained in:
@@ -800,8 +800,8 @@ func (e *Executor) reconsider(ctx context.Context, p Plan, it volition.Intention
|
||||
rc := volition.Reconsider(it, t, volition.ReconsiderContext{Replans: p.Revision - 1, MaxReplans: p.MaxReplans, Now: e.now()})
|
||||
switch rc.Outcome {
|
||||
case volition.Replan, volition.Tighten:
|
||||
if err := e.Plans.SetStatus(ctx, nil, p.ID, PlanReplanning, rc.Reason); err != nil {
|
||||
return err
|
||||
if won, err := e.Plans.BeginReplan(ctx, p.ID, rc.Reason); err != nil || !won {
|
||||
return err // another reconsideration is already replanning or has closed this plan
|
||||
}
|
||||
cur, err := e.Volition.Apply(ctx, r, p.MindID, it.ID, rc, t)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user