From 777d38bdbfd8fe678aaca07b60219f8a0d1bc76c Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Tue, 10 Nov 2026 17:25:44 +0530 Subject: [PATCH 1/3] fix(providers): let one probe through a half-open circuit breaker After the recovery timeout the breaker moved to half-open and then allowed every caller, so a backlog of compress and summarize calls hit a provider that was still down all at once. Half-open now admits a single probe. Success closes the breaker, failure reopens it with a fresh openedAt. A probe that never reports a result (for example a payload rejection, which records neither) is released after the recovery timeout so the breaker cannot wedge. Fixes #1732 --- src/providers/circuit-breaker.ts | 18 ++++++++----- test/circuit-breaker.test.ts | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/providers/circuit-breaker.ts b/src/providers/circuit-breaker.ts index 0bce44dab7..7383073d54 100644 --- a/src/providers/circuit-breaker.ts +++ b/src/providers/circuit-breaker.ts @@ -15,6 +15,7 @@ export class CircuitBreaker { private failures = 0; private lastFailureAt: number | null = null; private openedAt: number | null = null; + private probeStartedAt: number | null = null; private readonly failureThreshold: number; private readonly failureWindowMs: number; @@ -31,16 +32,19 @@ export class CircuitBreaker { get isAllowed(): boolean { if (this.state === "closed") return true; + const now = Date.now(); if (this.state === "open") { - if ( - this.openedAt && - Date.now() - this.openedAt >= this.recoveryTimeoutMs - ) { - this.state = "half-open"; - return true; + if (!this.openedAt || now - this.openedAt < this.recoveryTimeoutMs) { + return false; } + this.state = "half-open"; + } else if ( + this.probeStartedAt !== null && + now - this.probeStartedAt < this.recoveryTimeoutMs + ) { return false; } + this.probeStartedAt = now; return true; } @@ -50,6 +54,7 @@ export class CircuitBreaker { this.failures = 0; this.lastFailureAt = null; this.openedAt = null; + this.probeStartedAt = null; } recordFailure(): void { @@ -57,6 +62,7 @@ export class CircuitBreaker { if (this.state === "half-open") { this.state = "open"; this.openedAt = now; + this.probeStartedAt = null; return; } if (this.lastFailureAt && now - this.lastFailureAt > this.failureWindowMs) { diff --git a/test/circuit-breaker.test.ts b/test/circuit-breaker.test.ts index 52cd6d0e76..9426ecb68f 100644 --- a/test/circuit-breaker.test.ts +++ b/test/circuit-breaker.test.ts @@ -178,6 +178,52 @@ describe("CircuitBreaker", () => { expect(cb.getState().state).toBe("half-open"); }); + it("lets only one probe through while half-open", () => { + const cb = new CircuitBreaker(); + cb.recordFailure(); + cb.recordFailure(); + cb.recordFailure(); + vi.advanceTimersByTime(30_000); + expect(cb.isAllowed).toBe(true); + expect(cb.isAllowed).toBe(false); + expect(cb.isAllowed).toBe(false); + cb.recordSuccess(); + expect(cb.getState().state).toBe("closed"); + expect(cb.isAllowed).toBe(true); + expect(cb.isAllowed).toBe(true); + }); + + it("reopens with a fresh openedAt when the probe fails", () => { + const cb = new CircuitBreaker(); + cb.recordFailure(); + cb.recordFailure(); + cb.recordFailure(); + vi.advanceTimersByTime(30_000); + expect(cb.isAllowed).toBe(true); + const probeAt = Date.now(); + cb.recordFailure(); + expect(cb.getState().state).toBe("open"); + expect(cb.getState().openedAt).toBe(probeAt); + expect(cb.isAllowed).toBe(false); + vi.advanceTimersByTime(30_000); + expect(cb.isAllowed).toBe(true); + expect(cb.isAllowed).toBe(false); + }); + + it("releases a probe that never reports a result after the recovery timeout", () => { + const cb = new CircuitBreaker(); + cb.recordFailure(); + cb.recordFailure(); + cb.recordFailure(); + vi.advanceTimersByTime(30_000); + expect(cb.isAllowed).toBe(true); + vi.advanceTimersByTime(29_999); + expect(cb.isAllowed).toBe(false); + vi.advanceTimersByTime(1); + expect(cb.isAllowed).toBe(true); + expect(cb.isAllowed).toBe(false); + }); + it("still opens after consecutive failures with no success between them", () => { const cb = new CircuitBreaker(); cb.recordSuccess(); From 6cfe85ec556a5556a5ed350fbdc24ba33cd7e021 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Wed, 11 Nov 2026 12:09:55 +0530 Subject: [PATCH 2/3] fix(providers): ignore outcomes from expired half-open probes A half-open probe that outlives the recovery timeout releases its slot to a replacement, but its late result could still reopen or close the breaker the replacement now owns. CircuitBreaker.admit() returns 0 for a closed-state call, an increasing probe id for a half-open probe, or null when the call is refused. recordSuccess and recordFailure take that ticket and drop outcomes from any probe that is no longer the current one. ResilientProvider.call passes the ticket through. Calls without a ticket behave as before. --- src/providers/circuit-breaker.ts | 26 +++++++++++++----- src/providers/resilient.ts | 7 ++--- test/circuit-breaker.test.ts | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/providers/circuit-breaker.ts b/src/providers/circuit-breaker.ts index 7383073d54..094f54d45f 100644 --- a/src/providers/circuit-breaker.ts +++ b/src/providers/circuit-breaker.ts @@ -16,6 +16,7 @@ export class CircuitBreaker { private lastFailureAt: number | null = null; private openedAt: number | null = null; private probeStartedAt: number | null = null; + private probeId = 0; private readonly failureThreshold: number; private readonly failureWindowMs: number; @@ -31,25 +32,35 @@ export class CircuitBreaker { } get isAllowed(): boolean { - if (this.state === "closed") return true; + return this.admit() !== null; + } + + admit(): number | null { + if (this.state === "closed") return 0; const now = Date.now(); if (this.state === "open") { if (!this.openedAt || now - this.openedAt < this.recoveryTimeoutMs) { - return false; + return null; } this.state = "half-open"; } else if ( this.probeStartedAt !== null && now - this.probeStartedAt < this.recoveryTimeoutMs ) { - return false; + return null; } this.probeStartedAt = now; - return true; + this.probeId += 1; + return this.probeId; + } + + private isStale(probe: number | undefined): boolean { + if (probe === undefined) return false; + return this.state === "half-open" ? probe !== this.probeId : probe !== 0; } - recordSuccess(): void { - if (this.state === "open") return; + recordSuccess(probe?: number): void { + if (this.state === "open" || this.isStale(probe)) return; this.state = "closed"; this.failures = 0; this.lastFailureAt = null; @@ -57,7 +68,8 @@ export class CircuitBreaker { this.probeStartedAt = null; } - recordFailure(): void { + recordFailure(probe?: number): void { + if (this.isStale(probe)) return; const now = Date.now(); if (this.state === "half-open") { this.state = "open"; diff --git a/src/providers/resilient.ts b/src/providers/resilient.ts index f82e578d72..abbb3f6b9f 100644 --- a/src/providers/resilient.ts +++ b/src/providers/resilient.ts @@ -18,16 +18,17 @@ export class ResilientProvider implements MemoryProvider { } private async call(fn: () => Promise): Promise { - if (!this.breaker.isAllowed) { + const probe = this.breaker.admit(); + if (probe === null) { throw new Error("circuit_breaker_open"); } try { const result = await fn(); - this.breaker.recordSuccess(); + this.breaker.recordSuccess(probe); return result; } catch (err) { if (!isPayloadRejection(err)) { - this.breaker.recordFailure(); + this.breaker.recordFailure(probe); } throw err; } diff --git a/test/circuit-breaker.test.ts b/test/circuit-breaker.test.ts index 9426ecb68f..b8cfff2ed7 100644 --- a/test/circuit-breaker.test.ts +++ b/test/circuit-breaker.test.ts @@ -234,4 +234,49 @@ describe("CircuitBreaker", () => { expect(cb.getState().state).toBe("open"); expect(cb.isAllowed).toBe(false); }); + + function openAndExpireFirstProbe() { + const cb = new CircuitBreaker(); + cb.recordFailure(); + cb.recordFailure(); + cb.recordFailure(); + vi.advanceTimersByTime(30_000); + const first = cb.admit(); + vi.advanceTimersByTime(30_000); + const second = cb.admit(); + return { cb, first: first!, second: second! }; + } + + it("ignores a late failure from an expired probe while its replacement runs", () => { + const { cb, first, second } = openAndExpireFirstProbe(); + expect(second).toBeGreaterThan(first); + cb.recordFailure(first); + expect(cb.getState().state).toBe("half-open"); + cb.recordSuccess(second); + expect(cb.getState().state).toBe("closed"); + }); + + it("ignores a late success from an expired probe", () => { + const { cb, first, second } = openAndExpireFirstProbe(); + cb.recordSuccess(first); + expect(cb.getState().state).toBe("half-open"); + expect(cb.admit()).toBeNull(); + cb.recordFailure(second); + expect(cb.getState().state).toBe("open"); + }); + + it("ignores an expired probe outcome after the current probe closed the breaker", () => { + const { cb, first, second } = openAndExpireFirstProbe(); + cb.recordSuccess(second); + cb.recordFailure(first); + cb.recordFailure(first); + cb.recordFailure(first); + expect(cb.getState()).toMatchObject({ state: "closed", failures: 0 }); + }); + + it("counts closed-state call outcomes as before", () => { + const cb = new CircuitBreaker(); + for (let i = 0; i < 3; i++) cb.recordFailure(cb.admit()!); + expect(cb.getState().state).toBe("open"); + }); }); From 35f7611fd4eb783835c5e5fd2a3b9aab5bee55fd Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Wed, 11 Nov 2026 12:23:51 +0530 Subject: [PATCH 3/3] fix(providers): release a half-open probe rejected by the content filter A content-filter 400 means the provider answered, but the call path recorded neither success nor failure. When that call was the half-open probe, admit() refused every caller until the recovery timeout passed. Add CircuitBreaker.releaseProbe(), which clears only the current probe without touching failure counters, and call it from ResilientProvider for payload rejections. --- AGENTS.md | 4 ++-- README.md | 4 ++-- READMEs/README.ar-SA.md | 4 ++-- READMEs/README.bn-BD.md | 4 ++-- READMEs/README.cs-CZ.md | 4 ++-- READMEs/README.da-DK.md | 4 ++-- READMEs/README.de-DE.md | 4 ++-- READMEs/README.el-GR.md | 4 ++-- READMEs/README.es-ES.md | 4 ++-- READMEs/README.fi-FI.md | 4 ++-- READMEs/README.fr-FR.md | 4 ++-- READMEs/README.he-IL.md | 4 ++-- READMEs/README.hi-IN.md | 4 ++-- READMEs/README.hu-HU.md | 4 ++-- READMEs/README.id-ID.md | 4 ++-- READMEs/README.it-IT.md | 4 ++-- READMEs/README.ja-JP.md | 4 ++-- READMEs/README.ko-KR.md | 4 ++-- READMEs/README.nb-NO.md | 4 ++-- READMEs/README.nl-NL.md | 4 ++-- READMEs/README.pl-PL.md | 4 ++-- READMEs/README.pt-BR.md | 4 ++-- READMEs/README.pt-PT.md | 4 ++-- READMEs/README.ro-RO.md | 4 ++-- READMEs/README.ru-RU.md | 4 ++-- READMEs/README.sv-SE.md | 4 ++-- READMEs/README.th-TH.md | 4 ++-- READMEs/README.tl-PH.md | 4 ++-- READMEs/README.tr-TR.md | 4 ++-- READMEs/README.uk-UA.md | 4 ++-- READMEs/README.ur-PK.md | 4 ++-- READMEs/README.vi-VN.md | 4 ++-- READMEs/README.zh-CN.md | 4 ++-- READMEs/README.zh-TW.md | 4 ++-- assets/tags/light/stat-tests.svg | 4 ++-- assets/tags/stat-tests.svg | 4 ++-- scripts/docs-sync.state.json | 2 +- src/providers/circuit-breaker.ts | 4 ++++ src/providers/resilient.ts | 4 +++- test/circuit-breaker.test.ts | 18 ++++++++++++++++ test/resilient-content-filter.test.ts | 30 ++++++++++++++++++++++++++- 41 files changed, 127 insertions(+), 75 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3897c7910e..81b4eed6fa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -101,7 +101,7 @@ Hook scripts in `src/hooks/` are standalone Node.js scripts (no iii-sdk import). ## Testing -- Before every commit run, in order: `npm run build`, `npm run skills:gen`, `npm run docs:sync`, `npm run skills:check`, `npm test` (4,700+ tests). Commit anything the generators changed. CI runs the same build, skills check and tests. +- Before every commit run, in order: `npm run build`, `npm run skills:gen`, `npm run docs:sync`, `npm run skills:check`, `npm test` (4,800+ tests). Commit anything the generators changed. CI runs the same build, skills check and tests. - Before any npm publish: `npm run release:gate` must pass. It installs the packed tarballs into a clean home and runs capture, recovery, restart, export/import, MCP and status checks against the installed CLI (see CONTRIBUTING.md, Release process) - Mock pattern: `vi.mock("iii-sdk")` with mock `sdk.trigger`, `kv.get/set/list` - Test files go in `test/` with `.test.ts` extension @@ -114,4 +114,4 @@ Hook scripts in `src/hooks/` are standalone Node.js scripts (no iii-sdk import). - 6 MCP resources, 3 MCP prompts - 12 hooks, 17 skills - 322+ iii functions -- 4,700+ tests +- 4,800+ tests diff --git a/README.md b/README.md index cd40701a05..7590f939b8 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1313,7 +1313,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ar-SA.md b/READMEs/README.ar-SA.md index 19dfdad2f8..40b6c0699d 100644 --- a/READMEs/README.ar-SA.md +++ b/READMEs/README.ar-SA.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1244,7 +1244,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.bn-BD.md b/READMEs/README.bn-BD.md index a0881d0c27..b16b1f7bd4 100644 --- a/READMEs/README.bn-BD.md +++ b/READMEs/README.bn-BD.md @@ -69,7 +69,7 @@ 54 MCP টুল 12 অটো হুক 0 এক্সটার্নাল ডিবি - 4,700+ টেস্ট পাস + 4,800+ টেস্ট পাস

