Skip to content

fix(schema): make schema roundtrip corpus-backed #601

Closed

Description

@Sinity

Problem

verify-schema-roundtrip now exists and is wired into quick verification, but it is still shallow relative to the intended inference-to-validation roundtrip.

Current behavior checks package/catalog structure: package versions, manifest roundtrip through SchemaVersionPackage, element presence, supported elements having schema_file, schema loadability, and root type.

The missing property is stronger: a schema inferred/promoted from representative provider samples should be consumed by the runtime parser/validator against those same kinds of samples.

Design constraints (from comment thread)

  • Privacy-safe and deterministic: Use committed, minimized, redacted provider fixtures or generated fixtures, not ad hoc local exports. Must not depend on whatever live private archive happens to be present.
  • Dependency order: refactor(manifests): type repo-control manifests and schema catalogs #629 (typed manifests/packages with Pydantic) should land first. Once schema packages use model_validate(model_dump(original)), corpus-backed verification becomes a clean roundtrip test.
  • Do not create a second schema-package parser: Reuse the same typed loader as normal schema package loading and verify-schema-roundtrip.

Acceptance criteria

  • Extend verify-schema-roundtrip with a --corpus flag for corpus-backed mode.
  • For each provider/package version, load representative or training samples, parse them through the runtime parser path, and validate emitted elements against committed package schemas.
  • Report provider, element kind, package version, sample path, parser identity, schema path, instance pointer, and validation failure as machine-readable JSON.
  • Keep the existing structural roundtrip as the fast/default check; make the stronger mode available to CI or a lab lane.
  • Include at least one regression where a schema is syntactically valid but rejects a real emitted element shape (e.g., remove or type-change a required emitted field and assert corpus-backed verification fails).

Implementation anchors

  1. devtools/verify_schema_roundtrip.py — the current gate; extend to accept --corpus flag
  2. polylogue/schemas/verification.py — verify_raw_corpus() already does batched corpus reads with progress callback; pattern is reusable
  3. polylogue/schemas/packages.py — Pydantic migration (refactor(manifests): type repo-control manifests and schema catalogs #629) should land first

Ref #590
Ref #629

Activity

  1. added
    type:fix
    theme:verifiability
    area:devtools
    on May 1, 2026
  2. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Corpus-backed schema roundtrip should be deterministic and privacy-safe, not dependent on whatever live private archive happens to be present.

    Suggested acceptance additions:

    • use committed, minimized, redacted provider fixtures or generated fixtures with the same parser path, not ad hoc local exports;
    • report failures with provider, package version, element kind, sample id/path, parser stage, and schema path;
    • keep structural package roundtrip fast, but make the corpus-backed mode runnable in a named verification lane and eligible for CI/lab scheduling;
    • include at least one regression where a schema is syntactically valid but rejects a real emitted element shape.

    This keeps the check from proving only “schemas load” while the runtime parser and validator still disagree.

  3. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Implementation anchors and acceptance additions from the 2026-05-01 follow-up audit.

    Anchor for current shallow command:

    • devtools/verify_schema_roundtrip.py:36-68: validates package versions, package/catalog roundtrip, element presence, schema loadability, and root type.

    Acceptance additions:

    • Corpus mode loads representative/training samples for every provider/package version.
    • For each sample, run the runtime parser/normalizer path, then validate emitted element payloads against committed schemas.
    • Machine JSON report includes provider, package version, element kind, representative path, parser identity/version, schema path, instance pointer, and validation failure.
    • Regression proves a syntactically valid but semantically incompatible schema fails. A simple test should remove or type-change a required emitted field and assert corpus-backed verification fails.
    • Reuse refactor(manifests): type repo-control manifests and schema catalogs #629 typed package loaders; do not create a second schema-package parser.
  4. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Schema roundtrip decision from 2026-05-01 bundle

    Integrated decisions:

    • Structural schema roundtrip stays quick.
    • Corpus-backed validation runs in lab and targeted CI for schema/parser changes.
    • Typed manifests/schema package catalogs are accepted and should share the same loader used by runtime schema package loading.

    Acceptance refinements:

    • verify-schema-roundtrip should use the same typed package loader as normal schema package loading.
    • Corpus-backed mode reports provider, element kind, package version, sample path, parser identity, schema path, and failure pointer.
    • Do not create parallel dataclass/Pydantic/manual parsing paths.

    Ref #629

  5. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Schema roundtrip current state

    The existing roundtrip infrastructure:

    • devtools verify-schema-roundtrip — committed gate that verifies schema packages reload and roundtrip cleanly
    • polylogue/schemas/packages.py — schema package loading with custom to_dict()/from_dict()
    • polylogue/schemas/verification.py — raw corpus verification with keyset pagination

    The gap this issue describes (making roundtrip "corpus-backed") means: instead of roundtripping against the committed schema package alone, verify that real observed message shapes from the raw corpus survive the parse → model → serialize → deserialize → compare cycle without loss.

    Implementation anchors

    1. devtools/verify_schema_roundtrip.py — the current gate; extend to accept --corpus flag
    2. polylogue/schemas/verification.py — verify_raw_corpus() already does batched corpus reads with progress; its progress_callback pattern is reusable
    3. polylogue/schemas/packages.py — Pydantic migration (refactor(manifests): type repo-control manifests and schema catalogs #629) should land first, then corpus-backed verification becomes a clean model_validate(model_dump(original)) roundtrip

    The dependency order is: #629 (typed manifests/packages) → this issue (corpus-backed verification).

  6. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Closed by #763. devtools verify-schema-roundtrip --corpus validates all 5 providers against committed schema packages using SyntheticCorpus.for_provider() + jsonschema.Draft202012Validator.

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

    area:devtoolsarea:schematheme:verifiabilitytool:codextype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions