Skip to content
Registry StackDocsv0.48.0

Schedule Actions with Record timers

View as Markdown

If a governed Record carries its own due instant, such as an activation date, a Record timer lets Base Registry Engine (BReg) run one bounded immediate Action when that instant arrives. You declare the timer on the Record type, grant it from the root project, and operate its work with bregctl timer.

A timer is part of the reviewed Registry package. It is not a caller route, a queue payload, or a general scheduler. Use a timer when the due instant and scheduling controls belong to the anchor Record, and the Action can decide and shape its effect from current governed facts within its declared local read scope. Keep external calendar coordination, capacity scheduling, and cross-system orchestration outside BReg.

The Record type declares the timer. The root project separately grants the exact recordType and timer pair:

recordTypes:
service:
fields:
- id: status
type: vocabulary-code
vocabulary: service-status
classification: internal
- id: activates-at
type: timestamp
classification: internal
- id: activation-not-after
type: timestamp
classification: internal
- id: activation-revision
type: uuid
classification: internal
timers:
- id: activate
at: activates-at
notAfter: activation-not-after
rearmOn: activation-revision
when:
type: fields
equals:
status: scheduled
invoke: activate-service
input:
service:
fromRecordId: true
planned-at:
fromField: activates-at
occurrence:
fromTimer: occurrence-id
timerGrants:
- recordType: service
timer: activate

The invoked Action is an ordinary immediate Action, and the timer must map every one of its inputs. The compiler refuses a timer that invokes a Proposal Action, a publicly invokable Action, or an Action with remote Function, Evidence, commit-Evidence, or consent-issuance capability. A local bounded handler remains available when it needs none of those capabilities.

The timer’s plan may Patch only the exact anchor Record and may Create bounded new Records. A timer Action cannot Tombstone a Record. Its declared guards and linked reads stay bounded by the compiled system grant; that read scope does not grant mutation of another existing Record. Ordinary authorised tombstoning of the anchor cancels its timer work.

timerGrants is root-project authority. A module may contribute a timer definition, but it cannot enable autonomous work. A project that imports the module must name the exact contributed timer in its root timerGrants; without that grant, compilation fails. To remove a timer, activate a reviewed successor that removes both its declaration and its matching grant. A false when predicate or a global pause is not permanent disablement.

A timer does not backfill historical Records. A newly created Record can arm its timer from its initial control values. A Record that existed before the timer was activated needs a later material write to at, notAfter, or rearmOn.

Record timers do not cover these cases:

  • A timer-initiated Action that would arm a successor timer is refused. The refusal is atomic, so the Action writes nothing.
  • There is no command to force a timer to run.
  • There is no payment observation, Messaging delivery, Proposal timing, or membership scheduling.
  • There is no per-Record timer projection.
  • Studio and App Kit do not author timers.
  • No capacity is claimed for a large backlog of due timers.
  • No full backup-and-restore or downstream-reconciliation exercise is claimed (see Restore a database).

at and notAfter name timestamp fields. rearmOn names a UUID or integer field whose changed value distinguishes a new occurrence even when its due time is unchanged. notAfter, rearmOn, and when are optional. Control fields cannot be encrypted, because their admitted types are not encryptable.

The material control tuple is the current value of at, notAfter, and rearmOn. Any change to that tuple creates a new occurrence, including a change from A to B and later back to A. Changing only fields named by when does not create an occurrence: a false predicate holds the current unfinished occurrence, and a later true predicate releases that same unfinished occurrence. Settled work stays settled. BReg refuses a new or materially changed control tuple whose notAfter is not later than at.

That refusal is not a general editing block. If a current occurrence is already configuration-blocked by an invalid window inherited across a package change, an unrelated Record edit may preserve the unchanged controls. It keeps that exact configuration block and creates no timer work. This exception does not create a configuration block for a Record with no current occurrence or for settled work, and it does not replace a preserved technical block or exhausted attempt history.

when.type: fields is a bounded conjunction of equality checks over current stored fields. Every named field and literal must agree with the field’s declared type. BReg checks the predicate against the locked current Record, not against a payload captured when the timer was armed.

Each Action input selects exactly one source:

  • fromRecordId: true maps the anchor Record UUID to a reference input that targets that Record type.
  • fromField: FIELD maps the field’s current locked value to an input of the same type.
  • fromTimer: occurrence-id maps the durable occurrence UUID.
  • fromTimer: due-at maps the occurrence’s intended timestamp.
  • value: VALUE maps a typed non-null literal.

