Skip to content

Config-driven metadata validation — checks as data, one engine per port (write-once across 5 languages) #51

Open

Description

@dmealing

Summary

Make metadata validation data, not per-port code: declare each check as data on the type's registration, and give each port one generic interpreter per rule-shape. A rule is then authored once (not re-coded in TS/Java/C#/Python/Kotlin), and a downstream provider's new type validates itself with zero new validation code in any port.

Design doc: docs/superpowers/specs/2026-06-21-config-driven-validation-design.md.

Sibling to #23 (FR-033, "Provider definitions as declarative data") — same philosophy; if provider definitions become declarative data, validation rules are just more fields in that data.

Why

Validation today is split across three mechanisms, inconsistently:

  1. Reference descriptors (objectRef/references) — declarative data, but constructed in code per port (same rule written 5×).
  2. ~20 free-floating imperative passes — hand-coded per port.
  3. A validate hook on the TypeDefinition — invoked in all ports but registered by no core type (an extension point core doesn't use itself).

Net: every rule is implemented N=5 times, and a downstream provider must write validators in every language it targets — contrary to the metadata-is-the-spine thesis and ADR-0023 (providers add types via registered data).

The four closed rule-shapes

Shape Covers today
reference objectRef, references, payloadRef/responseRef existence
allowedValues @format, @kind, @promptStyle (closed sets)
requires email needs subjectRef+htmlBodyRef; document needs textRef
fieldPathRef requiredSlots are fields on the payloadRef target

These cover the entire current reference + template corpus. Anything that fits no shape falls back to the validate hook (rare escape hatch). No speculative shapes — a fifth requires a real rule + the ADR-0023 can't-be-computed justification.

Phasing (earn it; conformance-gated; behavior-neutral)

  • Phase 0 — cleanup: align all ports' reference validation (revert the TS payloadRef descriptor split). done, 599a4aed — that commit never reached main (see Status correction below).
  • Phase 1 — proof slice: move the reference shape from per-port code into shared JSON; one generic interpreter per port; conformance unchanged. De-risks "is config-driven byte-identical across 5 ports" before extending.
  • Phase 2 — allowedValues (format/kind/promptStyle).
  • Phase 3 — requires + fieldPathRef; delete the bespoke template pass in all ports.
  • Phase 4 — opportunistically migrate remaining datafiable passes; keep the validate hook for the rest.

Risks

  • 4 interpreters × 5 ports (bounded, fixed-size — not proportional to type count).
  • FR5d resolved-source envelope fidelity (template fixtures gate it).
  • ADR-0023 strict provenance: rule data is provider data; spec readers must tolerate the new reference/rules fields (guard first).

Open questions


Status correction (2026-08-24) — Phase 0 was checked off but never landed

Found while sweeping for unfinished work after a session ended abruptly. The commit this issue
credits Phase 0 to, 599a4aed, is not on main — it lived only on an unmerged local branch,
proto/validation-registry (20 commits, 2026-06-21). The design doc landed; the code did not. The
checkbox has been cleared so the next person does not start from a false baseline.

The prototype is preserved at archive/validation-registry-proto (e19937c3a) — an
archive ref, not a merge candidate. It is worth reading before starting Phase 1: it already carried
the registry-derived mechanism through all five ports, which is exactly the risk Phase 1 exists
to de-risk ("is config-driven byte-identical across 5 ports").

What has landed independently since

  • Reference enforcement — ERR_INVALID_REFERENCE, ERR_UNRESOLVED_OBJECT_REF,
    ERR_OBJECT_FIELD_WITHOUT_OBJECT_REF, ERR_STORAGE_WITHOUT_OBJECT_REF are all on main, so the
    branch's 08c090ed is superseded by a different implementation.
  • The FR-024 friction fixes the branch carried alongside the prototype — validate-max-occurs.ts,
    the singleton identity default-name, and the error-identity-name-required fixture — are all on
    main in their own form.

What is still open

  • The #51 core. On main, rules?: string on TypeDefinition is a prose documentation
    field — precisely the thing this issue proposes replacing with executable data. The mechanism has
    not landed in any port.
  • Java collect-all — "a load reports every error, not the first" (1e512ea1, 1fab2c98). This is
    separable from the config-driven mechanism and independently valuable; it could ship on its own.

Do not try to rebase the archive branch

Measured: it conflicts on commit 1 of 20, nine files, including an add/add on
validate-max-occurs.ts because main now owns its own copy. Roughly two months and ~2000 commits
sit in between — ADR-0040/0044/0050/0051, FR-036, FR-038, the ADR-0052/0053 template-direction split,
and 0.24.0's five vocabulary retirements all moved the surfaces the prototype patches. Phase 1 should
be written fresh against current main, using the archive as a reference for the shape that worked.

Activity

  1. added
    FR
    area:metamodel
    on Jun 21, 2026
  2. dmealing commented on Jun 21, 2026

    @dmealing
    MemberAuthor

    Phase 1 implementation map (parked — for whenever this is picked up)

    Survey of the FR-033 spec-reader pipeline + current reference-validation sites, so Phase 1 (move the reference shape into shared JSON) can start without re-deriving.

    Key architectural finding — two reader shapes: only TS lowers the full attr schema from spec/metamodel/*.json (provider-data.ts toAttrSchema). Java/C#/Python readers are doc/extends overlay only — they do NOT build the attr schema from JSON (it's hand-coded), so Phase 1 must add a new "apply reference rules from spec" path in those three, not just extend an existing lowering. Kotlin inherits the Java module for free (resolves the issue's open question). Also: there is no ReferenceDescriptor type yet — today the reference rule is hand-registered attrs + imperative passes; Phase 1 introduces the descriptor as JSON data + one generic interpreter per port.

    No tolerance guard needed — every reader (.get()/TryGetProperty/Gson) already silently ignores unknown attr keys; allowedValues is the live optional-field precedent. The issue's "guard first" risk is satisfied structurally.

    (a) Add the reference block as a sibling key on the attr object (like allowedValues):

    • spec/metamodel/relationship.json — @objectRef repeated on base/association/aggregation/composition
    • spec/metamodel/identity.json — subtype reference, @references (line ~28)
    • spec/metamodel/field.json — field.object @objectRef (decide if in scope or stays a field-object pass)

    (b) Reader hook points: TS provider-data.ts toAttrSchema (~410-432, after the allowedValues spread) + regen embedded via scripts/generate-embedded-metamodel.ts. Java SpecMetamodelReader.parseAttrChildren (~273-294) + new apply path by MetaDataRegistry.applySpecDescriptions (JSON auto-copied to classpath via maven-resources). C# SpecMetamodelReader.ParseAttrChildren (~322-368) + manual cp to server/csharp/MetaObjects/SpecMetamodel/. Python spec_metamodel/__init__.py._parse_attr_children (~228-253) + manual cp.

    (c) Hand-construction to remove: Java MetaRelationship.registerTypes/ReferenceIdentity + concrete subtypes; C# RelationshipSchema/IdentitySchema (ReferenceIdentityAttrs); Python core_types.py _RELATIONSHIP_ATTRS/identity.reference; TS imperative passes in validation-passes.ts (objectRef ~494-507, M:N ~1169-1250).

    (d) Gates:

    • registry-conformance (fixtures/registry-conformance/expected-registry.json, byte-identical 5 ports) — DECISION POINT: the manifest emitter projects only name/valueType/isArray/required/description/rules?/...; it'll drop a new reference block unless extended. Either don't surface reference in the manifest (truly behavior-neutral) OR surface + regenerate the canonical in lockstep (TS-advances-first per the README).
    • Spec byte-identity/embed gates (TS regen script; Java auto; C#/Python manual cp).
    • Reference-behavior gates: C# IdentityReferenceTests, Java MetaRelationshipTest/Fr5dReferenceResolutionTest, Python test_fr5d_reference_resolution, + FR5d resolved-envelope shape, + M:N + persistence/api-contract corpora.

    Recommendation when resumed: keep reference OUT of the registry manifest for Phase 1 (so it stays byte-neutral), prove the JSON-driven interpreter cross-port, then decide on manifest surfacing in a later phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FRarea:metamodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions