From 681f0b488bfbcf37cc8cb69f412e5e53b01c3f91 Mon Sep 17 00:00:00 2001 From: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> Date: Wed, 7 Oct 2026 16:35:12 -0400 Subject: [PATCH] fix(memory): preserve frozen non-stateful invalidation patterns Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> --- .../src/cache-manager-invalidation-regression.test.ts | 8 ++++++++ v3/@claude-flow/memory/src/cache-manager.ts | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/v3/@claude-flow/memory/src/cache-manager-invalidation-regression.test.ts b/v3/@claude-flow/memory/src/cache-manager-invalidation-regression.test.ts index 93c2afce45..0b6125804d 100644 --- a/v3/@claude-flow/memory/src/cache-manager-invalidation-regression.test.ts +++ b/v3/@claude-flow/memory/src/cache-manager-invalidation-regression.test.ts @@ -27,4 +27,12 @@ describe('stateful cache invalidation patterns', () => { expect(cache.invalidatePattern(pattern)).toBe(1); expect(pattern.lastIndex).toBe(4); }); + it('accepts a frozen non-global pattern without mutating its cursor', () => { + const cache = new CacheManager(); + caches.push(cache); + cache.set('article-one', 'old'); + const pattern = Object.freeze(/article/); + expect(cache.invalidatePattern(pattern)).toBe(1); + expect(pattern.lastIndex).toBe(0); + }); }); diff --git a/v3/@claude-flow/memory/src/cache-manager.ts b/v3/@claude-flow/memory/src/cache-manager.ts index 191cf43417..0d1f64505d 100644 --- a/v3/@claude-flow/memory/src/cache-manager.ts +++ b/v3/@claude-flow/memory/src/cache-manager.ts @@ -297,10 +297,11 @@ export class CacheManager extends EventEmitter { for (const key of this.cache.keys()) { // RegExp cursors belong to a single input, not the whole key sequence. + const stateful = regex.global || regex.sticky; const lastIndex = regex.lastIndex; - regex.lastIndex = 0; + if (stateful) regex.lastIndex = 0; const matches = regex.test(key); - regex.lastIndex = lastIndex; + if (stateful) regex.lastIndex = lastIndex; if (matches) { this.delete(key); invalidated++;