diff --git a/.env.example b/.env.example index a9495aee55..f184ff9584 100644 --- a/.env.example +++ b/.env.example @@ -73,6 +73,15 @@ # OPENAI_TIMEOUT_MS alias for back-compat with v0.9.17 (precedence). # AGENTMEMORY_LLM_TIMEOUT_MS=60000 # Default: 60 000 ms (60 s) +# Max LLM calls in flight per worker, shared by every caller (compression, +# summarize chunks, consolidation) and by the whole FALLBACK_PROVIDERS chain. +# Up to 512 more wait in a queue; past that a call fails with +# provider_queue_full. Raise SUMMARIZE_CHUNK_CONCURRENCY and this together, +# since a chunk concurrency above the gate has no effect. Rate-limit errors +# (429, 529, rate_limit, overloaded_error) do not count toward the circuit +# breaker, except quota or billing 429s and a failed half-open probe. +# AGENTMEMORY_MAX_PROVIDER_CONCURRENCY=6 # Default: 6 + # Opt-in Claude-subscription fallback (spawns @anthropic-ai/claude-agent-sdk # child sessions). Off by default — the agent-sdk fallback can trigger # Stop-hook recursion when invoked from inside Claude Code. diff --git a/.gitignore b/.gitignore index 22064b389c..e8057580a4 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ integrations/openclaw/LICENSE integrations/omp/skills/ integrations/omp/LICENSE integrations/pi/skills/ + +# graft's local graph cache — regenerable, not committed (run `graft build`). +/graft/ diff --git a/AGENTS.md b/AGENTS.md index 81b4eed6fa..c2e9d97cc5 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,800+ 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,900+ 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,800+ tests +- 4,900+ tests diff --git a/README.md b/README.md index 2d8fe9476a..e12cba755a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 4,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 17ab19bd9a..de713f7766 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 72fb4d4af9..c878a5d8c8 100644 --- a/READMEs/README.bn-BD.md +++ b/READMEs/README.bn-BD.md @@ -69,7 +69,7 @@ 54 MCP টুল 12 অটো হুক 0 এক্সটার্নাল ডিবি - 4,800+ টেস্ট পাস + 4,900+ টেস্ট পাস

@@ -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,800+ tests +npm test # 4,900+ 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 f5e711dc12..05d3df1055 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,800+ testů úspěšně proběhlo + 4,900+ 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,800+ tests +npm test # 4,900+ 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 84b7ab09fa..62c1373564 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,800+ beståede tests + 4,900+ 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,800+ tests +npm test # 4,900+ 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 b3cc67f911..60cbd1df16 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,800+ bestandene Tests + 4,900+ 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,800+ tests +npm test # 4,900+ 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 d129d1da96..4962170a4c 100644 --- a/READMEs/README.el-GR.md +++ b/READMEs/README.el-GR.md @@ -69,7 +69,7 @@ 54 εργαλεία MCP 12 αυτόματα hooks 0 εξωτερικές βάσεις δεδομένων - 4,800+ επιτυχημένες δοκιμές + 4,900+ επιτυχημένες δοκιμές

@@ -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,800+ tests +npm test # 4,900+ 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 28cc4afeee..71d33dbb10 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,800+ tests superados + 4,900+ 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,800+ tests +npm test # 4,900+ 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 f1cec636e1..175efd508c 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,800+ testiä läpäisty + 4,900+ 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,800+ tests +npm test # 4,900+ 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 317ed9a426..c898e17a93 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 3db03a6560..0586f40d7b 100644 --- a/READMEs/README.he-IL.md +++ b/READMEs/README.he-IL.md @@ -71,7 +71,7 @@ 54 כלי MCP 12 hooks אוטומטיים 0 מסדי נתונים חיצוניים - 4,800+ בדיקות עוברות + 4,900+ בדיקות עוברות

@@ -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,800+ tests +npm test # 4,900+ 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 4e074331ad..9185983cda 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 92a7e06148..b1fcd2e91e 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,800+ sikeres teszt + 4,900+ 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,800+ tests +npm test # 4,900+ 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 64b78db504..6be8f90a25 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,800+ pengujian lolos + 4,900+ 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,800+ tests +npm test # 4,900+ 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 dbdedec687..341799588d 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 46de85bb2e..43913c0fd7 100644 --- a/READMEs/README.ja-JP.md +++ b/READMEs/README.ja-JP.md @@ -69,7 +69,7 @@ 54 MCP ツール 12 自動 hooks 外部 DB 0 個 - 4,800+ 件のテストが成功 + 4,900+ 件のテストが成功

