From 027bd8aa47ab5db7beb2082be187ffca6a121787 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 13:33:16 +0200 Subject: [PATCH] cultmesh-rs: size an admitted put under the shortest message id CultNet encodes The served-size check built its response under an empty message id, which the CultNet encoder refuses, so every put was rejected as ResponseEncodingFailed. No snapshot request can carry an id shorter than one character, so a one-character id gives the smallest response that could ever serve the document; that is the size a put is now judged by. Co-Authored-By: Claude Opus 5.5 --- packages/cultmesh-rs/src/rudp_document_server.rs | 9 ++++++--- packages/cultmesh-rs/tests/rudp_document_server.rs | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/cultmesh-rs/src/rudp_document_server.rs b/packages/cultmesh-rs/src/rudp_document_server.rs index 00dc37db..34794fc5 100644 --- a/packages/cultmesh-rs/src/rudp_document_server.rs +++ b/packages/cultmesh-rs/src/rudp_document_server.rs @@ -11,6 +11,9 @@ use std::net::{SocketAddr, UdpSocket}; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; const MAX_UDP_DATAGRAM_BYTES: usize = 65_535; +/// The shortest message id CultNet encodes: one character. A snapshot request +/// can carry no shorter id, so no response to it can be smaller. +const SHORTEST_MESSAGE_ID: &str = "0"; /// The transport identity of one remote CultNet RUDP session. /// @@ -186,7 +189,7 @@ pub enum CultMeshRudpRejectionReason { /// The caller's sink refused the document. Carries the sink's error text. SinkRefused(String), /// The document could never be served: a snapshot response carrying it - /// alone, with an empty message id, would exceed + /// alone, under the shortest message id CultNet allows, would exceed /// `max_snapshot_response_bytes`. It was not offered to the sink. DocumentUnservable { response_bytes: usize, @@ -555,9 +558,9 @@ where }; // Admit only what some snapshot request can return: the smallest // response that could carry this document is the document alone - // under an empty message id, sized by the snapshot path's encoder. + // under the shortest message id CultNet encodes, sized by the snapshot path's encoder. let alone = CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: SHORTEST_MESSAGE_ID.into(), documents: vec![document], }; let response_bytes = match encode_snapshot_response(&alone) { diff --git a/packages/cultmesh-rs/tests/rudp_document_server.rs b/packages/cultmesh-rs/tests/rudp_document_server.rs index 2e51cb2d..1d338058 100644 --- a/packages/cultmesh-rs/tests/rudp_document_server.rs +++ b/packages/cultmesh-rs/tests/rudp_document_server.rs @@ -212,11 +212,12 @@ fn connect( } /// The encoded size of the snapshot response that carries `document` alone -/// under an empty message id: the smallest response that could ever serve it. +/// under a one-character message id, the shortest CultNet encodes: the +/// smallest response that could ever serve it. fn served_alone_bytes(document: &CultNetRawDocumentRecord) -> Result { Ok(encode_cultnet_message_to_vec( &CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: "r".into(), documents: vec![document.clone()], }, CultNetWireContract::CultNetSchemaV0, @@ -758,7 +759,7 @@ fn a_put_the_server_could_never_serve_is_refused_and_one_at_the_bound_is_served( send( &mut writer, &CultNetMessage::SnapshotRequest { - message_id: String::new(), + message_id: "r".into(), schema_ids: None, record_keys: None, }, @@ -781,7 +782,7 @@ fn a_put_the_server_could_never_serve_is_refused_and_one_at_the_bound_is_served( assert_eq!( decode_cultnet_message_from_slice(&served, CultNetWireContract::CultNetSchemaV0)?, CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: "r".into(), documents: vec![at_bound], } );