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: keep the goal progress slider on the stored percentage when the update fails (#3520)
[._.]/ Adam Eivy1c14767b945e
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 149a215454..4a1484a767 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -144,3 +144,5 @@- **[issue-3527] The Brain Trust Panel no longer scrolls sideways on a phone.** Its header put the title block and the five audit counters — Total, Filed, Review, Corrected, Errors — on one row that was not allowed to wrap, so on a 375px screen the counters ran off the right edge and dragged the whole page's horizontal scrollbar with them. The title and the counters now stack under `sm` and re-join from `sm` up, the counters wrap among themselves, and the status-filter row wraps too so its Refresh button cannot spill off screen either. Every counter stays visible without scrolling; the desktop layout is unchanged.- **[issue-3528] The Notes header controls in Brain are now big enough to hit on a phone.** The "Manage vaults" and "New note" buttons wrapped 14px icons in nothing but `p-1.5`, giving them roughly 26x26px of tappable area right next to the vault dropdown — close enough that a thumb aiming for "New note" would land on the dropdown instead. Those two buttons, plus the vault selector, the search box, and the create-note row beside them, now all clear the 44px touch-target floor the rest of the app uses. The search box also gained enough right padding to clear its own clear-search button, which was already 44px wide and had been sitting on top of whatever you typed.++- **[issue-3520] The goal progress slider no longer sits on a percentage the server never stored.** Releasing the slider fired the update and left the dragged number on screen, and the only thing that ever corrected it was an effect that re-synced the slider the instant the drag ended — so on a normal save the percentage visibly snapped back to the old value while the request was still in flight and then jumped forward again when the refresh landed, and on a rejected save it was only that same flap that happened to leave the right number showing. Moving the slider with the keyboard never committed at all: arrow keys never produce a mouse release, so the value the user set stayed on screen, unsaved, until the panel was closed and re-opened — the reported symptom, reached by a different route than the drag. The slider now keeps the value it committed until the stored percentage actually changes underneath it, and resets to what is stored the moment the update reports it failed; the update handler reports that outcome rather than throwing it away. Arrow, Home/End and moving focus off the track all commit like a mouse release does, a release that lands while a save is already in flight is ignored instead of re-sending the same percentage, and the "Progress" label is now paired to the slider so screen readers and click-to-focus find it.diff --git a/client/src/components/goals/ProgressSlider.jsx b/client/src/components/goals/ProgressSlider.jsxindex d171ef24a5..94df2fdf7f 100644--- a/client/src/components/goals/ProgressSlider.jsx+++ b/client/src/components/goals/ProgressSlider.jsx@@ -1,28 +1,62 @@-import { useState, useEffect } from 'react';+import { useState, useEffect, useRef } from 'react';import { TrendingUp, TrendingDown, Minus, Clock } from 'lucide-react';import { formatDurationMin } from '../../utils/formatters';export default function ProgressSlider({ goal, onCommit }) {- const [draft, setDraft] = useState(goal.progress ?? 0);+ const stored = goal.progress ?? 0;+ const [draft, setDraft] = useState(stored);const [dragging, setDragging] = useState(false);+ const [saving, setSaving] = useState(false);+ // Per-goal so the label/input pairing stays unique if two panels ever co-exist.+ const sliderId = `goal-progress-${goal.id}`;- // Sync draft when goal changes externally (not during drag)+ // Adopt the stored percentage only when it actually changes underneath us (a+ // refresh, a peer sync, an edit elsewhere in the panel). Keying on the transition+ // instead of "any render where we aren't dragging" is what lets the committed+ // value stay on screen while the save is in flight and the goal prop is still the+ // pre-commit snapshot (issue #3520) — the old gate re-ran the moment `dragging`+ // flipped false and reset the slider before the request had even been answered.+ const lastStored = useRef(stored);useEffect(() => {- if (!dragging) setDraft(goal.progress ?? 0);- }, [goal.progress, dragging]);+ if (lastStored.current === stored) return;+ lastStored.current = stored;+ if (!dragging) setDraft(stored);+ }, [stored, dragging]);- const commit = () => {+ const commit = async () => {setDragging(false);- if (draft !== (goal.progress ?? 0)) onCommit(draft);+ // Re-entrancy guard: touch devices fire touchend AND a synthesized mouseup, and+ // a blur can follow both — none of them should re-send an in-flight percentage.+ if (saving || draft === stored) return;+ setSaving(true);+ let saved = false;+ try {+ // Only an explicit `false` means "the server never took this" — a handler+ // that returns nothing keeps the pre-#3520 optimistic behavior.+ saved = (await onCommit(draft)) !== false;+ } catch {+ // Deliberately swallowed — `request()` already toasted the failure, so this+ // stays a single-layer error UI. `try/finally` rather than `.catch()`: a+ // handler that throws before returning a promise would otherwise latch+ // `saving` on and freeze the slider on an unsaved value.+ } finally {+ setSaving(false);+ }+ // The reset is the fix: without it the panel keeps advertising a percentage the+ // database rejected until the user closes and re-opens it. Read through the ref+ // rather than this closure's `stored` so a value that arrived while the request+ // was in flight isn't undone by a rollback to the pre-commit snapshot.+ if (!saved) setDraft(lastStored.current);};return (<div><div className="flex items-center justify-between mb-1.5">- <span className="text-xs font-medium text-gray-400">Progress</span>+ <label htmlFor={sliderId} className="text-xs font-medium text-gray-400">Progress</label><span className="text-xs text-gray-300 font-mono">{draft}%</span></div><input+ id={sliderId}type="range"min="0"max="100"@@ -30,6 +64,11 @@ export default function ProgressSlider({ goal, onCommit }) {onChange={e => { setDragging(true); setDraft(parseInt(e.target.value, 10)); }}onMouseUp={commit}onTouchEnd={commit}+ // Arrow/Home/End keys move a range input without ever firing mouseup, so a+ // keyboard-only user could otherwise never persist a value; blur catches a+ // pointer released off the track.+ onKeyUp={commit}+ onBlur={commit}className="w-full h-1.5 rounded-full appearance-none cursor-pointer bg-port-border accent-port-accent"/>{goal.velocity && (diff --git a/client/src/components/goals/ProgressSlider.test.jsx b/client/src/components/goals/ProgressSlider.test.jsxnew file mode 100644index 0000000000..a97bf50569--- /dev/null+++ b/client/src/components/goals/ProgressSlider.test.jsx@@ -0,0 +1,173 @@+import { describe, it, expect, vi } from 'vitest';+import { act, render, screen, fireEvent } from '@testing-library/react';++import ProgressSlider from './ProgressSlider';++const GOAL = { id: 'goal-1', progress: 20 };++const renderSlider = (onCommit, goal = GOAL) => {+ const view = render(<ProgressSlider goal={goal} onCommit={onCommit} />);+ return { ...view, slider: screen.getByRole('slider') };+};++// Drag = the onChange stream a real pointer produces, then the release that commits.+const drag = (slider, value) => fireEvent.change(slider, { target: { value: String(value) } });++describe('ProgressSlider commit', () => {+ it('sends the released value to onCommit', async () => {+ const onCommit = vi.fn(() => Promise.resolve(true));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(onCommit).toHaveBeenCalledWith(85);+ });++ it('does not commit when the value lands back on the stored percentage', async () => {+ const onCommit = vi.fn(() => Promise.resolve(true));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ drag(slider, 20);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(onCommit).not.toHaveBeenCalled();+ });++ // Issue #3520: a rejected update left `draft` on the dragged value, so the panel+ // advertised a percentage the database never took.+ it('snaps back to the stored percentage when the commit reports failure', async () => {+ const onCommit = vi.fn(() => Promise.resolve(false));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ expect(screen.getByText('85%')).toBeTruthy();++ await act(async () => { fireEvent.mouseUp(slider); });++ expect(screen.getByText('20%')).toBeTruthy();+ expect(slider.value).toBe('20');+ });++ it('snaps back when the commit rejects', async () => {+ const onCommit = vi.fn(() => Promise.reject(new Error('server exploded')));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(screen.getByText('20%')).toBeTruthy();+ });++ // A bare `.catch()` never gets attached when the handler throws before returning a+ // promise, which would latch `saving` on and freeze the slider on an unsaved value.+ it('snaps back when the commit throws synchronously', async () => {+ const onCommit = vi.fn(() => { throw new Error('threw before returning a promise'); });+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(screen.getByText('20%')).toBeTruthy();+ });++ it('can be retried after a failed commit', async () => {+ const onCommit = vi.fn()+ .mockResolvedValueOnce(false)+ .mockResolvedValueOnce(true);+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });+ expect(screen.getByText('20%')).toBeTruthy();++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(onCommit).toHaveBeenCalledTimes(2);+ expect(screen.getByText('85%')).toBeTruthy();+ });++ // A handler that returns nothing keeps the pre-#3520 optimistic behavior.+ it('keeps the dragged value when the commit resolves with no outcome', async () => {+ const onCommit = vi.fn(() => Promise.resolve());+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(screen.getByText('85%')).toBeTruthy();+ });++ it('holds the dragged value while the commit is in flight', async () => {+ let release;+ const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });+ // The pre-fix effect reset draft the moment dragging flipped false.+ expect(screen.getByText('85%')).toBeTruthy();++ await act(async () => { release(true); });+ expect(screen.getByText('85%')).toBeTruthy();+ });++ it('ignores a second release while the first commit is still in flight', async () => {+ let release;+ const onCommit = vi.fn(() => new Promise((resolve) => { release = resolve; }));+ const { slider } = renderSlider(onCommit);++ drag(slider, 85);+ // Touch devices fire touchend and a synthesized mouseup for one release.+ await act(async () => { fireEvent.touchEnd(slider); });+ await act(async () => { fireEvent.mouseUp(slider); });++ expect(onCommit).toHaveBeenCalledTimes(1);++ await act(async () => { release(true); });+ });++ // Arrow/Home/End move a range input without ever firing mouseup.+ it('commits a keyboard-driven change on key release', async () => {+ const onCommit = vi.fn(() => Promise.resolve(true));+ const { slider } = renderSlider(onCommit);++ drag(slider, 21);+ await act(async () => { fireEvent.keyUp(slider, { key: 'ArrowRight' }); });++ expect(onCommit).toHaveBeenCalledWith(21);+ });++ // The parent refetch lands after the commit resolves, so a saved value has to+ // survive a render that still carries the pre-commit goal snapshot.+ it('keeps the saved value while the refreshed goal is still in flight', async () => {+ const onCommit = vi.fn(() => Promise.resolve(true));+ const { slider, rerender } = renderSlider(onCommit);++ drag(slider, 85);+ await act(async () => { fireEvent.mouseUp(slider); });+ await act(async () => { rerender(<ProgressSlider goal={GOAL} onCommit={onCommit} />); });+ expect(screen.getByText('85%')).toBeTruthy();++ await act(async () => { rerender(<ProgressSlider goal={{ ...GOAL, progress: 85 }} onCommit={onCommit} />); });+ expect(screen.getByText('85%')).toBeTruthy();+ });++ it('pairs the Progress label with the slider', () => {+ const { slider } = renderSlider(vi.fn());++ expect(screen.getByLabelText('Progress')).toBe(slider);+ });++ it('adopts an externally changed progress value', async () => {+ const onCommit = vi.fn(() => Promise.resolve(true));+ const { rerender } = renderSlider(onCommit);++ await act(async () => { rerender(<ProgressSlider goal={{ ...GOAL, progress: 60 }} onCommit={onCommit} />); });++ expect(screen.getByText('60%')).toBeTruthy();+ expect(onCommit).not.toHaveBeenCalled();+ });+});diff --git a/client/src/hooks/useGoalDetail.js b/client/src/hooks/useGoalDetail.jsindex 7f6fc5beb1..1b973ab62a 100644--- a/client/src/hooks/useGoalDetail.js+++ b/client/src/hooks/useGoalDetail.js@@ -268,9 +268,21 @@ export function useGoalDetail({ goal, allGoals, onClose, onRefresh }) {onRefresh();};+ // The return value is the signal (issue #3520): ProgressSlider renders its own+ // dragged `draft`, so a failed PUT has to tell it to snap back — otherwise the+ // panel keeps showing a percentage the database never took. No custom toast on+ // purpose — `request()` already toasts the failure, so this stays a single-layer+ // error UI. `try/catch` rather than a bare `.catch()` for the same reason as+ // runSchedulingAction above: a call that throws before handing back a promise+ // would skip the catch and report a save that never happened.const handleProgressChange = async (value) => {- await api.updateGoalProgress(goal.id, value);+ try {+ await api.updateGoalProgress(goal.id, value);+ } catch {+ return false;+ }onRefresh();+ return true;};const handleAddTodo = async () => {diff --git a/client/src/hooks/useGoalDetail.test.jsx b/client/src/hooks/useGoalDetail.test.jsxindex 3b38b19409..9fde215e22 100644--- a/client/src/hooks/useGoalDetail.test.jsx+++ b/client/src/hooks/useGoalDetail.test.jsx@@ -7,6 +7,7 @@ const scheduleGoalTimeBlocks = vi.fn(() => Promise.resolve({}));const removeGoalSchedule = vi.fn(() => Promise.resolve({}));const rescheduleGoalTimeBlocks = vi.fn(() => Promise.resolve({}));const checkInGoal = vi.fn(() => Promise.resolve({ id: 'check-in-1' }));+const updateGoalProgress = vi.fn(() => Promise.resolve({}));vi.mock('../services/api', () => ({getActivities: (...args) => getActivities(...args),@@ -14,7 +15,8 @@ vi.mock('../services/api', () => ({scheduleGoalTimeBlocks: (...args) => scheduleGoalTimeBlocks(...args),removeGoalSchedule: (...args) => removeGoalSchedule(...args),rescheduleGoalTimeBlocks: (...args) => rescheduleGoalTimeBlocks(...args),- checkInGoal: (...args) => checkInGoal(...args)+ checkInGoal: (...args) => checkInGoal(...args),+ updateGoalProgress: (...args) => updateGoalProgress(...args)}));const { useGoalDetail } = await import('./useGoalDetail');@@ -208,3 +210,58 @@ describe('useGoalDetail handleCheckIn', () => {expect(onRefresh).toHaveBeenCalledTimes(1);});});++// Issue #3520: the handler threw on a failed PUT, so ProgressSlider kept rendering+// the dragged percentage as if it had been saved.+describe('useGoalDetail handleProgressChange', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ getActivities.mockResolvedValue([]);+ getCalendarAccounts.mockResolvedValue([]);+ updateGoalProgress.mockResolvedValue({});+ });++ it('saves the value, refreshes, and reports success', async () => {+ const { result, onRefresh } = renderGoalDetail();++ let outcome;+ await act(async () => { outcome = await result.current.handleProgressChange(85); });++ expect(updateGoalProgress).toHaveBeenCalledWith(GOAL.id, 85);+ expect(onRefresh).toHaveBeenCalledTimes(1);+ expect(outcome).toBe(true);+ });++ it('reports failure and skips the refresh when the request rejects', async () => {+ updateGoalProgress.mockRejectedValue(new Error('server exploded'));+ const { result, onRefresh } = renderGoalDetail();++ let outcome;+ await act(async () => { outcome = await result.current.handleProgressChange(85); });++ expect(outcome).toBe(false);+ expect(onRefresh).not.toHaveBeenCalled();+ });++ // A bare `.catch()` never gets attached when the call throws before handing back a+ // promise, so the failure would surface as a rejection instead of a `false`.+ it('reports failure when the api call throws synchronously', async () => {+ updateGoalProgress.mockImplementation(() => { throw new Error('threw before returning a promise'); });+ const { result, onRefresh } = renderGoalDetail();++ let outcome;+ await act(async () => { outcome = await result.current.handleProgressChange(85); });++ expect(outcome).toBe(false);+ expect(onRefresh).not.toHaveBeenCalled();+ });++ it('does not surface a rejection to the caller as an unhandled promise', async () => {+ updateGoalProgress.mockRejectedValue(new Error('server exploded'));+ const { result } = renderGoalDetail();++ await act(async () => {+ await expect(result.current.handleProgressChange(85)).resolves.toBe(false);+ });+ });+});