Skip to content

feat(lifecycle): plan renders effect-will-fire; generic apply never writes a receipt (#1832) - #1879

Merged
lex00 merged 1 commit into
mainfrom
feat/1832-receipt-plan-apply
Aug 24, 2026
Merged

lex00 merged 1 commit into
mainfrom
feat/1832-receipt-plan-apply

Conversation

@lex00

@lex00 lex00 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Part of the effect-receipts epic #1703 (decision 3: receipts are declared, diffed, and observed like any resource, but observe-only to the generic apply path — the effect() step is the sole writer).

Plan: effect-will-fire

lifecycle plan now classifies every declared receipt by comparing its live value to the resolved expectation:

  • absent or differing → an effect entry, rendered effect will fire: <effect>, with effectReason (receipt-absent / receipt-stale) and the digests in effectDetail
  • matching → noop (clean)
  • unobservable → unobserved, loudly — including a receipt no loaded lexicon materializes or observes ("unknown, not clean"), which folds into the existing stderr incompleteness warning
  • a reference input that cannot resolve at plan time → effect with an unresolved-input note, never a guessed digest

Resolution uses resolveReceiptExpectation (#1831) with a resolver over the plan's merged observed values (observedValueResolver in packages/core/src/lifecycle/receipt-plan.ts): an attr-ref resolves to the referenced entity's observed attribute; anything else is an unresolved input. The effect step resolves again at run (#1834).

Entry-kind choice: an additive ChangeAction "effect" rather than reusing runtime with a reason. runtime means "live, undeclared, owned by a declared entity — not drift"; a receipt row is the opposite shape (declared, and something will happen), and the plan's consumers switch on action, so overloading runtime would have made every consumer parse a reason string to tell "ignore this" from "a migration is about to run". The new kind carries effect / effectReason / effectDetail beside the lexicon / physicalId attribution #1674 added, counts in summarize, and is excluded from the GitLab MR widget projection like the other non-mutating kinds.

Whatever the generic classification proposed for a receipt name (a create for a declared-absent receipt, a delete for a live-owned one missing from the declared axis) is replaced by the receipt's own entries (mergeReceiptEntries) — a receipt is never a create, never an update, and never a prune candidate in the plan.

Apply write-exclusion

Choke-point choice: build step 7, the serializer-input assembly in buildFromDiscoveryResult (packages/core/src/build.ts). Core never invokes appliers directly — every applier (temporal nativeApply targets, the component deploy verbs, npm run deploy) consumes the serialized build outputs (template.json, dist/gcp.yaml, …). Serialization is therefore what feeds appliers, so the exclusion sits in the assembly of the serializer's entity map: entities carrying EFFECT_RECEIPT_MARKER are split out (splitReceiptEntities) before any lexicon code runs, which is how every lexicon inherits it — a receipt can never appear in an apply-bound document, so no applier can write it and no desired-vs-live prune can sweep in a document-borne receipt.

Receipts still reach the serializer for visibility (#1835's design) via a new SerializeContext.receipts field — the seam a materializing lexicon renders them from, anywhere but the section an applier writes from. A serializer that ignores the field emits nothing for them, which is the safe default; a partition holding only core-factory receipts (the chant pseudo-lexicon) serializes nothing and no longer trips the missing-serializer warning.

packages/core/src/apply.ts needed no change: the tri-state envelope never sees a receipt because the plan handed to appliers cannot contain one.

Tests

  • receipt-plan.test.ts: absent → fire; stale hash → fire with both digests; matching → clean noop; unobservable → unobserved loudly (both the could-not-look and the nobody-observes cases); unresolved reference → fire with the note; resolved reference → clean; crash-between-effect-and-write → stale/absent receipt re-proposes the fire; generic create/delete for a receipt replaced (never a prune candidate); render contains effect will fire: <effect>
  • effect-receipt-exclusion.test.ts: a real build over a fixture with a receipt — the serializer spy receives only apply-bound entities (receipt rides ctx.receipts); a mock-plugin apply driven from the build output writes only the bucket and its prune candidates hold the genuine orphan, never the receipt; the receipts-only partition warns about nothing
  • cli/handlers/lifecycle.test.ts: runLifecyclePlan end-to-end with mock plugins — absent receipt → one effect row (no create), matching → clean render, stale → effect will fire render, unobservable core receipt → unobserved plus the stderr incompleteness warning

Docs: the lifecycle plan action table and prose gain the effect row.

Verified: core tsc clean, npx vitest run packages/core 4535 passed, just lint 0 errors, just docs-check clean.

Closes #1832

@lex00
lex00 merged commit 41fc6a1 into main Aug 24, 2026
6 checks passed
@lex00
lex00 deleted the feat/1832-receipt-plan-apply branch August 24, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lifecycle: plan renders effect-will-fire; generic apply never writes a receipt

1 participant