Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(memory): drop a stale read's failure too

M3gA-Mind3f78597a45d0
diff --git a/app/src/components/memory/MemoryImportBanner.test.tsx b/app/src/components/memory/MemoryImportBanner.test.tsx
index bd0c88920a..2a50145107 100644
--- a/app/src/components/memory/MemoryImportBanner.test.tsx
+++ b/app/src/components/memory/MemoryImportBanner.test.tsx
@@ -527,6 +527,36 @@ describe('MemoryImportBanner', () => {
expect(screen.queryByTestId('memory-migration-offer')).not.toBeInTheDocument();
});
+ it('keeps the offer when a stale read fails after a failed start', 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();
+
+ // A run ends; the read that follows is slow and will fail.
+ hoisted.mStatus.mockResolvedValueOnce(MOVE_IDLE);
+ let failRead: (reason: unknown) => void = () => {};
+ hoisted.mScan.mockReturnValueOnce(
+ new Promise((_, reject) => {
+ failRead = reject;
+ })
+ );
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(MIGRATION_POLL_MS + 10);
+ });
+ // The user starts again, and that start fails.
+ hoisted.mStart.mockRejectedValueOnce(new Error('boom'));
+ fireEvent.click(await screen.findByTestId('memory-migration-start'));
+ expect(await screen.findByTestId('memory-import-error')).toBeInTheDocument();
+
+ // The stale read fails last: the offer must stay, not vanish for a retry.
+ await act(async () => {
+ failRead(new Error('stale'));
+ });
+ expect(screen.getByTestId('memory-migration-start')).toBeInTheDocument();
+ });
+
it('drops a poll that fails after the user started the move', async () => {
hoisted.mScan.mockResolvedValue({ needed: true, shared: false });
vi.useFakeTimers({ shouldAdvanceTime: true });
diff --git a/app/src/components/memory/MemoryImportBanner.tsx b/app/src/components/memory/MemoryImportBanner.tsx
index 99428ae8b6..b6531bcddd 100644
--- a/app/src/components/memory/MemoryImportBanner.tsx
+++ b/app/src/components/memory/MemoryImportBanner.tsx
@@ -167,7 +167,9 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr
// 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) {
+ // A start or retry since this read began owns the state; its run's
+ // end reads again.
+ if (!cancelled && gen === mStatusGen.current) {
setMScan(null);
retry = setTimeout(rescanMove, MIGRATION_IDLE_POLL_MS);
}