Skip to content

Recurring meals API

A recurring meal is a rule that keeps a stretch of a Meal Space's Timeline filled with attached Entries on a schedule. It is implemented: reads, all commands, the occupied-Slot preview, and the blockers it places on Recipe and Variation removal. Materialization itself runs on a pg_cron sweep, not on request; see the materializer runbook.

Every route accepts first-party sessions, API keys, and OAuth access tokens. They use a user-scoped database client, the standard success/error envelope, and no-store caching. The prefix is /api/v1/meal-spaces/{groupId}/recurring-meals.

The "REST scope" column is the credential ceiling the bearer token must carry (read, write, or delete); it only decides whether a credential may reach the operation at all. "Authorization" is the separate access tier the database evaluates for that member — Write or Manage — described below.

Method and suffixREST scopeAuthorizationBehavior
GETread— (any reader)Page live or ended rules, ordered by title then id.
GET /previewread— (any reader)Preview a schedule's occurrence dates and the Slots already taken.
GET /{recurringMealId}read— (any reader)Read one rule.
POSTwriteManageMake a planned Entry recurring.
PATCH /{recurringMealId}writeManageEdit content, schedule, end date, or skipped dates.
DELETE /{recurringMealId}deleteWritePermanently remove a rule with no History.
POST /{recurringMealId}/pausewriteWritePause and remove upcoming planned Entries; keep today's.
POST /{recurringMealId}/resumewriteManageResume a paused or suspended rule.
POST /{recurringMealId}/endwriteWriteEnd on a date, keeping past meals.
POST /{recurringMealId}/skipwriteWriteSkip one upcoming occurrence.
POST /{recurringMealId}/restorewriteManageRestore one skipped occurrence.
POST /resume-suspendedwriteManageSpace-level: resume every rule Personal Pro ending suspended.

Authorization

Recurrence adds no new meal_space_action; it composes the existing evaluators.

  • Write: content.write must allow — Editor or higher, a writable space, not deletion-pending, not read-only.
  • Manage: Write, plus, in a Personal Meal Space, account.use_pro. Failure returns 403 pro_required. Shared Meal Spaces need nothing more; sponsorship already decides writability.
CommandRequires
create, edit, resume, resume-suspended, restoreManage
pause, end, delete, skipWrite

Cleanup never needs Pro, so a Free member can end or delete a suspended rule that is blocking Recipe deletion. Viewers read rules and cannot change them.

Content and schedule

RecurrenceContent mirrors Entry content: entry_type (simple, recipe, eating_out, or prep), slot (null exactly for prep), title (1–200 characters), notes (up to 10,000), recipe_id, variation_id, target_yield_quantity, and target_yield_unit. Non-Recipe rules carry no Recipe fields.

The schedule is interval_unit (day or week), interval_count (1–30 for day rules, 1–12 for week rules), and starts_on, the permanent interval anchor — a week rule's weekday comes from starts_on's ISO weekday. ends_on is a nullable last possible occurrence date. A create or edit request may carry at most 49 unique skip_dates, matching the generation horizon; the limit is per request, not a cap on the rule's skipped dates.

A rule read (RecurringMealRead) adds state (ended, suspended, paused, or active, in that precedence), next_occurrence_on (while the rule generates, its next occurrence from today that is not skipped, detached, made, or replaced), upcoming_skips (at most 367: the 366-day skip-ahead window plus the anchor day), upcoming_planned_count, and has_history — true when an attached Entry is dated before today, or has status completed or replaced.

Commands

Every command needs a UUID Idempotency-Key, the current membership_id, and — for create and edit — a version token (expected_entry_clock or expected_updated_at). A replay under the same key returns the original result; a changed body under the same key returns 409. Applied commands return:

{
  "outcome": "applied",
  "recurring_meal_id": "<uuid>",
  "updated_at": "2026-09-27T12:00:00.000000+00:00",
  "entries": { "created": 3, "updated": 0, "removed": 1, "detached": 0, "skipped": 0 }
}

outcome is applied, unchanged (a canonical no-op; no activity, no updated_at change), or stale (the version token is behind the stored rule; updated_at is null and nothing wrote). Every outcome, stale included, is HTTP 200; a stale token is not an error. resume-suspended instead returns { resumed, entries } across every rule it touched.

Create — recurring_meal_id, source_entry_id, expected_entry_clock, interval_unit, interval_count, optional skip_dates. The source Entry must be in the same Meal Space, planned, dated today or later, of an allowed type, unattached, not part of a replacement chain, and its client_updated_at must equal expected_entry_clock. Its Recipe must be active and its Variation unarchived. The rule's starts_on and generate_from are set to the source Entry's date, and the source Entry is attached.

