Skip to content

feat(peat-ffi): ADR-074 schema alignment — shrink FFI types to proto-backed fields#1022

Merged
kitplummer merged 3 commits into
mainfrom
schema-alignment
Jul 7, 2026
Merged

feat(peat-ffi): ADR-074 schema alignment — shrink FFI types to proto-backed fields#1022
kitplummer merged 3 commits into
mainfrom
schema-alignment

Conversation

@phornstein

Copy link
Copy Markdown
Contributor

Summary

  • ADR-074 establishes peat-schema protobuf definitions as the single source of truth for all message types. This PR eliminates schema drift in peat-ffi by shrinking FFI document types (NodeInfo, TrackInfo, CellInfo) to only contain fields that exist in their corresponding proto messages.
  • Removes CommandInfo/CommandStatus, NodeStatus, CellStatus, MarkerInfo, TrackCategory — types and enums with no proto backing or that belong at the consumer level.
  • Adds peat-schema dependency and From<proto> for FfiType bridges (From<Node> for NodeInfo, From<Track> for TrackInfo, From<CellState> for CellInfo, From<i32> for HealthStatus).
  • Net -1,849 lines (200 added, 2,049 removed across 9 files).

Field changes

Type Dropped Renamed
NodeInfo name, readiness, battery_percent, heart_rate, last_heartbeat statushealth (HealthStatus enum), haealtitude
TrackInfo cell_id, formation_id haealtitude
CellInfo name, status, center_lat, center_lon, scenario_command formation_idcohort_id
CommandInfo (entire type removed)

Breaking changes for consumers

  • Consumers using MarkerInfo, TrackCategory, CommandInfo, or any dropped field must define their own types. See peat-atak-plugin/docs/SCHEMA-MIGRATION-NOVEL-TYPES.md for migration guidance.
  • NodeStatus enum replaced by HealthStatus (Unspecified/Nominal/Degraded/Critical/Failed) matching node.proto HealthStatus.

Test plan

  • cargo check -p peat-ffi (lib, tests, examples) — clean
  • cargo test -p peat-ffi --lib — 84 tests pass
  • Grep-clean: no references to NodeStatus, CommandInfo, CommandStatus, CellStatus, MarkerInfo, TrackCategory, battery_percent, heart_rate, last_heartbeat in peat-ffi/src/, examples/, tests/
  • CI passes
  • Consumer plugin (peat-atak-plugin) defines its own MarkerInfo/TrackCategory before pulling this dependency

🤖 Generated with Claude Code

phornstein and others added 2 commits July 6, 2026 13:03
…age types

Establishes that all mesh document schemas must originate in peat-schema
protos. Sub-crates derive types at build time via From impls rather than
maintaining hand-written parallel structs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ields (ADR-074)

Eliminates schema drift between peat-ffi's hand-written document types
and peat-schema's protobuf definitions. FFI types now contain only
fields that exist in the corresponding proto messages; drifted fields
are dropped, not backfilled into protos.

Removed entirely:
- CommandInfo struct, CommandStatus enum, get_commands/put_command,
  parse/serialize helpers, JNI fn + registrations, Dart FFI bindings
- NodeStatus enum (replaced by HealthStatus wrapper over proto)
- CellStatus enum
- Battery/heart-rate/last-heartbeat parsing helpers and ~15 tests

Field changes:
- NodeInfo: drop name/readiness/battery_percent/heart_rate/last_heartbeat;
  status→health (HealthStatus), hae→altitude (f64)
- TrackInfo: drop cell_id/formation_id; hae→altitude, cep to f64
- CellInfo: drop name/status/center_lat/center_lon/scenario_command;
  formation_id→cohort_id

Added:
- peat-schema dependency for proto type bridging
- From<Node/Track/CellState> for FFI types + From<i32> for HealthStatus
- Rewritten node_tests covering proto-backed field set

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@phornstein phornstein requested a review from kitplummer July 6, 2026 20:52

@peat-bot peat-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peat QA Review (SHA: ad64fe7)

Scope: ADR-074 schema alignment for peat-ffi — shrinks NodeInfo/TrackInfo/CellInfo to proto-backed field sets, removes MarkerInfo/CommandInfo/NodeStatus/CellStatus/TrackCategory, adds From<proto> bridges from peat-schema, and drops the corresponding JNI/UniFFI/Dart FFI symbols. Net −1,849 lines.

