The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory): the memory banner drops stale migration reads
M3gA-Mind37c2d0a19e07
diff --git a/app/src/components/memory/MemoryImportBanner.test.tsx b/app/src/components/memory/MemoryImportBanner.test.tsxindex e5537ef6f9..74af20b01a 100644--- a/app/src/components/memory/MemoryImportBanner.test.tsx+++ b/app/src/components/memory/MemoryImportBanner.test.tsx@@ -410,6 +410,56 @@ describe('MemoryImportBanner', () => {expect(screen.getByTestId('memory-import-retry-failed')).toBeInTheDocument();});+ it('offers nothing while the scan after a finished run fails', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ hoisted.mStatus.mockResolvedValue(moving(1));+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-running')).toBeInTheDocument();++ // The run ends; the scan that follows fails.+ hoisted.mStatus.mockResolvedValue({+ state: { phase: 'cleaned', copied: 3 },+ running: false,+ interrupted: false,+ });+ hoisted.mScan.mockRejectedValue(new Error('not ready'));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_POLL_MS + 10);+ });+ await waitFor(() =>+ expect(screen.queryByTestId('memory-migration-banner')).not.toBeInTheDocument()+ );+ expect(screen.queryByTestId('memory-migration-offer')).not.toBeInTheDocument();+ });++ it('drops a poll answered after the user started the move', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-offer')).toBeInTheDocument();++ // An idle poll goes out and is slow to answer.+ let answerPoll: (value: unknown) => void = () => {};+ hoisted.mStatus.mockReturnValueOnce(+ new Promise(resolve => {+ answerPoll = resolve;+ })+ );+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_IDLE_POLL_MS + 10);+ });+ fireEvent.click(screen.getByTestId('memory-migration-start'));+ expect(await screen.findByTestId('memory-migration-running')).toHaveTextContent('4');++ // Its stale idle answer must not take the running move off the screen.+ await act(async () => {+ answerPoll(MOVE_IDLE);+ });+ expect(screen.getByTestId('memory-migration-running')).toBeInTheDocument();+ expect(screen.queryByTestId('memory-migration-offer')).not.toBeInTheDocument();+ });+it('scans again after a failed scan', async () => {hoisted.mScan.mockRejectedValueOnce(new Error('not ready'))diff --git a/app/src/components/memory/MemoryImportBanner.tsx b/app/src/components/memory/MemoryImportBanner.tsxindex ce43bb59c6..6d86d0e842 100644--- a/app/src/components/memory/MemoryImportBanner.tsx+++ b/app/src/components/memory/MemoryImportBanner.tsx@@ -158,8 +158,11 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr}).catch(err => {// A transient failure must not hide the move for good: try again.+ // Meanwhile what is left to move is unknown, so offer nothing (a run+ // that just ended may have moved it all).mlog('scan failed: %o', err);if (!cancelled) {+ setMScan(null);retry = setTimeout(rescanMove, MIGRATION_IDLE_POLL_MS);}});@@ -173,11 +176,16 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr// One status request at a time: a slow answer must not land after, and// overwrite, a newer one.const mPolling = useRef(false);+ // Bumped by a start or retry: a poll asked before it answers for an older+ // state, and is dropped.+ const mStatusGen = useRef(0);const mPoll = useCallback(async () => {if (mPolling.current) return;mPolling.current = true;+ const gen = mStatusGen.current;try {const next = await memoryMigrationStatus();+ if (gen !== mStatusGen.current) return;setMStatus(next);// A run just ended: whether anything is still left to move changed.if (wasMoving.current && !next.running) rescanMove();@@ -208,6 +216,7 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPrasync (takeover: boolean) => {setMBusy(true);setError(null);+ mStatusGen.current += 1;try {const next = await memoryMigrationStart(takeover);mlog('start: takeover=%s phase=%s running=%s', takeover, next.state.phase, next.running);@@ -226,6 +235,7 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPrconst retryMove = async () => {setMBusy(true);setError(null);+ mStatusGen.current += 1;try {await memoryMigrationRetry();setMStatus(await memoryMigrationStart(false));