commit 53f7c6f732e22972fe0c4b24ac1225e6511b7925
parent ed0fc2554206b600d7965d5461d916f7c2c2c668
Author: triesap <tyson@radroots.org>
Date: Mon, 12 Oct 2026 16:56:55 +0000
simplex_smp_proto: propagate broker error encoding failures
- Return typed short-field length errors from nested broker encoders.
- Preserve accepted wire bytes and versioned compatibility behavior.
- Exercise public ASCII, UTF-8, nested and transmission boundaries.
- Verify 43 tests, no-std checking and scoped Rust 1.99.0 quality gates.
Diffstat:
4 files changed, 151 insertions(+), 18 deletions(-)
diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml
@@ -2,6 +2,34 @@ schema_version = 1
architecture_id = "radroots.crates.release.v1"
[[deviation]]
+id = "RCRV1-DEV-030"
+date = "2026-10-12"
+status = "closed"
+approval = "The user approved the successor refactor and local verified checkpoints through RCLD-RDP-030; publication and supported consumer qualification remain separate."
+affected_steps = ["010", "040", "070", "130"]
+spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#repository_policy"]
+source_evidence = [
+ "The public fallible broker-message encoder panics when unrestricted Response or Unexpected strings exceed the one-byte short-field length.",
+ "An isolated public-API probe reproduced both panics at 256 bytes, including multibyte UTF-8, while both variants round-tripped at 255 bytes and all 39 existing package tests passed.",
+ "The freshly fetched upstream integration branch retains the identical wire blob; no newer correction is available there.",
+]
+replacement_action = "Bring forward the contained short-field failure propagation during source reevaluation. Return the existing typed length error through private nested error encoders and public message/transmission APIs, preserving accepted bytes, tested version downgrades, network-detail compatibility, public API shapes and feature boundaries."
+verification = [
+ "Validate this standalone deviation before changing production encoding, then record failing public regressions against unchanged production source.",
+ "Prove UTF-8 byte-length rejection and valid boundaries through direct, versioned and nested message/transmission APIs without truncation or panic.",
+ "Run exact Rust 1.99.0 scoped formatting, all-feature/all-target check, full package tests, no-default-feature library check and warnings-as-errors Clippy; review the exact owner diff before a local commit.",
+]
+unresolved_risk = "The contained short-field repair is locally verified. Aggregate frame and recursion bounds, private diagnostics, actual crypto/transport/caller qualification and supported consumer adoption remain separate; no deployed incident or complete platform acceptance is claimed."
+normative_architecture_change = false
+adr_required = false
+closure_evidence = [
+ "The isolated unchanged-source public probe reproduced both 256-byte panics with valid 255-byte controls; the retained public regression suite also failed nested transmission propagation before the production repair.",
+ "Direct and versioned message/transmission encoders now return InvalidShortFieldLength for oversized details, including nested proxy protocol errors, without truncation or panic. Empty and 255-byte ASCII/multibyte details round-trip.",
+ "Exact Rust 1.99.0 scoped formatting, all-feature/all-target check, 43 passing package tests with zero ignored, no-default-feature library check and warnings-as-errors all-target Clippy passed on local macOS arm64.",
+ "Only private encoding failure propagation, meaningful public boundary regressions, package guidance and this deviation changed. Accepted wire bytes, existing version/network-detail compatibility, public API shapes, dependencies, features and effect ownership remain unchanged.",
+]
+
+[[deviation]]
id = "RCRV1-DEV-029"
date = "2026-10-12"
status = "closed"
diff --git a/crates/simplex_smp_proto/README b/crates/simplex_smp_proto/README
@@ -11,6 +11,11 @@ wire protocol primitives for the `radroots` core libraries.
* portable shared models with optional serialization and shared type export
support.
+Broker response and unexpected-error details use the protocol's one-byte
+length prefix. Message and transmission encoders reject details over 255
+UTF-8 bytes with `InvalidShortFieldLength`, including nested proxy errors;
+they do not truncate the detail or panic at that boundary.
+
## Copyright
Except as otherwise noted, all files in the `radroots_simplex_smp_proto`
diff --git a/crates/simplex_smp_proto/src/wire.rs b/crates/simplex_smp_proto/src/wire.rs
@@ -691,7 +691,7 @@ impl RadrootsSimplexSmpBrokerMessage {
{
buffer.extend_from_slice(b"AUTH");
} else {
- buffer.extend_from_slice(&encode_error(error));
+ buffer.extend_from_slice(&encode_error(error)?);
}
}
Self::Pong => buffer.extend_from_slice(TAG_PONG),
@@ -1374,8 +1374,8 @@ fn decode_send_payload(
})
}
-fn encode_error(error: &RadrootsSimplexSmpError) -> Vec<u8> {
- match error {
+fn encode_error(error: &RadrootsSimplexSmpError) -> Result<Vec<u8>, RadrootsSimplexSmpProtoError> {
+ Ok(match error {
RadrootsSimplexSmpError::Block => b"BLOCK".to_vec(),
RadrootsSimplexSmpError::Session => b"SESSION".to_vec(),
RadrootsSimplexSmpError::Command(command_error) => {
@@ -1393,7 +1393,7 @@ fn encode_error(error: &RadrootsSimplexSmpError) -> Vec<u8> {
}
RadrootsSimplexSmpError::Proxy(proxy_error) => {
let mut bytes = b"PROXY ".to_vec();
- bytes.extend_from_slice(&encode_proxy_error(proxy_error));
+ bytes.extend_from_slice(&encode_proxy_error(proxy_error)?);
bytes
}
RadrootsSimplexSmpError::Auth => b"AUTH".to_vec(),
@@ -1416,7 +1416,7 @@ fn encode_error(error: &RadrootsSimplexSmpError) -> Vec<u8> {
RadrootsSimplexSmpError::Internal => b"INTERNAL".to_vec(),
RadrootsSimplexSmpError::Duplicate => b"DUPLICATE_".to_vec(),
RadrootsSimplexSmpError::Other(raw) => raw.clone(),
- }
+ })
}
fn decode_error(bytes: &[u8]) -> Result<RadrootsSimplexSmpError, RadrootsSimplexSmpProtoError> {
@@ -1485,21 +1485,23 @@ fn decode_error(bytes: &[u8]) -> Result<RadrootsSimplexSmpError, RadrootsSimplex
Ok(RadrootsSimplexSmpError::Other(bytes.to_vec()))
}
-fn encode_proxy_error(error: &RadrootsSimplexSmpProxyError) -> Vec<u8> {
- match error {
+fn encode_proxy_error(
+ error: &RadrootsSimplexSmpProxyError,
+) -> Result<Vec<u8>, RadrootsSimplexSmpProtoError> {
+ Ok(match error {
RadrootsSimplexSmpProxyError::Protocol(error) => {
let mut bytes = b"PROTOCOL ".to_vec();
- bytes.extend_from_slice(&encode_error(error));
+ bytes.extend_from_slice(&encode_error(error)?);
bytes
}
RadrootsSimplexSmpProxyError::Broker(error) => {
let mut bytes = b"BROKER ".to_vec();
- bytes.extend_from_slice(&encode_broker_error(error));
+ bytes.extend_from_slice(&encode_broker_error(error)?);
bytes
}
RadrootsSimplexSmpProxyError::BasicAuth => b"BASIC_AUTH".to_vec(),
RadrootsSimplexSmpProxyError::NoSession => b"NO_SESSION".to_vec(),
- }
+ })
}
fn decode_proxy_error(
@@ -1519,18 +1521,18 @@ fn decode_proxy_error(
}
}
-fn encode_broker_error(error: &RadrootsSimplexSmpBrokerError) -> Vec<u8> {
- match error {
+fn encode_broker_error(
+ error: &RadrootsSimplexSmpBrokerError,
+) -> Result<Vec<u8>, RadrootsSimplexSmpProtoError> {
+ Ok(match error {
RadrootsSimplexSmpBrokerError::Response(response_error) => {
let mut bytes = b"RESPONSE ".to_vec();
- push_short_string(&mut bytes, response_error)
- .expect("response_error length is bounded by SMP short-string encoding");
+ push_short_string(&mut bytes, response_error)?;
bytes
}
RadrootsSimplexSmpBrokerError::Unexpected(response_error) => {
let mut bytes = b"UNEXPECTED ".to_vec();
- push_short_string(&mut bytes, response_error)
- .expect("response_error length is bounded by SMP short-string encoding");
+ push_short_string(&mut bytes, response_error)?;
bytes
}
RadrootsSimplexSmpBrokerError::Network(_) => b"NETWORK".to_vec(),
@@ -1542,7 +1544,7 @@ fn encode_broker_error(error: &RadrootsSimplexSmpBrokerError) -> Vec<u8> {
bytes
}
RadrootsSimplexSmpBrokerError::Timeout => b"TIMEOUT".to_vec(),
- }
+ })
}
fn decode_broker_error(
@@ -2767,7 +2769,8 @@ mod tests {
assert_eq!(
encode_broker_error(&RadrootsSimplexSmpBrokerError::Network(
RadrootsSimplexSmpNetworkError::Connect("dns".to_string()),
- )),
+ ))
+ .unwrap(),
b"NETWORK".to_vec()
);
}
diff --git a/crates/simplex_smp_proto/tests/broker_encoding.rs b/crates/simplex_smp_proto/tests/broker_encoding.rs
@@ -0,0 +1,97 @@
+use radroots_simplex_smp_proto::prelude::*;
+
+fn broker(error: RadrootsSimplexSmpBrokerError) -> RadrootsSimplexSmpBrokerMessage {
+ RadrootsSimplexSmpBrokerMessage::Err(RadrootsSimplexSmpError::Proxy(
+ RadrootsSimplexSmpProxyError::Broker(error),
+ ))
+}
+
+#[test]
+fn oversized_response_is_a_typed_error() {
+ for detail in ["p".repeat(256), "🍓".repeat(64)] {
+ let message = broker(RadrootsSimplexSmpBrokerError::Response(detail));
+ for version in [
+ RADROOTS_SIMPLEX_SMP_INITIAL_TRANSPORT_VERSION,
+ RADROOTS_SIMPLEX_SMP_CURRENT_TRANSPORT_VERSION,
+ ] {
+ assert_eq!(
+ message.encode_for_version(version),
+ Err(RadrootsSimplexSmpProtoError::InvalidShortFieldLength(256))
+ );
+ }
+ }
+}
+
+#[test]
+fn oversized_unexpected_is_a_typed_error() {
+ for detail in ["p".repeat(256), "🍓".repeat(64)] {
+ let message = broker(RadrootsSimplexSmpBrokerError::Unexpected(detail));
+ assert_eq!(
+ message.encode(),
+ Err(RadrootsSimplexSmpProtoError::InvalidShortFieldLength(256))
+ );
+ }
+}
+
+#[test]
+fn valid_byte_boundaries_round_trip_through_messages_and_transmissions() {
+ for detail in [
+ String::new(),
+ "p".repeat(255),
+ format!("{}abc", "🍓".repeat(63)),
+ ] {
+ for error in [
+ RadrootsSimplexSmpBrokerError::Response(detail.clone()),
+ RadrootsSimplexSmpBrokerError::Unexpected(detail.clone()),
+ ] {
+ let message = broker(error);
+ for version in [
+ RADROOTS_SIMPLEX_SMP_INITIAL_TRANSPORT_VERSION,
+ RADROOTS_SIMPLEX_SMP_CURRENT_TRANSPORT_VERSION,
+ ] {
+ let encoded = message.encode_for_version(version).unwrap();
+ assert_eq!(
+ RadrootsSimplexSmpBrokerMessage::decode_for_version(version, &encoded).unwrap(),
+ message
+ );
+ }
+ let transmission = RadrootsSimplexSmpBrokerTransmission {
+ authorization: Vec::new(),
+ correlation_id: None,
+ entity_id: Vec::new(),
+ message,
+ };
+ let encoded = transmission.encode().unwrap();
+ assert_eq!(
+ RadrootsSimplexSmpBrokerTransmission::decode(&encoded).unwrap(),
+ transmission
+ );
+ }
+ }
+}
+
+#[test]
+fn nested_oversized_errors_propagate_through_transmissions() {
+ for error in [
+ RadrootsSimplexSmpBrokerError::Response("p".repeat(256)),
+ RadrootsSimplexSmpBrokerError::Unexpected("🍓".repeat(64)),
+ ] {
+ let mut nested =
+ RadrootsSimplexSmpError::Proxy(RadrootsSimplexSmpProxyError::Broker(error));
+ for _ in 0..3 {
+ nested = RadrootsSimplexSmpError::Proxy(RadrootsSimplexSmpProxyError::Protocol(
+ Box::new(nested),
+ ));
+ }
+ let transmission = RadrootsSimplexSmpBrokerTransmission {
+ authorization: Vec::new(),
+ correlation_id: None,
+ entity_id: Vec::new(),
+ message: RadrootsSimplexSmpBrokerMessage::Err(nested),
+ };
+ assert_eq!(
+ transmission.encode(),
+ Err(RadrootsSimplexSmpProtoError::InvalidShortFieldLength(256))
+ );
+ }
+}