Skip to content

Dispatch channel assessment: proposed contract

Status: proposed contract with an isolated email assessment experiment. Channels::Email::DispatchAssessor returns eligible/excluded results, and Core::ChannelAssessment validates that result against a channel-neutral internal shape and the assessor’s declared reason codes. Channels::DispatchAssessment resolves the explicitly configured email channel and invokes that validator; it is not wired to dispatch creation. This does not change the existing destination creation or Visitor preview APIs, choose a provider, send messages, or establish that a destination is reachable. See dispatch snapshot contract and application trust boundary.

  • Channels::Email::AddressNormalizer accepts a deliberately conservative ASCII email subset, strips surrounding whitespace, lowercases the domain and preserves local-part case. It returns Core::ContactDestinations::Assessment with normalized_value and version; malformed or unsupported input raises ArgumentError. It does not distinguish an invalid address from an address outside its supported subset or prove that a mailbox exists. The experimental dispatch assessor uses the same rules and reports the deliberately combined unsupported_or_invalid_format reason rather than making that distinction.
  • Channels::Sms::PhoneNumber returns a status, optional E.164 number, region, calling code and a version tied to the installed Phonelib version. National numbers need region context. PreviewNormalizer maps this to the existing preview’s valid, invalid and needs_review statuses.
  • Core::DestinationSelection reads active stored destinations and their creation-time normalization values and versions. It does not reassess them for a dispatch. Visitor’s current preview instead uses legacy phone fields.

These are different contracts. Do not treat either current exception behavior or a previously normalized value as a complete dispatch assessment API.

The product selects an allowed channel. A trusted application composition boundary resolves its channel-owned assessor through explicit application code or configuration. Unknown or unconfigured channels fail the command. Request parameters cannot name a Ruby class, executable, provider or arbitrary callback. Core receives the resolved dependency through an internal interface; neither Core nor Visitor embeds channel-specific address rules. An assessor is local, deterministic for the same input, declared context and implementation/version, and has no external calls or database side effects during the transaction. The current validator accepts a callable passed by its trusted caller; it does not itself establish that the dependency was selected from trusted code, verify the assessor’s version against a registry, or authorize an actor. The separate Channels::DispatchAssessment composition boundary resolves only email from trusted code and rejects unknown channels. The product still authorizes the channel and operation; version lifecycle and eventual dispatch integration remain to be designed.

For each selected active stored destination, supply its original value, channel and any explicitly defined, non-secret channel context necessary for a repeatable assessment. Context provenance and storage are channel-specific; never invent a default region. Assess the original value at dispatch time using the configured assessment version; the creation-time normalized value and version are not silently treated as a fresh validation. Whether to retain both creation-time and dispatch-time versions is a data-retention decision.

Conceptually return one of:

Outcome Fields Meaning
eligible normalized destination; assessment/normalization version Usable by the configured channel rules for this dispatch; not proof of mailbox ownership, reachability, provider acceptance or delivery.
excluded stable machine-readable reason; assessment/normalization version This value cannot be used under the configured rules. Examples include invalid syntax, insufficient region context or an unsupported format. Channel-specific reasons may distinguish those cases without claiming an unsupported value is universally invalid.

A selected recipient without any active destination for the channel is a Core selection result, not a fictional value sent to an assessor. Inactive and explicitly unselected destinations are not eligible. The precise visibility and snapshot representation of missing versus inactive values remain open.

Reason codes are bounded, versioned and machine-readable; user-facing text is mapped by the product through localization. Do not embed raw addresses, exception messages or provider responses in reason codes. Eligible results must have a nonempty canonical value and no exclusion reason; excluded results have no usable destination and require a recognized reason. Validate type, encoding, size and status combinations before persisting anything. Stable equality of normalized values for grouping is channel-defined; do not lower-case email local parts generically. Reassessment or version changes cannot silently change an already committed snapshot or a replay of the same idempotency key.

A malformed assessor result, missing assessor, unexpected exception, unavailable dependency or unknown assessment version is a command failure, not an invalid destination or a silently excluded recipient. Roll back the entire creation transaction and do not claim a dispatch was created. Distinguish such failures from legitimate excluded results under the product’s explicit exclusion policy. Never broadly rescue ArgumentError as an invalid address: the existing email normalizer uses it for bad input, but the same exception class may also arise from a programming or configuration error. An email adapter to this contract needs a deliberately narrow, typed invalid-input boundary or an explicit result API. Do not expose sensitive input in logs or errors.

An ambiguous database commit remains an idempotency recovery problem, not an assessment failure. No assessor contacts a transport provider; network delivery, timeouts and retries are separate contracts.

For each selected active destination preserve the assessed outcome, the assessment/normalization version and, for eligible entries, the exact normalized value used for grouping and future delivery. Persist an excluded reason for excluded entries. The original source reference, any retained raw value and context are subject to minimization, access and deletion rules. Recording a version alone does not ensure the old code or metadata remains available to reproduce a result; the frozen outcome is authoritative for that dispatch.

The product’s explicitly chosen exclusion policy governs whether confirmed exclusions permit creation. How newly excluded destinations are treated at confirmation, and what happens if none are eligible, are still product decisions. Core must not equate any exclusion or successful assessment with delivery.

  • Define a typed result and recognized reason/version identifiers, input/context semantics and channel selection mechanism, including dependencies and upgrades.
  • Design an email assessment implementation that distinguishes unsupported input from operational failures without relying on broad exception handling. Keep the existing destination-creation API compatible unless explicitly changed.
  • Test representative email inputs, domain case and local-part preservation, unsupported formats, malformed values, malformed results, absent assessor, unexpected exceptions and rollback. Later test SMS region handling and Phonelib upgrades against the same contract.
  • Verify dispatch uses only a trusted registered assessor, always reassesses at confirmation, preserves its version/result, keeps exclusions separate from operational errors, and returns the original snapshot on idempotent replay.
  • Resolve transaction duration and batch limits before using the design at scale.