@@ -1257,7 +1257,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.cs-CZ.md b/READMEs/README.cs-CZ.md index 3837c5eb6e..41c98ab4df 100644 --- a/READMEs/README.cs-CZ.md +++ b/READMEs/README.cs-CZ.md @@ -69,7 +69,7 @@ 54 MCP nástrojů 12 automatických hooks 0 externích databází - 4,700+ testů úspěšně proběhlo + 4,800+ testů úspěšně proběhlo

@@ -1243,7 +1243,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.da-DK.md b/READMEs/README.da-DK.md index 209257de1f..6e96f1ad65 100644 --- a/READMEs/README.da-DK.md +++ b/READMEs/README.da-DK.md @@ -69,7 +69,7 @@ 54 MCP-værktøjer 12 automatiske hooks 0 eksterne databaser - 4,700+ beståede tests + 4,800+ beståede tests

@@ -1251,7 +1251,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.de-DE.md b/READMEs/README.de-DE.md index a0b4b683b8..f09b2211b6 100644 --- a/READMEs/README.de-DE.md +++ b/READMEs/README.de-DE.md @@ -69,7 +69,7 @@ 54 MCP-Tools 12 Auto-Hooks 0 externe DBs - 4,700+ bestandene Tests + 4,800+ bestandene Tests

