Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(settings): drop a coalesced save whose timer outlives window
Fabricio Casalifc87bfdf68b9
diff --git a/src/renderer/state/settings.test.ts b/src/renderer/state/settings.test.tsindex 085908afb..761394074 100644--- a/src/renderer/state/settings.test.ts+++ b/src/renderer/state/settings.test.ts@@ -1,7 +1,42 @@-import { beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { DEFAULT_SETTINGS } from '@shared/types'import { useSettings } from './settings'+describe('coalesced settings save', () => {+ const g = globalThis as { window?: unknown }++ afterEach(() => {+ delete g.window+ vi.useRealTimers()+ })++ // A jsdom test file can end inside the coalesce window: vitest then deletes `window` from the+ // globals while the Node timer is still pending, and a callback that dereferences `window`+ // throws an unhandled ReferenceError that fails the whole run.+ it('drops the pending save when window is gone by the time the timer fires', () => {+ vi.useFakeTimers()+ const save = vi.fn(async (_s: unknown) => undefined)+ g.window = { nodeTerminal: { settings: { save } } }+ useSettings.getState().update({ panHoverDelay: 123 })+ delete g.window++ expect(() => vi.runAllTimers()).not.toThrow()+ expect(save).not.toHaveBeenCalled()+ })++ it('still writes the latest snapshot once when window is present', () => {+ vi.useFakeTimers()+ const save = vi.fn(async (_s: unknown) => undefined)+ g.window = { nodeTerminal: { settings: { save } } }+ useSettings.getState().update({ panHoverDelay: 1 })+ useSettings.getState().update({ panHoverDelay: 2 })+ vi.runAllTimers()++ expect(save).toHaveBeenCalledTimes(1)+ expect(save.mock.calls[0][0]).toMatchObject({ panHoverDelay: 2 })+ })+})+describe('agent launch mode settings mirror', () => {beforeEach(() => {useSettings.setState({ settings: { ...DEFAULT_SETTINGS }, hydrated: false })diff --git a/src/renderer/state/settings.ts b/src/renderer/state/settings.tsindex cb885d773..2d171b233 100644--- a/src/renderer/state/settings.ts+++ b/src/renderer/state/settings.ts@@ -24,6 +24,12 @@ function scheduleSave(next: Settings): void {if (saveTimer) returnsaveTimer = setTimeout(() => {saveTimer = null+ // Re-checked at fire time: a jsdom test file can end inside the coalesce window, and vitest+ // deletes `window` from the globals while this Node timer is still pending. Drop the save.+ if (typeof window === 'undefined') {+ pendingSave = null+ return+ }if (pendingSave) void window.nodeTerminal.settings.save(pendingSave)pendingSave = null}, SAVE_COALESCE_MS)