Skip to content

feat!: contract helpers require the key-declared schema - #488

Merged
lxsaah merged 8 commits into
feat/typed-record-keysfrom
claude/elegant-mendel-kwt6jt
Nov 15, 2026
Merged

lxsaah merged 8 commits into
feat/typed-record-keysfrom
claude/elegant-mendel-kwt6jt

Conversation

@lxsaah

@lxsaah lxsaah commented Nov 15, 2026

Copy link
Copy Markdown
Member

Description

Follow-up to #487. With typed keys the key is the only source of a record's schema, so a contract record declared with a schema-free Name<T> compiled, worked on the wire and silently dropped its schema from the dependency graph, record.list and the MCP output. The mechanical migration in #487 did this at many call sites. This PR keeps the one-source model and makes that mistake fail build() instead.

Core (aimdb-core)

  • RecordRegistrar::declared_schema() reads the schema the key declared.
  • RecordRegistrar::require_contract(name, version) checks that schema and never sets it. With no declared schema, or a different one, it records a config error that points to Key<T> or #[record_key(contract = T)].
  • InboundLink / OutboundLink get a public requires_contract(name, version), replacing the test-only with_schema. Registering such a link calls require_contract; the check runs even if the link itself is rejected. It is named requires_contract so it does not shadow data-contracts' existing with_contract::<V>().
  • Name<T> gains Debug, matching Key<T>.
  • Fixed stale docs on schema() and the link methods, and renamed the &'static str key test.

Data contracts

  • publish, subscribe, linked_to, linked_from, their _with forms and observe() now require the key to declare T.
  • The raw .link_to() / .link_from() builders and the versioned-link builders (sends_as, with_link_codec) check nothing, so a plain Name<T> record with a hand-built link stays schema-free. This keeps typed_keys_keep_schema_on_downgrade_and_plain_names_stay_schema_free valid.

Call sites

  • Contract records now use Key<T> in: the zenoh ros2_gateway, ros2_listener and turtlesim_mcp examples, remote-access-demo (Temperature, used with .observe() and as a transform input), and the docs and READMEs that use contract helpers (zenoh README, usage guide, aimdb-and-ros2, ros2-walkthrough, embassy-mqtt README, builder.rs docs).
  • Tests: aimdb-mqtt-connector/tests/link_ext_tests.rs, and the zenoh ros2_inbound, ros2_outbound and shared_session tests.
  • The usage guide's leftover configure::<ButtonPress>(..) turbofish is removed.
  • The CHANGELOGs for aimdb-core and aimdb-data-contracts are updated.

Not changed: several READMEs still use the old keyless configure::<T>(|reg| ..) form from before #487: aimdb-embassy-adapter, aimdb-mqtt-connector and aimdb-knx-connector. They are out of scope here.

Related Issue

Validation

  • Run locally and passing: aimdb-core lib tests, including the new requires_contract_checks_the_key_schema; aimdb-mqtt-connector --test link_ext_tests; aimdb-zenoh-connector --features std,tracing,log.
  • The full make test matrix was not finished locally. The container ran out of disk partway through, and the later failures were disk-full build errors, not test results. CI is the full check.

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have added tests to cover my changes.
  • All new and existing tests passed (make check): awaiting CI.
  • I have updated the documentation accordingly.

Generated by Claude Code

Link helpers (publish, subscribe, linked_to/from and their _with forms)
and observe() now require the record's key to declare the contract they
carry, so a contract record declared with a schema-free Name<T> fails
build() instead of silently dropping its schema from the graph and
record.list. The key stays the only source of a record's schema.

- core: RecordRegistrar::declared_schema / require_contract; links get
  a public with_contract (a requirement, never a setter); Name<T>: Debug
- examples/docs: declare contract records with Key<T>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
…re_contract message

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
…with_contract::<V>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Replace the build()-time contract check with a type-state on the
registrar. TypedKey gains an associated Schema state (Declared for
Key<T> / contract = T, Undeclared for Name<T> / payload = T), and
configure hands out RecordRegistrar<'_, T, K::Schema>.

- linked_to / linked_from / their _with forms and observe() require
  S: ContractDeclared, so they do not compile on a Name<T> record.
- publish / subscribe return ContractOutboundLink / ContractInboundLink,
  which implement Output / Input only for ContractDeclared records.
- Input / Output take the schema state as a parameter; registrar
  extension traits implement for any S and return &mut Self.
- Remove declared_schema, require_contract and requires_contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
@lxsaah
lxsaah merged commit 1dfbee2 into feat/typed-record-keys Nov 15, 2026
@lxsaah
lxsaah deleted the claude/elegant-mendel-kwt6jt branch November 15, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants