Recorder Contract Generation and Projection Architecture
Executive Overview
recorder-contract is the canonical deterministic generator/checker for Recorder
projection artifacts. It emits schema/contract/example/glossary/tooltip outputs
under Docs/generated/recorder/, now including SDK projection artifacts under
Docs/generated/recorder/sdk/, and enforces fail-closed drift checks.
Tooltip generation is now world-class projection metadata with:
- backward-compatible tooltip manifest (
tooltips.json), - rich term catalog (
tooltips.catalog.json), - pointer/token bindings for code blocks and JSON examples
(
tooltips.annotations.json), - glossary markdown (
glossary.md) generated from the same term source.
Artifact Authority
Authoritative generator code:
crates/recorder-contract/src/lib.rscrates/recorder-contract/src/contract_generation.rscrates/recorder-contract/src/contract_generation_artifacts.rscrates/recorder-contract/src/contract_generation_schema.rscrates/recorder-contract/src/contract_generation_samples.rscrates/recorder-contract/src/contract_generation_sdk_types.rscrates/recorder-contract/src/contract_generation_sdk_sidecar.rscrates/recorder-contract/src/contract_generation_sdk_vectors.rscrates/recorder-contract/src/sidecar_api.rscrates/recorder-contract/src/sidecar_api/openapi.rscrates/recorder-contract/src/sidecar_api/artifacts.rscrates/recorder-contract/src/sidecar_api/specs/mod.rscrates/recorder-contract/src/tooltips.rscrates/recorder-contract/src/tooltips_base_terms.rscrates/recorder-contract/src/tooltips_builders.rs
Authoritative generated root:
Docs/generated/recorder/
Machine manifest authority:
index.json includes contract version plus per-artifact SHA-256 hash metadata.
When sidecar API artifacts are present, compatibility gates are enforced from
generated artifacts via scripts/ci/sidecar_contract_gates.py.
Generator Modes
recorder-contract supports two deterministic modes:
GenerateMode::Generate- Regenerates artifacts and rewrites output root.
- Removes stale unexpected files under output root.
- Fails closed if output-root traversal encounters symlinks, hard-linked artifact files, or unsupported filesystem entry types.
GenerateMode::Check- Fails closed on missing files, byte drift, or unexpected files.
- Fails closed if expected paths resolve through symlinked roots/components, non-regular files, or hard-linked artifact files.
CLI integration:
recorder contract generaterecorder contract check
Determinism Model
Determinism controls include:
- stable artifact ordering via ordered maps/sets,
- canonical JSON encoding via JCS,
- explicit SHA-256 hashing for manifest entries,
- check-mode byte comparison against committed files.
Constraint-Aware Schema Projection
Schema generation is two-stage:
- infer structural shape from deterministic sample artifacts,
- apply authoritative domain constraints by JSON-pointer overlay.
Constraint overlays include:
- strict UUID text shape policies for all ID fields,
- hostile-string and max-length constraints for identifier/text fields,
- strict event-type regex policy and length ceiling,
- strict
key_idregex policy (^[0-9a-f]{64}$), - fixed-length byte-array constraints for hash/signature fields,
- explicit nullable representations for optional fields,
- full
BundleSelectoralgebra projection (BySegment,BySegments,ByTrace,ByTimeRange,ByEnvelopeIds,ByFilter, recursiveComposite) via schema$defs.
Projection fails closed if expected pointer paths are missing while applying constraints.
Produced Artifact Set
Current v1 emitted files:
index.jsonschemas/envelope.schema.jsonschemas/segment.schema.jsonschemas/bundle.schema.jsoncontracts/adapter.jsoncontracts/provider.jsoncontracts/integrations/decision_gate.mapping.jsoncontracts/integrations/otel.mapping.jsonglossary.mdtooltips.jsontooltips.catalog.jsontooltips.annotations.jsonexamples/envelope.jsonexamples/segment.jsonexamples/bundle.jsonapis/sidecar.openapi.jsonapis/sidecar.errors.jsonapis/sidecar.enums.jsonapis/sidecar.examples.jsonapis/sidecar.compat.jsonconfig/sidecar.schema.jsonconfig/sidecar.compat.jsonconfig/sidecar.example.tomlconfig/sidecar.mdsdk/types.jsonsdk/methods.jsonsdk/test_vectors.jsonsdk/manifest.json
Conformance and Validation
recorder-contract unit tests validate:
- repeated generation determinism,
- manifest hash/file-byte consistency,
- generated examples validate against generated schemas,
- tooltip catalog includes all adapter/provider contract method names,
- required world-class core term coverage,
- tooltip catalog pointers resolve against generated JSON artifacts,
- tooltip annotation bindings only reference defined term keys,
- schema/runtime invariance for
key_id, hostile text fields, and identifier max-length constraints. - sidecar artifact emission and manifest inclusion.
- sidecar error-registry and compatibility-baseline consistency.
- sidecar OpenAPI/compat idempotency contract consistency.
- sidecar config artifact consistency (schema/compat/example/docs linkage).
- sidecar OpenAPI component typing strength for
BundleandVerificationVerdict(generator-friendly, non-loose object contracts). - SDK artifact emission and manifest inclusion (
types/methods/test_vectors/manifest). - SDK manifest required-script declarations and target-language registry consistency.
- SDK type projection hardening (field-level constraints + OpenAPI component bindings) and SDK method projection hardening (request/response schema refs, error/enum contract linkage, auth/idempotency metadata) for adapter/provider/sidecar surfaces.
- SDK methods/test vectors coverage for adapter/provider/sidecar core surfaces.
- Integration mapping contract drift checks for Decision Gate and OTel generated artifacts against adapter runtime constants.
- Sidecar media-type contract drift checks ensuring runtime policy-derived request media allowlists are projected consistently in OpenAPI and compatibility artifacts.
recorder-contract dedicated path-safety tests validate:
- generate mode rejects symlinked output roots,
- generate mode rejects symlinked child paths under output root,
- generate mode rejects hard-linked expected artifact files,
- check mode reports byte drift for modified artifacts,
- check mode rejects hard-linked expected artifact files,
- check mode rejects symlinked expected artifact files.
Orchestration and CI
One-command orchestration entrypoint:
scripts/ci/generate_all.sh
Behavior:
generate: regenerate contract artifacts + regenerate Python SDK contract constants (sdk/python/generate.sh) + run sidecar contract gates + regenerate testing coverage docs.check: run contract drift check + Python SDK drift/unit/system gates (sdk/python/check.sh,sdk/python/test.sh) + sidecar contract gates + docs drift check (fail closed).- Optional perf matrix mode: if
RECORDER_PERF_MATRIX=1(or legacyRECORDER_SIDECAR_PERF_GATE=1), execute debug/test + release perf suites viascripts/ci/perf_matrix.pyand enforce release gate policy viascripts/ci/perf_gate.pyagainst committed baseline contracts.
CI workflows run this in required quality gates.
Projection Handoff Boundary
Website/i18n handoff and glossary ownership policy:
Docs/roadmap/recorder_generated_contract_sync_and_glossary_policy.md
This defines required file presence, hash verification, path stability, and single-source glossary/tooltip ownership.