mediation

One pass, and the order it runs in

How `process` assembles the pieces, and why the order matters.

Each record reaches the first outcome that applies:

#TestOutcome
1no natural keyrejected, NotKeyable
2key already billed, held or suppressed inside the windowduplicate
3no charged partyrejected, Unattributable
4opens after as_ofrejected, FutureTimestamp
5past the inclusion deadlinerejected, BeyondDeadline
6a blocking rule firedrejected, Malformed
7its partial run can never be reassembled (V19)rejected, Malformed
8its partial run is not finished, first record included (V20)held, AwaitingPartial
9the suppression policy says sosuppressed
10its source has an unfilled sequence holeheld, SequenceGap
11otherwisebillable
  • Keyability first: an unkeyed record could be billed twice.
  • Deduplication before judgement: a malformed retransmission is one fault.
  • Steps 4 and 5 use the LatenessPolicy in ProcessConfig::validation.
  • Completeness last, per source: only the source with the hole is held, and only records that would otherwise be billed.
use mediation::{Batch, DedupWindow, Disposition, ProcessConfig, ProcessState, RejectReason, process};
use mediation::{ChargedParty, RecordType, SourceRef, SubscriberRef, UsageRecord};
use time::{Duration, macros::datetime};

// No correlator, so no natural key.
let bare = UsageRecord::new(
    RecordType::PduSession,
    ChargedParty::Subscriber(SubscriberRef::new("imsi-262021234567890".parse().unwrap())),
    "2026-07-28T10:00:00+02:00".parse().unwrap(),
    SourceRef::new("pgw-01".parse().unwrap(), 0),
);

let mut state = ProcessState::new(DedupWindow::from_bound(Duration::days(7)).unwrap());
let outcome = process(
    &Batch::new(&[bare]),
    &ProcessConfig::default(),
    datetime!(2026-07-28 12:00:00 UTC),
    &mut state,
);

assert!(matches!(
    outcome.dispositions()[0],
    Disposition::Rejected(RejectReason::NotKeyable(_)),
));
assert!(outcome.reconciliation().balances());

Suppression

process_with takes your Suppression policy; process suppresses nothing.

Held records come back

Batch::with_carry marks the leading records as carried in. They are counted through observe_carried and refresh their dedup key instead of being checked against it. Chain reconciliations through a PeriodLedger.

The state is yours

ProcessState holds the dedup store and sequence trackers. process reads no clock, so the same inputs give the same answer. Persist the state across restarts (DedupStore::iter / restore, SequenceTracker::snapshot / restore, or serde):

#[cfg(feature = "serde")] {
use mediation::{DedupWindow, ProcessState};
use time::Duration;

let state = ProcessState::new(DedupWindow::from_bound(Duration::days(7)).unwrap());

let saved = serde_json::to_string(&state).unwrap();
let restored: ProcessState = serde_json::from_str(&saved).unwrap();
assert_eq!(restored.dedup().len(), state.dedup().len());
}

process does not correlate (that changes record cardinality; see correlation), rate or round.

Improve this page on GitHub