Skip to main content

validate_contribution

Function validate_contribution 

Source
pub fn validate_contribution(
    contribution: &MemoryContextContribution,
    expected_project: &ProjectId,
    max_rendered_tokens: u64,
    permitted_classes: &DisclosureGrantSet,
) -> Result<(), MemoryContextError>
Expand description

Host-side contribution acceptance gate — the FULL spec §6.5 rejection matrix (task B1): “The host validates project ID, record count, record sizes, total size, disclosure classes, and schema version”.

  • project identity mismatch fails closed (spec §5.2 isolation);
  • schema version must be non-empty (already guaranteed by the ContributionSchemaVersion parse gate; re-checked here so the validator stays the single acceptance authority when task B3 adds boundary deserialization);
  • record count, per-record size, and total rendered size are bounded (max_rendered_tokens is the ENGINE-provided budget from memory_budget_tokens — never plugin-chosen);
  • duplicate memory_id values across records are rejected;
  • every record’s disclosure class must be inside the originating recall request’s permitted_classes grant (spec §6.4) — a provider cannot volunteer classes the host never authorized;
  • every non-empty record body is gated through the ONE model-visibility gate, gate_for_model (spec §5.5 / §14.2), with fail-closed inputs (no consent, no redactor): if the class would be withheld yet the body is non-empty, the WHOLE contribution is rejected — defense in depth against a compromised or buggy plugin leaking withheld content. A correct provider never includes such a record at all.

One failure rejects everything: no partial admission, and no rejected content ever influences budgeting or request assembly.