@@ -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,800+ tests +npm test # 4,900+ 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 aac97124a3..a70c02477a 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 3540b1d50b..9cce02dcf8 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 9fe0188c54..6af924de0f 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 9faffcbeed..098d6dbdd2 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,800+ zaliczonych testów + 4,900+ 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,800+ tests +npm test # 4,900+ 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 8162bee293..fee630c5cd 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 9cc009a92c..91747393a5 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,800+ testes aprovados + 4,900+ 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,800+ tests +npm test # 4,900+ 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 1b9e97df25..d6173acd64 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,800+ teste trecute + 4,900+ 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,800+ tests +npm test # 4,900+ 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 122669c3da..be1e91e4e4 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 c0a4b80af6..82f04762eb 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,800+ godkända tester + 4,900+ 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,800+ tests +npm test # 4,900+ 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 c45966a18e..c93db2f895 100644 --- a/READMEs/README.th-TH.md +++ b/READMEs/README.th-TH.md @@ -69,7 +69,7 @@ 54 เครื่องมือ MCP 12 hook อัตโนมัติ ไม่ต้องพึ่ง external DB เลย - ผ่านการทดสอบ 4,800+ รายการ + ผ่านการทดสอบ 4,900+ รายการ

@@ -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,800+ tests +npm test # 4,900+ 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 06c531fd55..6d50865f29 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,800+ pumapasang test + 4,900+ 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,800+ tests +npm test # 4,900+ 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 e4e26929b0..d4ef91d08b 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 0945eecee3..b26305144d 100644 --- a/READMEs/README.uk-UA.md +++ b/READMEs/README.uk-UA.md @@ -69,7 +69,7 @@ 54 інструменти MCP 12 автоматичних хуків 0 зовнішніх БД - 4,800+ тестів пройдено + 4,900+ тестів пройдено

@@ -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,800+ tests +npm test # 4,900+ 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 23c7add9c0..31250f113a 100644 --- a/READMEs/README.ur-PK.md +++ b/READMEs/README.ur-PK.md @@ -71,7 +71,7 @@ 54 MCP ٹولز 12 خودکار ہکس 0 خارجی ڈیٹابیسز - 4,800+ ٹیسٹس پاس ہو رہے ہیں + 4,900+ ٹیسٹس پاس ہو رہے ہیں

@@ -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,800+ tests +npm test # 4,900+ 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 6ee0e285b7..fd842721a3 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,800+ tests passing + 4,900+ 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,800+ tests +npm test # 4,900+ 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 262c222377..4c56b9e1e0 100644 --- a/READMEs/README.zh-CN.md +++ b/READMEs/README.zh-CN.md @@ -69,7 +69,7 @@ 54 个 MCP 工具 12 个自动 hooks 0 个外部数据库 - 4,800+ 项测试通过 + 4,900+ 项测试通过

@@ -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,800+ tests +npm test # 4,900+ 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 26d095b60e..16d550226f 100644 --- a/READMEs/README.zh-TW.md +++ b/READMEs/README.zh-TW.md @@ -69,7 +69,7 @@ 54 個 MCP 工具 12 個自動 hooks 0 個外部資料庫 - 4,800+ 測試通過 + 4,900+ 測試通過

