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 composed memory drills runnable (#3254)

[._.]/ Adam Eivy8a4463d74d1c
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsx
index b22c53c395..c56c02bcdc 100644
--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx
+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx
@@ -4,7 +4,7 @@ import { Zap, History, Settings, Play, Brain, BookOpen, Dumbbell, Timer, Radio,
import { getProviders, getPostReviewReps, getPostRecommendations, getMorseProgress, getPostProgress, getMemoryItems } from '../../../services/api';
import { FormField } from '../../ui/FormField';
import { isApiProvider } from '../../../utils/providers';
-import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, computeDomainAverages, computeGoalProgress, isTopicEnabled, resolveTopicForDrillType } from './constants';
+import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, computeDomainAverages, computeGoalProgress, isTopicEnabled, memoryItemSupportsDrill, resolveTopicForDrillType } from './constants';
import { streakGlyph } from '../../../lib/streakGlyph.js';
import useUserTimezone from '../../../hooks/useUserTimezone.js';
import { todayKeyInTimezone } from '../../../utils/timezone.js';
@@ -183,12 +183,14 @@ export default function PostSessionLauncher({ config, recentSessions, stats, sta
? Object.entries(config.cognitive?.drillTypes || {}).filter(([type, cfg]) => cfg.enabled !== false && topicAllowed(type))
: [];
- const hasEnabledMemoryItem = memoryItemsState.status === 'ready'
- && memoryItemsState.items.some(item => config.memory?.items?.[item.id]?.enabled !== false);
- const enabledMemoryDrills = config.memory?.enabled !== false && hasEnabledMemoryItem
+ const enabledMemoryItems = memoryItemsState.status === 'ready'
+ ? memoryItemsState.items.filter(item => config.memory?.items?.[item.id]?.enabled !== false)
+ : [];
+ const enabledMemoryDrills = config.memory?.enabled !== false && enabledMemoryItems.length > 0
? DOMAINS.memory.drillTypes
.map(type => [type, config.memory?.drillTypes?.[type]])
- .filter(([type, cfg]) => cfg && cfg.enabled !== false && topicAllowed(type))
+ .filter(([type, cfg]) => cfg && cfg.enabled !== false && topicAllowed(type)
+ && enabledMemoryItems.some(item => memoryItemSupportsDrill(item, type)))
: [];
// Only the fields each cognitive generator reads; extras are harmless.
@@ -265,7 +267,10 @@ export default function PostSessionLauncher({ config, recentSessions, stats, sta
const memoryConfigs = (moduleAllowed('memory') ? enabledMemoryDrills : []).map(([type, cfg]) => ({
type,
domain: 'memory',
- config: { count: cfg.count },
+ config: {
+ count: cfg.count,
+ ...(type === 'memory-element-flash' && { memoryItemId: 'elements-song' }),
+ },
timeLimitSec: DOMAINS.memory.timeBudgetSec,
}));
@@ -341,7 +346,10 @@ export default function PostSessionLauncher({ config, recentSessions, stats, sta
// Keep the drill short for a balanced 5-minute session.
quickConfig = { ...cognitiveDrillConfig(cfg), count: cfg.count ? Math.min(cfg.count, 10) : undefined };
} else {
- quickConfig = { count: Math.min(cfg.count || 5, 3) }; // Fewer prompts for quick session
+ quickConfig = {
+ count: Math.min(cfg.count || 5, 3),
+ ...(pick.type === 'memory-element-flash' && { memoryItemId: 'elements-song' }),
+ }; // Fewer prompts for quick session
}
const drillConfig = {
@@ -397,7 +405,10 @@ export default function PostSessionLauncher({ config, recentSessions, stats, sta
} else if (source === 'cognitive') {
focusConfig = cognitiveDrillConfig(cfg);
} else {
- focusConfig = { count: cfg.count || 5 };
+ focusConfig = {
+ count: cfg.count || 5,
+ ...(type === 'memory-element-flash' && { memoryItemId: 'elements-song' }),
+ };
}
const drillConfig = {
type,
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
index be6c52ff7c..cc4e705581 100644
--- a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
+++ b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
@@ -682,4 +682,44 @@ describe('PostSessionLauncher composed memory drills (issue #3254)', () => {
fireEvent.click(screen.getByText('Full POST'));
expect(onStart.mock.calls[0][0].some(d => d.domain === 'memory')).toBe(false);
});
+
+ it('omits Element Flash when the built-in elements item is unavailable', async () => {
+ const onStart = vi.fn();
+ getMemoryItems.mockResolvedValue([{ id: 'example-memory', mastery: { overallPct: 0 } }]);
+ renderWith(memoryConfig({
+ memory: {
+ enabled: true,
+ drillTypes: { 'memory-element-flash': { enabled: true, count: 6 } },
+ items: {},
+ },
+ }), onStart);
+ await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());
+
+ fireEvent.click(screen.getByText('Full POST'));
+ expect(onStart.mock.calls[0][0].some(d => d.type === 'memory-element-flash')).toBe(false);
+ });
+
+ it('pins Element Flash to the compatible elements item', async () => {
+ const onStart = vi.fn();
+ getMemoryItems.mockResolvedValue([
+ { id: 'example-memory', mastery: { overallPct: 0 } },
+ { id: 'elements-song', mastery: { overallPct: 90 } },
+ ]);
+ renderWith(memoryConfig({
+ memory: {
+ enabled: true,
+ drillTypes: { 'memory-element-flash': { enabled: true, count: 6 } },
+ items: {},
+ },
+ }), onStart);
+ await waitFor(() => expect(getMemoryItems).toHaveBeenCalled());
+
+ fireEvent.click(screen.getByText('Full POST'));
+ expect(onStart.mock.calls[0][0]).toEqual(expect.arrayContaining([
+ expect.objectContaining({
+ type: 'memory-element-flash',
+ config: { count: 6, memoryItemId: 'elements-song' },
+ }),
+ ]));
+ });
});
diff --git a/client/src/components/meatspace/post/PracticePlan.jsx b/client/src/components/meatspace/post/PracticePlan.jsx
index 2e8a52a23a..e57aface1b 100644
--- a/client/src/components/meatspace/post/PracticePlan.jsx
+++ b/client/src/components/meatspace/post/PracticePlan.jsx
@@ -116,7 +116,9 @@ export default function PracticePlan({ config, onSaved, onBack }) {
memory: { ...config?.memory, ...modules.memory, enabled: memoryOn, items: memoryItemFlags },
};
- const preview = composedSessionDrillTypes(draftConfig);
+ // Until the item list resolves, fail closed for Memory just like the launcher.
+ // This also keeps incompatible/unsupported memory drills out of the summary.
+ const preview = composedSessionDrillTypes(draftConfig, memoryItems || []);
const previewTopicIds = Object.keys(preview);
// Standalone topics still shape the daily rotation (they drive "Up next"
diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.js
index 472b3a1f16..906e8d50ad 100644
--- a/client/src/components/meatspace/post/constants.js
+++ b/client/src/components/meatspace/post/constants.js
@@ -15,6 +15,13 @@ export const COGNITIVE_DRILL_TYPES = ['n-back', 'digit-span', 'stroop', 'schulte
// isn't one of the types PostSessionLauncher offers to pick from yet.
export const POST_UNSUPPORTED_DRILL_TYPES = ['memory-fill-blank'];
+// Element Flash is backed by the built-in periodic-table item. Other memory
+// drills can use any enabled memorized text, but selecting a custom item for
+// Element Flash makes the server generator return null.
+export function memoryItemSupportsDrill(item, drillType) {
+ return drillType !== 'memory-element-flash' || item?.id === 'elements-song';
+}
+
// The four wordplay drill types with a dedicated standalone trainer
// (WordplayTrainer.jsx) that shares its render+scoring core (WordplayDrillUI.jsx)
// with the in-session runner (PostLlmDrillRunner.jsx) — see issue #2097.
@@ -210,9 +217,11 @@ export function isModuleInSession(config, module) {
* same reason the launcher does: a drill type absent from the config was never
* offered by the launcher either, so the preview must not invent it. Math drills
* are opt-IN (`enabled` truthy) while LLM/cognitive/memory are opt-OUT
- * (`enabled !== false`) — again matching the launcher exactly.
+ * (`enabled !== false`) — again matching the launcher exactly. When the loaded
+ * memory item list is supplied, memory drills also require a compatible enabled
+ * item, and drill types the session runner does not expose are always omitted.
*/
-export function composedSessionDrillTypes(config) {
+export function composedSessionDrillTypes(config, memoryItems = null) {
const out = {};
for (const topic of POST_TOPICS) {
if (topic.surface !== 'session' || !topic.module) continue;
@@ -221,9 +230,13 @@ export function composedSessionDrillTypes(config) {
const mod = config?.[MODULE_CONFIG_KEY[topic.module]];
if (!mod || mod.enabled === false) continue;
const types = topic.drillTypes.filter((t) => {
+ if (POST_UNSUPPORTED_DRILL_TYPES.includes(t)) return false;
const cfg = mod.drillTypes?.[t];
if (!cfg) return false;
- return topic.module === 'mental-math' ? !!cfg.enabled : cfg.enabled !== false;
+ const enabled = topic.module === 'mental-math' ? !!cfg.enabled : cfg.enabled !== false;
+ if (!enabled) return false;
+ if (topic.module !== 'memory' || !Array.isArray(memoryItems)) return true;
+ return memoryItems.some(item => isMemoryItemEnabled(config, item.id) && memoryItemSupportsDrill(item, t));
});
if (types.length) out[topic.id] = types;
}
diff --git a/client/src/components/meatspace/post/constants.test.js b/client/src/components/meatspace/post/constants.test.js
index 5305ac80d6..cf5c82fcc4 100644
--- a/client/src/components/meatspace/post/constants.test.js
+++ b/client/src/components/meatspace/post/constants.test.js
@@ -186,6 +186,26 @@ describe('composedSessionDrillTypes (issue #3252)', () => {
expect(out.memory).toEqual(['memory-sequence']);
expect(out.morse).toBeUndefined();
});
+
+ it('previews only memory drills runnable with the enabled item pool', () => {
+ const memoryConfig = {
+ memory: {
+ enabled: true,
+ drillTypes: {
+ 'memory-fill-blank': { enabled: true },
+ 'memory-sequence': { enabled: true },
+ 'memory-element-flash': { enabled: true },
+ },
+ items: { 'elements-song': { enabled: false } },
+ },
+ };
+
+ expect(composedSessionDrillTypes(memoryConfig, [
+ { id: 'elements-song' },
+ { id: 'example-memory' },
+ ])).toEqual({ memory: ['memory-sequence'] });
+ expect(composedSessionDrillTypes(memoryConfig, [])).toEqual({});
+ });
});
describe('isTopicEnabled / isMemoryItemEnabled client mirrors', () => {
diff --git a/server/lib/README.md b/server/lib/README.md
index fb18b7af1f..e463136f13 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -252,7 +252,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `postMultiplicationLadder.js` | Pure progressive multiplication ladder — mastery-gated difficulty rungs (`[1,1]` → `[1,2]` → `[1,1,1]` → …). Resolves the user's current level from per-level speed+accuracy stats so the plain multiplication drill ramps up instead of starting at a fixed hard difficulty. On by default. Built on `postProgression.js`. |
| `postPowersLadder.js` | Pure technique-anchored Powers ladder — cumulative named-method pools, full supported-pair registry, and speed+accuracy mastery progression built on `postProgression.js`. |
| `postProgression.js` | Generic mastery-gated progression ladder (extracted from `postMultiplicationLadder.js`) — `createProgression({ levels, describeLevel, speedTargetForLevel? })` resolves a user's current rung from per-level stats with an anti-demotion floor. Also defines the cognitive-drill ladders (n-back / digit-span / schulte / mental-rotation / stroop) and their level→generator-config mapping. |
-| `postTopics.js` | Pure POST practice-topic registry — `POST_TOPICS` (`{ id, label, module, surface, drillTypes }`) is the single source of truth for "what am I studying?", plus `resolveTopicForDrillType` / `isTopicEnabled` / `isMemoryItemEnabled`. Gates session composition and recommendations, incl. the standalone Memory and Morse surfaces. Mirrored to the client's post `constants.js` (parity test). |
+| `postTopics.js` | Pure POST practice-topic registry — `POST_TOPICS` (`{ id, label, module, surface, drillTypes }`) is the single source of truth for "what am I studying?", plus `resolveTopicForDrillType` / `isTopicEnabled` / `isMemoryItemEnabled`. Gates session composition and recommendations, including Memory's composed and dedicated practice routes plus standalone Morse. Mirrored to the client's post `constants.js` (parity test). |
| `postStreak.js` | Pure DST-safe POST practice-streak math — the single `computePostStreaks` implementation shared by scored sessions and the training log, plus `computeUnifiedStreak` (a day is active with EITHER a session or a practice entry). |
| `planIds.js` | Utilities for PLAN.md `[slug]` IDs. |
| `renderSlot.js` | Render-slot helpers for `(proof\|final)Image` per stage. |
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index 25bb53798f..1bf809f77a 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -1181,10 +1181,10 @@ function recModuleForDrillType(type, fallback) {
*
* Three gates, checked in order (issue #3252):
* 1. The drill's practice TOPIC — off means off everywhere, including the
- * standalone surfaces (Memory, Morse) that session composition never gated.
- * 2. Module-specific participation — `memory` and `morse` run from their own
- * tabs, so `sessionModules` doesn't apply to them; memory additionally
- * honors the per-ITEM toggle when the caller knows which item is involved.
+ * dedicated Memory and Morse practice routes.
+ * 2. Recommendation-specific participation — memory due-item recommendations
+ * deep-link to dedicated practice, so `sessionModules` doesn't apply;
+ * memory still honors the per-ITEM toggle when the caller knows the item.
* 3. Session composition + the per-module/per-drill `enabled` flags.
*
* `memoryItemId` is only meaningful for `module === 'memory'`; absent means