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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: guard goal milestone mutations (#5205) (#5276)
[._.]/ Adam Eivy93c3868d41be
diff --git a/client/src/components/goals/GoalDetailPanel.jsx b/client/src/components/goals/GoalDetailPanel.jsxindex b7d0489e4c..4e49796a13 100644--- a/client/src/components/goals/GoalDetailPanel.jsx+++ b/client/src/components/goals/GoalDetailPanel.jsx@@ -198,6 +198,8 @@ export default function GoalDetailPanel({ goal, allGoals, onClose, onRefresh })handleAddMilestone={s.handleAddMilestone}handleCompleteMilestone={s.handleCompleteMilestone}handleCompleteMilestoneTask={s.handleCompleteMilestoneTask}+ milestoneSubmitting={s.milestoneSubmitting}+ milestoneActions={s.milestoneActions}/>{/* Target Date */}diff --git a/client/src/components/goals/GoalMilestones.jsx b/client/src/components/goals/GoalMilestones.jsxindex 71abef30ce..fe319bdf81 100644--- a/client/src/components/goals/GoalMilestones.jsx+++ b/client/src/components/goals/GoalMilestones.jsx@@ -4,7 +4,7 @@ import { formatDateNumeric } from '../../utils/formatters';export default function GoalMilestones({goal, newMilestone, setNewMilestone, handleAddMilestone, handleCompleteMilestone,- handleCompleteMilestoneTask+ handleCompleteMilestoneTask, milestoneSubmitting, milestoneActions}) {return (<div>@@ -21,6 +21,7 @@ export default function GoalMilestones({<div className="flex items-center gap-2 text-sm"><buttononClick={() => !ms.completedAt && handleCompleteMilestone(ms.id)}+ disabled={ms.completedAt || milestoneActions?.has(`milestone:${ms.id}`)}aria-label={ms.completedAt ? `${ms.title} — completed` : `Mark ${ms.title} complete`}className={`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${ms.completedAt@@ -48,6 +49,7 @@ export default function GoalMilestones({<div key={task.id} className="flex items-center gap-1.5 text-[11px]"><buttononClick={() => handleCompleteMilestoneTask?.(ms.id, task.id)}+ disabled={milestoneActions?.has(`task:${ms.id}:${task.id}`)}aria-label={done ? `Mark ${task.title} incomplete` : `Mark ${task.title} complete`}className={`w-3.5 h-3.5 rounded border flex items-center justify-center shrink-0 ${done@@ -87,7 +89,7 @@ export default function GoalMilestones({/><buttononClick={handleAddMilestone}- disabled={!newMilestone.title.trim()}+ disabled={milestoneSubmitting || !newMilestone.title.trim()}className="px-2 py-1 text-xs rounded bg-port-accent/20 text-port-accent disabled:opacity-50">Adddiff --git a/client/src/hooks/useGoalDetail.js b/client/src/hooks/useGoalDetail.jsindex facb45266b..5fadeba1e0 100644--- a/client/src/hooks/useGoalDetail.js+++ b/client/src/hooks/useGoalDetail.js@@ -10,6 +10,9 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {const [form, setForm] = useState({});const [tagInput, setTagInput] = useState('');const [newMilestone, setNewMilestone] = useState({ title: '', targetDate: '' });+ const [milestoneSubmitting, setMilestoneSubmitting] = useState(false);+ const milestoneSubmittingRef = useRef(false);+ const [milestoneActions, setMilestoneActions] = useState(() => new Set());const [activities, setActivities] = useState([]);const [selectedActivity, setSelectedActivity] = useState('');const [showProgressForm, setShowProgressForm] = useState(false);@@ -165,8 +168,21 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {};const handleCompleteMilestoneTask = async (milestoneId, taskId) => {- await api.completeMilestoneTask(goal.id, milestoneId, taskId);- onRefresh();+ const actionKey = `task:${milestoneId}:${taskId}`;+ if (milestoneActions.has(actionKey)) return;+ setMilestoneActions(prev => new Set(prev).add(actionKey));+ try {+ await api.completeMilestoneTask(goal.id, milestoneId, taskId);+ onRefresh();+ } catch {+ // The request helper owns the toast; keep the task available for retry.+ } finally {+ setMilestoneActions(prev => {+ const next = new Set(prev);+ next.delete(actionKey);+ return next;+ });+ }};// The response is the signal (issue #3518): a failed check-in used to expand the@@ -233,18 +249,40 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {};const handleAddMilestone = async () => {- if (!newMilestone.title.trim()) return;- await api.addGoalMilestone(goal.id, {- title: newMilestone.title,- ...(newMilestone.targetDate ? { targetDate: newMilestone.targetDate } : {})- });- setNewMilestone({ title: '', targetDate: '' });- onRefresh();+ if (milestoneSubmittingRef.current || !newMilestone.title.trim()) return;+ milestoneSubmittingRef.current = true;+ setMilestoneSubmitting(true);+ try {+ await api.addGoalMilestone(goal.id, {+ title: newMilestone.title,+ ...(newMilestone.targetDate ? { targetDate: newMilestone.targetDate } : {})+ });+ setNewMilestone({ title: '', targetDate: '' });+ onRefresh();+ } catch {+ // Keep the form intact so the user can retry. The request helper owns the toast.+ } finally {+ milestoneSubmittingRef.current = false;+ setMilestoneSubmitting(false);+ }};const handleCompleteMilestone = async (milestoneId) => {- await api.completeGoalMilestone(goal.id, milestoneId);- onRefresh();+ const actionKey = `milestone:${milestoneId}`;+ if (milestoneActions.has(actionKey)) return;+ setMilestoneActions(prev => new Set(prev).add(actionKey));+ try {+ await api.completeGoalMilestone(goal.id, milestoneId);+ onRefresh();+ } catch {+ // The request helper owns the toast; keep the milestone available for retry.+ } finally {+ setMilestoneActions(prev => {+ const next = new Set(prev);+ next.delete(actionKey);+ return next;+ });+ }};const handleLinkActivity = async () => {@@ -404,6 +442,7 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {form, setForm,tagInput, setTagInput,newMilestone, setNewMilestone,+ milestoneSubmitting, milestoneActions,activities,selectedActivity, setSelectedActivity,showProgressForm, setShowProgressForm,diff --git a/client/src/hooks/useGoalDetail.test.jsx b/client/src/hooks/useGoalDetail.test.jsxindex a50d3d6822..0ca035a681 100644--- a/client/src/hooks/useGoalDetail.test.jsx+++ b/client/src/hooks/useGoalDetail.test.jsx@@ -13,6 +13,9 @@ const addGoalProgress = vi.fn(() => Promise.resolve({}));const addGoalTodo = vi.fn(() => Promise.resolve({}));const generateGoalPhases = vi.fn(() => Promise.resolve([]));const decomposeGoal = vi.fn(() => Promise.resolve([]));+const addGoalMilestone = vi.fn(() => Promise.resolve({}));+const completeGoalMilestone = vi.fn(() => Promise.resolve({}));+const completeMilestoneTask = vi.fn(() => Promise.resolve({}));vi.mock('../services/api', () => ({getActivities: (...args) => getActivities(...args),@@ -26,7 +29,10 @@ vi.mock('../services/api', () => ({addGoalProgress: (...args) => addGoalProgress(...args),addGoalTodo: (...args) => addGoalTodo(...args),generateGoalPhases: (...args) => generateGoalPhases(...args),- decomposeGoal: (...args) => decomposeGoal(...args)+ decomposeGoal: (...args) => decomposeGoal(...args),+ addGoalMilestone: (...args) => addGoalMilestone(...args),+ completeGoalMilestone: (...args) => completeGoalMilestone(...args),+ completeMilestoneTask: (...args) => completeMilestoneTask(...args)}));const { useGoalDetail } = await import('./useGoalDetail');@@ -466,3 +472,80 @@ describe('useGoalDetail handleDecompose', () => {});});});++describe('useGoalDetail milestone actions', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ getActivities.mockResolvedValue([]);+ getCalendarAccounts.mockResolvedValue([]);+ addGoalMilestone.mockResolvedValue({});+ completeGoalMilestone.mockResolvedValue({});+ completeMilestoneTask.mockResolvedValue({});+ });++ it('gates duplicate milestone submissions and clears the form after success', async () => {+ let release;+ addGoalMilestone.mockReturnValue(new Promise(resolve => { release = resolve; }));+ const { result } = renderGoalDetail();+ act(() => { result.current.setNewMilestone({ title: 'Ship it', targetDate: '' }); });++ let first;+ act(() => { first = result.current.handleAddMilestone(); });+ expect(result.current.milestoneSubmitting).toBe(true);+ await act(async () => { await result.current.handleAddMilestone(); });+ expect(addGoalMilestone).toHaveBeenCalledTimes(1);+ await act(async () => { release({}); await first; });+ expect(result.current.milestoneSubmitting).toBe(false);+ expect(result.current.newMilestone).toEqual({ title: '', targetDate: '' });+ });++ it('preserves milestone input and clears submitting after failure', async () => {+ addGoalMilestone.mockRejectedValue(new Error('server exploded'));+ const { result, onRefresh } = renderGoalDetail();+ act(() => { result.current.setNewMilestone({ title: 'Retry me', targetDate: '2026-09-01' }); });++ await act(async () => { await result.current.handleAddMilestone(); });+ expect(result.current.newMilestone).toEqual({ title: 'Retry me', targetDate: '2026-09-01' });+ expect(result.current.milestoneSubmitting).toBe(false);+ expect(onRefresh).not.toHaveBeenCalled();+ });++ it.each([+ ['completeGoalMilestone', completeGoalMilestone, 'handleCompleteMilestone'],+ ['completeMilestoneTask', completeMilestoneTask, 'handleCompleteMilestoneTask']+ ])('%s swallows rejected requests and can be retried', async (_name, apiFn, handler) => {+ apiFn.mockRejectedValueOnce(new Error('server exploded'));+ const { result, onRefresh } = renderGoalDetail();++ await act(async () => {+ await expect(handler === 'handleCompleteMilestone'+ ? result.current[handler]('milestone-1')+ : result.current[handler]('milestone-1', 'task-1')).resolves.toBeUndefined();+ });+ expect(onRefresh).not.toHaveBeenCalled();+ expect(result.current.milestoneActions.size).toBe(0);++ await act(async () => {+ await (handler === 'handleCompleteMilestone'+ ? result.current[handler]('milestone-1')+ : result.current[handler]('milestone-1', 'task-1'));+ });+ expect(apiFn).toHaveBeenCalledTimes(2);+ expect(onRefresh).toHaveBeenCalledTimes(1);+ });++ it.each([+ ['completeGoalMilestone', completeGoalMilestone, 'handleCompleteMilestone'],+ ['completeMilestoneTask', completeMilestoneTask, 'handleCompleteMilestoneTask']+ ])('%s clears its action state when the API throws synchronously', async (_name, apiFn, handler) => {+ apiFn.mockImplementation(() => { throw new Error('threw before returning a promise'); });+ const { result, onRefresh } = renderGoalDetail();+ await act(async () => {+ await expect(handler === 'handleCompleteMilestone'+ ? result.current[handler]('milestone-1')+ : result.current[handler]('milestone-1', 'task-1')).resolves.toBeUndefined();+ });+ expect(result.current.milestoneActions.size).toBe(0);+ expect(onRefresh).not.toHaveBeenCalled();+ });+});