Edit — expected_updated_at, content fields, optional schedule { interval_unit, interval_count, starts_on }, optional ends_on (a date on or after today, or null), optional skip_dates. Refused with recurrence_ended once the rule has ended. A schedule change needs an explicit starts_on >= today, which becomes the new generate_from; an unchanged schedule keeps its past anchor. Every edit rewrites the rule's remaining attached planned and skipped Entries dated today or later, including a paused rule's kept meal for today, so a skipped date that is restored later comes back with the rule's current content. Every schedule or end change, generating or not, removes the attached planned and skipped Entries dated today or later that are no longer occurrences (before starts_on, after ends_on, or off the step), and deletes skipped exceptions on such dates; only a generating rule inserts new Entries. An edit that only adds skip_dates removes nothing.

Pause — no extra input. Removes attached planned Entries dated after today; today's meal stays attached. unchanged if already paused. Pause never removes the rule's source Entry — if it would otherwise be removed, it is detached instead (see Entry hook).

Resume — optional resume_on in [today, today + 366], default today. Clears pause and suspension and sets generate_from = max(resume_on, starts_on), then only inserts: a meal kept by Pause stays attached even before resume_on. Refused with recurrence_ended once the rule has ended, and with recurrence_date_invalid when resume_on is after a live rule's ends_on. unchanged if the rule is neither paused nor suspended.

Resume suspended (space-level, REST only) — optional resume_on. Clears suspension on every live suspended rule in the space; a rule that is also paused stays paused.

End — optional ends_on >= today - 1, default today, meaning "after today's meal" — End keeps today's meal by default. Sets ends_on to the earlier of the current and requested dates; a later date returns unchanged (use edit to lengthen instead). Removes attached planned and skipped Entries dated after ends_on and on or after today, and deletes the rule's skipped exceptions dated after ends_on and on or after today. Passing ends_on: today - 1 ends the rule immediately, including today's meal — except the source Entry, which is detached rather than removed.

Delete — expected_updated_at. Refused with recurrence_has_history unless has_history is false. Detaches the source Entry, deletes every other attached Entry, then deletes the rule row; its exceptions cascade. Delete, like Pause and End, never removes the source Entry.

Skip — occurrence_date, an occurrence date in [today, today + 366], not after ends_on, and not before generate_from unless an Entry is still attached on that date (a meal kept across Pause and a later Resume), otherwise recurrence_date_invalid. Edit's skip_dates follow the same rule. An attached planned Entry on that date is set to status: "skipped" and stays attached — skipping does not detach it. An already-skipped attached Entry, or an existing exception, returns unchanged. An attached completed or replaced Entry refuses with recurrence_occurrence_resolved. With no attached Entry, this inserts a skipped exception that blocks materialization for that date.

Restore — occurrence_date, which must be today or later, on a live rule, and a valid occurrence of the rule's current schedule (recurrence_date_invalid otherwise — restoring does not honor a schedule the rule has since moved away from). An attached skipped Entry returns to planned, with the rule's current content. Otherwise, a matching skipped exception is deleted and the rule fills in missing dates, which recreates the date if it is within the horizon and the rule still generates. Restore only inserts; it never removes or rewrites another Entry. Anything else returns unchanged.

Deleting an existing attached Entry dated today or later, through the ordinary Entry DELETE route, records a restorable skipped exception rather than losing the occurrence outright — the same restore command brings it back.

Entry hook and detaching

Ordinary Entry commands (entries.md) keep occurrences honest through a server-side hook on any write to an attached Entry. For edit and move it runs before the row write, in the same transaction, so a move onto a date the rule already occupies never collides with the rule's own occurrence; for delete it runs after the row is gone:

Change to an attached EntryResult
Status only (made, skipped, back to planned)Stays attached.
A move that keeps the same date and SlotStays attached.
A change to entry_date, slot, entry_type, title, recipe_id, variation_id, target_yield_quantity, target_yield_unit, or notes — including a move to a different date or SlotDetaches: recurring_meal_id is cleared, recurrence_origin_id is kept, and a detached exception is recorded for the original date.
ReplaceThe original keeps its link and becomes replaced. The replacement Entry has neither link nor origin.
Delete of an attached Entry dated today or laterRecords a restorable skipped exception; no Entry is deleted from the rule's perspective until the exception is spent.
Delete of a past attached EntryNo exception — past dates never materialize.

An Entry that detaches keeps its origin, so a read can still say where the meal came from, but it is no longer part of the generating set: further rule edits, pauses, or ends do not touch it, and restoring the occurrence's date creates a new, separate Entry rather than reattaching this one.

Entry reads carry both links as recurring_meal_id and recurrence_origin_id; see entries.md.

Sync

Rules sync in each Meal Space's shared stream as recurring_meals, keyed by id, after meal_entries (content projection 4). A rule is in the stream while ends_on is null or on or after the view's from date, so ended rules age out with the window. The row is the rule's columns plus skipped_dates: the sorted dates of its skipped exceptions from from on. Exceptions are not mirrored; detached exceptions are never projected, because the Entry's origin carries that fact. It has no derived state, next_occurrence_on, or counts.

