Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep due POST recommendations out of the Quick-session recency rotation (#5319)

[._.]/ Adam Eivyffcf13efebfa
diff --git a/client/src/lib/postQuickSession.js b/client/src/lib/postQuickSession.js
index b3806682ba..f080ebb401 100644
--- a/client/src/lib/postQuickSession.js
+++ b/client/src/lib/postQuickSession.js
@@ -159,18 +159,36 @@ function recentPracticeMatcher({ drillTypes = [], memoryItemIds = [] } = {}) {
);
}
+// Recommendation kinds whose priority is SCHEDULE-driven, not heuristic. The
+// server deliberately keeps these outside the multi-day recency window (a
+// genuinely due item wins the top slot even if practiced yesterday), so the
+// client must not re-apply that window to them either — rotating away from a
+// due item is exactly the spaced-repetition miss the schedule exists to prevent.
+const SCHEDULED_RECOMMENDATION_KINDS = new Set(['memory-due', 'skill-review']);
+
function candidateForDomain(domain, drills, recommendation, memoryItemIds = {}, { dayKey = null, isRecent = () => false } = {}) {
const list = drills || [];
if (!list.length) return null;
- const memoryItemIdFor = drill => drill.memoryItemId ?? memoryItemIds[drill.type];
+ // A memory recommendation names the ITEM it wants practiced; honor that over
+ // the domain drill's configured default, or Quick "satisfies" a due rec by
+ // running a different item entirely.
+ const memoryItemIdFor = drill => (
+ (drill.type === recommendation?.drillType && recommendation?.memoryItemId)
+ || drill.memoryItemId
+ || memoryItemIds[drill.type]
+ || undefined
+ );
const recentDrill = drill => isRecent(drill, memoryItemIdFor(drill));
const recommended = recommendation?.drillType
? list.find(drill => drill.type === recommendation.drillType)
: null;
- // The recommendation wins its domain only while it is still fresh. Once it
- // has been practiced inside the window, this domain rotates to another
- // enabled candidate instead of re-serving registry-order `list[0]`.
- const pick = (recommended && !recentDrill(recommended))
+ // A heuristic recommendation wins its domain only while it is still fresh —
+ // once practiced inside the window this domain rotates to another enabled
+ // candidate instead of re-serving registry-order `list[0]`. A scheduled one
+ // always wins, whatever the window says.
+ const recommendedWins = recommended
+ && (SCHEDULED_RECOMMENDATION_KINDS.has(recommendation.kind) || !recentDrill(recommended));
+ const pick = recommendedWins
? recommended
: orderByRecencyRotation(list, { dayKey, isRecent: recentDrill })[0];
const quickConfig = pick.quickConfig || buildQuickDrillConfig({
diff --git a/client/src/lib/postQuickSession.test.js b/client/src/lib/postQuickSession.test.js
index 2b5ee77f4b..56f7f0f157 100644
--- a/client/src/lib/postQuickSession.test.js
+++ b/client/src/lib/postQuickSession.test.js
@@ -119,6 +119,32 @@ describe('postQuickSession', () => {
expect(plan.selected.map(c => c.type)).toEqual(["n-back"]);
});
+ const memoryPick = (recommendation, drillItemId) => composeQuickSession({
+ durationMinutes: 15,
+ domainEntries: [{ domain: "memory", drills: [
+ { type: "memory-fill-blank", source: "memory", cfg: { count: 3 }, memoryItemId: "example-poem" },
+ { type: "memory-sequence", source: "memory", cfg: { count: 3 }, memoryItemId: drillItemId },
+ ] }],
+ recommendation,
+ recentPractice: { dayKey: "2026-03-02", drillTypes: ["memory-sequence"], memoryItemIds: ["elements-song"] },
+ }).selected.find(candidate => candidate.domain === "memory");
+
+ it("never rotates away from a SCHEDULE-driven recommendation, even one practiced yesterday", () => {
+ // The server keeps due memory items and due reviews outside the recency
+ // window on purpose — re-applying it here would skip the very item spaced
+ // repetition just brought up. A heuristic rec for the same drill DOES
+ // rotate away, which is what makes the kind gate load-bearing.
+ const forDue = { kind: "memory-due", drillType: "memory-sequence", memoryItemId: "elements-song" };
+ const forWeak = { kind: "weak-skill", drillType: "memory-sequence" };
+ expect(memoryPick(forDue, "elements-song").type).toBe("memory-sequence");
+ expect(memoryPick(forWeak, "elements-song").type).toBe("memory-fill-blank");
+ });
+
+ it("practices the ITEM a memory recommendation named, not the drill's configured default", () => {
+ const forDue = { kind: "memory-due", drillType: "memory-sequence", memoryItemId: "elements-song" };
+ expect(memoryPick(forDue, "example-poem").quickConfig.memoryItemId).toBe("elements-song");
+ });
+
it("identifies a memory drill by its ITEM, so practicing one item does not sink the others", () => {
const memoryDomain = [{ domain: "memory", drills: [
{ type: "memory-sequence", source: "memory", cfg: { count: 3 }, memoryItemId: "elements-song" },