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
stop daily-log autosave from silently retrying a failed body every debounce tick
[._.]/ Adam Eivy6b18bd0b6400
diff --git a/client/src/components/brain/tabs/DailyLogTab.jsx b/client/src/components/brain/tabs/DailyLogTab.jsxindex ca4d868a36..2963ac67cc 100644--- a/client/src/components/brain/tabs/DailyLogTab.jsx+++ b/client/src/components/brain/tabs/DailyLogTab.jsx@@ -98,6 +98,12 @@ export default function DailyLogTab() {// Suppresses repeat failure toasts — a failing autosave retries on the next// keystroke, so an unreachable server would otherwise toast every tick.const autoSaveFailedRef = useRef(false);+ // The body of the last FAILED save. The autosave effect refuses to re-arm+ // while `content` still equals it — without this, a failed PUT flips+ // `saving`, the effect re-runs, and an unreachable server gets a silent+ // PUT every debounce tick. Cleared on success; a keystroke (content change),+ // explicit save, or blur/visibility flush still retries.+ const lastFailedBodyRef = useRef(null);// Which date the text in `content` actually belongs to. `date` flips before// the new entry loads, so this is the only safe answer to "what am I about// to overwrite?" — see the guard in saveRef.@@ -321,9 +327,11 @@ export default function DailyLogTab() {if (!res?.entry) {if (!auto || !autoSaveFailedRef.current) toast.error('Save failed');autoSaveFailedRef.current = true;+ lastFailedBodyRef.current = body;return;}autoSaveFailedRef.current = false;+ lastFailedBodyRef.current = null;// Adopt the server's metadata but deliberately leave the textarea alone.// Anything typed during the in-flight PUT stays in `content` and stays// dirty against res.entry.content, so the next tick saves it — whereas@@ -349,6 +357,13 @@ export default function DailyLogTab() {firstDirtyAtRef.current = null;return undefined;}+ // A body that just failed doesn't get an automatic re-attempt — that loops+ // a PUT per debounce tick against a down server. Wait for a content change+ // (or an explicit save / blur / visibility flush, which bypass this effect).+ if (lastFailedBodyRef.current !== null && content === lastFailedBodyRef.current) {+ firstDirtyAtRef.current = null;+ return undefined;+ }if (firstDirtyAtRef.current === null) firstDirtyAtRef.current = Date.now();const waited = Date.now() - firstDirtyAtRef.current;const wait = Math.max(0, Math.min(AUTOSAVE_DEBOUNCE_MS, AUTOSAVE_MAX_WAIT_MS - waited));diff --git a/client/src/components/brain/tabs/DailyLogTab.test.jsx b/client/src/components/brain/tabs/DailyLogTab.test.jsxindex 212adc874e..b33baac5cd 100644--- a/client/src/components/brain/tabs/DailyLogTab.test.jsx+++ b/client/src/components/brain/tabs/DailyLogTab.test.jsx@@ -238,6 +238,34 @@ describe('DailyLogTab autosave', () => {expect(api.updateDailyLog).toHaveBeenCalledTimes(1);});+ it('does not re-attempt a failed body until the content changes', async () => {+ api.updateDailyLog.mockRejectedValue(new Error('offline'));+ await renderTab();++ fireEvent.change(editor(), { target: { value: 'stuck' } });+ await act(async () => { await vi.advanceTimersByTimeAsync(1600); });+ expect(api.updateDailyLog).toHaveBeenCalledTimes(1);++ // Same body, server still down: the failure must not loop a silent PUT+ // per debounce tick (`saving` flipping false re-runs the effect).+ await act(async () => { await vi.advanceTimersByTimeAsync(10_000); });+ expect(api.updateDailyLog).toHaveBeenCalledTimes(1);++ // A keystroke changes the body and re-arms the autosave.+ fireEvent.change(editor(), { target: { value: 'stuck plus more' } });+ await act(async () => { await vi.advanceTimersByTimeAsync(1600); });+ expect(api.updateDailyLog).toHaveBeenCalledTimes(2);++ // Once a save succeeds, the gate clears and normal autosave resumes.+ api.updateDailyLog.mockImplementation(async (date, content) => ({ date, entry: entryFor(date, content) }));+ fireEvent.change(editor(), { target: { value: 'recovered' } });+ await act(async () => { await vi.advanceTimersByTimeAsync(1600); });+ expect(api.updateDailyLog).toHaveBeenCalledTimes(3);+ fireEvent.change(editor(), { target: { value: 'recovered again' } });+ await act(async () => { await vi.advanceTimersByTimeAsync(1600); });+ expect(api.updateDailyLog).toHaveBeenCalledTimes(4);+ });+it('keeps keystrokes typed while a save is in flight', async () => {let release;api.updateDailyLog.mockImplementation((date, content) => new Promise((resolve) => {