Skip to content

Provenance Report

A hybrid plan or apply can record what it reads of state and report it: for every plan node, which state entries, outputs and enumerations its values came from, at which revision; for the run, the write set and the read set that resource leases would need; and how far a static estimate of that read set, made from the configuration alone, falls short.

It is instrumentation for the graph state backend RFC (phase 3, "Read Provenance"). It observes and reports; it changes nothing a plan or apply does, and it is off by default. The data it produces on real apps decides whether concurrent applies can lease from static references or need declared scopes and run-time validation. Zero gaps on the runs observed is evidence, not proof, that every read path is instrumented.

Turning it on

Where Setting
App App(provenance_report=True)
pyproject.toml provenance_report = true in [tool.nf.config]
CLI nf plan --provenance-report, nf apply --provenance-report, nf deploy --provenance-report

The report is the plan summary's provenance_report (HybridExecutionMode.plan()), the apply's ExecutionResult.provenance_report, and HybridExecutionMode.provenance_report (the last one built, also for create_plan_artifact() and stack plans). The CLI prints it after the plan or apply, and the log has the same lines at INFO.

For document backends, off means recording calls return at once. Graph backends always record authoritative inputs for reconciliation; this setting controls the diagnostic report. Cached runtime values retain their original reads, and opaque functions and observations can declare reads= / observes= scopes (see Graph State Backend).

What is recorded

Every value the evaluation layer produces from state is a read: what it is of, the key, the key's revision, and how it was reached.

Kind Key Recorded when
entry a resource's state key (app.aws_vpc.main) a reference resolves to a stored or refreshed entry
absent the key looked up a reference, check or lookup finds no entry (revision 0)
output <stack>.output.<name> a remote-state import or a runtime check reads an output
enumeration stack:<id> or app something depends on which members a stack or the app has
observation a data source's (or ephemeral resource's) key a data source result is used: a cache, never leased
planned a resource's key a planned value is used (the planned node is in the write set)
decision a resource's key replace_triggered_by, a deferral or depends_on was decided from whether it has a planned change

Provenance travels with values, not with state lookups: a read lands in the scope of whatever is being evaluated, so derived values (expressions, f-strings, runtime functions, and the runtime values a runtime function returns, evaluated afterwards) carry the union of their operands' reads. Expression memo hits replay their captured reads into an inner runtime capture even when another field evaluated that operand first. Caches keep the provenance of each value they hold and add it back on every read, marked mediated_by the cache:

  • data source results (data:<key>): a result carries what its configuration was evaluated from, including results read for provider settings and carried from the plan to its apply. Graph plans retain this proof with the result's address, value fingerprint and original scope members. Missing evidence is unknown; an explicit empty proof means no managed reads. A stored cache without qualified evidence cannot certify a graph consumer;
  • ephemeral results (ephemeral:<key>): each open result carries its configuration's and provider settings' managed reads and its declared observes= scope to write-only consumers, including chained ephemeral results. Omitted observations conservatively cover the app; [] removes the opaque scope while preserving actual configuration/provider reads. The proof stays with the session result; the temporary value and private bytes are not stored in a plan or managed operation template;
  • remote-state imports: the import reads its source stack's members, outputs and entries;
  • planned values and planned outputs (planned:<key>, planned_output:<key>).

Ephemeral context checks run independently of this report. Runtime-returned references and memoized expressions retain their temporary-value marker, including unknown references. Cached runtime computations that consume ephemeral values are evaluated again for the current session. In graph runs, cached computations with managed reads are also bound to their state, run and evaluation phase, so a provisional or foreign-state value cannot borrow current revisions. Results cached before authoritative recording are evaluated once to establish their proof; missing evidence cannot certify an empty set of operand reads.

Provider settings are attributed to a node of their own (provider:<stack>:<name>); every change through that provider inherits its reads. Runtime checks read through a recording stack_outputs: a lookup reads the entry or output, a membership test reads it or its absence, iterating reads the stack's (or the app's) members.

Revisions

Document state has no revisions. A read's revision is d<position>:<hash>: the entry's position in the stored document and a hash of its content, taken when the run first reads state under its lock, so values read through the refreshed and stack-filtered copies of state keep the stored entry's revision. A stack's or the app's generation is a hash of its member keys. A row backend supplies real revisions by implementing provenance_revisions() on its StateBackend, returning a RevisionSource (entry, output, generation).

