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([issue-2098]): clear stale wordplay loading when leaving a mode mid-generation

Adam Eivy017d6f0992c1
diff --git a/client/src/components/meatspace/post/WordplayTrainer.jsx b/client/src/components/meatspace/post/WordplayTrainer.jsx
index d939ce3318..74a9b9d4f7 100644
--- a/client/src/components/meatspace/post/WordplayTrainer.jsx
+++ b/client/src/components/meatspace/post/WordplayTrainer.jsx
@@ -124,7 +124,20 @@ export default function WordplayTrainer({ onBack, config, onConfigUpdate, mode =
// no-surprise-LLM-calls rule. `initiatedRef` prevents re-generating on
// unrelated re-renders and after a consent-driven start.
useEffect(() => {
- if (!selectedMode) return;
+ if (!selectedMode) {
+ // Left a mode — via the in-app Back button OR the browser Back button
+ // (this is now a URL-routed view). Drop ALL transient run state, crucially
+ // `loading`: a generation aborted by leaving mid-flight never clears it, and
+ // a stale `loading` would be misread as "the next mode is already
+ // generating" (the `drill || loading` guard below), wedging it on a
+ // permanent spinner. Guard against a re-run loop — only clear when dirty.
+ if (drill || loading || feedback || results.length || initiatedRef.current) {
+ setDrill(null); setLoading(false); setQuestionIndex(0);
+ setInputValue(''); setItems([]); setFeedback(null); setResults([]);
+ initiatedRef.current = null;
+ }
+ return;
+ }
// A drill left over from a PREVIOUS mode (e.g. browser-back to the grid, then
// pick a different mode — the URL changed without going through
// handleBackToModes) must be cleared first. Otherwise the `drill || loading`
diff --git a/client/src/components/meatspace/post/WordplayTrainer.test.jsx b/client/src/components/meatspace/post/WordplayTrainer.test.jsx
index c7fa9b8cbd..933597bea9 100644
--- a/client/src/components/meatspace/post/WordplayTrainer.test.jsx
+++ b/client/src/components/meatspace/post/WordplayTrainer.test.jsx
@@ -87,6 +87,29 @@ describe('WordplayTrainer — training-log persistence (issue #2097)', () => {
expect(entry.totalMs).toBeGreaterThanOrEqual(0);
});
+ it('does not wedge on a permanent spinner after leaving a mode mid-generation then picking another (issue #2098)', async () => {
+ generatePostDrill
+ .mockImplementationOnce(() => new Promise(() => {})) // mode A generation hangs
+ .mockResolvedValueOnce({
+ type: 'bridge-word',
+ puzzles: [{ clues: ['news___', '___back'], answer: 'paper' }],
+ });
+
+ render(<TrainerHarness onBack={() => {}} config={{}} onConfigUpdate={() => {}} />);
+
+ fireEvent.click(await screen.findByText('Compound Chain')); // enter mode A → loading (hangs)
+ await waitFor(() => expect(screen.getByText(/Generating/i)).toBeInTheDocument());
+
+ // Leave mid-generation via the header Back (mirrors browser-back off the URL).
+ // The stale `loading` from the aborted generation must be cleared, or the
+ // next mode would be stuck on a permanent spinner.
+ fireEvent.click(screen.getAllByRole('button')[0]);
+ await screen.findByText('Bridge Word'); // back on the mode grid
+
+ fireEvent.click(screen.getByText('Bridge Word')); // enter mode B
+ await waitFor(() => expect(screen.getByText('news___')).toBeInTheDocument()); // B generated, not wedged
+ });
+
it('does not submit a training entry before the round completes', async () => {
generatePostDrill.mockResolvedValue({
type: 'bridge-word',