commit 4a79700fc420253090e3fb21315d8a5613015680
parent 418acecb49437ce1200a6916822af9ef83eefec3
Author: triesap <tyson@radroots.org>
Date: Mon, 12 Oct 2026 00:20:17 +0000
transport_nostr: require positive acknowledgement for acceptance
- Keep negative relay acknowledgements and untyped publication errors unsuccessful.
- Preserve matching event and connection authority, exact EVENT bytes, and positive duplicate acceptance.
- Add real loopback and private-normalization regressions with a recorded failing baseline.
- Verify Rust 1.99.0 scoped format, check, package tests, Clippy and architecture controls.
Diffstat:
6 files changed, 151 insertions(+), 14 deletions(-)
diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml
@@ -2,6 +2,33 @@ schema_version = 1
architecture_id = "radroots.crates.release.v1"
[[deviation]]
+id = "RCRV1-DEV-025"
+date = "2026-10-12"
+status = "closed"
+approval = "The user approved the full successor refactor and local verified checkpoint commits; publication remains separate."
+affected_steps = ["010", "070", "130"]
+spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#package.radroots_transport_nostr"]
+source_evidence = [
+ "A real loopback relay sent a matching OK with accepted=false and the message 'blocked: not a duplicate; event was rejected'; the transport returned a satisfied acceptance receipt.",
+ "The shared failure classifier turns any occurrence of 'duplicate' or 'already have' into Accepted, including untyped publication errors without an acknowledgement.",
+ "NIP-01 requires the acknowledgement boolean to be true for acceptance and illustrates duplicate acceptance with true.",
+]
+replacement_action = "Bring forward this contained safety correction during source review: failure classification can never produce acceptance, while matching positive acknowledgements retain acceptance. Preserve event-ID and connection binding without changing public APIs, dependencies, retry policy or package ownership."
+verification = [
+ "Validate the standalone architecture deviation before editing the relay classifier.",
+ "Record a failing real-loopback regression on the old classifier, then prove negative acknowledgements never satisfy delivery and positive duplicate acknowledgements remain accepted.",
+ "Run exact Rust 1.99.0 scoped formatting, all-target check, full package tests and warnings-as-errors Clippy; review the final diff and preserve unrelated source candidates.",
+]
+unresolved_risk = "The contained local repair is verified. Published consumer adoption and the broader successor transport/platform qualification remain separate and pending."
+normative_architecture_change = false
+adr_required = false
+closure_evidence = [
+ "The real loopback regression failed on the original classifier; the repaired package rejects seven negative-ACK message variants while accepting positive empty and duplicate acknowledgements.",
+ "Exact Rust 1.99.0 scoped format, all-target check, full package tests and all-target warnings-as-errors Clippy passed on local macOS arm64. Generic error normalization and matching-ID/disconnect regressions also passed.",
+ "Only private failure classification, tests and package guidance changed; public APIs, features, dependencies, retained EVENT bytes and target/connection binding are unchanged. Unrelated source candidates are excluded from this checkpoint.",
+]
+
+[[deviation]]
id = "RCRV1-DEV-023"
date = "2026-09-22"
status = "closed"
diff --git a/crates/transport_nostr/README.md b/crates/transport_nostr/README.md
@@ -71,7 +71,11 @@ bytes in the Nostr `EVENT` frame without parsing and serializing them again;
whitespace, field order, and admitted extension fields remain unchanged. The
frame must fit the existing 512 KiB wire bound. Publication shares the existing
hardened connection writer with SDK authentication and subscription messages.
-It requires a matching event-ID `OK` from that relay before recording acceptance.
+It requires a matching event-ID `OK` with `accepted=true` from that relay before
+recording acceptance. Duplicate-event acceptance also requires `true`, as
+defined by [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md).
+A negative acknowledgement or untyped error remains unsuccessful regardless
+of message text, including `duplicate` or `already have`.
Closed or replaced connections do not grant fresh send authority to a retained
writer. Missing acknowledgements remain unknown or unavailable evidence.
diff --git a/crates/transport_nostr/src/exact_delivery.rs b/crates/transport_nostr/src/exact_delivery.rs
@@ -114,9 +114,20 @@ mod tests {
acknowledgement(id, ok(id, true, "")).unwrap(),
DeliveryOutcome::accepted()
);
- assert!(!status::delivery_succeeded(
- &acknowledgement(id, ok(id, false, "blocked: denied")).unwrap()
- ));
+ assert_eq!(
+ acknowledgement(id, ok(id, true, "duplicate: already have this event")).unwrap(),
+ DeliveryOutcome::accepted()
+ );
+ for message in [
+ "blocked: denied",
+ "blocked: not a duplicate; event was rejected",
+ "duplicate: already have this event",
+ "already have this event",
+ ] {
+ assert!(!status::delivery_succeeded(
+ &acknowledgement(id, ok(id, false, message)).unwrap()
+ ));
+ }
for status in [
nostr_sdk::RelayStatus::Disconnected,
nostr_sdk::RelayStatus::Terminated,
diff --git a/crates/transport_nostr/src/sink.rs b/crates/transport_nostr/src/sink.rs
@@ -526,7 +526,7 @@ mod tests {
#[test]
fn upstream_messages_map_to_stable_outcomes() {
let cases = [
- ("duplicate: already have", DeliveryOutcomeKind::Accepted),
+ ("duplicate: already have", DeliveryOutcomeKind::Unavailable),
("blocked by policy", DeliveryOutcomeKind::Rejected),
("rate limited", DeliveryOutcomeKind::Unavailable),
("auth required", DeliveryOutcomeKind::Failed),
diff --git a/crates/transport_nostr/src/status.rs b/crates/transport_nostr/src/status.rs
@@ -12,7 +12,6 @@ use std::sync::Mutex;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum FailureClass {
- Duplicate,
Rejected,
AuthRequired,
Quota,
@@ -26,7 +25,6 @@ enum FailureClass {
impl FailureClass {
const fn code(self) -> &'static str {
match self {
- Self::Duplicate => "duplicate",
Self::Rejected => "rejected",
Self::AuthRequired => "auth_required",
Self::Quota => "quota_exceeded",
@@ -40,7 +38,6 @@ impl FailureClass {
const fn message(self) -> &'static str {
match self {
- Self::Duplicate => "relay already has the event",
Self::Rejected => "relay rejected the event",
Self::AuthRequired => "relay authentication is required",
Self::Quota => "relay quota was exhausted",
@@ -580,9 +577,9 @@ pub(crate) fn sink_status(tracker: &StatusTracker) -> SinkStatus {
}
pub(crate) fn delivery_failure(upstream: &str) -> DeliveryOutcome {
+ // Error text can classify a failure, but cannot establish relay acceptance.
let class = classify(upstream).class;
let outcome = match class {
- FailureClass::Duplicate => DeliveryOutcome::accepted(),
FailureClass::Rejected | FailureClass::Malformed | FailureClass::Quota => {
DeliveryOutcome::rejected()
}
@@ -611,9 +608,7 @@ pub(crate) fn fetch_failure(upstream: &str) -> (FetchTargetState, &'static str)
fn classify(upstream: &str) -> RedactedDiagnostic {
let message = upstream.to_ascii_lowercase();
- let class = if message.contains("duplicate") || message.contains("already have") {
- FailureClass::Duplicate
- } else if message.contains("auth") {
+ let class = if message.contains("auth") {
FailureClass::AuthRequired
} else if message.contains("quota") {
FailureClass::Quota
@@ -668,7 +663,7 @@ mod tests {
fn every_upstream_class_maps_to_stable_secret_safe_output() {
let secret = "token=very-secret-value";
let cases = [
- ("duplicate: already have", "duplicate"),
+ ("duplicate: already have", "relay_failure"),
("blocked by policy", "rejected"),
("auth required", "auth_required"),
("quota exceeded", "quota_exceeded"),
@@ -688,6 +683,21 @@ mod tests {
}
#[test]
+ fn duplicate_text_cannot_turn_an_untyped_failure_into_acceptance() {
+ for message in [
+ "duplicate: already have this event",
+ "already have this event",
+ "blocked: not a duplicate; event was rejected",
+ "auth-required: duplicate path requires login",
+ "connection failed: duplicate acknowledgement unavailable",
+ "error: duplicate detector unavailable",
+ ] {
+ let outcome = delivery_failure(message);
+ assert!(!delivery_succeeded(&outcome), "{message}");
+ }
+ }
+
+ #[test]
fn quota_refusal_requires_action_without_reclassifying_other_failures() {
for text in ["quota exceeded", "blocked: account QUOTA exhausted"] {
let outcome = delivery_failure(text);
@@ -898,7 +908,10 @@ mod tests {
failed.record_write(&writable, false, false, 10);
assert_eq!(failed.report().state(), RelayAggregateState::Failed);
- assert_eq!(delivery_failure("already have").code(), Some("duplicate"));
+ assert_eq!(
+ delivery_failure("already have").code(),
+ Some("relay_failure")
+ );
assert_eq!(
fetch_failure("timed out").0,
FetchTargetState::FailedRetryable
diff --git a/crates/transport_nostr/tests/exact_delivery.rs b/crates/transport_nostr/tests/exact_delivery.rs
@@ -271,6 +271,88 @@ async fn rejection_lost_ack_and_disconnect_never_invent_acceptance() {
}
#[tokio::test]
+async fn matching_negative_ack_never_accepts_duplicate_text() {
+ for message in [
+ "blocked: not a duplicate; event was rejected",
+ "duplicate: already have this event",
+ "already have this event",
+ "error: duplicate detector unavailable",
+ "auth-required: duplicate path requires login",
+ "rate-limited: duplicate retries",
+ "invalid: duplicate event format",
+ ] {
+ let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let config = config(&format!("ws://{}", listener.local_addr().unwrap()), 2_000);
+ let raw = raw_event();
+ let expected = format!("[\"EVENT\",{raw}]");
+ let (done, wait) = tokio::sync::oneshot::channel();
+ let server = tokio::spawn(async move {
+ let (tcp, _) = listener.accept().await.unwrap();
+ let mut socket = accept_async(tcp).await.unwrap();
+ let wire = text(&mut socket).await;
+ assert_eq!(wire, expected);
+ let event: Value = serde_json::from_str(&wire).unwrap();
+ reply(&mut socket, json!(["OK", event[1]["id"], false, message])).await;
+ tokio::time::timeout(Duration::from_secs(5), wait)
+ .await
+ .unwrap()
+ .unwrap();
+ });
+ let transport = NostrTransport::new(config.clone());
+ let request = request(&config, &raw);
+ let receipt =
+ tokio::time::timeout(Duration::from_secs(5), transport.deliver(request.clone()))
+ .await
+ .unwrap()
+ .unwrap();
+ done.send(()).unwrap();
+ server.await.unwrap();
+ receipt.validate_for_request(&request).unwrap();
+ assert!(receipt.target_receipts()[0].was_attempted());
+ assert!(!receipt.is_satisfied(&request).unwrap(), "{message}");
+ assert!(
+ !receipt.target_receipts()[0]
+ .outcome()
+ .satisfies(SatisfactionClass::Accepted),
+ "{message}"
+ );
+ }
+}
+
+#[tokio::test]
+async fn matching_positive_ack_accepts_existing_duplicate_and_empty_messages() {
+ for message in ["", "duplicate: already have this event"] {
+ let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let config = config(&format!("ws://{}", listener.local_addr().unwrap()), 2_000);
+ let raw = raw_event();
+ let (done, wait) = tokio::sync::oneshot::channel();
+ let server = tokio::spawn(async move {
+ let (tcp, _) = listener.accept().await.unwrap();
+ let mut socket = accept_async(tcp).await.unwrap();
+ let event: Value = serde_json::from_str(&text(&mut socket).await).unwrap();
+ assert_eq!(event[0], "EVENT");
+ reply(&mut socket, json!(["OK", event[1]["id"], true, message])).await;
+ tokio::time::timeout(Duration::from_secs(5), wait)
+ .await
+ .unwrap()
+ .unwrap();
+ });
+ let request = request(&config, &raw);
+ let receipt = tokio::time::timeout(
+ Duration::from_secs(5),
+ NostrTransport::new(config).deliver(request.clone()),
+ )
+ .await
+ .unwrap()
+ .unwrap();
+ done.send(()).unwrap();
+ server.await.unwrap();
+ receipt.validate_for_request(&request).unwrap();
+ assert!(receipt.is_satisfied(&request).unwrap(), "{message}");
+ }
+}
+
+#[tokio::test]
async fn quota_refusal_is_terminal_and_redacted_at_the_receipt_boundary() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let config = config(&format!("ws://{}", listener.local_addr().unwrap()), 2_000);