@@ -1249,7 +1249,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.el-GR.md b/READMEs/README.el-GR.md index 49f0fb50b2..20190d727a 100644 --- a/READMEs/README.el-GR.md +++ b/READMEs/README.el-GR.md @@ -69,7 +69,7 @@ 54 εργαλεία MCP 12 αυτόματα hooks 0 εξωτερικές βάσεις δεδομένων - 4,700+ επιτυχημένες δοκιμές + 4,800+ επιτυχημένες δοκιμές

@@ -1243,7 +1243,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.es-ES.md b/READMEs/README.es-ES.md index 0cf25dab97..6ca88703a2 100644 --- a/READMEs/README.es-ES.md +++ b/READMEs/README.es-ES.md @@ -69,7 +69,7 @@ 54 tools MCP 12 hooks automáticos 0 bases de datos externas - 4,700+ tests superados + 4,800+ tests superados

@@ -1245,7 +1245,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.fi-FI.md b/READMEs/README.fi-FI.md index c580718e9f..c82e700071 100644 --- a/READMEs/README.fi-FI.md +++ b/READMEs/README.fi-FI.md @@ -69,7 +69,7 @@ 54 MCP-työkalua 12 automaattista hookia 0 ulkoista tietokantaa - 4,700+ testiä läpäisty + 4,800+ testiä läpäisty

