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: retain completed recipe saves after closing the editor (#7194)

[._.]/ Adam Eivyd22086e5fb34
diff --git a/client/src/components/cos/PersistentMindRecipeLibrary.jsx b/client/src/components/cos/PersistentMindRecipeLibrary.jsx
index 6fdd012b8d..f764b5eb56 100644
--- a/client/src/components/cos/PersistentMindRecipeLibrary.jsx
+++ b/client/src/components/cos/PersistentMindRecipeLibrary.jsx
@@ -63,8 +63,8 @@ function RecipeEditor({ id, onChanged, onSelect }) {
};
const apply = (saved) => {
- if (!active.current) return;
onChanged(saved);
+ if (!active.current) return;
setDetail((current) => ({
recipe: saved,
versions: [{ revision: saved.activeRevision, definition: saved.definition, author: 'user', createdAt: saved.updatedAt }, ...(current?.versions || [])],
@@ -133,9 +133,10 @@ export default function PersistentMindRecipeLibrary() {
const [recipes, setRecipes] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
- const [reload, setReload] = useState(0);
+ const mounted = useRef(false);
const version = useRef(0);
- useEffect(() => {
+ const load = useCallback(() => {
+ if (!mounted.current) return;
const request = ++version.current;
setLoading(true);
api.getMindRecipes({ silent: true }).then((result) => {
@@ -152,11 +153,21 @@ export default function PersistentMindRecipeLibrary() {
setError(null);
}).catch((failure) => { if (request === version.current) setError(failure.message); })
.finally(() => { if (request === version.current) setLoading(false); });
- return () => { version.current += 1; };
- }, [reload]);
- const onChanged = useCallback((recipe) => {
- setRecipes((current) => current.some((entry) => entry.id === recipe.id) ? current.map((entry) => entry.id === recipe.id ? recipe : entry) : [recipe, ...current]);
}, []);
+ useEffect(() => {
+ mounted.current = true;
+ load();
+ return () => { mounted.current = false; version.current += 1; };
+ }, [load]);
+ const onChanged = useCallback((recipe) => {
+ if (!mounted.current) return;
+ setRecipes((current) => current.some((entry) => entry.id === recipe.id)
+ ? current.map((entry) => entry.id === recipe.id && entry.activeRevision <= recipe.activeRevision ? recipe : entry)
+ : [recipe, ...current]);
+ // Publish the completed mutation even if its editor closed. Refresh to
+ // recover the complete library when the initial read was still pending.
+ load();
+ }, [load]);
const onSelect = (id) => setSearchParams((current) => {
const next = new URLSearchParams(current);
if (id) next.set('recipe', id);
@@ -169,7 +180,7 @@ export default function PersistentMindRecipeLibrary() {
<button type="button" className={buttonClass} onClick={() => onSelect('new')}>New recipe</button>
</div>
<p className="text-sm text-port-text-muted">Manage reusable read definitions and their history with Mind grants off. Saved recipes are not yet callable by the Mind. Nothing executes when you save or validate.</p>
- {error && <Banner tone="error" title="Recipe library unavailable">{error} <button type="button" className={buttonClass} onClick={() => setReload((value) => value + 1)}>Retry library</button></Banner>}
+ {error && <Banner tone="error" title="Recipe library unavailable">{error} <button type="button" className={buttonClass} onClick={load}>Retry library</button></Banner>}
{loading ? <p role="status" className="text-sm text-port-text-muted">Loading recipes…</p> : !recipes.length && !error ? <p className="text-sm text-port-text-muted">No saved recipes. Create one from the editable example.</p> : null}
<ul className="space-y-2">
{recipes.map((recipe) => <li key={recipe.id} className="flex flex-wrap items-center justify-between gap-2 rounded border border-port-border p-2">
diff --git a/client/src/components/cos/PersistentMindRecipeLibrary.test.jsx b/client/src/components/cos/PersistentMindRecipeLibrary.test.jsx
index 42d77cda3e..2ae9b05fdf 100644
--- a/client/src/components/cos/PersistentMindRecipeLibrary.test.jsx
+++ b/client/src/components/cos/PersistentMindRecipeLibrary.test.jsx
@@ -42,7 +42,7 @@ describe('PersistentMindRecipeLibrary', () => {
await user.click(screen.getByRole('button', { name: 'Save recipe' }));
expect(await screen.findByRole('button', { name: definition.name })).toBeInTheDocument();
expect(screen.getByTestId('location')).toHaveTextContent('?panel=tools&recipe=first');
- expect(api.getMindRecipes).toHaveBeenCalledTimes(1);
+ expect(api.getMindRecipes).toHaveBeenCalledTimes(2);
expect(api.createMindRecipe).toHaveBeenCalledWith(expect.objectContaining({ schemaVersion: 1, name: definition.name }), { silent: true });
});
@@ -88,7 +88,7 @@ describe('PersistentMindRecipeLibrary', () => {
expect(api.restoreMindRecipe).toHaveBeenCalledWith('first', { expectedRevision: 2, revision: 1 }, { silent: true });
expect(screen.getByRole('button', { name: 'Save new revision' })).toBeEnabled();
expect(within(screen.getByRole('list')).getByText('Revision 3 · Saved')).toBeInTheDocument();
- expect(api.getMindRecipes).toHaveBeenCalledTimes(1);
+ expect(api.getMindRecipes).toHaveBeenCalledTimes(3);
});
it('ignores stale detail and save responses when the URL selection changes', async () => {
@@ -112,10 +112,40 @@ describe('PersistentMindRecipeLibrary', () => {
expect(screen.queryByText(/Revision 2 · user/)).not.toBeInTheDocument();
});
+ it('updates the list when creation completes after closing its editor without reopening it', async () => {
+ const user = userEvent.setup();
+ const pendingSave = deferred();
+ api.createMindRecipe.mockReturnValueOnce(pendingSave.promise);
+ renderPage('?panel=tools&recipe=new');
+ await screen.findByText(/No saved recipes/);
+ await user.click(screen.getByRole('button', { name: 'Save recipe' }));
+ await user.click(screen.getByRole('button', { name: 'Close editor' }));
+ await act(async () => pendingSave.resolve(recipe()));
+ expect(await screen.findByRole('button', { name: definition.name })).toBeInTheDocument();
+ expect(screen.queryByLabelText('Recipe definition (JSON)')).not.toBeInTheDocument();
+ expect(screen.getByTestId('location')).toHaveTextContent('?panel=tools');
+ expect(api.getMindRecipes).toHaveBeenCalledTimes(2);
+ expect(api.getMindRecipe).not.toHaveBeenCalled();
+ });
+
+ it('does not refresh the library when a pending save completes after the panel unmounts', async () => {
+ const user = userEvent.setup();
+ const pendingSave = deferred();
+ api.createMindRecipe.mockReturnValueOnce(pendingSave.promise);
+ const view = renderPage('?panel=tools&recipe=new');
+ await screen.findByText(/No saved recipes/);
+ await user.click(screen.getByRole('button', { name: 'Save recipe' }));
+ view.unmount();
+ await act(async () => pendingSave.resolve(recipe()));
+ expect(api.getMindRecipes).toHaveBeenCalledTimes(1);
+ expect(api.getMindRecipe).not.toHaveBeenCalled();
+ });
+
it('keeps newer saved rows and unrelated recipes when an earlier library read finishes', async () => {
const user = userEvent.setup();
const lateList = deferred();
- api.getMindRecipes.mockReturnValueOnce(lateList.promise);
+ api.getMindRecipes.mockReturnValueOnce(lateList.promise)
+ .mockResolvedValueOnce({ recipes: [recipe(), recipe({ id: 'second', name: 'recipe.second' })] });
api.archiveMindRecipe.mockResolvedValue(recipe({ activeRevision: 2, archived: true }));
renderPage('?panel=tools&recipe=first');
await user.click(await screen.findByRole('button', { name: 'Archive recipe' }));
diff --git a/server/lib/mindToolRecipes.js b/server/lib/mindToolRecipes.js
index 7c9a911b16..75251b1839 100644
--- a/server/lib/mindToolRecipes.js
+++ b/server/lib/mindToolRecipes.js
@@ -8,7 +8,7 @@ const key = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/)
const fields = (schema) => z.record(key, schema).refine((value) => Object.keys(value).length <= 30, 'at most 30 fields');
const primitiveMatches = (value, type) => type === 'null' ? value === null
: type === 'integer' ? Number.isInteger(value)
- : typeof value === type;
+ : ['string', 'number', 'boolean'].includes(type) && typeof value === type;
const parameter = z.lazy(() => z.object({
type: z.enum(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']),
description: z.string().max(500).optional(),
diff --git a/server/lib/mindToolRecipes.test.js b/server/lib/mindToolRecipes.test.js
index 8c7bd2dec1..0e60176b85 100644
--- a/server/lib/mindToolRecipes.test.js
+++ b/server/lib/mindToolRecipes.test.js
@@ -24,6 +24,7 @@ describe('closed, governed recipe definition boundary', () => {
['arbitrary code', (value) => { value.steps[0].code = 'process.exit()'; }],
['dynamic tools', (value) => { value.steps[0].tool = { input: 'query' }; }],
['expression binding', (value) => { value.steps[0].arguments.query = { expression: 'query + 1' }; }],
+ ['object with a primitive enum', (value) => { value.parameters.enum = [null]; }],
['enum with wrong primitive type', (value) => { value.parameters.properties.query.enum = [3]; }],
['open parameters', (value) => { value.parameters.additionalProperties = true; }],
['nested recipes', (value) => { value.steps[0].tool = 'recipe.other'; }],