Events
Record practice observations, credited retrievals and lifecycle controls.
Call validateEvents(scopeId, events) to check the event shapes and identity conflicts. The scope identifies the caller's history; the application must authorize access separately.
import { validateEvents } from "@0xbuff/retention";
const result = validateEvents("local-deck", [
{
schemaVersion: 1,
kind: "practice_observation",
scopeId: "local-deck",
conceptId: "binary-search",
eventId: "review-1",
sequence: 0,
atMs: 0,
sessionId: "session-1",
outcome: "pass",
},
]);
if (result.ok) {
// Validated, immutable events; no schedule or credit decision is produced.
console.log(result.value);
}Event shapes
Every event requires schemaVersion: 1, kind, scopeId, eventId, sequence and atMs. All variants except scope deletion also require conceptId.
| Kind | Additional fields |
|---|---|
practice_observation | sessionId, outcome; optional fresh, hints, ladder |
eligible_credited_retrieval | Credited evidence, creditDecisionId, decisionVersion: 1 |
credited_decision_correction | supersedesDecisionId, replacementDecisionId, decisionVersion, replacement, reasonCode |
credited_decision_revocation | supersedesDecisionId, reasonCode |
review_event_deletion | targetEventId |
review_scope_deletion | throughSequence |
Credited evidence requires sessionId, outcome, fresh, hints, ladder and eligibilityPolicyVersion. Practice outcomes are pass, fail or not_observed; credited outcomes are pass or fail. A correction carries its evidence in replacement and uses a decision version of at least 2. Lifecycle reconciliation checks the exact successor version. Controls have no outer session or outcome. Scope deletion has an inclusive cutoff strictly before the control's sequence.
Validation and limits
The validator accepts plain inert JSON data with closed schemas. It copies records, normalizes negative zero and freezes the result, including replacement data. Identifiers are case-sensitive ASCII with at most 128 characters; reason codes are nonempty strings of at most 256 UTF-16 code units. Sequences are nonnegative safe integers, timestamps are bounded integer milliseconds, and hints and ladder values range from zero to 1000.
A scope may contain at most 20,000 raw entries, 10,000 distinct events and 1,000 distinct concepts. The aggregate limit of four million UTF-16 code units counts string values in raw entries, including duplicates and nested replacement evidence. Closed event shapes bound nesting depth.
Events with identical canonical content collapse to their first occurrence, regardless of object key order. Reusing an event ID for different content, or assigning the same sequence to different event IDs, returns a typed failure. The returned array is not necessarily in chronological order.
Validation does not resolve credit targets or correction chains, apply deletion controls or handle future events. Replay checks credited decision target integrity, resolves chains and deletion semantics, and handles future events. Missing deletion targets remain valid tombstones.
Your application must authenticate evidence and supply the complete relevant history. Validation and reconciliation cannot establish either of those properties. The application also owns evidence admission, durable sequencing, authorization, storage and physical erasure. Bound serialized inputs before materializing them; the validator is not a sandbox for proxies or hostile JavaScript.
For error codes and numeric bounds, see contracts.