@@ -1243,7 +1243,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.fr-FR.md b/READMEs/README.fr-FR.md index 3f508c8454..981e72e4f9 100644 --- a/READMEs/README.fr-FR.md +++ b/READMEs/README.fr-FR.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1252,7 +1252,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.he-IL.md b/READMEs/README.he-IL.md index 73f6e4a233..313f456302 100644 --- a/READMEs/README.he-IL.md +++ b/READMEs/README.he-IL.md @@ -71,7 +71,7 @@ 54 כלי MCP 12 hooks אוטומטיים 0 מסדי נתונים חיצוניים - 4,700+ בדיקות עוברות + 4,800+ בדיקות עוברות

@@ -1244,7 +1244,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.hi-IN.md b/READMEs/README.hi-IN.md index 4c3a8d31e2..9bed3ca5eb 100644 --- a/READMEs/README.hi-IN.md +++ b/READMEs/README.hi-IN.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1258,7 +1258,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.hu-HU.md b/READMEs/README.hu-HU.md index 20d0e86604..819b196d68 100644 --- a/READMEs/README.hu-HU.md +++ b/READMEs/README.hu-HU.md @@ -69,7 +69,7 @@ 54 MCP eszköz 12 automatikus hook 0 külső adatbázis - 4,700+ sikeres teszt + 4,800+ sikeres teszt

