Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(memory): match each cache key independently during invalidation

Rudy Celeklie0fb4ebd7426
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
new file mode 100644
index 0000000000..93c2afce45
--- /dev/null
+++ b/v3/@claude-flow/memory/src/cache-manager-invalidation-regression.test.ts
@@ -0,0 +1,30 @@
+import { afterEach, describe, it, expect } from 'vitest';
+import { CacheManager } from './cache-manager.js';
+const caches: CacheManager<string>[] = [];
+afterEach(() => {
+ for (const cache of caches.splice(0)) cache.shutdown();
+});
+describe('stateful cache invalidation patterns', () => {
+ it.each([/article/g, /article/y])(
+ 'invalidates every matching entry with %s',
+ (pattern) => {
+ const cache = new CacheManager<string>();
+ caches.push(cache);
+ cache.set('article-one', 'old result one');
+ cache.set('article-two', 'old result two');
+ cache.set('article-three', 'old result three');
+ cache.set('unrelated', 'valid');
+ expect(cache.invalidatePattern(pattern)).toBe(3);
+ expect(cache.keys()).toEqual(['unrelated']);
+ },
+ );
+ it('preserves the caller pattern cursor instead of skipping the first key', () => {
+ const cache = new CacheManager<string>();
+ caches.push(cache);
+ cache.set('article-one', 'old');
+ const pattern = /article/g;
+ pattern.lastIndex = 4;
+ expect(cache.invalidatePattern(pattern)).toBe(1);
+ expect(pattern.lastIndex).toBe(4);
+ });
+});
diff --git a/v3/@claude-flow/memory/src/cache-manager.ts b/v3/@claude-flow/memory/src/cache-manager.ts
index 2bb67f2e6b..191cf43417 100644
--- a/v3/@claude-flow/memory/src/cache-manager.ts
+++ b/v3/@claude-flow/memory/src/cache-manager.ts
@@ -296,7 +296,12 @@ export class CacheManager<T = MemoryEntry> extends EventEmitter {
let invalidated = 0;
for (const key of this.cache.keys()) {
- if (regex.test(key)) {
+ // RegExp cursors belong to a single input, not the whole key sequence.
+ const lastIndex = regex.lastIndex;
+ regex.lastIndex = 0;
+ const matches = regex.test(key);
+ regex.lastIndex = lastIndex;
+ if (matches) {
this.delete(key);
invalidated++;
}