Skip to content

feat(airc-core): convert ID newtypes from String to UUIDv4 - #664

Merged
joelteply merged 1 commit into
rust-rewritefrom
feat/airc-core-uuid-ids
May 19, 2026
Merged

joelteply merged 1 commit into
rust-rewritefrom
feat/airc-core-uuid-ids

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Locks the UUIDv4 mesh-native identifier discipline at the compile-time level. Every runtime ID in airc-core is now a typed UUID newtype.

Companion to docs PR #663 (which anchors the policy). This PR is the code-side implementation.

Changes

  • `Cargo.toml`: add `uuid = { version = "1", features = ["v4", "serde"] }`
  • `ids.rs`: macro-generated UUID newtypes — `EventId(Uuid)`, `RoomId(Uuid)`, `PeerId(Uuid)`, `ClientId(Uuid)`, `FileId(Uuid)`. Each gets:
    • `::new()` → UUIDv4 random
    • `::from_u128(N)` → deterministic for tests
    • `::from_uuid(u)` → construct from existing
    • `::as_uuid()` → access underlying
    • `Default`, `Display` (hyphenated lowercase)
  • `ContentHash` stays `pub struct ContentHash(pub String)` — content addressing has different requirements than runtime IDs (deterministic + payload-derived). UUIDs would defeat both properties. Discipline distinction pinned by a dedicated test.
  • `transcript.rs`: `event_id.clone()` → `event_id` (now Copy)
  • `cursor.rs` + `filter.rs`: test helpers use `from_u128(N)` + named locals so assertions reference UUIDs directly instead of string literals
  • `attachment.rs`: test uses deterministic UUID for FileId; serde assertion updated to expect canonical hyphenated UUID string on the wire

Wire shape unchanged

serde encodes Uuid as the canonical hyphenated string (`"550e8400-e29b-41d4-a716-446655440000"`). JSON envelopes stay human-readable and cross-language parsers work. Backward-compat with Python+bash airc envelopes that happen to carry UUID-shaped strings.

Fail-loud upgrade: non-UUID strings (e.g. legacy "e1" test IDs) now fail to parse at envelope deserialize instead of silently coercing into a String. This is the substrate's discipline — malformed identifiers don't reach routing.

Test plan

  • 7 new ids.rs tests pin the UUIDv4 contract:
    • `new_event_id_is_random_uuidv4`
    • `from_u128_is_deterministic_for_tests`
    • `serde_roundtrips_via_hyphenated_string`
    • `display_uses_hyphenated_lowercase`
    • `malformed_uuid_string_fails_parse` (fail-loud at envelope deserialize)
    • `all_id_newtypes_share_the_uuidv4_contract`
    • `content_hash_is_not_uuid_typed` (pins the discipline distinction)
  • Full airc-core: 23/23 tests pass (was 16; +7 new)
  • `cargo clippy --all-targets --all-features -- -D warnings`: 0 warnings
  • `cargo fmt --check`: 0 diffs
  • Conforms to the rust.yml gates landing in ci: rust quality gates — fmt + clippy (deny warnings) + test on every Rust PR #661

What this does NOT add

🤖 Generated with Claude Code

PR-1 of the airc-core UUID migration per the substrate design doc's
"Identifiers — UUIDv4 everywhere" section. Locks the mesh-native
identifier discipline at compile time: every runtime ID is now a
typed UUIDv4 wrapper, not a bare String.

Changes:
  - Cargo.toml: add `uuid = { version = "1", features = ["v4", "serde"] }`
  - ids.rs: rewrite as macro-generated UUIDv4 newtypes —
    EventId(Uuid), RoomId(Uuid), PeerId(Uuid), ClientId(Uuid),
    FileId(Uuid). Each gets `::new()` (UUIDv4 random), `::from_u128()`
    (deterministic for tests), `::from_uuid()`, `::as_uuid()`,
    `Default`, `Display`.
  - ContentHash stays as `pub struct ContentHash(pub String)` —
    content addressing has different requirements (deterministic +
    payload-derived) than runtime ids; UUIDs would defeat both
    properties.
  - transcript.rs: `event_id.clone()` → `event_id` (now Copy)
  - cursor.rs + filter.rs: test helpers use `EventId::from_u128(N)`
    + named locals so assertions reference UUIDs directly instead
    of string literals.
  - attachment.rs: test uses deterministic UUID for FileId; serde
    assert updated to expect canonical hyphenated UUID string on
    the wire.

7 new ids.rs tests pin the contract:
  - new_event_id_is_random_uuidv4
  - from_u128_is_deterministic_for_tests
  - serde_roundtrips_via_hyphenated_string
  - display_uses_hyphenated_lowercase
  - malformed_uuid_string_fails_parse (fail-loud at envelope deserialize)
  - all_id_newtypes_share_the_uuidv4_contract
  - content_hash_is_not_uuid_typed (pins the discipline distinction)

Wire shape unchanged: serde encodes Uuid as canonical hyphenated
string, so JSON envelopes stay human-readable and cross-language
parsers work. Backward-compat with Python+bash airc envelopes that
happen to carry UUID-shaped strings already; non-UUID strings now
fail to parse (fail-loud over silent String coercion).

Full airc-core: 23/23 tests pass (was 16; +7 from ids.rs). Clippy
`--all-targets --all-features -- -D warnings`: 0 warnings. cargo
fmt --check: 0 diffs. Conforms to the rust.yml gates landing in #661.

Stacks on the rust-rewrite integration branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit c2f8ed2 into rust-rewrite May 19, 2026
1 check passed
@joelteply
joelteply deleted the feat/airc-core-uuid-ids branch May 19, 2026 02:09
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.

1 participant