Edit in scope
Author a clinic override relative to its tenant baseline.
Clinic appointment · policy foundation
Combine tenant defaults and clinic overrides as typed policy, bind every command to a trusted actor, and preserve the effective snapshot used by each consequential scheduling decision.
9008d3eSimulation · Default view
An operator never writes a clinic override directly into live configuration. Compilation and preview explain its effect; approvals and compare-and-set protect the immutable snapshot used by new decisions.
Author a clinic override relative to its tenant baseline.
Merge typed payloads and reject attempts to relax non-negotiable safety rules.
Show affected decisions, constraint changes, a bounded sample, and metrics.
Require the right assurances and reject stale revisions or out-of-scope actors.
Use CAS to advance generation and write the immutable snapshot plus outbox atomically.
Read the authoritative scope head and record snapshot version and hash.
The previous snapshot remains valid through explicit expiry.
Activation never silently cancels or rewrites an existing confirmation.
History · Decision provenance
This visual companion supports understanding. The Markdown design remains normative for detailed contracts and acceptance criteria.
Issue #182 records the need for reproducible clinic-specific scheduling policy.
The normative design defines lifecycle, compiler, approval, generation, cache correctness, and failure semantics.
The companion design and delivery plan add provenance and fail-closed publication rules.
Problem and selected approach
Strong SQL constraints, but migrations and compiler branches multiply with every policy kind.
Easy to extend, but lifecycle, revision, interval uniqueness, and typed validation become weak.
Normalize lifecycle, concurrency, and audit fields while validating payloads as Kotlin sealed types.
Policy model
Defines defaults and hard ceilings that clinic policy cannot relax.
Changes only allowed typed fields within the clinic and actor scope.
Stores compiler version, canonical payload, source revisions, hash, generation, and activation interval.
Derives tenant, clinic, subject, assurance, and permissions from trusted gateway identity rather than request payload.
Activation safety
Reject stale drafts and previews whose revision or generation no longer matches.
Require policy-specific approval count and actor assurance before activation.
Advance the scope head, persist the snapshot, and emit the activation event atomically and idempotently.
Storage contract
| Surface | Responsibility | Invariant |
|---|---|---|
scheduling_policy_set | Scope and lifecycle envelope | Tenant/clinic ownership never comes from caller-controlled payload. |
scheduling_policy_version | Typed draft and revision history | Accepted revisions are append-oriented and auditable. |
scheduling_policy_snapshot | Compiled effective policy | Payload, hash, compiler version, and source revisions are immutable. |
scheduling_policy_scope_head | Authoritative generation pointer | CAS prevents concurrent activation from silently winning. |
scheduling_* Flyway schema names are a compatibility contract and are not renamed by this design.Failure semantics
POLICY_PAYLOAD_INVALID, POLICY_OVERRIDE_FORBIDDEN, and POLICY_ACTOR_FORBIDDEN require payload, scope, or authority correction.
POLICY_DRAFT_STALE, POLICY_PREVIEW_STALE, and POLICY_ACTIVATION_CONFLICT require a fresh read or preview.
POLICY_IDEMPOTENCY_CONFLICT means the same key was used for a different command.
Only POLICY_PREVIEW_LIMITED is automatically retryable, and callers honor Retry-After.
Operations
Start behind a disabled flag, compile without effect, and compare results before activating reads.
Measure activation lateness, compile latency, generation reads, stale rejection, preview deadlines, and outbox state.
Activate a previous compatible version as a new snapshot. Never mutate old evidence or rely on destructive down migration.
Delivery boundary
Typed policy, actor context, compiler, snapshot, approval, generation, preview, cache, generic outbox, and admin API.
PROPOSED, HELD, CONFIRMED, customer consent, allocation, waitlist, disruption, and overbooking.