Skip to content

fix(plugin-email): an option hole prints the option label in each recipient's language - #30781

Merged
objectstack-fleet[bot] merged 13 commits into
mainfrom
claude/project-thread-9ookwa
Nov 6, 2026
Merged

objectstack-fleet[bot] merged 13 commits into
mainfrom
claude/project-thread-9ookwa

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #30730

Clause-②: no
Metadata-protocol: none

domain:server#5 card thread · session session_016WV4czh582ycXhGxZNVPVi · branch claude/project-thread-9ookwa (the card thread's platform-assigned branch, named in the re-posted claim on #30730). Built on PR #30727's head 98f61ec6 (branch claude/project-thread-d8v0qv, the spec half), then origin/main b3098661 merged in. Until #30727 lands, this PR's diff against main also carries #30727's commits; the plugin-email half is the last three commits.

维护者速读

  • 改了什么:邮件模板里的 {{ stage | option:opportunity.stage }} 现在真正按收件人的语言印出选项标签:同一封商机滞留通知,英文同事读到 Needs Analysis,中文同事读到「需求分析」;定时流程以系统身份发出也一样逐人翻译。
  • 为什么改:规格半(PR feat(spec,formula,lint): a mail template's option formatter prints a select value as its option label in the recipient's language #30727)让这种写法通过保存校验,但邮件服务从不准备标签表,所以每次发送都以裸 RangeError 失败、一封也发不出;HotCRM 至今只能手写各语言标签表。
  • 风险与回滚:只影响写了 option 的模板;对象不存在、字段不存在、字段没有选项(含空选项列表)都整封拒发并报 TEMPLATE_INVALID,不会发出错误内容。回滚即还原本 PR(之后这类模板回到发不出去的状态)。
  • 先看:packages/plugins/plugin-email/src/option-label-table.ts(建表与拒绝);src/email-service.ts 中 resolveAndRenderTemplate 新增的建表段(语言取发送的 locale);src/template-engine.ts 的 option 判定。
  • 两分钟验证:pnpm --filter @objectstack/plugin-email exec vitest run src/template-option-formatter.render.test.ts src/template-option-labels.integration.test.ts,预期 2 个文件 20 例全绿,其中 zh-CN 收件人读到「需求分析」「赢单」,en-US 读到 Needs Analysis。
  • 需要你做的:无,席位落地(与 feat(spec,formula,lint): a mail template's option formatter prints a select value as its option label in the recipient's language #30727 背靠背,规格半先落)。

What changes

  • The label table (option-label-table.ts, new). buildOptionLabelTable(faces, locale, sources) collects the object.field keys the template's option holes name (parseMailHole(...).optionField), reads each named object's SERVED definition (IDataEngine.getObject, where a picklist-bound field carries its resolved list and its picklist name), and builds, per key, stored value to label, with the i18n service's bundle laid over the option-declaring fields by translateObject with the same fallbackChain / defaultLocale options. That is the step sequence of @objectstack/objectql's readerOptionLabels (formula-option-labels.ts), the path a formula's label() reads; see Acceptance notes for why it is taken through the same two published functions rather than imported. A test holds the two answers equal.
  • Which locale. The send's own locale (the recipient's; the messaging channels resolve it per recipient and pass it to sendTemplate / renderTemplate), trimmed as the template ladder reads it. Never the resolved row's locale and never an execution context's, so a scheduled flow running as the system still mails each recipient in their language. No locale reads the declared labels (ruling F, parameter 3).
  • Refusals. Before any face renders, every face is judged with judgeMailHoleGrammar(face, { objects, liveUniverse: true }) against the served objects the holes name: an object nothing serves (option-object-unknown), a field the object does not have (option-field-unknown), a field with no options (option-field-no-options). Each throws TEMPLATE_INVALID, prefixed with the template and locale as every renderer refusal is, and the whole send is refused: nothing reaches the transport. Decided here (the carry note leaves it to this card): a field whose served option list is empty (options: [], which the formula side answers with a {} table and no refusal) is judged as a field with no options and refused the same way; the renderer also refuses a {} table handed to it directly.
  • The renderer (template-engine.ts). RenderOptions.optionLabels (new) is passed to formatValue. For an option hole the renderer asks optionTableRefusal before formatValue and prefixes TEMPLATE_INVALID, the way it asks currencyDefaultRefusal; so a send with no table (a host with no data engine) is refused TEMPLATE_INVALID with the formula's sentence, never a bare RangeError.
  • The wiring (email-service.ts, email-plugin.ts). EmailService.setOptionLabelSources(read) (new, not exported from the package index); the plugin wires it in init to read the data engine (objectql, else data) and the i18n service at each send (resolve where used: a service registered later is seen, nothing is recorded). The table is built once per send for the three faces, and only when a face has an option hole.
  • Changeset: @objectstack/plugin-email patch.

Tests

  • src/template-option-formatter.render.test.ts (new), through EmailService.renderTemplate / sendTemplate with a recording transport:
    • an en-US and a zh-CN recipient each read their own label on all three faces (subject, HTML double and triple brace, text);
    • a scheduled flow running as the system: one data object built once, sent to en-US, zh-CN, en-US recipients with no sentBy and no organization, each reading their own label, the payload unchanged;
    • no locale reads the declared labels even when the resolved row is zh-CN; a value outside the options prints as stored and a multi-select labels each value; a picklist-bound field reads the shared list's translation; the sources are asked once, only for the named object;
    • refusals: an unknown object, an unknown field, a field with no options, an empty option list, each TEMPLATE_INVALID naming the template and hole, with nothing sent; no sources wired is TEMPLATE_INVALID with optionTableRefusal's sentence; the renderer refuses an empty table; a template with no option hole never asks for the sources;
    • parity: for zh-CN, zh, en-US and no locale, the mail table's stage labels equal what a real ObjectQL engine's formula label(record.stage) reads for the same object and i18n service.
  • src/template-option-labels.integration.test.ts (new): the real EmailServicePlugin booted on an ObjectKernel with ObjectQLPlugin, an app declaring the object and templates, and an i18n service: en-US and zh-CN recipients read Needs Analysis and 需求分析; a template naming an object the deployment does not serve is refused TEMPLATE_INVALID and nothing is sent.

Acceptance notes

  • Why not import readerOptionLabels. @objectstack/objectql is only a dev dependency of @objectstack/plugin-email, so no export of formula-option-labels.ts reaches it at runtime, and promoting it to a runtime dependency is a package.json / lockfile change outside this card's surface. So formula-option-labels.ts is untouched (no export added), and the table takes the same steps through the same published functions (translateObject from @objectstack/spec/system, declaresOptions from @objectstack/formula), as service-analytics' translateSelectOptions already does. The parity describe holds the answers equal; a later move of the shared steps into one module both packages depend on would delete the copy.
  • The system-run pin is at the plugin-email layer. It drives sendTemplate the way the email channel does after fan-out (one payload, the recipient's locale, no user, no organization). The fan-out itself (service-automation notify, service-messaging channels) is outside this card's file surface and is not driven here; the channels already pass the recipient's locale (decision analysis 6658266694, reading 1).
  • Clause-②: no, Metadata-protocol: none, re-derived from this diff. What an author can write is unchanged here: the option formatter, its grammar and its authoring checks are feat(spec,formula,lint): a mail template's option formatter prints a select value as its option label in the recipient's language #30727's (which declares yes (widening) / added). This diff makes the runtime deliver what that grammar promises; no public export of the package changes (EmailService is not exported from the index) and IEmailService is unchanged.
  • Skills follow-up for the formatter is skills(objectstack-automation): a notice prints a select field's label with the mail option formatter, not label() in templateData (ruling F parameter 6, #30172) #30731 (the spec half's); nothing in skills/** changes here.

Verification

At head f5fee1af, after a whole-tree turbo run build (119/119 tasks, os-verify-lock VERDICT command-exit 0).

Reproduction on PR #30727's head 98f61ec (before this change)
  • EmailService.sendTemplate of a template with {{ stage | option:opportunity.stage }}, en-US and zh-CN: both threw RangeError: the hole option:opportunity.stage prints the option labels of opportunity.stage, and no label table for that field reached this render ..., outside the TEMPLATE_INVALID vocabulary.
  • The new integration test on that head (plugin-email sources restored to 98f61ec6): 2 failed / 2, the first with that RangeError, the second "expected TEMPLATE_INVALID ... but got 'the hole option:mol_deal.stage prints…'".
Package suite and typecheck
  • pnpm --filter @objectstack/plugin-email test && pnpm --filter @objectstack/plugin-email typecheck under os-verify-lock: Test Files 50 passed (50), Tests 825 passed (825), VERDICT command-exit 0.
  • eslint --no-inline-config on the six changed .ts files: exit 0.
Ablation (scripts/ablation-replace.mjs; the tests import src, no dist involved)
  • Per-recipient lookup removed: buildOptionLabelTable(..., preferred || undefined, sources) to (..., undefined, sources) in email-service.ts (anchor 1 to 0, blob 61d0dba1 to fa994bdd): 5 failed / 15 passed (zh-CN faces, the system-run fan-out, the out-of-options/multi-select zh-CN case, the picklist case, the booted en-US + zh-CN case). Restored: blob 61d0dba1 equals HEAD, git diff HEAD empty.
Derived gates (dispatch-gates --commands)
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack at f5fee1af: 105 families derived, every one run, every one exit 0 (after the whole-tree build, a deepened clone and the pinned teardown-shape commit fetched).
  • dispatch-gates --ran: 105 derived, 105 run, 0 NOT-MEASURED, 0 UNRUN.
  • Beyond the derivation: pnpm lint exit 0, pnpm check:cli-command-ids exit 0, pnpm check:adr-symbol-anchors exit 0.
  • CI check-runs on this PR: in progress at open.

Generated by Claude Code

claude added 12 commits November 5, 2026 23:00
…a select value as its option label

`{{ stage | option:opportunity.stage }}` names the object and field the
value belongs to; the mail renderer hands `formatValue` a label table per
recipient locale, and a value outside the options prints as stored. The
mail grammar accepts it, the in-app dialect refuses it as an unknown
formatter, the email-template-hole-grammar rule judges the object and
field against the app's objects, and the spec's hole grammar sentence
quotes OPTION_ARGUMENT_RULE.

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…erate the email_template reference page

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…itten in backticks

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…; option objects resolve on the object-reference ladder

The `option` formatter throws optionTableRefusal's sentence when no label
table for its object.field reached the render, as `currency` does with no
tenant default, so the stored value is never printed where the grammar
promises a label. The lint arm resolves the object on the
object-reference ladder (own objects, the artifact's packages[] objects,
platform-provided names with the field unjudged). OPTION_ARGUMENT_RULE
states the multi-select reading.

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…fixed object is advised, not refused

The object-reference ladder's rung four: a name with a platform prefix that
no rung above carries may still be registered by a package outside the app,
so the mail grammar neither refuses nor judges it, and email-template-hole-grammar
advises at warning at every door alike.

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…ainst the live universe alone

At the metadata publish door the objects are every object the deployment
serves, so no sibling-package, platform-name or rung-four reading applies
there: a name the live universe does not carry is refused, as a list view's
unresolvable binding is. The CLI doors keep the ladder and its warning.

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
…package's closure gets the closure verdict

At the publish door a write into a package is judged against the live
universe narrowed to that package's closure, so an object missing there is
outside the closure, refused with the declare-the-dependency remedy the list
view door gives, not as an unknown object. The rule's options type is
exported beside its finding type.

Claude-Session: https://claude.ai/code/session_01L6bhgUtH2CXA8Qb8bDBRom
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation protocol:system tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-email, touching 32 documentable anchor(s).

17 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 3da9a4c132db7bf5ae1ca673930c1034e50d0195.

⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 63 of 221 client-bound route-ledger rows — the other 158 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 158: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 103 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 7 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 3da9a4c132db7bf5ae1ca673930c1034e50d0195 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from ed91d60f3cb735a4a239f3a1e3a82281cdeaaed8 — the merge of head 6e5e8c9f9d87c0bfd16c1421a23d151bafda9cf4 into base 3da9a4c132db7bf5ae1ca673930c1034e50d0195, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin ed91d60f3cb735a4a239f3a1e3a82281cdeaaed8 && git checkout ed91d60f3cb735a4a239f3a1e3a82281cdeaaed8
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 3da9a4c132db7bf5ae1ca673930c1034e50d0195 6e5e8c9f9d87c0bfd16c1421a23d151bafda9cf4 && git checkout -B drift-repro 3da9a4c132db7bf5ae1ca673930c1034e50d0195 && git merge --no-ff 6e5e8c9f9d87c0bfd16c1421a23d151bafda9cf4

node scripts/docs-audit/affected-docs.mjs --json 3da9a4c132db7bf5ae1ca673930c1034e50d0195

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 3da9a4c132db7bf5ae1ca673930c1034e50d0195 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@github-actions github-actions Bot added size/l and removed size/xl labels Nov 6, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · os-elon-musk · session_016WV4cyvF7SP65frVFAYLv7

席位核对 · ACCEPT

PR #30781 · head 6e5e8c9f · 2026-11-06T04:54Z · card #30730 under ruling F on #30172 (6670405874, parameters 3 and 5) · claim re-posted with the branch on #30730 · os-dev report 6675470627 (head f5fee1af) and the dev's head-moved note (one plain merge of origin/main after #30727 landed as 3da9a4c1)

维护者速读(席位校正)

The body's six lines stand as written, read against the diff at this head. One correction: the body still says the diff carries #30727's commits until #30727 lands. #30727 has landed, so against main this PR is now only the seven plugin-email files (4 source, 2 tests, 1 changeset; +704/-4).

席位核对

  • Ruling fit: the send builds a label table per object.field that the template's option holes name. It is built once for the three faces, in the send's own locale (the recipient's), never the row's or an execution context's, so a scheduled flow running as the system still mails each recipient in their language. No locale reads the declared labels. A value outside the options prints as stored. A missing object, a missing field, or a field with no options refuses the whole send with TEMPLATE_INVALID before any face renders. The renderer asks optionTableRefusal before formatValue, the way currencyDefaultRefusal is asked.
  • Decided on the card's open point (accepted): an empty served option list (options: []) is refused like a field with no options, and the renderer also refuses an empty table handed to it directly.
  • Accepted deviation: formula-option-labels.ts is untouched. @objectstack/objectql is only a dev dependency of plugin-email, so the table takes the same translateObject / declaresOptions steps through the published functions, with a parity test against a real ObjectQL label() read for zh-CN, zh, en-US and no locale. The seat accepts the copy. Moving the shared steps into one module both packages depend on is left for a later card if the two drift.
  • Not driven here: the fan-out (service-automation notify, service-messaging channels) is outside the surface. The system-run pin drives sendTemplate the way the email channel does after fan-out.
  • Declarations: Fixes #30730, Clause-②: no, Metadata-protocol: none, and a patch changeset on @objectstack/plugin-email, all consistent with the diff now that feat(spec,formula,lint): a mail template's option formatter prints a select value as its option label in the recipient's language #30727's changesets left it. No public export changes; IEmailService is unchanged.
  • Gates: report on f5fee1af: 105 derived, 105 exit 0, --ran 0 NOT-MEASURED, plus pnpm lint, check:cli-command-ids and check:adr-symbol-anchors 0, and an ablation of the per-recipient lookup (5 red, restored). On 6e5e8c9f: the plugin-email suite and typecheck (50 files, 829 tests) and the five changeset gates exit 0. The only red on f5fee1af was Check Changeset, caused by the stacking.
  • Landing: check-governed-merges --pr 30781: NOT governed, +704/-4. The seat lands with pr_ready + automerge_enable once every check on 6e5e8c9f is green or expected-skip.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 6, 2026 05:20
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 6, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:system size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-email: render a mail template's option formatter with each recipient's option labels (server half of ruling F on #30172)

2 participants