fromField may name an optional field even when the Action input is required. If the current Record omits that field, ordinary live Action input validation refuses the occurrence. It does not substitute a value or bypass the input’s required constraint.

Encrypted predicate and fromField values remain supported. Runtime execution reads only the exact grant-covered fields from the locked anchor. Field-at-rest encryption protects the stored Record value, not the policy itself: authored when.equals and input.value literals remain visible in the project and in compiled or effective package inspection. Do not put secrets in those literals.

On the successful worker path, the plaintext of a mapped encrypted field does not appear in the timer tables, the operator projection, captured audit entries, or the worker’s scoped tracing. That coverage does not extend to actual bregctl process logging or to every failure path. Encrypt a field covers the encryption itself.

Run the normal authoring checks and inspect the compiled access report:

Terminal window
bregctl check ./registry --production
bregctl --format json explain access ./registry

The access explanation lists each timer’s control, predicate, and effect-shaping input fields, the profiles and operations that can write those fields, and the exact product-owned future-effect grant. That system grant is not an access profile or a token-selectable identity. Its target operation member reuses the shared Operation representation, which is a superset of timer authority. A realizable timer grant contains only get for exact reads, create for bounded new Records, and patch for the exact anchor. Other Operation values in the shared schema do not grant a timer those capabilities.

A timer-only Action remains in governed compiled inspection, but it has no public Action route, access entry, default profile, generated invoke method, portable Action contract, or public Registry metadata entry. Do not add a synthetic profile to make it callable.

The timer commands use the runtime configuration of the Registry deployment you are operating. The path must be absolute. They use the runtime database credential and the keyed companion audit journal from that configuration. JSON output suits scripts and keeps the closed state, block, outcome, and technical-code vocabularies explicit:

Terminal window
runtime_config=/absolute/path/to/runtime.yaml
bregctl --format json timer status --runtime-config "$runtime_config"
bregctl --format json timer list --runtime-config "$runtime_config" --limit 50
bregctl --format json timer show --runtime-config "$runtime_config" \
--occurrence-id 00000000-0000-0000-0000-000000000000

The status member of each report is the shared CLI result class. Timer status reports the scheduler state in its timer member. Status, list, and show remain available while timer claims are paused or in adoption hold.

The operator surface is separate from ordinary Record APIs. Its list and show reports contain bounded operational metadata and keyed Record references, not mapped input values, participants, result payloads, or claim tokens.

List pages use an opaque cursor returned by the preceding page. --limit defaults to 50 and accepts at most 200. Show returns at most the latest 100 retained attempts, in chronological order. attemptsTruncated reports either pagination or expired attempt detail that is no longer retained. attemptCount remains the cumulative count even after attempt detail expires. detailAvailable and detailExpiresAt describe retained occurrence-level diagnostic detail, not whether the Action executed.

Status scans each occurrence state and each block kind independently, with a 10,000-row ceiling for every category. It reports each capped count and sets countsTruncated when any category or the separate live-lease sample exceeds its ceiling. staleRevisionCount is a separate sum over capped samples of up to 10,000 pending, leased, and blocked rows per state. Prometheus current-occurrence and block gauges also use independent category caps, while current executed-attempt and stale-current gauges are sums over a separate sample of at most 10,000 current rows. Those gauges need not reconcile with the category counts after truncation.

Status is a bounded live observation assembled from several database reads, not a transactionally coherent snapshot. Its category counts, stale-revision count, lease owners, and lag can therefore reflect slightly different moments. Each mutating command rechecks the exact current control epoch and occurrence state. List pagination is also a live diagnostic view, not a durable event feed or a snapshot: work committed after a page can sort behind its cursor and be absent from the remainder of that scan. Start a new scan when completeness matters.

There is no separate timer operator database role. Protect the runtime configuration and its credential as operator capability: the database cannot distinguish bregctl timer from another holder of the same credential. That holder could use the runtime role’s database grants to write timer tables and control columns without the reason, audit, and compare-and-set checks of bregctl. Migration-owned protocol and instance-binding state remains outside those runtime writes.

Pause and resume use the control epoch that status returns. Re-read status after an epoch mismatch. Supply a bounded change reference and reason that serve your institutional audit process, and put no secrets or personal data in either value:

Terminal window
bregctl --format json timer pause --runtime-config "$runtime_config" \
--expected-control-epoch 42 \
--operator-reference CHG-1234 \
--reason 'Pause while the downstream service is unavailable'
bregctl --format json timer resume --runtime-config "$runtime_config" \
--expected-control-epoch 43 \
--operator-reference CHG-1235 \
--reason 'Resume after downstream recovery was verified'

