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
ContributionSchemaVersionparse 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_tokensis the ENGINE-provided budget frommemory_budget_tokens— never plugin-chosen); - duplicate
memory_idvalues across records are rejected; - every record’s disclosure class must be inside the originating recall
request’s
permitted_classesgrant (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.