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: wait for the ladder rung instead of flashing the stored knobs, and narrow the fetch gate

[._.]/ Adam Eivyf35449224ae5
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
index 11adcfd39d..1b1baedf2a 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
@@ -1,6 +1,6 @@
import { useState, useEffect, useRef, useCallback } from 'react';
import { Brain, Check, X, BookOpen, Play } from 'lucide-react';
-import { DRILL_LABELS, nBackBalancedAccuracy } from './constants';
+import { DRILL_LABELS, nBackBalancedAccuracy, effectiveCognitiveDrillConfig, cognitiveRungPending } from './constants';
import { safeReadJsonStorage, safeWriteStorage } from '../../../lib/safeStorage.js';
import useMounted from '../../../hooks/useMounted';
import useKeyCapture from '../../../hooks/useKeyCapture';
@@ -128,6 +128,17 @@ export function hasDrillTutorial(type) {
return getDrillTutorial({ type }) != null;
}
+/**
+ * Drill types whose how-to copy actually VARIES with the drill config — the
+ * n-back lag, the digit-span recall direction, the reaction-time mode. Only
+ * these need the effective (ladder) config resolved before the card can be
+ * shown; every other card reads the same at any difficulty, so it opens
+ * immediately. Guarded by a property test that probes `getDrillTutorial` with
+ * two configs, so a new config-dependent branch can't be added without landing
+ * on this list.
+ */
+export const CONFIG_DEPENDENT_TUTORIAL_TYPES = ['n-back', 'digit-span', 'reaction-time'];
+
// Per-type how-to content. A pure function of the drill so config-dependent
// copy (n-back lag, digit-span direction, reaction-time mode) reads correctly.
// Returns null for types with no tutorial (which skip the gate entirely).
@@ -329,10 +340,28 @@ function CognitiveDrillTutorial({ drill, tut, header = null, onAction, actionLab
* `drill` may be null (nothing selected) or a type with no tutorial — both
* render nothing, so callers can pass state straight through.
*/
-export function CognitiveDrillTutorialPreview({ drill, onClose }) {
+export function CognitiveDrillTutorialPreview({ type, drillConfig, cognitiveProgress, onClose }) {
+ // Both the effective config and the "can we show it yet?" question are decided
+ // HERE, not at each call site: the two surfaces would otherwise each carry
+ // (and each get to drift on) the same three-way derivation.
+ const drill = type ? { type, config: effectiveCognitiveDrillConfig(drillConfig, cognitiveProgress?.[type]) } : null;
const tut = drill ? getDrillTutorial(drill) : null;
if (!tut) return null;
- const label = DRILL_LABELS[drill.type] || drill.type;
+ const label = DRILL_LABELS[type] || type;
+ const pending = CONFIG_DEPENDENT_TUTORIAL_TYPES.includes(type)
+ && cognitiveRungPending(type, drillConfig, cognitiveProgress);
+ if (pending) {
+ // The rung that decides this drill's lag / recall direction hasn't loaded.
+ // Waiting beats rendering the stored knobs, which would state one rule and
+ // then swap it for another mid-read.
+ return (
+ <Modal open onClose={onClose} size="md" usePortal ariaLabel={`How ${label} works`}>
+ <div className="bg-port-card border border-port-border rounded-xl p-5 text-center text-sm text-gray-400" role="status">
+ Resolving your current {label} difficulty…
+ </div>
+ </Modal>
+ );
+ }
return (
// `usePortal` per the overlay convention in client/src/CLAUDE.md: this is
// rendered mid-tree inside two long settings/launcher pages, and a
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
index 7ca0016c41..e349ce0e53 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx
@@ -20,7 +20,10 @@ import PostCognitiveDrillRunner, {
markDrillTutorialSeen,
buildNBackExample,
CognitiveDrillTutorialPreview,
+ CONFIG_DEPENDENT_TUTORIAL_TYPES,
+ hasDrillTutorial,
} from './PostCognitiveDrillRunner';
+import { COGNITIVE_DRILL_TYPES } from './constants';
// Result-assembly tests for PostCognitiveDrillRunner's `finish()` builders.
// The server rescores each drill deterministically from `drillData`/`questions`
@@ -668,6 +671,25 @@ describe('first-run tutorial gate', () => {
});
});
+// Property guard for CONFIG_DEPENDENT_TUTORIAL_TYPES (issue #4732): the preview
+// waits for the ladder rung only for the types on that list, so a new
+// config-dependent branch in `getDrillTutorial` that ISN'T listed would silently
+// go back to describing the stored knobs. Probing the real function beats
+// re-listing the types by hand — the test can't drift from the code it guards.
+describe('CONFIG_DEPENDENT_TUTORIAL_TYPES', () => {
+ // Every knob any cognitive ladder or drill config can move, at two distinct
+ // values — if the copy reads ANY of them, one of these pairs shifts it.
+ const CONFIG_A = { n: 1, direction: 'forward', mode: 'simple', startLength: 4, maxLength: 6, size: 4, incongruentPct: 10, optionCount: 3, stimulusMs: 2500, ruleCount: 2, switchRatePct: 10, noGoPct: 10, lureSimilarity: 'low', congruentPct: 10, flankerStrength: 1, count: 5 };
+ const CONFIG_B = { n: 3, direction: 'backward', mode: 'choice', startLength: 6, maxLength: 9, size: 6, incongruentPct: 90, optionCount: 4, stimulusMs: 1600, ruleCount: 3, switchRatePct: 90, noGoPct: 90, lureSimilarity: 'high', congruentPct: 90, flankerStrength: 3, count: 20 };
+
+ it('lists exactly the drill types whose how-to copy changes with config', () => {
+ const varies = COGNITIVE_DRILL_TYPES.filter(type => hasDrillTutorial(type)
+ && JSON.stringify(getDrillTutorial({ type, config: CONFIG_A }))
+ !== JSON.stringify(getDrillTutorial({ type, config: CONFIG_B })));
+ expect(varies.sort()).toEqual([...CONFIG_DEPENDENT_TUTORIAL_TYPES].sort());
+ });
+});
+
// Standalone how-to preview (issue #4732) — the way back to a tutorial card the
// one-shot first-run gate has already been spent on. The load-bearing property
// is that it renders the SAME body with NO runner behind it, so nothing is
@@ -677,7 +699,7 @@ describe('CognitiveDrillTutorialPreview', () => {
afterEach(() => window.localStorage.clear());
it('renders the how-to card, including the n-back worked example, with no runner mounted', () => {
- render(<CognitiveDrillTutorialPreview drill={{ type: 'n-back', config: { n: 3 } }} onClose={vi.fn()} />);
+ render(<CognitiveDrillTutorialPreview type="n-back" drillConfig={{ n: 3, progressive: false }} onClose={vi.fn()} />);
expect(screen.getByText(/catch when one repeats from 3 steps earlier/i)).toBeInTheDocument();
// The worked example strip — the whole reason the card needs to stay reachable.
const example = screen.getByRole('list', { name: /example letter stream/i });
@@ -689,32 +711,67 @@ describe('CognitiveDrillTutorialPreview', () => {
});
it('does not consume the first-run gate for the type it previewed', () => {
- render(<CognitiveDrillTutorialPreview drill={{ type: 'stroop', config: {} }} onClose={vi.fn()} />);
+ render(<CognitiveDrillTutorialPreview type="stroop" drillConfig={{}} onClose={vi.fn()} />);
expect(screen.getByRole('button', { name: /got it/i })).toBeInTheDocument();
expect(hasSeenDrillTutorial('stroop')).toBe(false);
});
it('closes on "Got it"', () => {
const onClose = vi.fn();
- render(<CognitiveDrillTutorialPreview drill={{ type: 'flanker', config: {} }} onClose={onClose} />);
+ render(<CognitiveDrillTutorialPreview type="flanker" drillConfig={{}} onClose={onClose} />);
fireEvent.click(screen.getByRole('button', { name: /got it/i }));
expect(onClose).toHaveBeenCalledTimes(1);
});
+ it('waits for the ladder rung rather than showing the stored knobs first', () => {
+ // Laddered + progressive (the default) + progress not loaded (`null` = not
+ // fetched). Rendering the card now would state a lag that changes under the
+ // reader a moment later.
+ render(<CognitiveDrillTutorialPreview type="n-back" drillConfig={{ n: 1 }} cognitiveProgress={null} onClose={vi.fn()} />);
+ expect(screen.getByRole('status')).toHaveTextContent(/resolving your current n-back difficulty/i);
+ expect(screen.queryByText(/repeats from 1 step earlier/i)).toBeNull();
+ });
+
+ it('shows the card immediately once the rung has resolved', () => {
+ render(<CognitiveDrillTutorialPreview
+ type="n-back"
+ drillConfig={{ n: 1 }}
+ cognitiveProgress={{ 'n-back': { config: { n: 3 } } }}
+ onClose={vi.fn()}
+ />);
+ expect(screen.getByText(/catch when one repeats from 3 steps earlier/i)).toBeInTheDocument();
+ });
+
+ it('falls back to the stored knobs when the rung fetch came back empty, rather than hanging', () => {
+ // `{}` = fetched-or-failed. The card is the best available answer; waiting
+ // forever on a rung that is never coming is not.
+ render(<CognitiveDrillTutorialPreview type="n-back" drillConfig={{ n: 1 }} cognitiveProgress={{}} onClose={vi.fn()} />);
+ expect(screen.getByText(/catch when one repeats from 1 step earlier/i)).toBeInTheDocument();
+ expect(screen.queryByText(/resolving your current/i)).toBeNull();
+ });
+
+ it('opens a config-independent card straight away, with no rung to wait for', () => {
+ // Flanker is laddered, but its copy never mentions a config value — making it
+ // wait would be a spinner for nothing.
+ render(<CognitiveDrillTutorialPreview type="flanker" drillConfig={{}} cognitiveProgress={null} onClose={vi.fn()} />);
+ expect(screen.getByText(/report the center arrow/i)).toBeInTheDocument();
+ expect(screen.queryByText(/resolving your current/i)).toBeNull();
+ });
+
it('renders nothing for no selection or a type with no tutorial', () => {
- const { container, rerender } = render(<CognitiveDrillTutorialPreview drill={null} onClose={vi.fn()} />);
+ const { container, rerender } = render(<CognitiveDrillTutorialPreview type={null} onClose={vi.fn()} />);
expect(container).toBeEmptyDOMElement();
- rerender(<CognitiveDrillTutorialPreview drill={{ type: 'not-a-drill' }} onClose={vi.fn()} />);
+ rerender(<CognitiveDrillTutorialPreview type="not-a-drill" onClose={vi.fn()} />);
expect(container).toBeEmptyDOMElement();
});
it('reflects the drill config it is handed, so a re-read matches the configured difficulty', () => {
const { rerender } = render(
- <CognitiveDrillTutorialPreview drill={{ type: 'digit-span', config: { direction: 'backward' } }} onClose={vi.fn()} />,
+ <CognitiveDrillTutorialPreview type="digit-span" drillConfig={{ direction: 'backward', progressive: false }} onClose={vi.fn()} />,
);
expect(screen.getByText(/then type them in reverse/i)).toBeInTheDocument();
rerender(
- <CognitiveDrillTutorialPreview drill={{ type: 'digit-span', config: { direction: 'forward' } }} onClose={vi.fn()} />,
+ <CognitiveDrillTutorialPreview type="digit-span" drillConfig={{ direction: 'forward', progressive: false }} onClose={vi.fn()} />,
);
expect(screen.queryByText(/then type them in reverse/i)).not.toBeInTheDocument();
expect(screen.getByText(/then type them back in order/i)).toBeInTheDocument();
diff --git a/client/src/components/meatspace/post/PostDrillConfig.jsx b/client/src/components/meatspace/post/PostDrillConfig.jsx
index 64d4ab226c..039b4232a4 100644
--- a/client/src/components/meatspace/post/PostDrillConfig.jsx
+++ b/client/src/components/meatspace/post/PostDrillConfig.jsx
@@ -4,7 +4,7 @@ import { updatePostConfig, getProviders, getPostAdaptivePreview, getPostMultipli
import toast from '../../ui/Toast';
import { FormField } from '../../ui/FormField';
import { filterSelectableModels, enabledApiProviderFilter } from '../../../utils/providers';
-import { GOAL_DEFS, POST_TOPICS, MODULE_LABELS, DRILL_LABELS, DRILL_DESCRIPTIONS, composedSessionDrillTypes, effectiveCognitiveDrillConfig } from './constants';
+import { GOAL_DEFS, POST_TOPICS, MODULE_LABELS, DRILL_LABELS, DRILL_DESCRIPTIONS, composedSessionDrillTypes } from './constants';
import { CognitiveDrillTutorialPreview, CognitiveDrillHowItWorksButton } from './PostCognitiveDrillRunner';
// Modules a Full/Quick composed session can draw from (issue #2100), DERIVED
@@ -693,8 +693,13 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {
if (!anyCognitiveProgressive) { setCognitiveProgress(null); return; }
let cancelled = false;
getPostCognitiveProgress({ silent: true })
- .then(p => { if (!cancelled) setCognitiveProgress(p); })
- .catch(err => console.warn('⚠️ Failed to load cognitive progress: ' + err.message));
+ .then(p => { if (!cancelled) setCognitiveProgress(p || {}); })
+ // `{}` on failure, not null: null means "not fetched yet", which would
+ // leave the how-to preview waiting on a rung that is never coming.
+ .catch(err => {
+ console.warn('⚠️ Failed to load cognitive progress: ' + err.message);
+ if (!cancelled) setCognitiveProgress({});
+ });
return () => { cancelled = true; };
}, [anyCognitiveProgressive]);
@@ -1124,10 +1129,9 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {
that is backward recall. Built at render, not at click, so editing a
knob and reopening shows the new value. */}
<CognitiveDrillTutorialPreview
- drill={howItWorksType ? {
- type: howItWorksType,
- config: effectiveCognitiveDrillConfig(cognitiveDrillTypes[howItWorksType], cognitiveProgress?.[howItWorksType]),
- } : null}
+ type={howItWorksType}
+ drillConfig={howItWorksType ? cognitiveDrillTypes[howItWorksType] : null}
+ cognitiveProgress={cognitiveProgress}
onClose={() => setHowItWorksType(null)}
/>
diff --git a/client/src/components/meatspace/post/PostDrillConfig.test.jsx b/client/src/components/meatspace/post/PostDrillConfig.test.jsx
index 8afb200995..d15b476d7c 100644
--- a/client/src/components/meatspace/post/PostDrillConfig.test.jsx
+++ b/client/src/components/meatspace/post/PostDrillConfig.test.jsx
@@ -14,7 +14,7 @@ vi.mock('../../ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn() }
import PostDrillConfig from './PostDrillConfig';
import { updatePostConfig, getProviders, getPostAdaptivePreview, getPostMultiplicationProgress, getPostPowersProgress, getPostCognitiveProgress, getMemoryItems } from '../../../services/api';
-import { LLM_DRILL_TYPES, DRILL_LABELS, COGNITIVE_DRILL_TYPES } from './constants';
+import { LLM_DRILL_TYPES, DRILL_LABELS, COGNITIVE_DRILL_TYPES, COGNITIVE_LADDER_TYPES } from './constants';
// The generatable LLM drill types + labels, imported from the canonical
// client constant (mirrors server LLM_DRILL_TYPES in meatspacePostLlm.js) —
@@ -391,6 +391,26 @@ describe('PostDrillConfig', () => {
}
});
+ // Drift guard for the COGNITIVE_LADDER_TYPES mirror in constants.js: the
+ // launcher's fetch gate and `cognitiveRungPending` both key on it, so if it
+ // and this file's per-drill `progressive` flags ever disagree, the how-to
+ // card silently goes back to describing the stored knobs.
+ it('COGNITIVE_LADDER_TYPES matches exactly the drills that expose a Progressive toggle', async () => {
+ // Every cognitive drill switched ON — the three executive-control drills
+ // ship disabled, and the Progressive toggle only renders on an enabled card.
+ const allOn = {
+ ...config,
+ cognitive: {
+ enabled: true,
+ drillTypes: Object.fromEntries(COGNITIVE_DRILL_TYPES.map(t => [t, { enabled: true }])),
+ },
+ };
+ await renderConfig(<PostDrillConfig config={allOn} onSaved={vi.fn()} onBack={vi.fn()} />);
+ const laddered = COGNITIVE_DRILL_TYPES.filter(type =>
+ screen.queryByRole('switch', { name: `Progressive difficulty — ${DRILL_LABELS[type]}` }) != null);
+ expect(laddered.sort()).toEqual([...COGNITIVE_LADDER_TYPES].sort());
+ });
+
// The DEFAULT configuration: progressive is on, so the server runs the
// ladder rung's config and IGNORES the stored knobs. The card has to teach
// the rung, or it explains a different drill than the one about to run.
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsx
index 45069bfa7d..09c15a4f10 100644
--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx
+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx
@@ -6,7 +6,7 @@ import { FormField } from '../../ui/FormField';
import Pill from '../../ui/Pill';
import { enabledApiProviderFilter } from '../../../utils/providers';
import useProviderModels from '../../../hooks/useProviderModels.js';
-import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, effectiveCognitiveDrillConfig, computeDomainAverages, computeGoalProgress, isTopicEnabled, selectMemoryItemForDrill, resolveTopicForDrillType } from './constants';
+import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, COGNITIVE_LADDER_TYPES, computeDomainAverages, computeGoalProgress, isTopicEnabled, selectMemoryItemForDrill, resolveTopicForDrillType } from './constants';
import { otherPostSections, TOPIC_SURFACE_SECTIONS } from './practiceCatalog';
import { postIcon } from './postIcons';
import BrowseCatalogLink from './BrowseCatalogLink';
@@ -231,14 +231,21 @@ export default function PostSessionLauncher({
// Conditional-fetch like the goal-scoped effects above — nothing is requested
// on an install with no progressive cognitive drill enabled.
const needsCognitiveProgress = config?.cognitive?.enabled !== false
- && Object.values(config?.cognitive?.drillTypes || {})
- .some(cfg => cfg?.enabled !== false && cfg?.progressive !== false);
+ && COGNITIVE_LADDER_TYPES.some(type => {
+ const cfg = config?.cognitive?.drillTypes?.[type];
+ return cfg && cfg.enabled !== false && cfg.progressive !== false;
+ });
useEffect(() => {
if (!needsCognitiveProgress) { setCognitiveProgress(null); return; }
let cancelled = false;
getPostCognitiveProgress({ silent: true })
- .then(p => { if (!cancelled) setCognitiveProgress(p); })
- .catch(err => console.warn('⚠️ Failed to load cognitive progress: ' + err.message));
+ .then(p => { if (!cancelled) setCognitiveProgress(p || {}); })
+ // `{}` on failure, not null: null means "not fetched yet" and would leave
+ // the preview waiting forever on a rung that is never coming.
+ .catch(err => {
+ console.warn('⚠️ Failed to load cognitive progress: ' + err.message);
+ if (!cancelled) setCognitiveProgress({});
+ });
return () => { cancelled = true; };
}, [needsCognitiveProgress]);
@@ -1243,10 +1250,9 @@ export default function PostSessionLauncher({
</div>
<CognitiveDrillTutorialPreview
- drill={howItWorksType ? {
- type: howItWorksType,
- config: effectiveCognitiveDrillConfig(config.cognitive?.drillTypes?.[howItWorksType], cognitiveProgress?.[howItWorksType]),
- } : null}
+ type={howItWorksType}
+ drillConfig={howItWorksType ? config.cognitive?.drillTypes?.[howItWorksType] : null}
+ cognitiveProgress={cognitiveProgress}
onClose={() => setHowItWorksType(null)}
/>
</div>
diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.js
index 7772abd528..beaee93f83 100644
--- a/client/src/components/meatspace/post/constants.js
+++ b/client/src/components/meatspace/post/constants.js
@@ -9,6 +9,28 @@ export const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memo
// COGNITIVE_DRILL_TYPES in server/services/meatspacePostCognitive.js.
export const COGNITIVE_DRILL_TYPES = ['n-back', 'digit-span', 'stroop', 'schulte-table', 'mental-rotation', 'reaction-time', 'task-switching', 'go-no-go', 'flanker'];
+// Cognitive drills that have a progressive difficulty ladder. Mirror of the
+// COGNITIVE_LADDERS keys in server/lib/postProgression.js — reaction-time is the
+// one cognitive drill with no ladder, so its stored config always runs as-is.
+export const COGNITIVE_LADDER_TYPES = ['n-back', 'digit-span', 'schulte-table', 'mental-rotation', 'stroop', 'task-switching', 'go-no-go', 'flanker'];
+
+/**
+ * Whether this drill's effective config is still UNKNOWN: a laddered drill left
+ * progressive (the default) whose rung has not been fetched yet. Anything that
+ * DESCRIBES the drill must wait rather than fall back to the stored knobs —
+ * rendering those first would state the wrong rule and then silently swap it
+ * out from under the reader.
+ *
+ * `cognitiveProgress` is the whole `getPostCognitiveProgress()` map, using the
+ * `null` = not fetched / `{}` = fetched-or-failed sentinel, so a failed fetch
+ * degrades to the stored knobs instead of hanging on "resolving" forever.
+ */
+export function cognitiveRungPending(type, drillConfig, cognitiveProgress) {
+ if (!COGNITIVE_LADDER_TYPES.includes(type)) return false;
+ if (drillConfig?.progressive === false) return false;
+ return cognitiveProgress == null;
+}
+
/**
* The config a cognitive drill will ACTUALLY run with — not necessarily the one
* stored in POST config. Mirrors the server's override in `resolveDrillConfig`