Skip to content
MSO CloudDocumentation

ADR 0032 — brand alias ("bí danh thương hiệu"): a deck-scoped presentation alias

On this page
  • Status: Accepted (CI configurable-deck programme, wave C, 2026-08-20). Code in tree.
  • Date: 2026-08-20
  • Owners: Platform (Audience CI programme).
  • Related: distinct from ADR 0007 (demo posture + masking — its super-admin invariant is untouched); configured through ADR 0031 D2 and stored per ADR 0029; §44 (store verbatim, mask at display), §49, §76.

Context#

A delivered deck is shown to audiences the client's identity is not for: an internal review, a method walk-through, a link forwarded past the room it was presented in. The org admin needs the document to read "Bank A" where the corpus says "ACB", everywhere in the deck, its public share and its chat answers — and nowhere else.

Nothing that shipped fits. market_intel_settings.demo_mask (ADR 0007) is a platform POSTURE a super admin sets ABOUT a tenant, with a fixed maskLabel() scheme on the 3rd-party estimate plane; maskFreeText masks PII by stored spans; the demo-display mask is env-global. The CI deck and share plane sit outside all three by decision (demoMask: false).

Decisions#

D1 — A DISTINCT feature, not a second caller of demo masking

Different actor (org admin, not super admin), different semantics (an authored pseudonym the tenant chooses, not a platform posture), different mechanism (a substring alias over prose and labels, not a kind-alias for a market entity). Neither may be implemented in terms of the other. ADR 0007's two standing rules still bind here and are restated in code: a masked display value is NEVER reused as a lookup key, and this is not anonymisation — §44 holds end to end, the row keeps the real string and only the display is rewritten, at the server's return boundary.

D2 — The declaration is a presentation field

deck_presentation.brandMask { enabled: boolean, aliases: [{ match, alias }] }, capped at EIGHT pairs, match ≥ 2 characters. Written by the ADR 0031 D2 patch procedure, so the toggle is org-admin self-serve and survives a regen. A LIST, not a map: the order is the operator's own priority and a record cannot carry one. Masking is on only when enabled is true AND at least one usable pair remains.

D3 — ONE alias primitive, in @yng/ui/brand-alias

Pure, DOM-free, dependency-free, subpath-exported (never re-exported from the @yng/ui barrel — §76). What it guarantees:

  • fold for MATCHING only: per-code-point NFD folding with a source-offset view, so a match found in folded space cuts the right span out of the ORIGINAL and every character outside a match is copied through with its diacritics and casing intact. đ/Đ are mapped by hand (they do not decompose), so "Đông Á" and "Dong A" are the same name;
  • Unicode word boundaries: a letter or digit on either side blocks the match, so ACB never fires inside MACBOOK;
  • longest match first: "Ngân hàng Á Châu" wins over "Á Châu" wherever both could match;
  • markdown carve-outs: a fenced code block, an inline code span, a link destination, an autolink and a bare URL survive verbatim — the link TEXT is prose and is rewritten. A line + segment scanner, never a markdown parser: a scanner only copies or replaces, so a document it does not understand comes out byte-identical (and ADR 0030 D1 keeps markdown as the wire format, so a second re-emitter would be a second markdown writer);
  • compile-time idempotence: an entry whose alias still contains any declared needle is DROPPED at compile time. apply(apply(x)) === apply(x) is load-bearing — the same payload is aliased on the way out of a cache, a streamed answer is filtered in chunks, and a deck is re-read constantly; a rule that is not a fixed point corrupts the document it is applied to.

D4 — ONE policy door, and a CLOSED set of chokepoints

apps/web/src/server/deck-brand-mask.ts is the only importer of the primitive: the primitive answers "how is a name rewritten", the policy module answers "whose names, on which surfaces, and when NOT to". A masking rule is only as good as its least covered surface — a sixth boundary nobody aliased prints the client's identity beside four cards that say "Bank A", which is worse than never masking, because a reader can line the two up.

Applied at: the public share payload, explore.dataset label cells, dashboards.bySlug chrome, the deck chat's scope strings, its tool results, its prompt rule and its streamed answer. Derived (they consume what the share module resolved): the share registry's payload walker and the public-share record refusal.