POST /api/v1/sync/push accepts recurrence_create, recurrence_edit, recurrence_pause, recurrence_resume, recurrence_end, recurrence_delete, recurrence_skip, and recurrence_restore. Each command is { operation_id, group_id, recurring_meal_id, kind, input }, where input is the matching REST request body; a create's input.recurring_meal_id must equal the envelope's. Commands run the same checks as REST, with the operation ID as the idempotency key. A stale outcome is rejected as domain_conflict/conflict and leaves no receipt, so it stays in Needs review. personal_pro_required is access_denied/forbidden, and a changed Membership is membership_changed. Resume suspended is REST only. Timeline Skip and its Undo stay ordinary queued Entry edits.

Blockers on Recipe and Variation removal

A live rule (active, paused, or suspended — not ended) referencing a Recipe blocks Recipe deletion and Transfer. A live rule referencing a Variation blocks Variation removal, whether that removal would archive or delete it.

OperationErrorPreview
Recipe delete409 conflict — "A recurring meal still uses this Recipe. Change it to other content or end it first."GET .../recipes/{recipeId}/deletion-preview adds active_recurrences
Recipe TransferSame errorUses the deletion preview
Variation remove409 conflict — "A recurring meal still uses this Variation. Change it or end it first."GET .../variations/{variationId}/removal-preview adds result: "blocked" and active_recurrences

active_recurrences items are {id, title, entry_type, interval_unit, interval_count, starts_on, state}, ordered by title then id, at most 100. Allowance archival never checks these blockers — Personal Pro lapsing suspends the affected rules instead of failing the archival.

GET /api/v1/meal-spaces/<groupId>/recipes/<recipeId>/deletion-preview
{
  "future_entries": [],
  "past_entry_count": 12,
  "active_recurrences": [
    {
      "id": "<recurring-meal-id>",
      "title": "Pizza night",
      "entry_type": "recipe",
      "interval_unit": "week",
      "interval_count": 1,
      "starts_on": "2026-10-03",
      "state": "active"
    }
  ]
}

Occupied-Slot preview

GET .../recurring-meals/preview is a read, not a command. It takes exactly one mode:

  • By source Entry (create): source_entry_id, interval_unit, interval_count.
  • By rule (edit that changes schedule or Slot): recurring_meal_id, interval_unit, interval_count, starts_on, and slot — omit slot for a rule with no Slot (a prep rule); the server treats an absent slot as null.

It returns the horizon's occurrence dates and, for each, the planned Entries already in the same Meal Space, date, and Slot that are not this rule's own — both unattached Entries and Entries attached to a different rule — as occupied: [{date, entry_id, title}]. In create mode, the source Entry's own date always reports no occupancy (that date cannot be skipped), though it still appears in dates. Prep rules report no occupancy at all. The server never skips occupied dates implicitly — the caller passes the dates it chose back as skip_dates on create or edit, and occupancy that changes between preview and save changes nothing.

GET .../recurring-meals/preview?recurring_meal_id=<id>&interval_unit=week&interval_count=1&starts_on=2026-10-03&slot=dinner
{
  "dates": ["2026-10-03", "2026-10-10", "2026-10-17"],
  "occupied": [
    { "date": "2026-10-10", "entry_id": "<entry-id>", "title": "Leftover soup" }
  ]
}

Horizon

Generation looks 49 days ahead (RECURRENCE_HORIZON_DAYS), from today through today + 48. The mobile mirror's future sync window is 42 days, so a member with a fully synced offline device always sees at least a week of already-materialized occurrences ahead of what they can see locally. Skip and restore accept dates up to 366 days out (RECURRENCE_SKIP_AHEAD_DAYS), further than generation reaches, so a member can plan a skip for a date the sweep has not materialized yet.

Errors

  • 422 — malformed input, or an out-of-bounds schedule/date.
  • 409 conflict — an ineligible or already-linked source Entry (recurrence_entry_ineligible, recurrence_entry_changed), an ended rule (recurrence_ended), History blocking delete (recurrence_has_history), the 100-rule cap (recurrence_limit_reached), an invalid occurrence date (recurrence_date_invalid), an already-resolved occurrence (recurrence_occurrence_resolved), an unavailable Recipe or Variation (recurrence_recipe_unavailable), a changed Membership (recurrence_membership_changed), or the Recipe/Variation blockers above.
  • 403 pro_required — a Manage command in a Personal Meal Space without Pro.
  • 404 — the rule (or, for create, the source Entry) was not found or is not readable.
  • 503 — an unmapped database failure; retry.

Unknown failures return a sanitized 503 without database messages or content, matching the rest of v1.