diff --git a/contracts/cultnet/cultnet-distributed-database.md b/contracts/cultnet/cultnet-distributed-database.md index a1c20466..0ed19837 100644 --- a/contracts/cultnet/cultnet-distributed-database.md +++ b/contracts/cultnet/cultnet-distributed-database.md @@ -141,7 +141,7 @@ A malformed put or delete is `message_invalid`, not a per-operation code: the pe shard view and advances the replica cursor to that sequence. - Realtime subscriptions publish domain changes, not storage envelopes. - A subscription's `database_change_raw` messages may carry `commitId` and `commitCount`: the changes of one cache - commit that this subscription delivers (`commitCount` of them, at least two). Both fields are optional and additive; a + commit that this subscription delivers (`commitCount` of them, at least two; a decoder refuses less). Both fields are optional and additive; a peer that does not know them ignores them and applies each change alone. A replica that knows them applies the commit's changes as one commit, so the replica judges the result (a swap of two unique-index values) and not the state between records. A replica whose cache refuses a commit is faulted, never silent. `commitId` is opaque and valid only @@ -149,7 +149,7 @@ A malformed put or delete is `message_invalid`, not a per-operation code: the pe never forwards a commit that its last snapshot to the subscription already reflects (the database server adopts next). A replica may bound how many changes it buffers across incomplete commits (the C# client: `MaxBufferedChanges`, 1,000,000). One bound covers every commit, whatever made it, a `Reconcile` diff included: a commit announcing more faults the replica loudly, and a faulted - consumer resubscribes for a snapshot, which is one message and has no such bound. A server does not split a commit to + consumer resubscribes for a snapshot, which is one message and has no such bound. A change for a subscription the client has ended or never began is dropped, never applied or buffered, whether it is a single change or part of a commit. A server does not split a commit to fit a replica's bound. The C# subscription server and database server tag commits; other runtimes adopt next. - The C# writer sets every key of a `database_change_raw` message, nil where unset: a removed change carries `document` nil, an added or updated one `recordKey` and `schemaId` nil. The schema accepts those nils; an added or updated change diff --git a/packages/cultnet-rs/tests/subscription.rs b/packages/cultnet-rs/tests/subscription.rs index 9bdd2229..b81c4e01 100644 --- a/packages/cultnet-rs/tests/subscription.rs +++ b/packages/cultnet-rs/tests/subscription.rs @@ -398,3 +398,15 @@ fn decode_refuses_an_unsubscribe_or_change_without_its_ids() { ]))) .contains("subscriptionId")); } + +#[test] +fn a_one_change_announcement_never_counts_against_a_full_buffer() { + let mut assembler = live("sub"); + for index in 0..MAX_PENDING_COMMITS { + let id = format!("c{index}"); + assert!(assembler.accept(change(&format!("m{index}"), "sub", "k", Some((&id, 2)))).is_empty()); + } + let events = assembler.accept(change("single", "sub", "k1", Some(("one", 1)))); + assert_eq!(keys(&events[0]), ["k1"], "a single change is not a buffered commit, so the full cap does not refuse it"); + assert!(assembler.fault().is_none()); +}