Due ranking
Rank due concepts using weighted features and concept relations.
Call scheduleDue(policy, scopeId, review, nowMs, relations?, limit?) with a successful rebuild or advance value and the same explicit clock, scope and complete policy. The review carries one scope-level identity; concept entries may be in any order, but must be unique. A stale clock or changed policy requires a fresh rebuild. The operation does not replay or authenticate the history.
import { rebuildReview, scheduleDue } from "@0xbuff/retention";
const review = rebuildReview(policy, scopeId, events, nowMs);
if (review.ok) {
const due = scheduleDue(policy, scopeId, review.value, nowMs, [], 10);
if (due.ok) {
// Present due.value to the learner.
}
}Only concepts whose due time is at or before the clock are selected. Each recommendation contains its concept ID, due time, recommendation kind, integer score, four features and fixed numeric reasons in feature order:
| Feature | Value |
|---|---|
| overdue | Whole elapsed days overdue, capped at 3650 |
| support | 1 if support is needed; otherwise 0 |
| relation | Distinct related due concepts, capped at 1000 |
| stage | Stage index plus one, or 0 before a stage |
The score is the sum of each feature multiplied by its policy weight. For example, a support feature of 1 with a support weight of 10 adds 10 points. Omitting priority gives all four weights zero. Results sort by descending score, ascending due time, then ascending ASCII concept ID. The optional limit (0 to 1000) applies after ranking. Omit it to return all due concepts.
A relation has kind (prerequisite or confusable), fromConceptId and toConceptId. A prerequisite points from prerequisite to dependent and only counts outgoing due dependents. A confusable pair counts in both directions. Duplicate edges and reversed confusable pairs count once; overlapping relation kinds do not double-count a neighbor. All endpoints must be present in the review, including non-due concepts. Self-relations and directed prerequisite cycles are rejected; confusable cycles are valid. At most 10,000 raw relations are accepted. The policy, scope, review and raw relations share a 4,000,000 UTF-16 code-unit budget for ordinary string values, including duplicate relation entries. Derived policy identity and watermark encodings retain separate size bounds.
Relations affect only the ranking. A prerequisite relation does not block review or change eligibility. Retention validates every input even when the limit is zero. Support and recommendation kinds must agree with the supplied scheduling policy and projection state. Malformed or incompatible inputs produce a typed failure without a partial queue. The host remains responsible for trustworthy current projections, history completeness, authorization, stale-generation rejection and delivery.
Example
// retention-docs: runnable
import { rebuildReview, scheduleDue } from "@0xbuff/retention";
const day = 86_400_000;
const policy = {
schemaVersion: 1,
algorithmVersion: "1",
policyId: "deck",
policyVersion: "v1",
scheduling: {
intervalsDays: [1, 3, 7],
retryDays: 1,
maintenanceDays: 30,
supportAfterMisses: 2,
longProbeAction: "restart",
dateArithmetic: "elapsed_milliseconds",
},
};
const event = {
schemaVersion: 1,
kind: "practice_observation",
scopeId: "deck",
conceptId: "binary-search",
eventId: "review-1",
sequence: 0,
atMs: 0,
sessionId: "session-1",
outcome: "pass",
};
function value(result) {
if (!result.ok) throw new Error(JSON.stringify(result.errors));
return result.value;
}
const weighted = { ...policy, priority: { overdue: 2, support: 0, relation: 5, stage: 0 } };
const other = { ...event, conceptId: "sorting", eventId: "other", sequence: 1 };
const review = value(rebuildReview(weighted, "deck", [event, other], day));
const due = value(scheduleDue(weighted, "deck", review, day, [
{ kind: "prerequisite", fromConceptId: "binary-search", toConceptId: "sorting" },
]));
console.log(due.map(item => item.conceptId + ":" + item.score).join(" "));Expected output:
binary-search:5 sorting:0