NOT applied, each for a reason: any value that travels BACK as a query input (*Key fields, ICT day edges, the mention column legs, row id, link — a masked address would return an empty drilldown under a bucket that has rows, §32); the uploaded records in-app (masking evidence would be editing it); anything persisted (nothing here writes).

Enforcement: scripts/audit/brand-alias-single-source.py, in audit:all — it pins the primitive's two legal importers, the chokepoint list with each one's reason, the two derived chokepoints by the exact line that does the work, the absence of a barrel re-export, and that brandMask still lives in deckPresentationSchema as a non-keyed field.

D5 — Alias on the way OUT of the cache; refuse the anonymous drilldown

The share payload cache stores the VERBATIM payload and the alias is applied after the read, so the cache is never keyed on a mask state and a toggle takes effect on the next read. The in-app record modal keeps the client's own words for the client's own staff; its ANONYMOUS twin (publicShare.audienceRecords) is REFUSED while the alias is on — one click must not undo for a stranger what the whole document just did.

D6 — A streamed answer is filtered with a boundary-aware carry-over

The model is told the rule in the deck-chat system prompt and its tool results already arrive aliased; the stream filter is the last line, for an echo of a name the user typed. A name split across two deltas ("…của A" + "CB trong kỳ…") is whole only if the filter holds a tail: it holds ONLY a trailing run that starts at a word boundary and could still be the head of a declared name (usually none, so a chunk is emitted whole and an answer never lags), and flush() emits what is left at the end of the message.

Consequences#

  • The alias is per DECK, authored by the tenant, and travels with the corpus's presentation document — including through a yng-deck-bundle restore (ADR 0031 D4).
  • ADR 0007's plane is untouched: demo masking stays super-admin-only, market-intel-scoped, with its own scheme.
  • Accepted limitation: a card title edited while the mask is ON is saved exactly as it stands in the field, and the field shows the ALIAS — so an unretyped title stores the pseudonym in the declaration. The mask panel says so before the edit (deckEditor.brandMask.editNote); the fix options (a verbatim edit session, or refusing a title patch while masked) are not built.
  • A new deck-printing boundary is a deliberate edit to the audit's chokepoint list, answering one question: does it print LABELS (alias it) or ADDRESSES (do not)?

Implementation status (declared 2026-08-20)#

Decision Status Evidence
D1 distinct feature Landed deck-brand-mask.ts + brand-alias.ts docstrings; no import path between this and mask-label.ts (audit-pinned)
D2 declaration Landed brandMask in deck-presentation.ts; written through contentDecks.updatePresentation; deck drawer mask panel
D3 primitive Landed packages/ui/src/brand-alias.ts (+ subpath export); packages/ui/src/brand-alias.test.ts
D4 chokepoints Landed deck-brand-mask.ts; share payload / explore.dataset / dashboards.bySlug / deck-chat scope, tools, prompt, route; audit brand-alias-single-source.py
D5 cache + refusal Landed share/registry.ts (maskPublicDeckPayload after the cached read); routers/public-share.ts (scope.brandMasked ⇒ unavailable)
D6 stream filter Landed createBrandMaskStreamFilter; brandAliasPendingTail; apps/web/src/__tests__/deck-brand-mask.test.ts
Browser proof Pending Post-deploy on the IVF deck: the real string appears nowhere in the DOM except the in-app record modal

Amendment — 2026-08-21 (A17 + A18)#

D7 — The PAIRS move to the brand; the deck keeps the SWITCH

D2 put both halves on the deck. One client is one BRAND with several delivery periods, and each period is its own content_datasets row — so the operator maintained the same two rows in five places, and two decks of one client could disagree about what that client is called.

brands.brand_alias (migration 0175) is now the pairs' home: { aliases: [{match, alias}] (≤8), maskChrome }, validated by brandAliasSchema and written by brands.updateBrandAlias (owner/org-admin, rate-limited, audited by COUNT and the chrome flag — never by the pairs, since the alias is what a client is called in front of an audience and the audit log is not that audience). deck_presentation.brandMask keeps enabled, which is the genuinely per-deliverable decision; its aliases stay declared as an optional LEGACY field the resolver falls back to, so a document written before 0175 keeps masking exactly as it did. The migration copies the pairs up, idempotently, only onto a brand whose column is still NULL.