Retry is limited to the exact current technically blocked occurrence and its observed cumulative attempt count. It grants one additional attempt to that occurrence; it does not run the Action synchronously, reset the count, or bypass current package, control, instance, or Action authority. BReg refuses retry unless the global timer control is running, so reconcile the block, then resume a paused or adoption-held control before you retry:

Terminal window
bregctl --format json timer retry --runtime-config "$runtime_config" \
--occurrence-id 00000000-0000-0000-0000-000000000000 \
--expected-attempt-count 5 \
--operator-reference INC-5678 \
--reason 'Retry after the transient runtime failure was resolved'

An expired valid notAfter window makes retry ineligible. The worker eventually materialises unfinished work as missed; status does not promise that this asynchronous transition is visible at the exact deadline. An invalid or unknown current window remains a configuration block until a corrective governed Record write or a reviewed successor timer configuration makes the window valid. A preserved technical block remains technical across those successor changes. BReg never infers an invalid window as missed from a stale predecessor deadline.

Pause, resume, and retry commit the database transition before they write the final companion-audit response. A timer.audit.unavailable result can therefore mean the transition committed but was not confirmed to you. Do not assume rollback, and do not repeat the command blindly. Re-read status and the exact occurrence, compare the control epoch, occurrence state, and attemptCount, then reconcile the unfinished audit request before you choose a follow-up.

Every package built with this release declares Record timer store support, including a project that defines no timers. A package built by an earlier release cannot be upgraded in place to this one. Starting the new runtime with that package neither adds tables nor rewrites the active catalog, and every command that reads it refuses it with one message. From this release the upgrade path restarts: create a fresh database, rebuild the package with this release, and activate it as the first package:

Terminal window
bregctl test PROJECT --runtime-config RUNTIME --credentials CREDENTIALS --output RECEIPT
bregctl package PROJECT --test-receipt RECEIPT --output BUILD
bregctl apply --runtime-config RUNTIME --package BUILD/package --initial

The package records the engine-owned timer store; you do not supply timer schema SQL. Later releases build successor packages from the package this release activated. Change an active registry covers successor packages in general.

For a successor, bregctl plan reports each added, changed, removed, or effect-input-migration timer without Record values. It includes predecessor and successor policy revisions plus a bounded observation of current unfinished markers. observedUnfinishedCount may be partial when truncated is true; hasStaleRevisions says the observed cache spans older policy revisions. Changed-policy outcomes remain unknown until refresh. A removed timer is known to be fenced from execution, and a newly added timer leaves historical Records unarmed. The plan does not scan business Records or offer backfill.

All replicas of one Registry deployment use the same active package, authoritative database, and logical identity.instanceId. They also need the same relevant runtime key and provider configuration. Keep identity.instanceId stable across replicas: it identifies the deployment and derives durable hook event identity, not the individual process or timer worker.

Configure a distinct durable audit sink for each process. Replica processes must connect directly to PostgreSQL or through session-mode pooling. Do not use transaction-mode PgBouncer: BReg’s registry interlocks use session-level PostgreSQL advisory locks that must remain on the same connection.

Use process IDs, logs, and the database connection’s application name to tell worker processes apart. Worker concurrency and database pool limits apply to each process. The number of lease owners visible in timer status is an observation of current ledger work, not a count of deployed replicas.

Fence the original primary before a restored or promoted copy can serve. Run the existing instance-claim adoption against the restored database, then keep timer work in adoption hold while you reconcile the recovery window. Inspect the timer status and resume only with the expected control epoch and an audited operator reference and reason. Resume is the only transition that releases an adoption hold.

A database restore carries the timer ledger and retained attempt history only up to the restore point. It cannot establish whether an external downstream effect completed after that point. Reconcile those downstream systems and any logical outbox delivery separately before you resume. No full backup-and-restore or downstream-reconciliation exercise is claimed for timers.

retention.receiptRetentionDays bounds terminal diagnostic detail and attempt history. Finished attempt detail may expire even while a current occurrence remains blocked; the cumulative attempt count and current failure metadata stay available. After detail expires, a restore cannot recover it. Retention may also remove expired non-current terminal occurrences. The current settled generation marker and binding-removal incarnation fences survive indefinitely, so do not infer missing execution from absent expired detail or older terminal rows.