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: surface job skill save and preview failures in the Prompt Manager (#3937)

[._.]/ Adam Eivyc14fbb086a81
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 754df16f18..a41535bb7d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -75,3 +75,4 @@
- A failed job-catalog read on the Quota Burn page no longer empties the config form silently. The fetch was `.catch(() => {})`, so a 500 or a network blip left the catalog at its empty default: the "Add a preset job" picker returned null and vanished, "Add job" sat disabled, and every job row's Job Type / Apps / Universes / Image Modes dropdown rendered blank — with nothing on screen naming a cause, and editing a step in that state saving `jobType: ""` into a 400 that stalls the whole save. The catalog read now keeps its failure in its own state (with a 200 carrying zero job types reported as its own distinct cause rather than as a successful load), and an expanded family card renders an inline warning banner naming it with a "Retry catalog load" button that re-reads the catalog in place — no browser reload, and the plan itself stays on screen throughout.
- Opening a job skill in the Prompt Manager now shows up in the URL. The Stages and Variables tabs already encode their selection as `?stage=` / `?var=`, but the Job Skills tab kept the open skill in local state, so the editor could not be linked or bookmarked and a reload — or a round-trip through another tab — dropped the user back on the "Select a job skill" placeholder. Selection now lives in `?skill=`, and a `selectedJobSkill`-keyed effect fetches the template and metadata, so `?tab=job-skills&skill=<name>` opens that skill's editor directly and a cleared param resets the panel.
- Exporting a catalog slice no longer issues three database queries per ingredient. `exportSliceForRef` hydrated scraps, refs and media one ingredient at a time, so a universe holding 100 ingredients cost 300 round-trips and pinned the connection pool for the length of the export. The three lookups are now batched with `WHERE ingredient_id = ANY($1)` and grouped in memory (`listScrapsForIngredients` / `listRefsForIngredients` / `listMediaForIngredients`, sharing `groupRowsByIngredient`), so one slice costs four queries regardless of how many ingredients it holds. The per-ingredient helpers stay on the same names and shapes — they now delegate to the batched query — and the exported payload, its ordering (scraps oldest-first, portraits ahead of other media) and its empty-array handling are unchanged.
+- A failed job-skill save in the Prompt Manager no longer looks like a successful one. `saveJobSkill` sent the PUT with `{ silent: true }` and an empty `.catch(() => {})`, so a network blip, an auth failure, or a 500 dropped the edit on the floor while the Save button simply re-enabled — the exact shape of a save that worked. The failure now raises a toast naming the cause, a successful save confirms itself ("Job skill saved"), and the Preview button on the same panel likewise reports a failed render instead of leaving the preview panel blank with no explanation.
diff --git a/client/src/pages/PromptManager.jsx b/client/src/pages/PromptManager.jsx
index d40ef85145..a365e9db10 100644
--- a/client/src/pages/PromptManager.jsx
+++ b/client/src/pages/PromptManager.jsx
@@ -313,16 +313,22 @@ export default function PromptManager() {
return () => { cancelled = true; };
}, [selectedJobSkill]);
+ // A failed save must say so: the button re-enabling on its own reads as
+ // "saved" and the edit is silently lost. `silent: true` + an explicit toast
+ // keeps the notification to one layer (see client/src/CLAUDE.md).
const saveJobSkill = async () => {
setSaving(true);
- // Swallow errors (matches the prior fire-and-forget PUT) but always clear
- // the saving flag so a failure can't leave the Save button stuck disabled.
- await apiSaveJobSkill(selectedJobSkill, jobSkillContent, { silent: true }).catch(() => {});
+ const ok = await apiSaveJobSkill(selectedJobSkill, jobSkillContent, { silent: true })
+ .then(() => true)
+ .catch((err) => { toast.error(`Failed to save job skill: ${err.message || 'Unknown error'}`); return false; });
setSaving(false);
+ if (ok) toast.success('Job skill saved');
};
const previewJobSkill = async () => {
- const res = await apiPreviewJobSkill(selectedJobSkill, { silent: true }).catch(() => ({}));
+ const res = await apiPreviewJobSkill(selectedJobSkill, { silent: true })
+ .catch((err) => { toast.error(`Failed to preview: ${err.message || 'Unknown error'}`); return null; });
+ if (!res) return;
setJobSkillPreview(res.preview || '');
};
diff --git a/client/src/pages/PromptManager.test.jsx b/client/src/pages/PromptManager.test.jsx
index 63a677049a..d370d9a1da 100644
--- a/client/src/pages/PromptManager.test.jsx
+++ b/client/src/pages/PromptManager.test.jsx
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
import { MemoryRouter, useLocation } from 'react-router';
import PromptManager from './PromptManager';
+import toast from '../components/ui/Toast';
// The Stages pane is the subject: 100+ rows with no way to reach one (#3284).
// Only the list-shaping API calls need real fixtures; everything else resolves
@@ -14,6 +15,8 @@ const getPromptVariables = vi.fn();
const deletePromptVariable = vi.fn();
const getJobSkills = vi.fn(() => Promise.resolve({ skills: [] }));
const getJobSkill = vi.fn(() => Promise.resolve({}));
+const saveJobSkill = vi.fn();
+const previewJobSkill = vi.fn();
vi.mock('../services/apiPrompts', () => ({
getPrompts: (...a) => getPrompts(...a),
@@ -29,8 +32,8 @@ vi.mock('../services/apiPrompts', () => ({
deletePromptVariable: (...a) => deletePromptVariable(...a),
getJobSkills: (...a) => getJobSkills(...a),
getJobSkill: (...a) => getJobSkill(...a),
- saveJobSkill: vi.fn(),
- previewJobSkill: vi.fn(),
+ saveJobSkill: (...a) => saveJobSkill(...a),
+ previewJobSkill: (...a) => previewJobSkill(...a),
}));
vi.mock('../services/apiProviders', () => ({
@@ -509,3 +512,66 @@ describe('PromptManager job skill selection', () => {
expect(screen.getByText('Select a job skill to edit its prompt template')).toBeTruthy();
});
});
+
+// A failed PUT used to be swallowed entirely: the Save button re-enabled and the
+// user believed the edit had persisted (#3937).
+describe('PromptManager job skill save feedback', () => {
+ const SKILLS = [{ name: 'code-fixer', jobId: 'job-code-fixer', hasTemplate: true }];
+
+ beforeEach(() => {
+ getPrompts.mockReset().mockResolvedValue({ stages: STAGES, systemStages: SYSTEM_STAGES });
+ getJobSkills.mockReset().mockResolvedValue({ skills: SKILLS });
+ getJobSkill.mockReset().mockResolvedValue({
+ content: '# code-fixer template', jobName: 'Job code-fixer', jobId: 'job-code-fixer',
+ });
+ saveJobSkill.mockReset().mockResolvedValue({ success: true });
+ previewJobSkill.mockReset().mockResolvedValue({ preview: 'rendered' });
+ toast.error.mockReset();
+ toast.success.mockReset();
+ });
+
+ const openEditor = async () => {
+ renderPage('/prompts?tab=job-skills&skill=code-fixer');
+ await screen.findByText('Job code-fixer');
+ };
+
+ it('toasts the failure message when the save rejects', async () => {
+ saveJobSkill.mockRejectedValueOnce(new Error('boom'));
+ await openEditor();
+
+ fireEvent.click(screen.getByRole('button', { name: /save/i }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Failed to save job skill: boom'));
+ expect(toast.success).not.toHaveBeenCalled();
+ });
+
+ it('re-enables Save after a failure so the user can retry', async () => {
+ saveJobSkill.mockRejectedValueOnce(new Error('boom'));
+ await openEditor();
+
+ const save = screen.getByRole('button', { name: /save/i });
+ fireEvent.click(save);
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalled());
+ await waitFor(() => expect(save.disabled).toBe(false));
+ });
+
+ it('confirms a successful save', async () => {
+ await openEditor();
+
+ fireEvent.click(screen.getByRole('button', { name: /save/i }));
+
+ await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Job skill saved'));
+ expect(saveJobSkill).toHaveBeenCalledWith('code-fixer', '# code-fixer template', { silent: true });
+ expect(toast.error).not.toHaveBeenCalled();
+ });
+
+ it('toasts a failed preview instead of blanking the panel', async () => {
+ previewJobSkill.mockRejectedValueOnce(new Error('nope'));
+ await openEditor();
+
+ fireEvent.click(screen.getByRole('button', { name: /preview/i }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Failed to preview: nope'));
+ });
+});