Editors follow the data: the deck drawer shows the brand's pairs read-only plus a link to /settings/brands, and the pair editor is settings/_components/brand-alias-editor.tsx.

D8 — maskChrome: the shell around a masked deck

A deck that says "Ngân Hàng A" inside a shell whose brand switcher, sidebar pins, deck list and home cards say "ACB" has masked nothing — a reader lines the two up in one glance. maskChrome extends the alias to the product's own chrome, resolved by ONE server rule (chromeBrandMask / maskedBrandName in deck-brand-mask.ts) and applied in the dashboard layout (brand switcher, pinned + custom nav labels) and dashboards.list (saved decks, CI home cards).

Two deliberate asymmetries. The chrome does NOT consult a deck's enabled switch: one shell covers every deck a brand owns, and a shell whose wording depends on which of five decks is open is worse than either state. And an owner / org admin / super admin is never masked — they have to find this client in a list of five and check the alias is the one they typed. The alias (real name) pairing this decision put on the brand itself is superseded by D10: an administrator reads the real name, and the mapping is shown only where it is typed.

D9 — The folded→source offset map is UTF-16-unit-consistent

brand-alias.ts matches on a diacritic-folded string and maps match positions back to the source. The folded string is indexed in UTF-16 units everywhere (folded[i], startsWith(needle, i)) while the offset map carried one entry per source CODE POINT — identical only while every folded character is BMP. An emoji is one code point and two units, so a narrative carrying astral emoji desynchronised the two by one entry per emoji and every match after them was cut that many characters too far right: stored kể cả khi nhắc ACB/eTax/TK HKD shipped as ACB/Ngân Hàng Ax/TK HKD, with the client's real name left on the page beside the alias.

foldWithOffsets now pushes one entry per folded UTF-16 UNIT, and foldChar clips a lowercase expansion (U+0130 → i + U+0307) to one code point, so a fold group is either one unit or a copied-through surrogate pair and a needle can never end half-way inside one. Guard: packages/ui/src/brand-alias.test.ts — "the folded→source offset map (A18)", including both prod strings byte-exactly and a prefix property test.

Decision Status Evidence
D7 pairs on brand Landed migration 0175 + brands.brand_alias; brandAliasSchema, brands.brandAlias / updateBrandAlias; A17 tests
D8 chrome Landed chromeBrandMask / maskedBrandName; (dashboard)/layout.tsx, dashboards.list; A17 chrome tests
D9 offset fix Landed packages/ui/src/brand-alias.ts foldWithOffsets / foldChar; 7 new regression tests
Migration applied Pending host prod runs db:migrate at deploy
Browser proof Pending post-deploy: viewer sees the alias in switcher + nav + home cards; admin sees the real name (D10)

Amendment — 2026-09-04 (D10)#

D10 — The alias is for the AUDIENCE; an administrator reads reality

An owner, org admin or super admin sees the client's REAL name on every surface: product chrome (brand switcher, sidebar pins, deck list, home cards), deck title, tab labels, period/dataset options, filter chips, deck-chat scope and answers, explore cells. A non-admin member and the anonymous public share link see the alias. Mixed wording within one reader's session is not a state the product has.

alias (real name) is not printed anywhere in the product. The mapping is shown where it is typed — the brand's alias editor (settings/_components/brand-alias-editor.tsx, Settings › Brands), which renders the pairs themselves.

Mechanism: the deck BODY mask takes the viewer as a required argument. DeckMaskViewer ({ isOrgAdmin }) is the third parameter of resolveDeckBrandMask / readDeckBrandMask, null means anonymous, and the exemption is checked BEFORE any read — an administrator's deck costs no extra query. isOrgAdmin is isOrgAdminRole(...), the same predicate chromeBrandMask applies, resolved once per request by orgViewerFor (server/access.ts) and never re-derived at a surface. The public share passes null unconditionally: its verbatim payload is cached and shared between readers, so the rule that payload carries may not depend on who asked for it.

Decision Status Evidence
D10 admin sees reality Landed DeckMaskViewer + orgViewerFor; dashboards.bySlug, explore.dataset, activeCorpusSpan, deck-chat scope, share (null); deck-brand-mask.test.ts "D10" block
Browser proof Pending post-deploy: an admin opens the ACB deck — chrome, title, "Kỳ" options, filters and chat all read the real name; a report_viewer and the share link read the alias