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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve failure state on character lora and chunk mastery reads (#12819)
[._.]/ Adam Eivy571cb702839d
diff --git a/client/src/components/loraTraining/CharacterLoraChip.jsx b/client/src/components/loraTraining/CharacterLoraChip.jsxindex 48c4d79b41..d2d5f7e3c7 100644--- a/client/src/components/loraTraining/CharacterLoraChip.jsx+++ b/client/src/components/loraTraining/CharacterLoraChip.jsx@@ -5,31 +5,33 @@* that find-or-creates the character's dataset and navigates to it.*/-import { useState, useEffect } from 'react';+import { useState, useEffect, useCallback } from 'react';import { useNavigate, Link } from 'react-router';import { Sparkles, GraduationCap, Loader2 } from 'lucide-react';import { getCharacterLoras, createLoraDataset, listLoraDatasets } from '../../services/api';+import useListResource from '../../hooks/useListResource';+import ListLoadError from '../ui/ListLoadError';export default function CharacterLoraChip({ entryId, ingredientId, universeId, showDatasetButton = true }) {const navigate = useNavigate();- const [loras, setLoras] = useState(null);// Existing dataset (looked up by ingredientId) — the link target on// surfaces like the catalog detail page that don't know the universe// entryId and therefore can't find-or-create.const [existingDataset, setExistingDataset] = useState(null);const [opening, setOpening] = useState(false);- useEffect(() => {- if (!entryId && !ingredientId) return undefined;- let active = true;- getCharacterLoras({ entryId, ingredientId }, { silent: true })- .then((list) => { if (active) setLoras(Array.isArray(list) ? list : []); })- .catch(err => {- console.warn('⚠️ Failed to load character LoRAs: ' + err.message);- if (active) setLoras([]);- });- return () => { active = false; };- }, [entryId, ingredientId]);+ const fetchLoras = useCallback(+ () => getCharacterLoras({ entryId, ingredientId }, { silent: true }),+ [entryId, ingredientId],+ );+ const {+ items: loras,+ state: lorasState,+ error: lorasError,+ retry: retryLoras,+ } = useListResource(fetchLoras, {+ enabled: Boolean(entryId || ingredientId),+ });const canCreate = !!(universeId && entryId);useEffect(() => {@@ -55,6 +57,9 @@ export default function CharacterLoraChip({ entryId, ingredientId, universeId, sreturn (<div className="flex items-center gap-2 flex-wrap text-xs">+ {lorasState === 'error' && (+ <ListLoadError what="character LoRAs" error={lorasError} onRetry={retryLoras} />+ )}{lora && (<Linkto="/models/loras"@@ -65,7 +70,7 @@ export default function CharacterLoraChip({ entryId, ingredientId, universeId, sLoRA{lora.triggerWords?.[0] ? ` · ${lora.triggerWords[0]}` : ''}</Link>)}- {showDatasetButton && canCreate && (+ {showDatasetButton && canCreate && lorasState === 'ready' && (<buttontype="button"onClick={openDataset}diff --git a/client/src/components/loraTraining/CharacterLoraChip.test.jsx b/client/src/components/loraTraining/CharacterLoraChip.test.jsxnew file mode 100644index 0000000000..5f30f2c9d7--- /dev/null+++ b/client/src/components/loraTraining/CharacterLoraChip.test.jsx@@ -0,0 +1,75 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { act, fireEvent, render, screen } from '@testing-library/react';++const getCharacterLoras = vi.fn();+const createLoraDataset = vi.fn();+const listLoraDatasets = vi.fn();++vi.mock('../../services/api', () => ({+ getCharacterLoras: (...args) => getCharacterLoras(...args),+ createLoraDataset: (...args) => createLoraDataset(...args),+ listLoraDatasets: (...args) => listLoraDatasets(...args),+}));++const mockNavigate = vi.fn();+vi.mock('react-router', () => ({+ useNavigate: () => mockNavigate,+ Link: ({ to, children, ...props }) => <a href={to} {...props}>{children}</a>,+}));++import CharacterLoraChip from './CharacterLoraChip';++describe('CharacterLoraChip', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ getCharacterLoras.mockResolvedValue([]);+ listLoraDatasets.mockResolvedValue([]);+ });++ it('shows a Retry — not "Train LoRA" — when the LoRA read fails, and shows "Train LoRA" after retry', async () => {+ getCharacterLoras.mockRejectedValueOnce(new Error('Server unavailable'));++ render(+ <CharacterLoraChip+ entryId="char-1"+ universeId="u1"+ showDatasetButton+ />+ );++ await act(async () => {});++ expect(screen.getByRole('alert')).toHaveTextContent('Could not load character LoRAs — Server unavailable');+ expect(screen.queryByRole('button', { name: /Train LoRA/i })).toBeNull();+ expect(screen.queryByRole('link', { name: /LoRA/i })).toBeNull();++ getCharacterLoras.mockResolvedValueOnce([]);+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ });++ expect(screen.queryByRole('alert')).toBeNull();+ expect(screen.getByRole('button', { name: /Train LoRA/i })).toBeInTheDocument();+ });++ it('renders LoRA chip and "Dataset" button only after a successful read', async () => {+ getCharacterLoras.mockResolvedValueOnce([+ { filename: 'alice.safetensors', triggerWords: ['alice_lora'] },+ ]);++ render(+ <CharacterLoraChip+ entryId="char-1"+ universeId="u1"+ showDatasetButton+ />+ );++ await act(async () => {});++ expect(screen.queryByRole('alert')).toBeNull();+ expect(screen.getByText('LoRA · alice_lora')).toBeInTheDocument();+ expect(screen.getByRole('button', { name: /Dataset/i })).toBeInTheDocument();+ expect(screen.queryByRole('button', { name: /Train LoRA/i })).toBeNull();+ });+});diff --git a/client/src/components/meatspace/post/MemoryPractice.jsx b/client/src/components/meatspace/post/MemoryPractice.jsxindex 1657419d89..07ddb4b0cd 100644--- a/client/src/components/meatspace/post/MemoryPractice.jsx+++ b/client/src/components/meatspace/post/MemoryPractice.jsx@@ -1,9 +1,11 @@-import { useState, useRef, useEffect, useMemo } from 'react';+import { useState, useRef, useEffect, useMemo, useCallback } from 'react';import { ChevronLeft, Check, X, SkipForward, RotateCcw, Target, ChevronDown, Loader, ShieldCheck } from 'lucide-react';import { submitMemoryPractice, getChunkMastery, getMemoryItem, attestMemoryMastery } from '../../../services/api';import ProgressBar from '../../ui/ProgressBar';import PostCompletionActions from './PostCompletionActions';import { startRetryableSave } from './completionSave';+import useListResource from '../../../hooks/useListResource';+import ListLoadError from '../../ui/ListLoadError';// Exported so the Practice Library (practiceCatalog.js) derives its study-mode// rows from this list rather than re-typing them — a new mode shows up in the@@ -125,7 +127,18 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, on}, [item.id, item.mastery]);// Spaced repetition state- const [chunkMastery, setChunkMastery] = useState(null);+ const fetchChunkMastery = useCallback(+ () => getChunkMastery(item?.id, { silent: true }),+ [item?.id],+ );+ const {+ items: chunkMastery,+ state: chunkMasteryState,+ error: chunkMasteryError,+ retry: retryChunkMastery,+ } = useListResource(fetchChunkMastery, {+ enabled: mode === 'spaced' && Boolean(item?.id),+ });const [spacedChunkIdx, setSpacedChunkIdx] = useState(0);const [spacedLineIdx, setSpacedLineIdx] = useState(0);@@ -168,19 +181,6 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, onif (mode && inputRef.current) inputRef.current.focus();}, [mode, currentIdx, spacedLineIdx]);- // Load chunk mastery when entering spaced mode- useEffect(() => {- if (mode !== 'spaced') return undefined;- let active = true;- getChunkMastery(item.id).then(data => {- if (active) setChunkMastery(data || []);- }).catch(err => {- console.warn('⚠️ Failed to load chunk mastery: ' + err.message);- if (active) setChunkMastery([]);- });- return () => { active = false; };- }, [mode, item.id]);-// Drive terminal transitions from an effect, never during render. The render// fallbacks below (chunk exhausted, line exhausted, sequence exhausted) return null// for a frame while this effect advances or marks the session done. Spaced@@ -188,7 +188,7 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, onuseEffect(() => {if (done) return;if (mode === 'spaced') {- if (!chunkMastery || chunkMastery.length === 0) return;+ if (chunkMasteryState !== 'ready' || !chunkMastery || chunkMastery.length === 0) return;const currentChunk = chunkMastery[spacedChunkIdx];if (!currentChunk) {setDone(true);@@ -205,7 +205,7 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, on} else if (mode === 'sequence' && !lines[currentIdx + 1]) {finishSequence();}- }, [mode, chunkMastery, spacedChunkIdx, spacedLineIdx, currentIdx, done]);+ }, [mode, chunkMastery, chunkMasteryState, spacedChunkIdx, spacedLineIdx, currentIdx, done]);// Back goes up exactly one level: from a running mode (or the results screen)// to the mode picker via `onExitMode`, and from the picker out to the item@@ -348,7 +348,7 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, on// SPACED REPETITION mode — focus on weakest chunks with graduated hintsif (mode === 'spaced') {- if (!chunkMastery) {+ if (chunkMasteryState === 'loading') {return (<div className="space-y-6 max-w-2xl"><div className="text-gray-400 text-sm">Loading chunk mastery...</div>@@ -356,7 +356,25 @@ function MemoryPracticeRunner({ item, mode, onSelectMode, onExitMode, onBack, on);}- if (chunkMastery.length === 0) {+ if (chunkMasteryState === 'error') {+ return (+ <div className="space-y-6 max-w-2xl">+ <div className="flex items-center gap-3">+ <button aria-label="Back" onClick={onExitMode} className="text-gray-400 hover:text-white transition-colors">+ <ChevronLeft size={20} />+ </button>+ <h2 className="text-lg font-bold text-white">Spaced Repetition — {item.title}</h2>+ </div>+ <ListLoadError+ what="chunk mastery"+ error={chunkMasteryError}+ onRetry={retryChunkMastery}+ />+ </div>+ );+ }++ if (chunkMasteryState === 'ready' && chunkMastery.length === 0) {return (<div className="space-y-6 max-w-2xl"><div className="flex items-center gap-3">diff --git a/client/src/components/meatspace/post/MemoryPractice.test.jsx b/client/src/components/meatspace/post/MemoryPractice.test.jsxindex 5bc36c4eab..6008aa473f 100644--- a/client/src/components/meatspace/post/MemoryPractice.test.jsx+++ b/client/src/components/meatspace/post/MemoryPractice.test.jsx@@ -401,4 +401,41 @@ describe('MemoryPractice daily routine actions', () => {expect(payload.results).toHaveLength(2);expect(payload.results.map(result => result.chunkId)).toEqual(['chunk-a', 'chunk-b']);});++ it('shows a Retry — not "No chunks available" — when chunk mastery read fails, and shows empty state after successful retry', async () => {+ getChunkMastery.mockRejectedValueOnce(new Error('Server unavailable'));+ const item = {+ id: 'example-memory',+ title: 'Example Memory',+ content: {+ lines: [{ text: 'First line.' }],+ chunks: [{ id: 'chunk-a', label: 'Chunk A', lineRange: [0, 0] }],+ },+ };++ render(+ <MemoryPractice+ itemId={item.id}+ item={item}+ mode="spaced"+ onSelectMode={() => {}}+ onExitMode={() => {}}+ onBack={() => {}}+ onContinue={() => {}}+ />+ );++ await waitFor(() => {+ expect(screen.getByRole('alert')).toHaveTextContent('Could not load chunk mastery — Server unavailable');+ });+ expect(screen.queryByText('No chunks available for spaced practice.')).not.toBeInTheDocument();++ getChunkMastery.mockResolvedValueOnce([]);+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));++ await waitFor(() => {+ expect(screen.getByText('No chunks available for spaced practice.')).toBeInTheDocument();+ });+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();+ });});diff --git a/client/src/listFetchConventions.test.js b/client/src/listFetchConventions.test.jsindex e9448ef00c..1ce2cfbc07 100644--- a/client/src/listFetchConventions.test.js+++ b/client/src/listFetchConventions.test.js@@ -70,9 +70,6 @@ export const LIST_COLLAPSE = new RegExp(*/const KNOWN = Object.freeze({'src/components/privacy/PrivacyOrgsTab.jsx': 2,- // Named-parameter, multi-statement spelling (#12807); migrated under #12819.- 'src/components/loraTraining/CharacterLoraChip.jsx': 1,- 'src/components/meatspace/post/MemoryPractice.jsx': 1,});/**diff --git a/client/src/services/apiMeatspace.js b/client/src/services/apiMeatspace.jsindex 011a39cca8..7e86f269ac 100644--- a/client/src/services/apiMeatspace.js+++ b/client/src/services/apiMeatspace.js@@ -242,7 +242,7 @@ export const attestMemoryMastery = (id, options = {}) => request(`/meatspace/pos...options});export const getMemoryMastery = (id) => request(`/meatspace/post/memory-items/${id}/mastery`);-export const getChunkMastery = (id) => request(`/meatspace/post/memory-items/${id}/chunk-mastery`);+export const getChunkMastery = (id, options = {}) => request(`/meatspace/post/memory-items/${id}/chunk-mastery`, options);// MeatSpace - POST Training Logexport const submitTrainingEntry = (data, options = {}) => request('/meatspace/post/training', {