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: toast an error instead of false success when applying a goal hierarchy fails (#3516)

[._.]/ Adam Eivy9672bbe7b498
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 22605af2f7..6ffcc1907a 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -129,3 +129,4 @@
- **[issue-3509] Opening your Bookmarks no longer reads and re-sorts every link you have ever saved.** Answering a single page of `/brain/links` meant loading and JSON-parsing every link record on disk, filtering the whole array in memory, sorting all of it by date, and then throwing away everything outside the fifty rows actually asked for — so the cost of showing page one grew with the size of the entire collection rather than with the size of the page. The links list now rides a small in-memory index of just the four fields the endpoint orders, filters, and counts on, refreshed per record as links change rather than rebuilt per request, so only the requested page's records are opened. The filters keep their exact previous meaning, including that a link saved before the GitHub flag existed still does not match "not a GitHub repo" — absent is not the same as false. Links sharing a timestamp, which is every link from one bulk import, are now ordered by id underneath the date so paging through them cannot skip or repeat a row at a page boundary, and a link with a missing or unreadable date sorts last instead of scrambling the order around it. Two neighbouring paths lost the same whole-collection read: checking that a drag-reorder batch refers to links that still exist, and checking whether a URL you are about to save is already bookmarked.
- **[issue-3510] Typing in your Daily Log no longer re-reads every day you have ever written.** Each daily-log entry is its own file on disk, and every save, autosave, and dictated segment against today was rebuilding a full date-to-entry map of your entire journal history — opening and parsing every past day, merging each one's local Obsidian mirror location back onto it — purely to fill in the payload of a store-wide "the journal changed" event. Nothing consumed that map: the write paths already announce the single affected day, and that is what the memory vectorizer listens on. The event now carries just the day that moved, so an append costs the one entry it touched instead of the whole archive, and a long dictation session no longer re-reads years of entries once per sentence. A delete reports the day with an explicitly empty entry, which is distinct from a day that simply was not part of the change.
+- **[issue-3516] Applying an AI-suggested goal hierarchy no longer reports success when it failed.** The routine that writes the suggestion back — creating the new north-star goal, creating the sub-goals under it, then re-parenting everything else — already gave up and reported failure the moment any of those steps was rejected by the server, but both views that call it threw that answer away and showed "Goal hierarchy applied" regardless. So a run that created nothing at all still looked like it had worked, and the list you were staring at kept showing the old arrangement. Both the list and the tree view now say so when the apply fails, and both refresh the goals afterwards either way, because a failure can still have created part of the hierarchy before aborting and leaving that half-written state off screen was the actual complaint. The apply routine swallows each server error on purpose so it can report one clean yes-or-no, so it now also asks those calls to stay quiet — otherwise the failure would have surfaced as two error toasts stacked on top of each other.
diff --git a/client/src/components/goals/GoalsListView.jsx b/client/src/components/goals/GoalsListView.jsx
index 3a6d4a95a5..524a1066a3 100644
--- a/client/src/components/goals/GoalsListView.jsx
+++ b/client/src/components/goals/GoalsListView.jsx
@@ -271,9 +271,13 @@ export default function GoalsListView({ data, onRefresh }) {
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);
- toast.success('Goal hierarchy applied');
+ const applied = await applyOrganizationSuggestion(result);
+ // Refresh either way: a failed apply can still have created the apex or some
+ // sub-apex goals before aborting, and leaving the stale list on screen is the
+ // out-of-sync state this guard exists to prevent (issue #3516).
onRefresh();
+ if (!applied) { toast.error('Failed to apply goal hierarchy'); return; }
+ toast.success('Goal hierarchy applied');
};
const handleDragStart = useCallback((event) => {
diff --git a/client/src/components/goals/GoalsListView.test.jsx b/client/src/components/goals/GoalsListView.test.jsx
index 07d04742a7..2b3bf54aa8 100644
--- a/client/src/components/goals/GoalsListView.test.jsx
+++ b/client/src/components/goals/GoalsListView.test.jsx
@@ -2,17 +2,21 @@ 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(() => ({
+const { toastError, toastSuccess, organizeGoals, createGoal, applyGoalOrganization } = vi.hoisted(() => ({
toastError: vi.fn(),
+ toastSuccess: vi.fn(),
organizeGoals: vi.fn(),
+ createGoal: vi.fn(),
+ applyGoalOrganization: vi.fn(),
}));
vi.mock('../ui/Toast', () => ({
- default: Object.assign(() => {}, { error: toastError, success: () => {} }),
+ default: Object.assign(() => {}, { error: toastError, success: toastSuccess }),
}));
vi.mock('../../services/api', () => ({
- createGoal: vi.fn(),
+ createGoal,
organizeGoals,
+ applyGoalOrganization,
}));
vi.mock('../../hooks/useProviderModels', () => ({
default: () => ({
@@ -36,8 +40,22 @@ const GOALS = [
// 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()} />);
+const renderList = async (onRefresh = vi.fn()) => {
+ render(<GoalsListView data={DATA} onRefresh={onRefresh} />);
+ await act(async () => {});
+ return onRefresh;
+};
+
+// A minimal suggestion that forces applyOrganizationSuggestion down the "create a new
+// apex first" branch, so a rejected createGoal makes it return false.
+const NEW_APEX_SUGGESTION = {
+ apexGoal: { existingId: null, suggestedTitle: 'Example apex', suggestedDescription: '' },
+ organization: [{ id: 'g1', goalType: 'sub-apex', suggestedParentId: '__new_apex__' }],
+ suggestedSubApex: [],
+};
+
+const clickOrganize = async (user) => {
+ await user.click(screen.getByRole('button', { name: /organize/i }));
await act(async () => {});
};
@@ -54,8 +72,7 @@ describe('handleOrganize error toasting', () => {
organizeGoals.mockRejectedValue(new Error('Organization failed'));
await renderList();
- await user.click(screen.getByRole('button', { name: /organize/i }));
- await act(async () => {});
+ await clickOrganize(user);
expect(organizeGoals).toHaveBeenCalledWith(
{ providerId: 'provider-1', model: 'example-model' },
@@ -65,3 +82,40 @@ describe('handleOrganize error toasting', () => {
expect(toastError).toHaveBeenCalledWith('Failed to organize goals');
});
});
+
+describe('handleOrganize apply-failure path', () => {
+ // Guards #3516: applyOrganizationSuggestion folds every API failure into a `false`
+ // return. Ignoring it toasted "Goal hierarchy applied" over a backend that never
+ // took the change.
+ it('toasts an error and no success when applying the hierarchy fails', async () => {
+ const user = userEvent.setup();
+ organizeGoals.mockResolvedValue(NEW_APEX_SUGGESTION);
+ createGoal.mockRejectedValue(new Error('apex create failed'));
+ const onRefresh = await renderList();
+
+ await clickOrganize(user);
+
+ // The apply helper stays silent so this handler is the only toast source.
+ expect(createGoal).toHaveBeenCalledWith(expect.objectContaining({ goalType: 'apex' }), { silent: true });
+ expect(applyGoalOrganization).not.toHaveBeenCalled();
+ expect(toastSuccess).not.toHaveBeenCalled();
+ expect(toastError).toHaveBeenCalledTimes(1);
+ expect(toastError).toHaveBeenCalledWith('Failed to apply goal hierarchy');
+ // Still refreshed — a partial apply must not leave a stale list on screen.
+ expect(onRefresh).toHaveBeenCalled();
+ });
+
+ it('toasts success and refreshes when the hierarchy applies cleanly', async () => {
+ const user = userEvent.setup();
+ organizeGoals.mockResolvedValue(NEW_APEX_SUGGESTION);
+ createGoal.mockResolvedValue({ id: 'apex-1' });
+ applyGoalOrganization.mockResolvedValue(true);
+ const onRefresh = await renderList();
+
+ await clickOrganize(user);
+
+ expect(toastError).not.toHaveBeenCalled();
+ expect(toastSuccess).toHaveBeenCalledWith('Goal hierarchy applied');
+ expect(onRefresh).toHaveBeenCalled();
+ });
+});
diff --git a/client/src/components/goals/GoalsTreeView.jsx b/client/src/components/goals/GoalsTreeView.jsx
index db71d25a75..674fe0b849 100644
--- a/client/src/components/goals/GoalsTreeView.jsx
+++ b/client/src/components/goals/GoalsTreeView.jsx
@@ -464,11 +464,14 @@ export default function GoalsTreeView({ data, onRefresh }) {
const handleApplyOrganization = async () => {
if (!orgSuggestion) return;
setApplyingOrg(true);
- await applyOrganizationSuggestion(orgSuggestion);
+ const applied = await applyOrganizationSuggestion(orgSuggestion);
setApplyingOrg(false);
setOrgSuggestion(null);
- toast.success('Goal hierarchy applied');
+ // Refresh either way — a failed apply can still have landed part of the hierarchy
+ // (issue #3516).
onRefresh();
+ if (!applied) { toast.error('Failed to apply goal hierarchy'); return; }
+ toast.success('Goal hierarchy applied');
};
return (
diff --git a/client/src/components/goals/applyOrganization.js b/client/src/components/goals/applyOrganization.js
index aaf83ee153..25d4940b38 100644
--- a/client/src/components/goals/applyOrganization.js
+++ b/client/src/components/goals/applyOrganization.js
@@ -1,5 +1,13 @@
import * as api from '../../services/api';
+// Every API call below swallows its rejection and folds it into the `false` return
+// value, so each one passes `{ silent: true }` — the caller that acts on `false` owns
+// the error toast, and without this the request helper would stack its own on top.
+const SILENT = { silent: true };
+
+// Returns true when the whole suggestion landed, false when any step failed. Callers
+// MUST branch on this — a false return means the backend is partially or wholly
+// unchanged, so a success toast would be a lie (issue #3516).
export async function applyOrganizationSuggestion(suggestion) {
let apexId = null;
// Clone organization array to avoid mutating caller's state
@@ -13,7 +21,7 @@ export async function applyOrganizationSuggestion(suggestion) {
horizon: 'lifetime',
category: 'legacy',
goalType: 'apex'
- }).then(res => res, () => null);
+ }, SILENT).then(res => res, () => null);
if (!apex?.id) return false;
apexId = apex.id;
}
@@ -43,14 +51,14 @@ export async function applyOrganizationSuggestion(suggestion) {
category: sg.category || 'legacy',
goalType: 'sub-apex',
...(parentId ? { parentId } : {})
- }).then(() => true, () => false);
+ }, SILENT).then(() => true, () => false);
}));
if (results.some(r => !r)) return false;
}
// Apply organization to existing goals
if (organization?.length) {
- const ok = await api.applyGoalOrganization(organization).then(() => true, () => false);
+ const ok = await api.applyGoalOrganization(organization, SILENT).then(() => true, () => false);
if (!ok) return false;
}
diff --git a/client/src/components/goals/applyOrganization.test.js b/client/src/components/goals/applyOrganization.test.js
index 2c090871b8..f037886dcc 100644
--- a/client/src/components/goals/applyOrganization.test.js
+++ b/client/src/components/goals/applyOrganization.test.js
@@ -40,7 +40,8 @@ describe('applyOrganizationSuggestion — __new_apex__ round-trip', () => {
// Apex created from the suggestion
expect(api.createGoal).toHaveBeenCalledWith(
- expect.objectContaining({ title: 'Live fully', goalType: 'apex' })
+ expect.objectContaining({ title: 'Live fully', goalType: 'apex' }),
+ { silent: true }
);
// The server received the rewritten organization — no raw sentinel survives
@@ -101,7 +102,8 @@ describe('applyOrganizationSuggestion — __new_apex__ round-trip', () => {
expect(api.createGoal.mock.calls[0][0]).toMatchObject({ title: 'Apex', goalType: 'apex' });
// ...then the sub-apex create is parented under the real apex id
expect(api.createGoal).toHaveBeenCalledWith(
- expect.objectContaining({ title: 'Health', goalType: 'sub-apex', parentId: 'apex-real-3' })
+ expect.objectContaining({ title: 'Health', goalType: 'sub-apex', parentId: 'apex-real-3' }),
+ { silent: true }
);
});
@@ -154,3 +156,54 @@ describe('applyOrganizationSuggestion — __new_apex__ round-trip', () => {
expect(api.applyGoalOrganization).not.toHaveBeenCalled();
});
});
+
+// Guards #3516: every failure has to surface as `false` so the calling view can toast
+// an error instead of a false "Goal hierarchy applied", and every call has to be
+// `silent` so that view's toast is the only one the user sees.
+describe('applyOrganizationSuggestion — failure reporting and toast layering', () => {
+ it('returns false when a suggested sub-apex goal fails to create', async () => {
+ api.createGoal
+ .mockResolvedValueOnce({ id: 'apex-real-5' }) // apex creates fine...
+ .mockRejectedValueOnce(new Error('sub-apex create failed')); // ...sub-apex does not
+
+ const suggestion = {
+ apexGoal: { existingId: null, suggestedTitle: 'Apex', suggestedDescription: '' },
+ organization: [{ id: 'g-1', goalType: 'standard', suggestedParentId: null }],
+ suggestedSubApex: [{ title: 'Health', description: '', category: 'health' }],
+ };
+
+ const ok = await applyOrganizationSuggestion(suggestion);
+ expect(ok).toBe(false);
+ // Aborts before pushing the organization, so the server isn't left half-applied.
+ expect(api.applyGoalOrganization).not.toHaveBeenCalled();
+ });
+
+ it('returns false when the organization apply call rejects', async () => {
+ api.applyGoalOrganization.mockRejectedValue(new Error('apply failed'));
+
+ const suggestion = {
+ apexGoal: { existingId: 'existing-apex', suggestedTitle: null, suggestedDescription: null },
+ organization: [{ id: 'g-1', goalType: 'standard', suggestedParentId: 'existing-apex' }],
+ suggestedSubApex: [],
+ };
+
+ expect(await applyOrganizationSuggestion(suggestion)).toBe(false);
+ });
+
+ it('passes silent:true on every API call so only the caller toasts', async () => {
+ api.createGoal.mockResolvedValue({ id: 'apex-real-6' });
+
+ const suggestion = {
+ apexGoal: { existingId: null, suggestedTitle: 'Apex', suggestedDescription: '' },
+ organization: [{ id: 'g-1', goalType: 'standard', suggestedParentId: null }],
+ suggestedSubApex: [{ title: 'Health', description: '', category: 'health' }],
+ };
+
+ expect(await applyOrganizationSuggestion(suggestion)).toBe(true);
+
+ for (const call of api.createGoal.mock.calls) {
+ expect(call[1]).toEqual({ silent: true });
+ }
+ expect(api.applyGoalOrganization).toHaveBeenCalledWith(expect.anything(), { silent: true });
+ });
+});
diff --git a/client/src/services/apiGoals.js b/client/src/services/apiGoals.js
index b2d4e8008c..7c13995943 100644
--- a/client/src/services/apiGoals.js
+++ b/client/src/services/apiGoals.js
@@ -17,9 +17,12 @@ export const setBirthDate = (birthDate) => request('/digital-twin/identity/goals
method: 'PUT',
body: JSON.stringify({ birthDate })
});
-export const createGoal = (data) => request('/digital-twin/identity/goals', {
+// `options` passes request-level flags through (e.g. `{ silent: true }`) for callers
+// that swallow the rejection and own the resulting error UI — see applyOrganization.js.
+export const createGoal = (data, options = {}) => request('/digital-twin/identity/goals', {
method: 'POST',
- body: JSON.stringify(data)
+ body: JSON.stringify(data),
+ ...options
});
export const updateGoal = (id, data, options = {}) => request(`/digital-twin/identity/goals/${id}`, {
method: 'PUT',
@@ -72,7 +75,7 @@ export const completeMilestoneTask = (goalId, milestoneId, taskId) => request(`/
// 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 applyGoalOrganization = (organization, options = {}) => request('/digital-twin/identity/goals/organize/apply', { method: 'POST', body: JSON.stringify({ organization }), ...options });
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' });
export const removeGoalSchedule = (goalId) => request(`/digital-twin/identity/goals/${goalId}/schedule`, { method: 'DELETE' });