Supplies

Auto-close on restock

When a supply drops below its reorder threshold, the platform auto-spawns a restock task. When the supply goes back above threshold (because a receipt was processed or operator manually added stock), the open task should close — automatically.

This page documents how the close behavior is configured.

The close-action knob (gh#529)

Each task template has a close-action field:

  • resolve — when the trigger condition is no longer valid, mark the task done and emit the standard completion side-effects (digest, audit log, completion timestamp). Use for tasks where "no longer needed" should feel like a completed task.
  • discard — when the trigger is no longer valid, mark the task cancelled with cancelReason=trigger-invalidated. No completion side-effects. Use for tasks where the auto-spawn was a heuristic and the operator never really had to act.

The default for supply templates is resolve (gh#487 + gh#529 — operator-tunable per template).

Edit the close-action in the Task Templates editor under Auto-close behavior.

What "trigger no longer valid" means

For supply tasks: the supply went back above the reorder threshold.

For other auto-spawn tasks the operator might add over time, the condition is whatever was registered as the spawn trigger. The engine evaluates every N minutes against current state.

When the close fires

The auto-close engine runs on the morning + afternoon crons, same as dailyTaskSeeder. For each open task with autoCloseOnInvalidTrigger=true:

  1. Re-evaluate the spawn condition.
  2. If now-false → fire the configured close action.

The operator sees the task disappear (discard) or move to "completed today" (resolve).

Auditing what auto-closed

Every auto-close is logged in Admin → Audit Log → Tasks with:

  • Actor: auto-close-engine
  • Trigger: the original condition that spawned the task
  • Now-state: the snapshot showing the condition is invalid
  • Action: resolve or discard

If you're confused why a task disappeared, the audit row tells you.

Tasks that should NOT auto-close

Some tasks should stay open even when the original trigger is no longer valid — e.g. a "Send Check-in" task that fires on reservation.checkin event; even after check-in passes, the task should remain (you may have to manually send late).

Those templates leave Auto-close behavior = off in the editor. The engine skips them.


Implements: gh#487 (auto-dismiss on restock), gh#529 (configurable resolve/discard close-action + V28 editor control + supply template enable).

Source: the FlatsBratislava operator manual.