Skip to content
MSO CloudDocumentation

ADR 0031 — deck presentation: a second writer, a persisted address space, yng-deck-bundle v1

On this page
  • Status: Accepted (CI configurable-deck programme, waves A + D, 2026-08-20). Code in tree; migration 0171 applies at the next deploy.
  • Date: 2026-08-20
  • Owners: Platform (Audience CI programme).
  • Related: extends ADR 0029 (presentation is DATA) and amends its D3; companions ADR 0024 (the deck is a saved dashboard), ADR 0012 (template origin); §49 (one impl per rule), §66 (RLS scope + outbox), §81.

Context#

ADR 0029 gave a delivered deck one declaration document and one writer — an onboarding script fed from the client's handoff file. Three gaps closed the product path:

  • an org admin has no CLI, so every editorial change was an operator errand;
  • an in-app edit wrote dashboard_widgets (the presentation) while a regen reads deck_presentation (the declaration), so the next rebuild discarded it;
  • the live deck could not be read back into the space that produced it — template_widget_key was NULL on every generated card and tabs carried no key at all — so nothing could export a delivered deck, and a DB-only field had no file home (IVF's widgetPromptOverrides lived in the database and in no artefact, where re-applying the handoff file would have blanked it).

Decisions#

D1 — The address space is PERSISTED, never reverse-engineered

Migration 0171: dashboard_tabs.template_tab_key (new, nullable) and dashboard_widgets.template_widget_key widened 64 → 128 (a generated key composes catalog dim_keys — cross-<dimKeyA>-<dimKeyB> — each of which the taxonomy allows 64 characters of). generateDeck writes both. The key is an ADDRESS, not lineage: the row stays origin: 'custom', so ADR 0012's template-update path (which requires origin = 'template') never claims a deck card, and nothing reads the column to decide what a tab or card renders. NULL means "not minted from a plan", which every hand-added row is; there is no backfill, because a generated deck is regenerated and guessing a key back off a stored label is the reverse-engineering this column removes.

D2 — A SECOND writer, patching FIELDS; presentation is the declaration of record

contentDecks.getPresentation / updatePresentation (brandProcedure, owner or org admin, write limited to 20/window, audited audience.presentation.update with FIELD NAMES and an orphan count, never values) write the same document the script writes. Semantics:

  • a patch names TOP-LEVEL fields and replaces each WHOLE — every keyed field is a map or list whose membership is the editorial statement, and a deep merge cannot express removing one entry;
  • null clears a field (back to the generator's default); an ABSENT field is "not stated" and carries the stored value through;
  • the MERGED document is validated by deckPresentationSchema, never the patch alone — a well-formed patch can still produce an illegal document;
  • an UNREADABLE stored document is refused (PRECONDITION_FAILED), never rebuilt from empty: a field-level patch over a document nobody can parse would drop every field it does not name. The repair is a full-document restore (D4). The READ path keeps ADR 0029 D3's safe degrade and says so in a storedUnreadable flag rather than reporting "no document";
  • the optimistic lock is expectedUpdatedAt, the row's own updatedAt compared VERBATIM as a string against a row re-read FOR UPDATE inside the transaction — an opaque token, so no second date grammar reaches this path (§41); stale ⇒ CONFLICT, absent ⇒ unconditional write.

UI edits (card rail, tab manager, AI direction, brand alias) therefore land in the DECLARATION as well as in dashboard_widgets, which is what makes a regen keep them.

D3 — ONE orphan resolver, shared by both writers; a REPORT, never a refusal

apps/web/src/server/deck-presentation-keys.ts (checkPresentationKeys, pure — the caller does its two reads inside its own RLS scope) is imported by the apply script AND by the patch procedure. The resolver answers the two spaces a corpus can decide (published block_ref, declared dim_key, plus seeded-* widget keys through seededWidgetKey's formula) and hands everything rule-dependent back as unchecked for the generator's own sweep. Orphans are REPORTED with the write: one stale key must not cost the other forty their edit.

D4 — yng-deck-bundle v1 — one portable document per corpus

deck-bundle.ts (pure; strict schema) carries what makes a deck THIS client's deck: the presentation document verbatim (including blockKinds), the client-facing glossary (dimKey → valueKey → {labelVi, definitionVi?}), the DECLARED cross pairs, the prose sections with their lifecycle status, and the org's themeSlug as a POINTER. It is assembled from the DATABASE, not from whichever file was applied last. It is NOT a deck: nothing here writes dashboards, dashboard_tabs or dashboard_widgets, so a restore changes nothing on screen until a regen runs.

Both legs are bounded at 2 MiB, and the import measures bytes BEFORE it parses. Per-artefact caps: 32 dims × 400 values, 24 cross pairs, 60 seeds, 20,000 body characters.

importDeckBundle runs mode: 'validate' (plans everything, writes nothing) and mode: 'apply' over the SAME planning code, in one transaction, in the order labels → pairs → prose → presentation — the orphan sweep resolves blockRefs against published publications, so sweeping before the bundle's own sections land would report every restored section as an orphan.

Artefact Import semantics
presentation FULL replace, spelled as a D2 patch naming every field (null for the ones the bundle omits) — one writer, one merge, one validation. Replaces an unreadable document.
valueLabels Label always wins; a DEFINITION an operator wrote is kept unless forceDefinitions. A value the target catalog does not hold is reported, never created.
crossPairs Canonical order through orderCrossPair; missing legs skipped; an archived pair is reactivated, said out loud.
insightSeeds Replaces prose, including human-authored (reported replaced_human_body). A body containing wsna.v1 that fails parseWsnaBody is REFUSED per item. published stamps the importer as approver; kind is NOT written here (it is a presentation field).
themeSlug Reported, never applied — who may select a skin is the appearance plane's rule (§69).

Every report row carries a stable CODE, never a sentence (the wording lives in @yng/i18n). The writes are direct SQL rather than nested calls into contentTaxonomy.updateValuePresentation / declareCrossPair / contentInsights.createManual: those are rate-limited procedures, and a limiter is external I/O inside a pinned RLS scope (§66b). Their RULES are imported, not restated. Export is a QUERY and writes no audit row; apply is audited audience.deck.restore with counts and addresses only.

scripts/onboarding/export-deck-bundle.ts / import-deck-bundle.ts call the REAL router (createCaller), so RBAC, limits, guards and planning are the shipped ones and the scripts are transports, not second implementations. Import defaults to a dry run (APPLY=1 writes).

Consequences#

  • Presentation has TWO writers and ONE set of rules: schema, merge, orphan resolution and key formula are each stated once and imported. A third writer is legitimate only on the same terms.
  • A stale handoff file is now dangerous in a way it was not: the apply script rewrites the whole document (except blockKinds), so it can blank fields the UI wrote. Export-before-apply is the standing discipline (docs/runbooks/ci-deck-delivery.md).
  • Backup, clone-to-next-quarter and hand-off-to-another-environment are one file and one dry run. Restoring a bundle does not redraw a deck — rebuild-content-deck.ts still mints the dashboard, and refresh-audience-rollups.ts runs first when a pair was declared.
  • A bundle carries no theme payload and no parked AI draft, by decision; a publication mid-approval is omitted from the export and named, never downgraded to draft.

Implementation status (declared 2026-08-20)#

Decision Status Evidence
D1 address space Landed packages/schema/drizzle/0171_deck_address_space.sql; dashboard-tabs.ts / dashboards.ts columns; generator writes in routers/content-decks.ts; deck-address-space.test.ts
D2 tRPC writer Landed deck-presentation-patch.ts (pure merge); contentDecks.getPresentation / updatePresentation; deck-presentation-patch.test.ts
D3 shared orphan sweep Landed deck-presentation-keys.ts; imported by scripts/onboarding/apply-deck-presentation.ts and the patch procedure; audit presentation-keys-resolve.py
D4 bundle v1 Landed deck-bundle.ts; contentDecks.exportDeckBundle / importDeckBundle; export-deck-bundle.ts / import-deck-bundle.ts; deck-bundle.test.ts
Live round trip on IVF Pending Post-deploy: export → validate → re-apply on dataset 45960944-b2a6-48c2-9ee3-48c383f690b7's corpus, then refresh the private handoff file from the export