Retention

Retention is a review-scheduling engine for learning applications. It uses past learning observations and a review policy to decide what is due, when to revisit it and when to recommend further practice.
Use it in a flashcard app, to revisit mathematical concepts or to reinforce programming skills. Retention works without a server, database, model provider or account. Applications retain ownership of their learning records and assessment decisions.
Retention has no runtime dependencies. The first release candidate is @0xbuff/retention@0.0.1. Registry publication is subject to maintainer approval.
Installation
Use Node.js 24 or later and ESM. After publication, install from npm:
npm install @0xbuff/retention@0.0.1
Before publication, install the verified candidate tarball with npm install /path/to/0xbuff-retention-0.0.1.tgz.
Quick start
Schedule a flashcard from a successful practice observation. Supply your own policy and clock; the example uses a fixed clock one day after the observation.
import {
rebuildReview,
scheduleDue,
type Policy,
type PracticeObservation,
} from "@0xbuff/retention";
const day = 86_400_000;
const policy: Policy = {
schemaVersion: 1,
algorithmVersion: "1",
policyId: "flashcards",
policyVersion: "v1",
scheduling: {
intervalsDays: [1, 3, 7],
retryDays: 1,
maintenanceDays: 30,
supportAfterMisses: 2,
longProbeAction: "restart",
dateArithmetic: "elapsed_milliseconds",
},
};
const event: PracticeObservation = {
schemaVersion: 1,
scopeId: "deck",
eventId: "review-1",
sequence: 0,
atMs: 0,
kind: "practice_observation",
conceptId: "binary-search",
sessionId: "session-1",
outcome: "pass",
};
const review = rebuildReview(policy, "deck", [event], day);
if (!review.ok) {
throw new Error("Review failed");
}
const due = scheduleDue(policy, "deck", review.value, day);
if (!due.ok || due.value[0]?.dueAtMs !== day) {
throw new Error("Expected a due review");
}
console.log(due.value);
The recommendation is due exactly one day after the observation. The application can present the queue without granting credit or changing the learner's official records.
How it works
Suppose a learner successfully recalls a concept on Monday. A review policy can schedule the next attempt for Tuesday, then increase the interval after each successful review. If the learner struggles, the policy can schedule an earlier retry or recommend additional practice.
For example, with intervals of 1, 3, 7, 16 and 35 elapsed days, a learner who passes each review when due follows this schedule:
| Retrieval succeeds on |
Next review |
| Day 0 |
Day 1 |
| Day 1 |
Day 4 |
| Day 4 |
Day 11 |
| Day 11 |
Day 27 |
| Day 27 |
Day 62 |
| Day 62 |
After the configured maintenance interval |
Practicing early does not advance an existing interval. A missed review follows the configured retry, restart and support rules. Choose intervals and maintenance rules appropriate to the material. This example is not a universal learning standard.
Capabilities
- Configurable spaced retrieval, retry intervals and maintenance reviews.
- Support recommendations and delayed retrieval probes.
- Due-review ranking across concepts, with optional priority weights and relationships.
- Elapsed-time or local-calendar scheduling using explicit timezone rules.
- Replay of duplicated, reordered, corrected, revoked or deleted observations.
- Optional advisory readiness based on independently admitted evidence.
Given the same validated history, policy, algorithm revision and clock, Retention produces the same result. Retention does not inspect answers, authenticate learners, issue grades, certify mastery or deliver notifications.
Architecture
The application records practice, supplies a policy and calls Retention with an explicit clock. Retention reconciles the history and calculates review projections. The application decides how to present and store the results.
flowchart LR
H["History, policy, clock"] --> R["Reconcile"]
R --> S["Schedule and rank"]
R --> C["Optional readiness"]
S --> A["Application"]
C --> A
Replay
Review histories can arrive out of order. An application may also need to correct a previous result or remove a learner's data. Retention validates the scope, schema and limits, then uses stable event identities and a durable sequence to reconcile corrections, revocations and deletions. It orders surviving observations and excludes future observations before rebuilding the practice and optional candidate projections. Invalid inputs return typed errors.
flowchart LR
H["Scoped history"] --> V["Validate and deduplicate"]
V --> C["Apply lifecycle controls"]
C --> R["Replay active observations"]
Identical duplicate events have no effect. Conflicting identities and invalid correction chains produce typed failures. A correction replaces the original observation and contributes no extra success. Deletion controls suppress affected history during replay; the application remains responsible for physical erasure and preventing obsolete histories from returning.
Full replay is the reference calculation. The advance operation verifies the previous projection identity and complete event prefix before rebuilding. Policy changes require explicit replay.
Readiness and evidence
Practice observations and admitted evidence can influence due dates and support recommendations. Only host-admitted evidence enters the separate advisory readiness calculation under an eligibility policy.
flowchart LR
P["Practice"] --> S["Review schedule"]
E["Admitted evidence"] --> S
E --> C["Eligible-only readiness"]
K["Eligibility policy"] --> C
An eligibility policy might require three fresh successes in at least two sessions over a minimum span of 24 hours. Only qualifying admitted observations start and extend that streak. A local study tool can omit this policy entirely.
Retention cannot establish whether evidence is authentic. The application admits evidence and makes any official assessment or credit decision independently.
API
| Operation |
Purpose |
validatePolicy |
validate scheduling and optional eligibility policy. |
validateEvents |
validate scoped events and detect identity conflicts. |
rebuildReview |
Reconstruct review projections from complete history. |
advanceReview |
Verify the prior identity and event prefix, then rebuild with new events. |
evaluateReadiness |
Calculate advisory readiness from reconciled eligible evidence. |
scheduleDue |
Select and rank due concepts. |
explainReview |
Return structured reasons for a recommendation. |
See due ranking, policy validation, event validation and replay and readiness for implemented behavior and limitations.
The review scheduling specification defines the event schemas, policy fields, transition rules, resource limits and error behavior.
Documentation
See the documentation homepage and the repository guides for API usage, integration and release verification.
Development
Install Node.js 24+ and pnpm 11.2.2, then run:
corepack enable
pnpm install --frozen-lockfile
pnpm check
The check covers architecture, TypeScript, Biome, Vitest, distribution verification and independent offline package installation. CI also exercises the packed library in Chromium. See development, contributing and the security policy.
See the source architecture for the repository layout, module dependencies, build configuration and testing conventions. The implementation tickets track progress toward the first release, including independent Node.js and browser consumer checks.
To contribute before the first release, review the architecture decision and implementation plan, then use the repository's issue tracker for questions or proposed changes.
License
Licensed under Apache-2.0. See source rights for provenance and publication requirements.