@@ -1241,7 +1241,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.id-ID.md b/READMEs/README.id-ID.md index 855cd4dd52..a5813dcfc8 100644 --- a/READMEs/README.id-ID.md +++ b/READMEs/README.id-ID.md @@ -69,7 +69,7 @@ 54 tool MCP 12 hook otomatis 0 DB eksternal - 4,700+ pengujian lolos + 4,800+ pengujian lolos

@@ -1258,7 +1258,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.it-IT.md b/READMEs/README.it-IT.md index cd396e06e9..a2e6f3aa8e 100644 --- a/READMEs/README.it-IT.md +++ b/READMEs/README.it-IT.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1251,7 +1251,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ja-JP.md b/READMEs/README.ja-JP.md index 9dfe1e726c..412d9f4224 100644 --- a/READMEs/README.ja-JP.md +++ b/READMEs/README.ja-JP.md @@ -69,7 +69,7 @@ 54 MCP ツール 12 自動 hooks 外部 DB 0 個 - 4,700+ 件のテストが成功 + 4,800+ 件のテストが成功

@@ -1257,7 +1257,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ko-KR.md b/READMEs/README.ko-KR.md index 4c77e312b0..db1bee6bd2 100644 --- a/READMEs/README.ko-KR.md +++ b/READMEs/README.ko-KR.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1256,7 +1256,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.nb-NO.md b/READMEs/README.nb-NO.md index e617bec5e1..def9fa24d0 100644 --- a/READMEs/README.nb-NO.md +++ b/READMEs/README.nb-NO.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1249,7 +1249,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.nl-NL.md b/READMEs/README.nl-NL.md index ab0aa4972b..a41ab0bf2e 100644 --- a/READMEs/README.nl-NL.md +++ b/READMEs/README.nl-NL.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1245,7 +1245,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pl-PL.md b/READMEs/README.pl-PL.md index c24834e624..be1064ea75 100644 --- a/READMEs/README.pl-PL.md +++ b/READMEs/README.pl-PL.md @@ -69,7 +69,7 @@ 54 narzędzia MCP 12 automatycznych hooków 0 zewnętrznych baz danych - 4,700+ zaliczonych testów + 4,800+ zaliczonych testów