Assessment: Field-set alignment is defensible and the JSON codec paths (parse_node_json / serialize_node_json / parse_node_publish_json / serialize_nodes_get_json) still have solid round-trip coverage in the rewritten node_tests module. Removal of MarkerInfo / CommandInfo / TrackCategory / NodeStatus / dropped fields is a breaking change; the author has already listed this under Breaking changes for consumers in the PR body and marked the peat-atak-plugin migration as an unchecked pre-merge item — so consumer coordination is tracked, not a fresh finding. The haealtitude Option-to-scalar collapse (also cep) matches peat-schema/proto/track.proto:68 (float altitude) and :71 (float cep_m) proto3 scalars, so semantic alignment with the proto is intentional under ADR-074 — not a regression to flag.

FIPS posture, Automerge / Iroh transport semantics, OTA safety, and BLE platform bindings are unaffected — this PR touches only FFI type-shape and JSON codecs.

Findings

[WARNING] From<peat_schema::*> for FfiType bridges are unused and untestedpeat-ffi/src/lib.rs:2784 (From<Node> for NodeInfo), :2806 (From<Track> for TrackInfo), :2839 (From<CellState> for CellInfo). A repo-wide grep for NodeInfo::from, TrackInfo::from, and CellInfo::from returns zero call sites — the only invocation is HealthStatus::from(state.health) at :2792, internal to the From<Node> impl itself. The actual FFI data path is still parse_node_json / serialize_node_json (the ~600 lines of manual JSON codec ADR-074 §Consequences promised would collapse). Compile-time field-rename drift protection does fire (the impls reference proto field names by identifier), but semantic-mapping bugs (swapped lat/lon, wrong enum variant mapping, off-by-one on HealthStatus::try_from) cannot be caught by the compiler and would ship undetected because nothing exercises the bridges. Action: either add unit tests that construct a representative peat_schema::node::v1::Node / Track / CellState and assert the derived FFI value field-for-field, or wire the bridges into the actual data path (proto→FfiType) so cargo test covers them via the existing codec suites. Without one of those, the PR delivers ADR-074's letter (field sets align with protos) but not its spirit (the "single auditable conversion layer" isn't audited by CI).

- Remove stale `node.name` reference in publishNodeJni android_log (lib.rs:8517)
- Fix `p.name` → `p.id` in dual_test_peer example
- Update JNI method count assertion from 30 → 27 (3 methods removed)
- Run cargo fmt to fix formatting diffs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@peat-bot peat-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peat QA Review (SHA: c684f80)

Scope: Incremental review over the CI-fix push on the ADR-074 schema-alignment PR. Base branch state (ad64fe7) already reviewed. The new commit is c684f807 fix(ci): resolve schema-alignment CI failures — four small changes: stale node.name reference removed from publishNodeJni android_log (now logs node.node_type), p.namep.id in dual_test_peer and iroh_test_peer println paths, JNI native-method-table count assertion updated from 30 → 27 to match the removal of getCommandsJni / getMarkersJni / publishMarkerJni, and cargo fmt fixups. Total delta: 4 files, +14 / −21.

Assessment: The CI fix is mechanical and consistent — the node.name field no longer exists on the shrunk NodeInfo, so the log-line update is correct; the JNI count arithmetic (30 − 3 removed methods = 27) tracks the diff exactly. cargo fmt and log-string edits don't touch protocol, transport, FFI ABI shape, or crypto surface. FIPS posture, Automerge / Iroh semantics, OTA safety, and BLE bindings remain unaffected by this push.

The prior QA review at ad64fe7 raised one [WARNING] finding: the From<peat_schema::*> for FfiType bridges (From<Node> for NodeInfo at peat-ffi/src/lib.rs:2784, From<Track> for TrackInfo at :2802, From<CellState> for CellInfo at :2835) are unused and untested — the actual FFI data path still runs through parse_node_json / serialize_node_json, so a semantic bug in the derived conversions would ship undetected. This push does not modify the bridge code, so per incremental-review rules the finding is considered known-to-author (the CI-fix scope narrows the intent of this push, and the author can address the coverage gap in a follow-up push or a subsequent PR under ADR-074's ongoing migration).

No findings.

@kitplummer kitplummer merged commit f767475 into main Jul 7, 2026
35 of 36 checks passed
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.

3 participants