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: forward request options through organizeGoals so a failed AI organize toasts once, not twice (#3515)

[._.]/ Adam Eivy850218eda0b6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 528df2b74c..2d27c1ea91 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -93,6 +93,8 @@
- **Composite boards were the only Universe Builder surface with no thumbnail, so a rendered board looked unrendered.** Characters, places, objects and category variations all show their latest render as an `EntryThumbSlot` avatar with a click-to-preview lightbox; the Composites tab showed label + prompt only. Nothing was missing server-side — `compile.js` already stamps an `entryRef` of kind `sheet` on each queued board render and the completion hook already appends the resulting filename to that board's `imageRefs[]`, so the data was sitting in the record with nothing reading it. Composite rows now render through the same `EntryCard` shell + three-state `EntryThumbSlot` the variation and canon rows use (in-flight spinner → rendered thumbnail → empty placeholder with a one-click render button), so their spacing and locked accent can no longer drift from the other surfaces, and clicking a board opens the same page-level lightbox with the real render prompt hydrated from the gallery sidecar. `useRenderJobQueue` had been dropping `sheet`-kind jobs on the grounds that no row consumed them; with every kind the server stamps now settled by a row, the filter is deleted rather than widened — an allowlist that already covers everything can only ever fail closed on the next kind added, silently, with no spinner and no error. Two things this collapsed rather than copied: the row settles through `EntryThumbSlot`'s existing `onComplete` bridge instead of opening a second `useMediaJobProgress` subscription against a jobId the slot is already watching (which is what the variation and canon rows do, at the cost of a row re-render per diffusion tick), and the two page-level job handlers that had each inlined the same append-dedupe-cap now share `appendImageRefById` in `lib/bibleLimits.js`, the client mirror of the server's `mapAppendImageRef` (three other surfaces still inline their own copy). The settle callback is memoized rather than rebuilt per render: `MediaJobThumb` fires its completion effect on `[filename, onFilename]`, so a fresh arrow would re-settle the same job on every keystroke in the builder draft, each one a full gallery refetch — there is a test that fails against the unstable form. Codex review then surfaced the gap that made the whole thing conditional: the draft never adopted the ids the server sanitizer mints, so a board added and rendered in the same session had no `id` to match the one the server stamped onto `entryJobs` — no spinner, no thumbnail until reload, and (now that sheet jobs are tracked) a pending entry with no consumer to clear it. `handleSave` had the server record in hand the whole time and only ever used it for the universe list, so it now adopts the minted ids into both the draft and its dirty baseline — backfilling only the draft would leave the page permanently dirty. That fixes variations, which had the identical latent bug, in the same place rather than special-casing boards. A second review round found the same mismatch in its other shape: on records written before entry ids were persisted at all, `ensureEntryId` mints a fresh uuid on every read, and `POST /render` migrates the record — persisting yet another set — before queueing jobs against it, so the draft is holding ids that exist nowhere. The render flow now reconciles from the persisted record before it enqueues, and the adopt rule is stated as "keep every id the server also has, replace the ones it does not": an id the server has never heard of cannot be the key anything is stored under, while a confirmed id is never re-pointed and so can never be pulled out from under an in-flight job. And a failed board render now says so, the way the variation and canon rows already did, instead of the spinner just vanishing — `EntryThumbSlot` reports the terminal status on a dedicated `onTerminalStatus` prop so a cancel can stay silent. That status deliberately does NOT ride on `onComplete`'s second argument, which was the first thing tried: `useSingleImageRender`'s `handleComplete(filename, key)` is wired straight into that prop by the base-style probe, so a status arriving where it expects a key looked up a job that did not exist, never cleared the real one, and left the probe spinning forever after a perfectly successful render. The full client suite did not catch it — the collision only shows up through a component boundary neither module's tests cross — so `EntryThumbSlot` now asserts `onComplete` is called with exactly one argument, which fails the moment anyone overloads it again.
+- **[issue-3515] A failed AI goal organization stacked two identical error toasts on top of each other.** Both the Goals list and the Goals tree already showed their own "Failed to organize goals" message, but the API wrapper they called dropped the caller's request-level options on the floor, so the shared request helper had no way to be told to stay quiet and toasted the same failure a second time. `organizeGoals` now takes the provider selection and the request options as separate arguments and forwards the latter, and both views ask for silence — the wrapper is not hard-coded silent, so a future caller with no error UI of its own still gets the helper's toast. Guarded from both ends: a service-level test drives the real request helper against a failing fetch and asserts nothing toasts, and each view asserts it passes `{ silent: true }` and fires exactly one toast.
+
## Three.js Models
- **[issue-3481] A generated model now tells you which of its own promises it did not actually build.** The spec check only ever proved that every feature the model listed pointed at a real part — so a spec could name eight defining features, aim all eight at the same box, and still validate clean: one fused mesh wearing a photograph. Each finished generation is now measured against its own inventory and the result is shown on the model's page: features collapsed onto a single shared part, geometry no feature claims, and features nothing was built for at all. Severity follows how much of the subject rides on the miss — a missing defining feature is an error, fine relief folded into the piece it sits on is called out as the correct modeling choice rather than a defect. When you hit Refine without typing your own notes, the refinement pass is now aimed at exactly those errors instead of a generic "improve it." The page states the check's honest limit alongside the findings: it proves the model built what its spec promised, never that the spec promised enough.
diff --git a/client/src/components/goals/GoalsListView.jsx b/client/src/components/goals/GoalsListView.jsx
index 9b04d276d9..3a6d4a95a5 100644
--- a/client/src/components/goals/GoalsListView.jsx
+++ b/client/src/components/goals/GoalsListView.jsx
@@ -266,7 +266,9 @@ export default function GoalsListView({ data, onRefresh }) {
const handleOrganize = async () => {
if (!selectedProviderId) { toast.error('No API provider available'); return; }
setOrganizing(true);
- const result = await api.organizeGoals({ providerId: selectedProviderId, model: selectedModel }).catch(() => null);
+ // `silent: true` — this handler owns the failure toast below; without it
+ // request() also toasts and the user sees two stacked errors.
+ const result = await api.organizeGoals({ providerId: selectedProviderId, model: selectedModel }, { silent: true }).catch(() => null);
setOrganizing(false);
if (!result) { toast.error('Failed to organize goals'); return; }
await applyOrganizationSuggestion(result);
diff --git a/client/src/components/goals/GoalsListView.test.jsx b/client/src/components/goals/GoalsListView.test.jsx
new file mode 100644
index 0000000000..07d04742a7
--- /dev/null
+++ b/client/src/components/goals/GoalsListView.test.jsx
@@ -0,0 +1,67 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, act } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+const { toastError, organizeGoals } = vi.hoisted(() => ({
+ toastError: vi.fn(),
+ organizeGoals: vi.fn(),
+}));
+
+vi.mock('../ui/Toast', () => ({
+ default: Object.assign(() => {}, { error: toastError, success: () => {} }),
+}));
+vi.mock('../../services/api', () => ({
+ createGoal: vi.fn(),
+ organizeGoals,
+}));
+vi.mock('../../hooks/useProviderModels', () => ({
+ default: () => ({
+ providers: [{ id: 'provider-1', name: 'Example Provider' }],
+ selectedProviderId: 'provider-1',
+ selectedModel: 'example-model',
+ availableModels: ['example-model'],
+ setSelectedProviderId: vi.fn(),
+ setSelectedModel: vi.fn(),
+ loading: false,
+ }),
+}));
+
+import GoalsListView from './GoalsListView';
+
+// Invented placeholder goals — never real records from a running install.
+const GOALS = [
+ { id: 'g1', title: 'Sail across an ocean', category: 'mastery', horizon: 'lifetime', goalType: 'apex', children: [] },
+ { id: 'g2', title: 'Restore the boat', category: 'creative', horizon: '3-year', children: [] },
+];
+// The Organize button only renders once there are >= 2 goals to reorganize.
+const DATA = { roots: GOALS, flat: GOALS };
+
+const renderList = async () => {
+ render(<GoalsListView data={DATA} onRefresh={vi.fn()} />);
+ await act(async () => {});
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+});
+
+describe('handleOrganize error toasting', () => {
+ // Guards #3515: this handler owns the "Failed to organize goals" toast, so the
+ // request helper must be told to stay quiet — otherwise a failed AI run stacks
+ // two error toasts on top of each other.
+ it('asks the API helper to stay silent and toasts the failure exactly once', async () => {
+ const user = userEvent.setup();
+ organizeGoals.mockRejectedValue(new Error('Organization failed'));
+ await renderList();
+
+ await user.click(screen.getByRole('button', { name: /organize/i }));
+ await act(async () => {});
+
+ expect(organizeGoals).toHaveBeenCalledWith(
+ { providerId: 'provider-1', model: 'example-model' },
+ { silent: true },
+ );
+ expect(toastError).toHaveBeenCalledTimes(1);
+ expect(toastError).toHaveBeenCalledWith('Failed to organize goals');
+ });
+});
diff --git a/client/src/components/goals/GoalsTreeView.jsx b/client/src/components/goals/GoalsTreeView.jsx
index 96aedf3377..db71d25a75 100644
--- a/client/src/components/goals/GoalsTreeView.jsx
+++ b/client/src/components/goals/GoalsTreeView.jsx
@@ -450,7 +450,9 @@ export default function GoalsTreeView({ data, onRefresh }) {
const handleOrganize = async () => {
if (!selectedProviderId) { toast.error('No API provider available'); return; }
setOrganizing(true);
- const result = await api.organizeGoals({ providerId: selectedProviderId, model: selectedModel }).catch(() => null);
+ // `silent: true` — this handler owns the failure toast below; without it
+ // request() also toasts and the user sees two stacked errors.
+ const result = await api.organizeGoals({ providerId: selectedProviderId, model: selectedModel }, { silent: true }).catch(() => null);
setOrganizing(false);
if (result) {
setOrgSuggestion(result);
diff --git a/client/src/components/goals/GoalsTreeView.test.jsx b/client/src/components/goals/GoalsTreeView.test.jsx
index ab7a92d600..7deb0b8be9 100644
--- a/client/src/components/goals/GoalsTreeView.test.jsx
+++ b/client/src/components/goals/GoalsTreeView.test.jsx
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { render, screen, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -18,13 +18,24 @@ vi.mock('@react-three/drei', () => ({
Text: () => null,
}));
+const { toastError, organizeGoals, providerState } = vi.hoisted(() => ({
+ toastError: vi.fn(),
+ organizeGoals: vi.fn(),
+ // Mutable so the organize tests can hand the view a selected provider (the
+ // Organize button is disabled without one) while the rest keep the bare default.
+ providerState: { providers: [], selectedProviderId: '', selectedModel: '', availableModels: [] },
+}));
+
+vi.mock('../ui/Toast', () => ({
+ default: Object.assign(() => {}, { error: toastError, success: () => {} }),
+}));
vi.mock('../../services/api', () => ({
createGoal: vi.fn(),
- organizeGoals: vi.fn(),
+ organizeGoals,
}));
vi.mock('../../hooks/useProviderModels', () => ({
default: () => ({
- providers: [], selectedProviderId: '', selectedModel: '', availableModels: [],
+ ...providerState,
setSelectedProviderId: vi.fn(), setSelectedModel: vi.fn(), loading: false,
}),
}));
@@ -85,3 +96,36 @@ describe('empty state', () => {
expect(screen.getByText(/no goals to display/i)).toBeInTheDocument();
});
});
+
+describe('handleOrganize error toasting', () => {
+ // Guards #3515: this handler owns the "Failed to organize goals" toast, so the
+ // request helper must be told to stay quiet — otherwise a failed AI run stacks
+ // two error toasts on top of each other.
+ beforeEach(() => {
+ Object.assign(providerState, {
+ providers: [{ id: 'provider-1', name: 'Example Provider' }],
+ selectedProviderId: 'provider-1',
+ selectedModel: 'example-model',
+ availableModels: ['example-model'],
+ });
+ });
+ afterEach(() => {
+ Object.assign(providerState, { providers: [], selectedProviderId: '', selectedModel: '', availableModels: [] });
+ });
+
+ it('asks the API helper to stay silent and toasts the failure exactly once', async () => {
+ const user = userEvent.setup();
+ organizeGoals.mockRejectedValue(new Error('Organization failed'));
+ await renderTree();
+
+ await user.click(screen.getByRole('button', { name: /organize/i }));
+ await act(async () => {});
+
+ expect(organizeGoals).toHaveBeenCalledWith(
+ { providerId: 'provider-1', model: 'example-model' },
+ { silent: true },
+ );
+ expect(toastError).toHaveBeenCalledTimes(1);
+ expect(toastError).toHaveBeenCalledWith('Failed to organize goals');
+ });
+});
diff --git a/client/src/services/apiGoals.js b/client/src/services/apiGoals.js
index 756541a5e8..b2d4e8008c 100644
--- a/client/src/services/apiGoals.js
+++ b/client/src/services/apiGoals.js
@@ -67,7 +67,11 @@ export const acceptGoalPhases = (goalId, phases) => request(`/digital-twin/ident
export const decomposeGoal = (goalId, options = {}) => request(`/digital-twin/identity/goals/${goalId}/decompose`, { method: 'POST', body: JSON.stringify(options) });
export const acceptGoalDecomposition = (goalId, milestones) => request(`/digital-twin/identity/goals/${goalId}/accept-decomposition`, { method: 'POST', body: JSON.stringify({ milestones }) });
export const completeMilestoneTask = (goalId, milestoneId, taskId) => request(`/digital-twin/identity/goals/${goalId}/milestones/${milestoneId}/tasks/${taskId}/complete`, { method: 'PUT' });
-export const organizeGoals = (options = {}) => request('/digital-twin/identity/goals/organize', { method: 'POST', body: JSON.stringify(options) });
+// `body` carries the AI provider selection ({ providerId, model }); the second
+// `options` arg passes request-level flags through (e.g. `{ silent: true }`) so
+// the Goals views, which own their own "Failed to organize goals" toast, don't
+// also get the helper's default error toast stacked on top of it.
+export const organizeGoals = (body = {}, options = {}) => request('/digital-twin/identity/goals/organize', { method: 'POST', body: JSON.stringify(body), ...options });
export const applyGoalOrganization = (organization) => request('/digital-twin/identity/goals/organize/apply', { method: 'POST', body: JSON.stringify({ organization }) });
export const checkInGoal = (goalId, options = {}) => request(`/digital-twin/identity/goals/${goalId}/check-in`, { method: 'POST', body: JSON.stringify(options) });
export const scheduleGoalTimeBlocks = (goalId) => request(`/digital-twin/identity/goals/${goalId}/schedule`, { method: 'POST' });
diff --git a/client/src/services/apiGoals.test.js b/client/src/services/apiGoals.test.js
new file mode 100644
index 0000000000..f533653f0b
--- /dev/null
+++ b/client/src/services/apiGoals.test.js
@@ -0,0 +1,49 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+
+// The real `request()` from apiCore runs here on purpose: the bug this guards
+// (#3515) was that `organizeGoals` dropped its caller's request-level options,
+// so `request()` toasted the failure AND the Goals views toasted it again —
+// two stacked error toasts for one failed AI organization run. Only the Toast
+// module and `fetch` are stubbed, so the assertion is about how many toasts the
+// helper layer actually fires.
+const { toastError } = vi.hoisted(() => ({ toastError: vi.fn() }));
+vi.mock('../components/ui/Toast', () => ({
+ default: Object.assign(() => {}, { error: toastError, success: () => {} }),
+}));
+
+import { organizeGoals } from './apiGoals.js';
+
+const failingFetch = () => Promise.resolve({
+ ok: false,
+ status: 500,
+ json: () => Promise.resolve({ error: 'Organization failed' }),
+});
+
+beforeEach(() => {
+ toastError.mockReset();
+ vi.stubGlobal('fetch', vi.fn(failingFetch));
+});
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+describe('organizeGoals', () => {
+ it('forwards { silent: true } so a caller with its own error toast gets only one', async () => {
+ await expect(organizeGoals({ providerId: 'p1', model: 'm1' }, { silent: true })).rejects.toThrow('Organization failed');
+ expect(toastError).not.toHaveBeenCalled();
+ });
+
+ it('still sends the provider selection as the request body', async () => {
+ await organizeGoals({ providerId: 'p1', model: 'm1' }, { silent: true }).catch(() => null);
+ const [, config] = fetch.mock.calls[0];
+ expect(config.method).toBe('POST');
+ expect(JSON.parse(config.body)).toEqual({ providerId: 'p1', model: 'm1' });
+ });
+
+ it('keeps the helper toast for callers that pass no options', async () => {
+ // Not hard-coded silent — a caller without its own error UI must still see one.
+ await organizeGoals({ providerId: 'p1' }).catch(() => null);
+ expect(toastError).toHaveBeenCalledTimes(1);
+ });
+});