@@ -1241,7 +1241,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pt-BR.md b/READMEs/README.pt-BR.md index 8cba9a4b83..14023e43ce 100644 --- a/READMEs/README.pt-BR.md +++ b/READMEs/README.pt-BR.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1249,7 +1249,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pt-PT.md b/READMEs/README.pt-PT.md index c237b780d8..3f2e79bb91 100644 --- a/READMEs/README.pt-PT.md +++ b/READMEs/README.pt-PT.md @@ -69,7 +69,7 @@ 54 ferramentas MCP 12 hooks automáticos 0 bases de dados externas - 4,700+ testes aprovados + 4,800+ testes aprovados

@@ -1245,7 +1245,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ro-RO.md b/READMEs/README.ro-RO.md index 620d55913d..91d70e2ffe 100644 --- a/READMEs/README.ro-RO.md +++ b/READMEs/README.ro-RO.md @@ -69,7 +69,7 @@ 54 de instrumente MCP 12 hook-uri automate 0 baze de date externe - 4,700+ teste trecute + 4,800+ teste trecute

@@ -1237,7 +1237,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ru-RU.md b/READMEs/README.ru-RU.md index 3086998cdd..aed56590dc 100644 --- a/READMEs/README.ru-RU.md +++ b/READMEs/README.ru-RU.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1243,7 +1243,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.sv-SE.md b/READMEs/README.sv-SE.md index c29d00dbee..fc2f4d5b80 100644 --- a/READMEs/README.sv-SE.md +++ b/READMEs/README.sv-SE.md @@ -69,7 +69,7 @@ 54 MCP-verktyg 12 automatiska hooks 0 externa databaser - 4,700+ godkända tester + 4,800+ godkända tester

@@ -1251,7 +1251,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.th-TH.md b/READMEs/README.th-TH.md index 49a0e9ce46..fa1bd6d710 100644 --- a/READMEs/README.th-TH.md +++ b/READMEs/README.th-TH.md @@ -69,7 +69,7 @@ 54 เครื่องมือ MCP 12 hook อัตโนมัติ ไม่ต้องพึ่ง external DB เลย - ผ่านการทดสอบ 4,700+ รายการ + ผ่านการทดสอบ 4,800+ รายการ

