Echo-Community-Toolkit-Monorepo

Phase 3 – Integrity & Error Correction

Phase 3 equips the MRP stack with integrity metadata and XOR-parity–based self-healing, ensuring payloads announce and repair corruption when possible.

Objectives

Implementation Plan

  1. Integrity payload schema
    • Define a JSON schema containing: {message_crc32, metadata_crc32, message_sha256, parity_hex, corrected_bytes}.
    • Encode schema into the B-channel frame as UTF-8 JSON; document in repo specs.
    • Extend encoder to compute CRC32/SHA-256 from the definitive R/G payloads after final packing.
  2. Parity generation
    • Use xor_parity_bytes(R_payload, G_payload) to derive parity bytes (already restored in Phase 0).
    • Store parity in both raw bytes (for decoder) and hex (for logging/testing).
  3. Decoder recovery workflow
    • After extracting all frames, verify CRCs; if mismatch occurs, attempt parity repair by computing R = parity ⊕ G or G = parity ⊕ R depending on the failing channel.
    • Re-run CRC and SHA-256 validation post-repair; track number of corrected bytes.
    • Surface structured result: {status, corrected_channels, unrecoverable_errors, integrity_log}.
    • Record failures when both channels disagree or SHA-256 still mismatches.
  4. Telemetry
    • Log integrity actions in a consistent format (consumed later by Ritual/Ledger).
    • Ensure CLI/API responses include integrity_status values such as ok, recovered_with_parity, failed_crc, failed_sha256.

Testing Strategy

Dependencies & Hand-offs

Risks & Mitigations