@@ -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,800+ tests +npm test # 4,900+ 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 743b0d095d..e6fccac91e 100644 --- a/assets/tags/light/stat-tests.svg +++ b/assets/tags/light/stat-tests.svg @@ -1,5 +1,5 @@ - + - 4800+ + 4900+ TESTS PASSING diff --git a/assets/tags/stat-tests.svg b/assets/tags/stat-tests.svg index 7b4a1c20eb..3b31eea1ea 100644 --- a/assets/tags/stat-tests.svg +++ b/assets/tags/stat-tests.svg @@ -1,5 +1,5 @@ - + - 4800+ + 4900+ TESTS PASSING diff --git a/deploy/coolify/docker-compose.yml b/deploy/coolify/docker-compose.yml index e35233996f..64955a0854 100644 --- a/deploy/coolify/docker-compose.yml +++ b/deploy/coolify/docker-compose.yml @@ -84,6 +84,7 @@ services: OPENROUTER_EMBEDDING_MODEL: "${OPENROUTER_EMBEDDING_MODEL:-}" OPENROUTER_EMBEDDING_DIMENSIONS: "${OPENROUTER_EMBEDDING_DIMENSIONS:-}" AGENTMEMORY_LLM_TIMEOUT_MS: "${AGENTMEMORY_LLM_TIMEOUT_MS:-}" + AGENTMEMORY_MAX_PROVIDER_CONCURRENCY: "${AGENTMEMORY_MAX_PROVIDER_CONCURRENCY:-}" AGENTMEMORY_CAPTURE_MAX_ATTEMPTS: "${AGENTMEMORY_CAPTURE_MAX_ATTEMPTS:-}" AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS: "${AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS:-}" AGENTMEMORY_CAPTURE_DEDUP_HOURS: "${AGENTMEMORY_CAPTURE_DEDUP_HOURS:-}" diff --git a/deploy/runtime/worker-compose.yaml b/deploy/runtime/worker-compose.yaml index d3f8b91308..e24911e90b 100644 --- a/deploy/runtime/worker-compose.yaml +++ b/deploy/runtime/worker-compose.yaml @@ -143,6 +143,7 @@ containers: OPENROUTER_EMBEDDING_MODEL: "${OPENROUTER_EMBEDDING_MODEL:-}" OPENROUTER_EMBEDDING_DIMENSIONS: "${OPENROUTER_EMBEDDING_DIMENSIONS:-}" AGENTMEMORY_LLM_TIMEOUT_MS: "${AGENTMEMORY_LLM_TIMEOUT_MS:-}" + AGENTMEMORY_MAX_PROVIDER_CONCURRENCY: "${AGENTMEMORY_MAX_PROVIDER_CONCURRENCY:-}" AGENTMEMORY_CAPTURE_MAX_ATTEMPTS: "${AGENTMEMORY_CAPTURE_MAX_ATTEMPTS:-}" AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS: "${AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS:-}" AGENTMEMORY_CAPTURE_DEDUP_HOURS: "${AGENTMEMORY_CAPTURE_DEDUP_HOURS:-}" diff --git a/docker-compose.yml b/docker-compose.yml index 0fd899e20e..2235eb5845 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -90,6 +90,7 @@ services: OPENROUTER_EMBEDDING_MODEL: "${OPENROUTER_EMBEDDING_MODEL:-}" OPENROUTER_EMBEDDING_DIMENSIONS: "${OPENROUTER_EMBEDDING_DIMENSIONS:-}" AGENTMEMORY_LLM_TIMEOUT_MS: "${AGENTMEMORY_LLM_TIMEOUT_MS:-}" + AGENTMEMORY_MAX_PROVIDER_CONCURRENCY: "${AGENTMEMORY_MAX_PROVIDER_CONCURRENCY:-}" AGENTMEMORY_CAPTURE_MAX_ATTEMPTS: "${AGENTMEMORY_CAPTURE_MAX_ATTEMPTS:-}" AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS: "${AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS:-}" AGENTMEMORY_CAPTURE_DEDUP_HOURS: "${AGENTMEMORY_CAPTURE_DEDUP_HOURS:-}" diff --git a/plugin/skills/agentmemory-config/REFERENCE.md b/plugin/skills/agentmemory-config/REFERENCE.md index e3439400a4..caf1f2063e 100644 --- a/plugin/skills/agentmemory-config/REFERENCE.md +++ b/plugin/skills/agentmemory-config/REFERENCE.md @@ -3,7 +3,7 @@ Generated by scanning `src/` for `AGENTMEMORY_*` usage. Do not edit the block below by hand; run `npm run skills:gen` after adding or removing a variable. Internal markers ending in two underscores are excluded. -Configuration is read from the environment and from `~/.agentmemory/.env` (no `export` prefix). 83 recognized variables: +Configuration is read from the environment and from `~/.agentmemory/.env` (no `export` prefix). 84 recognized variables: - `AGENTMEMORY_AGENT_SCOPE` - `AGENTMEMORY_ALLOW_AGENT_SDK` @@ -57,6 +57,7 @@ Configuration is read from the environment and from `~/.agentmemory/.env` (no `e - `AGENTMEMORY_LLM_PROVIDER` - `AGENTMEMORY_LLM_TIMEOUT_MS` - `AGENTMEMORY_LOCAL_DISPATCH` +- `AGENTMEMORY_MAX_PROVIDER_CONCURRENCY` - `AGENTMEMORY_MCP_BLOCK` - `AGENTMEMORY_METRICS_PORT` - `AGENTMEMORY_PRE_COMPACT_BUDGET` diff --git a/scripts/docs-sync.state.json b/scripts/docs-sync.state.json index 9433edebd3..7f6afbb042 100644 --- a/scripts/docs-sync.state.json +++ b/scripts/docs-sync.state.json @@ -20,16 +20,16 @@ "12" ], "tests": [ - "4800+" + "4900+" ], "functions": [ "323" ], "sourceFiles": [ - "260" + "262" ], "loc": [ - "61000" + "62000" ], "kvScopes": [ "65" diff --git a/src/cli/compose-project.ts b/src/cli/compose-project.ts index cd684ae8d2..da5a7f5c1f 100644 --- a/src/cli/compose-project.ts +++ b/src/cli/compose-project.ts @@ -72,7 +72,8 @@ const AGENTMEMORY_WORKER_ENV_ALLOWLIST = new Set([ "CLAUDE_MEMORY_LINE_BUDGET", "CLAUDE_PROJECT_PATH", "AGENTMEMORY_SUPPRESS_COST_WARNING", "FALLBACK_PROVIDERS", "OPENAI_API_VERSION", "OPENAI_REASONING_EFFORT", "OPENAI_TIMEOUT_MS", "MINIMAX_BASE_URL", "OPENROUTER_EMBEDDING_MODEL", "OPENROUTER_EMBEDDING_DIMENSIONS", - "AGENTMEMORY_LLM_TIMEOUT_MS", "AGENTMEMORY_CAPTURE_MAX_ATTEMPTS", + "AGENTMEMORY_LLM_TIMEOUT_MS", "AGENTMEMORY_MAX_PROVIDER_CONCURRENCY", + "AGENTMEMORY_CAPTURE_MAX_ATTEMPTS", "AGENTMEMORY_CAPTURE_RETRY_INTERVAL_MS", "AGENTMEMORY_CAPTURE_DEDUP_HOURS", "AGENTMEMORY_CAPTURE_INBOX_MAX", "AGENTMEMORY_CAPTURE_DEAD_MAX", "AGENTMEMORY_CAPTURE_EVENTS_MAX", "AGENTMEMORY_CAPTURE_SPOOL", "AGENTMEMORY_CAPTURE_SPOOL_DIR", diff --git a/src/providers/resilient.ts b/src/providers/resilient.ts index f82e578d72..9c8c345e95 100644 --- a/src/providers/resilient.ts +++ b/src/providers/resilient.ts @@ -1,5 +1,71 @@ import type { MemoryProvider, CircuitBreakerState } from "../types.js"; import { CircuitBreaker } from "./circuit-breaker.js"; +import { getEnvVar } from "../config.js"; + +// Matches CHUNK_CONCURRENCY_DEFAULT in src/functions/summarize.ts on purpose. +// That value is tuned so a ~100-chunk session finishes inside the 180s +// invocation budget at roughly 8s per call; a global gate below it would push +// that past the budget and silently make SUMMARIZE_CHUNK_CONCURRENCY a no-op +// above the gate. Raise them together, never one alone. +const DEFAULT_MAX_CONCURRENT = 6; + +// A queued call still holds its prompts alive, so an unbounded queue is a +// memory leak on a service that is already memory-constrained. Compression is +// dispatched fire-and-forget, so nothing upstream applies backpressure for us. +const MAX_QUEUED = 512; + +class Semaphore { + private active = 0; + private waiting: Array<() => void> = []; + + constructor(private readonly limit: number) {} + + async acquire(): Promise { + if (this.active < this.limit) { + this.active++; + return; + } + if (this.waiting.length >= MAX_QUEUED) { + throw new Error("provider_queue_full"); + } + await new Promise((resolve) => this.waiting.push(resolve)); + } + + release(): void { + const next = this.waiting.shift(); + if (next) next(); + else this.active--; + } +} + +function isBackpressure(err: unknown): boolean { + const message = err instanceof Error ? err.message : String(err); + // Quota exhaustion and billing failures also come back as 429, but they are + // persistent states rather than backpressure. Excusing them would mean the + // breaker could never open for a provider that will not recover on its own, + // so they are checked first and fall through to a genuine failure. + if (/insufficient_quota|exceeded your current quota|billing/i.test(message)) { + return false; + } + // Status codes and API error codes only. `rate.?limit` also matched the + // hyphenated form in a docs URL, so a genuine 500 whose body linked to + // /docs/guides/rate-limits was excused and the breaker stayed blind to a + // provider that was actually broken. `rate[ _]limit` covers prose and the + // rate_limit_error / rate_limit_exceeded codes without matching the URL. + // 529 / overloaded_error is Anthropic's form of the same backpressure signal. + return /\b429\b|\b529\b|rate[ _]limit|too many (concurrent )?requests|overloaded_error/i.test( + message, + ); +} + +function resolveMaxConcurrent(configured: number | undefined): number { + const candidate = + configured ?? + Number(getEnvVar("AGENTMEMORY_MAX_PROVIDER_CONCURRENCY") ?? NaN); + if (!Number.isFinite(candidate)) return DEFAULT_MAX_CONCURRENT; + const whole = Math.floor(candidate); + return whole >= 1 ? whole : DEFAULT_MAX_CONCURRENT; +} const FILTER_CODE = /content_filter|ResponsibleAIPolicyViolation/; const REJECTED_STATUS = /^[^{]*\(400\)/; @@ -10,10 +76,16 @@ export function isPayloadRejection(err: unknown): boolean { } export class ResilientProvider implements MemoryProvider { - private breaker = new CircuitBreaker(); + private breaker: CircuitBreaker; + private gate: Semaphore; name: string; - constructor(private inner: MemoryProvider) { + constructor( + private inner: MemoryProvider, + options: { maxConcurrent?: number } = {}, + ) { + this.breaker = new CircuitBreaker(); + this.gate = new Semaphore(resolveMaxConcurrent(options.maxConcurrent)); this.name = `resilient(${inner.name})`; } @@ -21,15 +93,35 @@ export class ResilientProvider implements MemoryProvider { if (!this.breaker.isAllowed) { throw new Error("circuit_breaker_open"); } + await this.gate.acquire(); + // Re-checked after queueing. A call that passed the first check may have + // waited while the running calls failed and opened the breaker; without + // this it would still be sent to a provider already known to be down, and + // each such failure pushes the recovery window further out. + if (!this.breaker.isAllowed) { + this.gate.release(); + throw new Error("circuit_breaker_open"); + } + // Read after the isAllowed checks, which are what move open -> half-open. + const probing = this.breaker.getState().state === "half-open"; try { const result = await fn(); this.breaker.recordSuccess(); return result; } catch (err) { - if (!isPayloadRejection(err)) { + // Backpressure normally must not open the breaker. The half-open probe is + // the exception: nothing else records an outcome for it, so excusing a + // rate-limited probe leaves the breaker sitting in half-open admitting + // every call, with no path back to either open or closed. A probe that + // came back rate-limited has still failed as a probe. + // A content-filter rejection is about the payload, not the provider, so + // it never counts (#1277). + if (!isPayloadRejection(err) && (probing || !isBackpressure(err))) { this.breaker.recordFailure(); } throw err; + } finally { + this.gate.release(); } } diff --git a/test/resilient-provider.test.ts b/test/resilient-provider.test.ts new file mode 100644 index 0000000000..b7a58cf681 --- /dev/null +++ b/test/resilient-provider.test.ts @@ -0,0 +1,300 @@ +import { describe, it, expect, vi } from "vitest"; +import { ResilientProvider } from "../src/providers/resilient.js"; +import type { MemoryProvider } from "../src/types.js"; + +// Tracks how many calls are inside the provider at once, which is the thing the +// upstream API actually rejects. Counting total calls would not discriminate. +function countingProvider( + behaviour: (n: number) => Promise = async () => "ok", +): MemoryProvider & { peak: number; calls: number } { + let inFlight = 0; + const state = { + name: "counting", + peak: 0, + calls: 0, + async compress(): Promise { + inFlight++; + state.calls++; + if (inFlight > state.peak) state.peak = inFlight; + try { + return await behaviour(state.calls); + } finally { + inFlight--; + } + }, + async summarize(): Promise { + return state.compress(); + }, + }; + return state; +} + +function rateLimited(): Error { + return new Error('OpenAI API error (429): {"error":"too many concurrent requests"}'); +} + +describe("ResilientProvider concurrency", () => { + it("never runs more than the configured number of calls at once", async () => { + const inner = countingProvider( + () => new Promise((resolve) => setTimeout(() => resolve("ok"), 5)), + ); + const provider = new ResilientProvider(inner, { maxConcurrent: 3 }); + + const results = await Promise.all( + Array.from({ length: 24 }, () => provider.compress("sys", "user")), + ); + + expect(inner.peak).toBeLessThanOrEqual(3); + // Bounding must not drop work: every call still ran and still resolved. + expect(inner.calls).toBe(24); + expect(results.every((r) => r === "ok")).toBe(true); + }); + + it("releases its slot when a call throws", async () => { + const inner = countingProvider(async (n) => { + if (n <= 2) throw new Error("boom"); + return "ok"; + }); + // maxConcurrent 1 is load-bearing here: at the default of 6 a leaked slot + // would not deadlock, and the test would pass despite the bug. + const provider = new ResilientProvider(inner, { maxConcurrent: 1 }); + + const settled = await Promise.allSettled( + Array.from({ length: 5 }, () => provider.compress("sys", "user")), + ); + + expect(settled).toHaveLength(5); + expect(settled.filter((s) => s.status === "fulfilled")).toHaveLength(3); + }); + + it("rejects calls past the queue cap without tripping the breaker", async () => { + let release!: () => void; + const gate = new Promise((resolve) => { + release = () => resolve("ok"); + }); + const inner = countingProvider(() => gate); + const provider = new ResilientProvider(inner, { maxConcurrent: 1 }); + + // One call in flight plus 512 queued fills the gate; the rest overflow. + const calls = Array.from({ length: 516 }, () => + provider.compress("sys", "user"), + ); + const overflow = await Promise.allSettled(calls.slice(513)); + release(); + const admitted = await Promise.allSettled(calls.slice(0, 513)); + + expect(overflow.every((s) => s.status === "rejected")).toBe(true); + expect( + overflow.map((s) => (s as PromiseRejectedResult).reason.message), + ).toEqual(["provider_queue_full", "provider_queue_full", "provider_queue_full"]); + expect(admitted.every((s) => s.status === "fulfilled")).toBe(true); + expect(inner.calls).toBe(513); + expect(provider.circuitState.state).toBe("closed"); + }); +}); + +describe("ResilientProvider rate limiting", () => { + it("does not open the breaker on 429s", async () => { + const inner = countingProvider(async (n) => { + if (n <= 5) throw rateLimited(); + return "ok"; + }); + const provider = new ResilientProvider(inner); + + // Five, against a default failure threshold of three. + for (let i = 0; i < 5; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + + expect(provider.circuitState.state).toBe("closed"); + await expect(provider.compress("sys", "user")).resolves.toBe("ok"); + }); + + it("still opens the breaker on genuine failures", async () => { + const inner = countingProvider(async () => { + throw new Error("upstream exploded"); + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 3; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + + expect(provider.circuitState.state).toBe("open"); + await expect(provider.compress("sys", "user")).rejects.toThrow( + "circuit_breaker_open", + ); + }); +}); + +describe("ResilientProvider rate-limit classification", () => { + it("still opens the breaker when a real failure merely mentions a rate limit", async () => { + // The filter matches on message text, and providers interpolate the whole + // upstream body. A 500 whose body carries a docs link like + // /docs/guides/rate-limits would otherwise be excused forever, leaving the + // breaker permanently blind to a genuinely broken provider. + const inner = countingProvider(async () => { + throw new Error( + "HTTP 500 upstream failure, see https://example.com/docs/guides/rate-limits", + ); + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 3; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + + expect(provider.circuitState.state).toBe("open"); + }); + + it("opens the breaker on quota exhaustion even though it arrives as a 429", async () => { + // Quota exhaustion and billing failures use the same status as + // backpressure, but they do not resolve on their own. Excusing them means + // the breaker can never open for a provider that will stay broken. + const inner = countingProvider(async () => { + throw new Error( + 'API error (429): {"error":{"code":"insufficient_quota","message":"You exceeded your current quota"}}', + ); + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 3; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + + expect(provider.circuitState.state).toBe("open"); + }); + + it("treats an overloaded provider as backpressure", async () => { + // Anthropic signals the same "busy, retry" condition as 529 + // overloaded_error rather than 429. + const inner = countingProvider(async (n) => { + if (n <= 5) throw new Error('{"type":"overloaded_error"} (529)'); + return "ok"; + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 5; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + + expect(provider.circuitState.state).toBe("closed"); + }); +}); + +describe("ResilientProvider half-open probe", () => { + it("does not get stuck in half-open when the probe is rate limited", async () => { + // Nothing else records an outcome for the probe, so excusing a + // rate-limited one leaves the breaker in half-open admitting every call, + // with no path back to open or closed. Half-open must never be a state you + // can enter and not leave. + let mode: "fail" | "ratelimit" = "fail"; + const inner = countingProvider(async () => { + throw mode === "fail" + ? new Error("upstream exploded") + : new Error("API error (429): rate limited"); + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 3; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + expect(provider.circuitState.state).toBe("open"); + + // Move the clock past the 30s recovery window so the next call is the + // probe. Sleeping a few milliseconds instead would leave the breaker still + // open, the probe would never happen, and this test would pass without + // exercising anything — it did exactly that before this was fixed. + vi.useFakeTimers(); + vi.setSystemTime(Date.now() + 31_000); + try { + mode = "ratelimit"; + await provider.compress("sys", "user").catch(() => undefined); + + // Assert the probe actually dispatched. Without this the test passes + // vacuously if the clock advance does not take: the breaker would still + // be open, the first isAllowed check would throw before reaching fn(), + // and "open" !== "half-open" would hold while nothing was exercised. + expect(inner.calls).toBe(4); + // Must be exactly open. `not.toBe("half-open")` would also accept + // "closed", which is the worse bug — a rate-limited probe mistaken for + // full recovery. + expect(provider.circuitState.state).toBe("open"); + } finally { + vi.useRealTimers(); + } + }); + + it("does not reopen on a content-filter rejection during the probe", async () => { + // The probe rule above counts a rate-limited probe as a failure. A + // content-filter rejection is different: the provider answered, and the + // refusal is about the payload (#1277), so the probe must not reopen the + // breaker. It stays half-open, and the next call decides. + let mode: "fail" | "filtered" | "ok" = "fail"; + const inner = countingProvider(async () => { + if (mode === "fail") throw new Error("upstream exploded"); + if (mode === "filtered") { + throw new Error( + 'OpenAI API error (400): {"error":{"code":"content_filter",' + + '"innererror":{"code":"ResponsibleAIPolicyViolation"}}}', + ); + } + return "ok"; + }); + const provider = new ResilientProvider(inner); + + for (let i = 0; i < 3; i++) { + await provider.compress("sys", "user").catch(() => undefined); + } + expect(provider.circuitState.state).toBe("open"); + + vi.useFakeTimers(); + vi.setSystemTime(Date.now() + 31_000); + try { + mode = "filtered"; + await provider.compress("sys", "user").catch(() => undefined); + expect(inner.calls).toBe(4); + expect(provider.circuitState.state).toBe("half-open"); + + mode = "ok"; + await expect(provider.compress("sys", "user")).resolves.toBe("ok"); + expect(provider.circuitState.state).toBe("closed"); + } finally { + vi.useRealTimers(); + } + }); + + it("fails a call queued before the breaker opened, without calling the provider", async () => { + // The post-acquire re-check. A call admitted while the breaker was closed + // can wait behind others that fail and open it; without the re-check it is + // still handed to a provider already known to be down. + let release!: () => void; + const gate = new Promise((r) => { + release = r; + }); + const inner = countingProvider(async (n) => { + if (n === 1) { + await gate; + throw new Error("upstream exploded"); + } + throw new Error("upstream exploded"); + }); + const provider = new ResilientProvider(inner, { maxConcurrent: 1 }); + + // One call occupies the only slot; three more queue behind it. + const first = provider.compress("sys", "user").catch((e) => e); + const queued = Array.from({ length: 3 }, () => + provider.compress("sys", "user").catch((e: Error) => e), + ); + release(); + const results = [await first, ...(await Promise.all(queued))]; + + // Three failures open the breaker, so the last queued call must be turned + // away at the re-check rather than reaching the provider. + expect(provider.circuitState.state).toBe("open"); + expect(inner.calls).toBeLessThan(4); + expect( + results.some((r) => (r as Error).message === "circuit_breaker_open"), + ).toBe(true); + }); +});