@@ -1244,7 +1244,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.tl-PH.md b/READMEs/README.tl-PH.md index 9eacba7baf..27cec827c0 100644 --- a/READMEs/README.tl-PH.md +++ b/READMEs/README.tl-PH.md @@ -69,7 +69,7 @@ 54 MCP tool 12 awtomatikong hook 0 panlabas na DB - 4,700+ pumapasang test + 4,800+ pumapasang test

@@ -1253,7 +1253,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.tr-TR.md b/READMEs/README.tr-TR.md index f1aa62a40a..d26df964c2 100644 --- a/READMEs/README.tr-TR.md +++ b/READMEs/README.tr-TR.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1243,7 +1243,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.uk-UA.md b/READMEs/README.uk-UA.md index 11019c61fe..08832163f6 100644 --- a/READMEs/README.uk-UA.md +++ b/READMEs/README.uk-UA.md @@ -69,7 +69,7 @@ 54 інструменти MCP 12 автоматичних хуків 0 зовнішніх БД - 4,700+ тестів пройдено + 4,800+ тестів пройдено

@@ -1244,7 +1244,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ur-PK.md b/READMEs/README.ur-PK.md index a4a9b37b3c..c61fdbc3ef 100644 --- a/READMEs/README.ur-PK.md +++ b/READMEs/README.ur-PK.md @@ -71,7 +71,7 @@ 54 MCP ٹولز 12 خودکار ہکس 0 خارجی ڈیٹابیسز - 4,700+ ٹیسٹس پاس ہو رہے ہیں + 4,800+ ٹیسٹس پاس ہو رہے ہیں

@@ -1248,7 +1248,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.vi-VN.md b/READMEs/README.vi-VN.md index 47177b4c47..6b3d54b63f 100644 --- a/READMEs/README.vi-VN.md +++ b/READMEs/README.vi-VN.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,700+ tests passing + 4,800+ tests passing

@@ -1253,7 +1253,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.zh-CN.md b/READMEs/README.zh-CN.md index 0a5f9c2d05..e7a3f90896 100644 --- a/READMEs/README.zh-CN.md +++ b/READMEs/README.zh-CN.md @@ -69,7 +69,7 @@ 54 个 MCP 工具 12 个自动 hooks 0 个外部数据库 - 4,700+ 项测试通过 + 4,800+ 项测试通过

@@ -1254,7 +1254,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.zh-TW.md b/READMEs/README.zh-TW.md index c2e315c886..74e1eca426 100644 --- a/READMEs/README.zh-TW.md +++ b/READMEs/README.zh-TW.md @@ -69,7 +69,7 @@ 54 個 MCP 工具 12 個自動 hooks 0 個外部資料庫 - 4,700+ 測試通過 + 4,800+ 測試通過