Attribution

A read is attributed to the plan node being evaluated: each planning step and each apply node runs in a scope of its own (a context variable, which follows anyio tasks, to_thread.run_sync workers and the threads run_sync starts). In a graph run, provisional desired-state evaluation is classified separately; final nodes evaluate their configurations in dependency order. Document runs continue to attribute provisional configurations to their constructs.

Reads outside any node are classified, each with its disposition under the RFC, in OUT_OF_NODE_READS (netherframe.core.execution.provenance_report):

Purpose Where Disposition
desired_state provisional graph configurations final nodes evaluate again; any cached values retain their captured reads
change_detection diff_states: each declared entry against its desired state decides the entry's own action: a no-op needs no lease under three-way rules; a change joins the write set
undeclared_enumeration diff_states: entries the code no longer declares the deletes join the write set; leased as S on the stack until three-way deletion discovery ships
destroy_ordering reverse dependency edges of every entry orders deletes after their dependents: must be leased (versioned reverse-edge index)
provider_startup_scan providers only state refers to decides which clients start: safe
provider_fingerprint, stale_plan_check saved-plan validation replaced by read-set validation: safe
store_outputs outputs whose nodes did not run, evaluated and written the outputs it writes join the write set
store_data_source_results data source results kept in state observations, last-writer-wins: never leased
refresh every stored object read back an observation; values through the copy keep the entry's revision
checkpoint, recovery, forget_deleted_outside, destroy_forget recovery and cleanup no mutation input, or the run's own write set

The table also lists places not instrumented (output annotation and the deferral of deletes in hybrid_planning.py, the plan summary, state operations). A read in no node and no classified purpose is a gap, reported with its call site (callee < caller); so is a read made in a thread that lost the run's context (lost-context:).

The report

Field Holds
write_set changed and deleted entries, deferred actions (deletes included), and outputs that change or depend on any of them
read_set the RFC's S: what write-set nodes consumed (their reads, their providers' settings', cached values' sources), minus the write set; enumerations at the scope they enumerate; observations excluded
static_estimate keys and scopes from the write-set constructs' compiled_config(...).references(), followed through data sources and remote-state imports, their providers' settings, deletes (the stack's enumeration) and runtime checks' declared scopes
missed_by_static_estimate read-set keys the estimate does not cover, by category
deferred_actions, deferred_estimate, deferred_uncovered the actions deferred to later rounds, the estimate leased for them up front, and what their rounds read beyond it
unattributed gaps
out_of_node classified reads outside nodes, with their dispositions
nodes every node's reads, by phase (plan, apply, round-<n>)

Categories of reads the static estimate misses:

  • dynamic_reference: read while evaluating a runtime value a runtime function returned; no static reference names it.
  • predicate: a reference resolved by scanning entries (referenced_address): the absence of the stack's own entry that sends a reference to another stack, or the scan of every entry of a type and name.
  • cache_mediated: reached only through a cache whose source the estimate did not follow.
  • runtime_check: read by a runtime check beyond its declared scope.
  • lifecycle_decision, enumeration, other.

Declared check scopes

Runtime checks can declare what they read, which narrows the estimated lease scope. In your importable app module, let logs be the logs bucket in the storage stack and user the resource you want to check before applying changes to it.

# coding: nf_autoid
from nf.core import App, Bind, BindContext, Stack
from nf.core.runtime.hybrid_runtime import RuntimeCheckContext, runtime_check
from nf.providers.hashicorp.aws import IamUser, S3Bucket


def bucket_in_state(context: RuntimeCheckContext) -> bool:
    return "aws_s3_bucket.logs" in context.stack_outputs.get("storage", {})


with App(nf_id="app") as app, Stack(nf_id="storage") as storage, BindContext:
    logs: Bind = S3Bucket(bucket="example-logs")
    user: Bind = IamUser(name="writer")

user.runtime_checks = [runtime_check(bucket_in_state, reads=[logs])]

reads accepts resources, stacks, "app" or state keys.

The declaration is not enforced yet: the report shows what a check read beyond it. A check that declares nothing is taken to read the whole app (undeclared_check_nodes); reads covered only by that are counted apart (missed_covered_only_by_undeclared_check_scope).