Reactors

The reactors plugin runs live mutations inside the transaction that changes the data. A live mutation is a stored mutation definition with live true and an optional integer priority. Enable it at open with plugins {reactors {}}. It has no settings. See plugin selection for the open options.

Store live mutations with patch_definition under the mutations kind. Each round evaluates affected live mutations against the same pending post-patch state. Their patches merge by priority, then the next round reads the combined pending state. When a round changes nothing, the source patch and every derived change commit together under one transaction ID. Readers and historical queries see the complete transaction. Intermediate rounds are never published. A successful write returns only after the reactor changes have settled. Reactors have no synchronization operation.

Priority and execution order

Priority resolves conflicting patch values. It does not set the order in which reactors run. Every affected reactor in a round reads the same pending snapshot. A priority of 10 does not make a reactor run after one with priority 0. Queries do not see proposals made in that same round. The next round reads the merged result. Definition order and creation order do not establish an execution order.

Larger priority values win when proposals differ at the same path. The default priority is 0; negative priorities are allowed. Identical proposals agree, including at equal priority. Different values at equal priority reject the write with reactor_conflict. Writes to different paths combine. Object patches combine member by member. A whole-entity delete competes with the entity's strongest field proposal at the entity path. When a field proposal wins, the whole-entity delete contributes no changes. When deletion wins, the field proposals contribute no changes.

For example, use these rules to maintain a person's readable-documents:

RulePriorityProposal
Reset0Set readable-documents to [] for each person
Grant10Set readable-documents to [Handbook] when the membership chain grants access

With a valid membership chain, both rules propose a value. Grant wins because 10 is larger than 0. When a membership link is removed, Grant no longer matches. Reset clears the saved grant in that same transaction. Both rules run together because they write the same field, regardless of their own input fields.

A rule that reads a field another rule changes reacts to that change in the next round. For example, a rule that reads readable-documents sees the merged permission result in the following round. Giving that rule a larger priority cannot make it see the result earlier.

Conflicts and failures

Every contributing mutation's scoped schemas must hold for the final state. Priority cannot override those schema requirements. Evaluation errors, schema rejection, cancellation and resource exhaustion reject the source write and all derived changes. The transaction permits at most 64 rounds, including the final unchanged round. Rules that keep changing data fail with reactor_non_convergent; no part of the transaction commits.

Selection and execution

Live mutations evaluate against pending facts, including changes from earlier rounds. A rule runs when changed fields intersect its query inputs or the fields it writes. Stored callables are expanded before extracting those dependencies. Negated facts also contribute their fields. Rules that write overlapping fields run together so that priority and default rules remain consistent. Each round's changed fields select the next round's affected rules. Whole-document reads depend on every field. If a dependency cannot be determined, changes to any field can run the rule. Definition changes invalidate the affected rule selection. A rule installed by a definition patch participates in that transaction. Restored transactions already contain their derived facts and are replayed without running reactors again.

Use explicit mutations for commands the application chooses to run. Use live mutations for derived data that must agree with the source change at every committed snapshot. All relevant writes must enable the reactors plugin to maintain that invariant. Large standing queries add work to the source write on the serialized committer.

Runtime status

Call status to inspect the enabled plugin and its installed rules:

FieldContents
enabledWhether the plugin is enabled
reactorsLive mutations, each with id, name, priority and sinceTx

sinceTx is the transaction that last changed the definition. A refused write reports its failure directly to its caller; it creates no pending reactor output.

Operations

OperationReturnsSummary
statusUnavailablereactors.status() returns the reactor runtime's owned status document.

status

C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.

Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release