@@ -1246,7 +1246,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Authorization: ```bash npm run dev # Hot reload npm run build # Production build -npm test # 4,700+ tests +npm test # 4,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/assets/tags/light/stat-tests.svg b/assets/tags/light/stat-tests.svg index 1b4179cfc2..743b0d095d 100644 --- a/assets/tags/light/stat-tests.svg +++ b/assets/tags/light/stat-tests.svg @@ -1,5 +1,5 @@ - + - 4700+ + 4800+ TESTS PASSING diff --git a/assets/tags/stat-tests.svg b/assets/tags/stat-tests.svg index 2b679ac742..7b4a1c20eb 100644 --- a/assets/tags/stat-tests.svg +++ b/assets/tags/stat-tests.svg @@ -1,5 +1,5 @@ - + - 4700+ + 4800+ TESTS PASSING diff --git a/scripts/docs-sync.state.json b/scripts/docs-sync.state.json index ef3f2b4c6b..6d5580a194 100644 --- a/scripts/docs-sync.state.json +++ b/scripts/docs-sync.state.json @@ -20,7 +20,7 @@ "12" ], "tests": [ - "4700+" + "4800+" ], "functions": [ "323" diff --git a/src/providers/circuit-breaker.ts b/src/providers/circuit-breaker.ts index 094f54d45f..cba4893068 100644 --- a/src/providers/circuit-breaker.ts +++ b/src/providers/circuit-breaker.ts @@ -68,6 +68,10 @@ export class CircuitBreaker { this.probeStartedAt = null; } + releaseProbe(probe: number): void { + if (this.state === "half-open" && probe === this.probeId) this.probeStartedAt = null; + } + recordFailure(probe?: number): void { if (this.isStale(probe)) return; const now = Date.now(); diff --git a/src/providers/resilient.ts b/src/providers/resilient.ts index abbb3f6b9f..202a3113a0 100644 --- a/src/providers/resilient.ts +++ b/src/providers/resilient.ts @@ -27,7 +27,9 @@ export class ResilientProvider implements MemoryProvider { this.breaker.recordSuccess(probe); return result; } catch (err) { - if (!isPayloadRejection(err)) { + if (isPayloadRejection(err)) { + this.breaker.releaseProbe(probe); + } else { this.breaker.recordFailure(probe); } throw err; diff --git a/test/circuit-breaker.test.ts b/test/circuit-breaker.test.ts index b8cfff2ed7..c0aaf0aeb4 100644 --- a/test/circuit-breaker.test.ts +++ b/test/circuit-breaker.test.ts @@ -274,6 +274,24 @@ describe("CircuitBreaker", () => { expect(cb.getState()).toMatchObject({ state: "closed", failures: 0 }); }); + it("releaseProbe frees only the current half-open probe without changing counters", () => { + vi.useFakeTimers(); + try { + const cb = new CircuitBreaker({ failureThreshold: 1, recoveryTimeoutMs: 1000 }); + cb.recordFailure(cb.admit()!); + vi.advanceTimersByTime(1000); + const probe = cb.admit()!; + expect(cb.admit()).toBeNull(); + cb.releaseProbe(probe + 1); + expect(cb.admit()).toBeNull(); + cb.releaseProbe(probe); + expect(cb.getState().state).toBe("half-open"); + expect(cb.admit()).toBe(probe + 1); + } finally { + vi.useRealTimers(); + } + }); + it("counts closed-state call outcomes as before", () => { const cb = new CircuitBreaker(); for (let i = 0; i < 3; i++) cb.recordFailure(cb.admit()!); diff --git a/test/resilient-content-filter.test.ts b/test/resilient-content-filter.test.ts index 0c6026a18c..42ccd3a3ba 100644 --- a/test/resilient-content-filter.test.ts +++ b/test/resilient-content-filter.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { ResilientProvider, isPayloadRejection } from "../src/providers/resilient.js"; import type { MemoryProvider } from "../src/types.js"; @@ -103,4 +103,32 @@ describe("ResilientProvider — content filter vs circuit breaker", () => { expect(provider.circuitState.state).toBe("open"); await expect(provider.compress("sys", "x")).rejects.toThrow("circuit_breaker_open"); }); + + it("releases a half-open probe rejected by the content filter so the next call can probe", async () => { + vi.useFakeTimers(); + try { + let mode: "down" | "filter" | "ok" = "down"; + const provider = new ResilientProvider({ + name: "stub", + async compress() { + if (mode === "down") throw new Error("OpenAI API error (503): upstream down"); + if (mode === "filter") throw CONTENT_FILTER_ERROR; + return ""; + }, + async summarize() { + return ""; + }, + } as MemoryProvider); + for (let i = 0; i < 3; i++) await expect(provider.compress("sys", "x")).rejects.toThrow(/503/); + expect(provider.circuitState.state).toBe("open"); + vi.advanceTimersByTime(30_000); + mode = "filter"; + await expect(provider.compress("sys", "bad")).rejects.toThrow(/content_filter/); + mode = "ok"; + await expect(provider.compress("sys", "fine")).resolves.toBe(""); + expect(provider.circuitState.state).toBe("closed"); + } finally { + vi.useRealTimers(); + } + }); });