@remnic/core 10.0.174 → 10.0.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/dist/access-admin-ops-surface.js +72 -71
  2. package/dist/access-audit.js +2 -2
  3. package/dist/access-cli.js +72 -71
  4. package/dist/access-cli.js.map +1 -1
  5. package/dist/access-extraction-force-flush-preempt.js +72 -71
  6. package/dist/access-extraction-force-flush.js +72 -71
  7. package/dist/access-http-briefing.js +72 -71
  8. package/dist/access-http-query.js +72 -71
  9. package/dist/access-http.js +72 -71
  10. package/dist/access-identity-continuity-surface.js +72 -71
  11. package/dist/access-lcm-surface.js +72 -71
  12. package/dist/access-mcp.js +72 -71
  13. package/dist/access-observe-write-surface.js +72 -71
  14. package/dist/access-operations-batch.js +72 -71
  15. package/dist/access-operations.js +72 -71
  16. package/dist/access-recall-concurrency.js +72 -71
  17. package/dist/access-recall-response.js +72 -71
  18. package/dist/access-recall-surface.js +72 -71
  19. package/dist/access-service.js +72 -71
  20. package/dist/active-recall.js +16 -14
  21. package/dist/active-recall.js.map +1 -1
  22. package/dist/adapters/index.js +4 -4
  23. package/dist/adapters/registry.js +2 -2
  24. package/dist/briefing.js +14 -13
  25. package/dist/buffer-add-turns-bounded.js +2 -2
  26. package/dist/buffer-session-cap.d.ts +1 -1
  27. package/dist/buffer-session-cap.d.ts.map +1 -1
  28. package/dist/buffer-session-cap.js +1 -1
  29. package/dist/buffer.js +11 -10
  30. package/dist/causal-consolidation.js +15 -14
  31. package/dist/causal-consolidation.js.map +1 -1
  32. package/dist/{chunk-IO4AAVYZ.js → chunk-2EKXMZ6E.js} +2 -2
  33. package/dist/{chunk-TOQK5A4Y.js → chunk-2LXROA34.js} +6 -6
  34. package/dist/{chunk-IUM3VSHI.js → chunk-2WREX7KD.js} +10 -1
  35. package/dist/chunk-2WREX7KD.js.map +1 -0
  36. package/dist/{chunk-IHB3JO4B.js → chunk-3FS6IVSU.js} +2 -2
  37. package/dist/{chunk-UBQ2ZOWA.js → chunk-3SP7EZWA.js} +2 -2
  38. package/dist/{chunk-4PBHMJRC.js → chunk-4GI2IGUK.js} +2 -2
  39. package/dist/{chunk-OWD365QW.js → chunk-4TIGRBKH.js} +5 -5
  40. package/dist/{chunk-HHVK2JRE.js → chunk-4TPU36X4.js} +2 -2
  41. package/dist/{chunk-DMPZABKG.js → chunk-4TZOOUMK.js} +2 -2
  42. package/dist/{chunk-Y2LZW3EQ.js → chunk-5CLKLKID.js} +3 -3
  43. package/dist/{chunk-5MTKGNZ5.js → chunk-5RBHL5TF.js} +121 -41
  44. package/dist/chunk-5RBHL5TF.js.map +1 -0
  45. package/dist/{chunk-HR3DKJCU.js → chunk-6SROXED4.js} +2 -2
  46. package/dist/{chunk-L3DDKXQJ.js → chunk-76LDFLAG.js} +2 -2
  47. package/dist/{chunk-5RONA5FF.js → chunk-7DFJ4JX2.js} +4 -4
  48. package/dist/{chunk-OK3X3TBR.js → chunk-7L73PLRG.js} +2 -2
  49. package/dist/{chunk-PUQQPLVV.js → chunk-AJQI2XCB.js} +2 -2
  50. package/dist/chunk-AJQI2XCB.js.map +1 -0
  51. package/dist/{chunk-RSUNBJ4I.js → chunk-AOHQ4OJR.js} +8 -8
  52. package/dist/{chunk-WKNMKV52.js → chunk-AQ6V47Q7.js} +2 -2
  53. package/dist/{chunk-H4KIMZJD.js → chunk-B4ZA2PZC.js} +3 -3
  54. package/dist/{chunk-DLR3SBOM.js → chunk-B7GZL7PR.js} +2 -2
  55. package/dist/{chunk-XYNUEXLC.js → chunk-BAMF6J4W.js} +4 -4
  56. package/dist/{chunk-WI2WTIMY.js → chunk-CFFYGKDJ.js} +5 -5
  57. package/dist/{chunk-NTR72OL5.js → chunk-CXIBBZ6N.js} +2 -2
  58. package/dist/{chunk-3DJ6R4CC.js → chunk-DLPS5YP3.js} +2 -2
  59. package/dist/{chunk-EXGY5TPU.js → chunk-EQSOXIIH.js} +7 -7
  60. package/dist/{chunk-6OMSYPOL.js → chunk-F2XXZR6A.js} +3 -3
  61. package/dist/{chunk-CY2C5LM4.js → chunk-FDLPNFKE.js} +2 -2
  62. package/dist/{chunk-KAGLV5KH.js → chunk-FTQF3G3B.js} +2 -2
  63. package/dist/{chunk-2GQVYLQK.js → chunk-FTV2C3CA.js} +2 -2
  64. package/dist/{chunk-B7HYXVME.js → chunk-FZF7JX76.js} +1 -1
  65. package/dist/chunk-FZF7JX76.js.map +1 -0
  66. package/dist/{chunk-ZKXNSPGQ.js → chunk-G77MHQFZ.js} +2 -2
  67. package/dist/{chunk-66DUCUOC.js → chunk-GGQ3CJVH.js} +2 -2
  68. package/dist/{chunk-BN5SK2RZ.js → chunk-HHKUWNHQ.js} +2 -2
  69. package/dist/{chunk-KMOH6W5B.js → chunk-HOTAHSO3.js} +3 -3
  70. package/dist/{chunk-OY3IULYL.js → chunk-IFXQGDMG.js} +2 -2
  71. package/dist/{chunk-OWBI5477.js → chunk-JUROR7PB.js} +2 -2
  72. package/dist/{chunk-4ACKO4U2.js → chunk-JXYFXVPB.js} +2 -2
  73. package/dist/{chunk-ASWECJXS.js → chunk-KYPFQO43.js} +3 -3
  74. package/dist/{chunk-4WOEEMGK.js → chunk-KZBE4KBZ.js} +2 -2
  75. package/dist/{chunk-V6MN37WG.js → chunk-MFJM35R7.js} +2 -2
  76. package/dist/{chunk-LKXW6W42.js → chunk-OTE5E44O.js} +2 -2
  77. package/dist/{chunk-KPLKABGR.js → chunk-P3SMXKFR.js} +2 -2
  78. package/dist/{chunk-27BH67PT.js → chunk-PCLTJUOY.js} +2 -2
  79. package/dist/{chunk-JDH2BA2P.js → chunk-RXAWE76Y.js} +2 -2
  80. package/dist/{chunk-IXI6S2VJ.js → chunk-S45VECVD.js} +29 -2
  81. package/dist/chunk-S45VECVD.js.map +1 -0
  82. package/dist/{chunk-WTFHZQXM.js → chunk-T3NEDSLZ.js} +3 -3
  83. package/dist/{chunk-HB2PRTXX.js → chunk-V425GW5W.js} +2 -2
  84. package/dist/{chunk-XKFL2WQO.js → chunk-V5FCMJW4.js} +2 -2
  85. package/dist/{chunk-SNI526DD.js → chunk-VR6NF6VX.js} +2 -2
  86. package/dist/{chunk-V6UFCV6T.js → chunk-VRDG7XFJ.js} +80 -80
  87. package/dist/{chunk-5ACIRCBO.js → chunk-WTXUUZYI.js} +6 -4
  88. package/dist/chunk-WTXUUZYI.js.map +1 -0
  89. package/dist/chunk-XBJOO7G5.js +87 -0
  90. package/dist/chunk-XBJOO7G5.js.map +1 -0
  91. package/dist/{chunk-RASE4TEF.js → chunk-Y26CFLHD.js} +5 -2
  92. package/dist/chunk-Y26CFLHD.js.map +1 -0
  93. package/dist/{chunk-AM6H7BIY.js → chunk-YMNPQMHA.js} +2 -2
  94. package/dist/{chunk-QVXRE66C.js → chunk-ZBDTOWGX.js} +7 -7
  95. package/dist/{chunk-YCK26VSL.js → chunk-ZMEEOLQG.js} +2 -2
  96. package/dist/{chunk-R2AJAAHJ.js → chunk-ZNHLUYIT.js} +90 -16
  97. package/dist/chunk-ZNHLUYIT.js.map +1 -0
  98. package/dist/{chunk-DAOMWGO2.js → chunk-ZX5N5D6M.js} +4 -4
  99. package/dist/cli.js +72 -71
  100. package/dist/coding/export-okf-codegraph.js +13 -12
  101. package/dist/coding/export-okf-codegraph.js.map +1 -1
  102. package/dist/compounding/engine.js +15 -14
  103. package/dist/config.d.ts.map +1 -1
  104. package/dist/config.js +16 -14
  105. package/dist/connectors/codex-materialize-runner.js +14 -13
  106. package/dist/connectors/index.js +14 -13
  107. package/dist/convergence-refresh.js +16 -15
  108. package/dist/corpus-watermark.js +16 -15
  109. package/dist/entity-retrieval.js +14 -13
  110. package/dist/explicit-capture.js +72 -71
  111. package/dist/extraction.js +18 -17
  112. package/dist/{first-start-migration-CCZ5SM3V.js → first-start-migration-TCPK2I7J.js} +4 -4
  113. package/dist/harmonic-retrieval.js +14 -13
  114. package/dist/index.js +104 -103
  115. package/dist/lcm/index.js +3 -3
  116. package/dist/location/index.js +15 -14
  117. package/dist/maintenance/memory-governance.js +14 -13
  118. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +14 -13
  119. package/dist/maintenance/rebuild-memory-projection-runner.js +16 -15
  120. package/dist/maintenance/rebuild-memory-projection.js +15 -14
  121. package/dist/memory-browse.js +9 -8
  122. package/dist/namespaces/migrate.js +15 -14
  123. package/dist/namespaces/search.d.ts +5 -1
  124. package/dist/namespaces/search.d.ts.map +1 -1
  125. package/dist/namespaces/search.js +12 -11
  126. package/dist/namespaces/storage.js +14 -13
  127. package/dist/operator-doctor-corpus.js +17 -16
  128. package/dist/operator-toolkit.js +23 -21
  129. package/dist/orchestration/backlog-scheduler.js +75 -74
  130. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  131. package/dist/orchestration/buffer-drain-runner.js +73 -72
  132. package/dist/orchestration/maintenance.js +22 -21
  133. package/dist/orchestrator.js +72 -71
  134. package/dist/peers/index.js +1 -1
  135. package/dist/peers/interaction-log-append.d.ts.map +1 -1
  136. package/dist/qmd-daemon-session.d.ts +8 -0
  137. package/dist/qmd-daemon-session.d.ts.map +1 -1
  138. package/dist/qmd-daemon-session.js +1 -1
  139. package/dist/qmd-health-metadata.d.ts +39 -0
  140. package/dist/qmd-health-metadata.d.ts.map +1 -0
  141. package/dist/qmd-health-metadata.js +12 -0
  142. package/dist/qmd-health-metadata.js.map +1 -0
  143. package/dist/qmd-status.d.ts.map +1 -1
  144. package/dist/qmd-status.js +1 -1
  145. package/dist/qmd.d.ts +5 -1
  146. package/dist/qmd.d.ts.map +1 -1
  147. package/dist/qmd.js +8 -7
  148. package/dist/recall-composition-decision.js +2 -2
  149. package/dist/recall-navigation.js +72 -71
  150. package/dist/recall-state-view-admission.js +9 -8
  151. package/dist/recall-why-service.js +9 -8
  152. package/dist/resume-bundles.js +19 -17
  153. package/dist/search/factory.js +11 -10
  154. package/dist/search/index.js +11 -10
  155. package/dist/search/lancedb-backend.js +2 -2
  156. package/dist/search/meilisearch-backend.js +2 -2
  157. package/dist/search/orama-backend.js +2 -2
  158. package/dist/search/port.d.ts +21 -0
  159. package/dist/search/port.d.ts.map +1 -1
  160. package/dist/search/port.js +1 -1
  161. package/dist/search/remote-backend.js +2 -2
  162. package/dist/semantic-consolidation.js +15 -14
  163. package/dist/semantic-rule-promotion.js +14 -13
  164. package/dist/semantic-rule-verifier.js +14 -13
  165. package/dist/source-agent-qualifier.js +17 -16
  166. package/dist/standup/build.js +14 -13
  167. package/dist/storage.js +13 -12
  168. package/dist/transcript.js +2 -2
  169. package/dist/transfer/export-okf.js +14 -13
  170. package/dist/verified-recall.js +14 -13
  171. package/dist/who-knows-cli.js +15 -14
  172. package/dist/who-knows.js +14 -13
  173. package/package.json +2 -2
  174. package/src/buffer-session-cap-default.test.ts +86 -0
  175. package/src/buffer-session-cap.ts +7 -1
  176. package/src/config.ts +2 -1
  177. package/src/namespaces/search.test.ts +320 -4
  178. package/src/namespaces/search.ts +147 -51
  179. package/src/peers/interaction-log-append.ts +11 -3
  180. package/src/peers/peers.test.ts +27 -0
  181. package/src/qmd-client.test.ts +34 -3
  182. package/src/qmd-daemon-session.ts +34 -1
  183. package/src/qmd-health-metadata.test.ts +493 -0
  184. package/src/qmd-health-metadata.ts +95 -0
  185. package/src/qmd-status.ts +10 -1
  186. package/src/qmd.ts +83 -3
  187. package/src/search/port.ts +23 -0
  188. package/dist/chunk-5ACIRCBO.js.map +0 -1
  189. package/dist/chunk-5MTKGNZ5.js.map +0 -1
  190. package/dist/chunk-B7HYXVME.js.map +0 -1
  191. package/dist/chunk-IUM3VSHI.js.map +0 -1
  192. package/dist/chunk-IXI6S2VJ.js.map +0 -1
  193. package/dist/chunk-PUQQPLVV.js.map +0 -1
  194. package/dist/chunk-R2AJAAHJ.js.map +0 -1
  195. package/dist/chunk-RASE4TEF.js.map +0 -1
  196. /package/dist/{chunk-IO4AAVYZ.js.map → chunk-2EKXMZ6E.js.map} +0 -0
  197. /package/dist/{chunk-TOQK5A4Y.js.map → chunk-2LXROA34.js.map} +0 -0
  198. /package/dist/{chunk-IHB3JO4B.js.map → chunk-3FS6IVSU.js.map} +0 -0
  199. /package/dist/{chunk-UBQ2ZOWA.js.map → chunk-3SP7EZWA.js.map} +0 -0
  200. /package/dist/{chunk-4PBHMJRC.js.map → chunk-4GI2IGUK.js.map} +0 -0
  201. /package/dist/{chunk-OWD365QW.js.map → chunk-4TIGRBKH.js.map} +0 -0
  202. /package/dist/{chunk-HHVK2JRE.js.map → chunk-4TPU36X4.js.map} +0 -0
  203. /package/dist/{chunk-DMPZABKG.js.map → chunk-4TZOOUMK.js.map} +0 -0
  204. /package/dist/{chunk-Y2LZW3EQ.js.map → chunk-5CLKLKID.js.map} +0 -0
  205. /package/dist/{chunk-HR3DKJCU.js.map → chunk-6SROXED4.js.map} +0 -0
  206. /package/dist/{chunk-L3DDKXQJ.js.map → chunk-76LDFLAG.js.map} +0 -0
  207. /package/dist/{chunk-5RONA5FF.js.map → chunk-7DFJ4JX2.js.map} +0 -0
  208. /package/dist/{chunk-OK3X3TBR.js.map → chunk-7L73PLRG.js.map} +0 -0
  209. /package/dist/{chunk-RSUNBJ4I.js.map → chunk-AOHQ4OJR.js.map} +0 -0
  210. /package/dist/{chunk-WKNMKV52.js.map → chunk-AQ6V47Q7.js.map} +0 -0
  211. /package/dist/{chunk-H4KIMZJD.js.map → chunk-B4ZA2PZC.js.map} +0 -0
  212. /package/dist/{chunk-DLR3SBOM.js.map → chunk-B7GZL7PR.js.map} +0 -0
  213. /package/dist/{chunk-XYNUEXLC.js.map → chunk-BAMF6J4W.js.map} +0 -0
  214. /package/dist/{chunk-WI2WTIMY.js.map → chunk-CFFYGKDJ.js.map} +0 -0
  215. /package/dist/{chunk-NTR72OL5.js.map → chunk-CXIBBZ6N.js.map} +0 -0
  216. /package/dist/{chunk-3DJ6R4CC.js.map → chunk-DLPS5YP3.js.map} +0 -0
  217. /package/dist/{chunk-EXGY5TPU.js.map → chunk-EQSOXIIH.js.map} +0 -0
  218. /package/dist/{chunk-6OMSYPOL.js.map → chunk-F2XXZR6A.js.map} +0 -0
  219. /package/dist/{chunk-CY2C5LM4.js.map → chunk-FDLPNFKE.js.map} +0 -0
  220. /package/dist/{chunk-KAGLV5KH.js.map → chunk-FTQF3G3B.js.map} +0 -0
  221. /package/dist/{chunk-2GQVYLQK.js.map → chunk-FTV2C3CA.js.map} +0 -0
  222. /package/dist/{chunk-ZKXNSPGQ.js.map → chunk-G77MHQFZ.js.map} +0 -0
  223. /package/dist/{chunk-66DUCUOC.js.map → chunk-GGQ3CJVH.js.map} +0 -0
  224. /package/dist/{chunk-BN5SK2RZ.js.map → chunk-HHKUWNHQ.js.map} +0 -0
  225. /package/dist/{chunk-KMOH6W5B.js.map → chunk-HOTAHSO3.js.map} +0 -0
  226. /package/dist/{chunk-OY3IULYL.js.map → chunk-IFXQGDMG.js.map} +0 -0
  227. /package/dist/{chunk-OWBI5477.js.map → chunk-JUROR7PB.js.map} +0 -0
  228. /package/dist/{chunk-4ACKO4U2.js.map → chunk-JXYFXVPB.js.map} +0 -0
  229. /package/dist/{chunk-ASWECJXS.js.map → chunk-KYPFQO43.js.map} +0 -0
  230. /package/dist/{chunk-4WOEEMGK.js.map → chunk-KZBE4KBZ.js.map} +0 -0
  231. /package/dist/{chunk-V6MN37WG.js.map → chunk-MFJM35R7.js.map} +0 -0
  232. /package/dist/{chunk-LKXW6W42.js.map → chunk-OTE5E44O.js.map} +0 -0
  233. /package/dist/{chunk-KPLKABGR.js.map → chunk-P3SMXKFR.js.map} +0 -0
  234. /package/dist/{chunk-27BH67PT.js.map → chunk-PCLTJUOY.js.map} +0 -0
  235. /package/dist/{chunk-JDH2BA2P.js.map → chunk-RXAWE76Y.js.map} +0 -0
  236. /package/dist/{chunk-WTFHZQXM.js.map → chunk-T3NEDSLZ.js.map} +0 -0
  237. /package/dist/{chunk-HB2PRTXX.js.map → chunk-V425GW5W.js.map} +0 -0
  238. /package/dist/{chunk-XKFL2WQO.js.map → chunk-V5FCMJW4.js.map} +0 -0
  239. /package/dist/{chunk-SNI526DD.js.map → chunk-VR6NF6VX.js.map} +0 -0
  240. /package/dist/{chunk-V6UFCV6T.js.map → chunk-VRDG7XFJ.js.map} +0 -0
  241. /package/dist/{chunk-AM6H7BIY.js.map → chunk-YMNPQMHA.js.map} +0 -0
  242. /package/dist/{chunk-QVXRE66C.js.map → chunk-ZBDTOWGX.js.map} +0 -0
  243. /package/dist/{chunk-YCK26VSL.js.map → chunk-ZMEEOLQG.js.map} +0 -0
  244. /package/dist/{chunk-DAOMWGO2.js.map → chunk-ZX5N5D6M.js.map} +0 -0
  245. /package/dist/{first-start-migration-CCZ5SM3V.js.map → first-start-migration-TCPK2I7J.js.map} +0 -0
@@ -0,0 +1,86 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { SmartBuffer, BufferSessionTurnRefusedError } from "./buffer.js";
4
+ import { parseConfig } from "./config.js";
5
+ import { FALLBACK_MAX_TURNS_PER_SESSION, resolveMaxTurnsPerSession } from "./buffer-session-cap.js";
6
+ import type { BufferState, BufferTurn } from "./types.js";
7
+
8
+ import type { BufferStorage } from "./buffer-persistence.js";
9
+
10
+ class FakeStorage {
11
+ public saved: BufferState | null = null;
12
+
13
+ constructor(private readonly initial: BufferState) {}
14
+
15
+ async loadBuffer(): Promise<BufferState> {
16
+ return structuredClone(this.initial);
17
+ }
18
+
19
+ async saveBuffer(state: BufferState): Promise<void> {
20
+ this.saved = structuredClone(state);
21
+ }
22
+ }
23
+
24
+ function makeTurn(sessionKey: string, content: string): BufferTurn {
25
+ return {
26
+ role: "user",
27
+ content,
28
+ timestamp: "2026-04-12T12:00:00.000Z",
29
+ sessionKey,
30
+ };
31
+ }
32
+
33
+ test("the per-session turn cap default outlives an extraction wedge", () => {
34
+ assert.ok(
35
+ FALLBACK_MAX_TURNS_PER_SESSION >= 1000,
36
+ `the default cap (${FALLBACK_MAX_TURNS_PER_SESSION}) must hold a long outage without refusing live captures`,
37
+ );
38
+ assert.equal(resolveMaxTurnsPerSession(undefined), FALLBACK_MAX_TURNS_PER_SESSION);
39
+ });
40
+
41
+ test("parseConfig honours bufferMaxTurnsPerSession and defaults to the backstop", () => {
42
+ assert.equal(parseConfig({}).bufferMaxTurnsPerSession, FALLBACK_MAX_TURNS_PER_SESSION);
43
+ assert.equal(parseConfig({ bufferMaxTurnsPerSession: 42 }).bufferMaxTurnsPerSession, 42);
44
+ });
45
+
46
+ test("a session keeps more turns than the old 200 cap while extraction is stuck", async () => {
47
+ const storage = new FakeStorage({ turns: [], lastExtractionAt: null, extractionCount: 0 });
48
+ // SAFETY: FakeStorage implements the full BufferStorage surface the
49
+ // constructor touches (loadBuffer/saveBuffer); the cast is exact.
50
+ const buffer = new SmartBuffer(
51
+ parseConfig({ bufferSaveDebounceMs: 0 }),
52
+ storage as BufferStorage,
53
+ );
54
+ await buffer.load();
55
+
56
+ const held = 250;
57
+ for (let i = 0; i < held; i += 1) {
58
+ await buffer.addTurnWithOutcome("wedged-session", makeTurn("wedged-session", `turn ${i}`));
59
+ }
60
+
61
+ assert.equal(
62
+ buffer.getTurns("wedged-session").length,
63
+ held,
64
+ "a lane's turns are buffered, not refused, while extraction is stuck",
65
+ );
66
+ });
67
+
68
+ test("a configured cap still refuses live captures once it is reached", async () => {
69
+ const storage = new FakeStorage({ turns: [], lastExtractionAt: null, extractionCount: 0 });
70
+ // SAFETY: FakeStorage implements the full BufferStorage surface the
71
+ // constructor touches (loadBuffer/saveBuffer); the cast is exact.
72
+ const buffer = new SmartBuffer(
73
+ parseConfig({ bufferSaveDebounceMs: 0, bufferMaxTurnsPerSession: 4 }),
74
+ storage as BufferStorage,
75
+ );
76
+ await buffer.load();
77
+
78
+ for (let i = 0; i < 4; i += 1) {
79
+ await buffer.addTurnWithOutcome("capped-session", makeTurn("capped-session", `turn ${i}`));
80
+ }
81
+ await assert.rejects(
82
+ buffer.addTurnWithOutcome("capped-session", makeTurn("capped-session", "one too many")),
83
+ BufferSessionTurnRefusedError,
84
+ "the configured cap still bounds a session",
85
+ );
86
+ });
@@ -4,7 +4,13 @@ import type { BufferEntryState, BufferTurn } from "./types.js";
4
4
 
5
5
  // Far above the extraction trigger (bufferMaxTurns, default 5), so healthy
6
6
  // sessions never touch it. Covers direct constructions predating the knob.
7
- export const FALLBACK_MAX_TURNS_PER_SESSION = 200;
7
+ // 200 was low enough that a wedged extraction (the daemon refusing 270,885
8
+ // captures in one outage) pushed live lanes past the cap within hours of the
9
+ // wedge starting; every later capture was refused and queued client-side.
10
+ // The cap is a memory backstop, not a policy: hosts tune it with
11
+ // bufferMaxTurnsPerSession. Refusals queue in the client's durable outbox,
12
+ // which spills to disk rather than evicting.
13
+ export const FALLBACK_MAX_TURNS_PER_SESSION = 2000;
8
14
 
9
15
  export function resolveMaxTurnsPerSession(configured: number | undefined): number {
10
16
  return configured ?? FALLBACK_MAX_TURNS_PER_SESSION;
package/src/config.ts CHANGED
@@ -35,6 +35,7 @@ import { parseConvergeConfig } from "./converge-config.js";
35
35
  import { parseExternalWikiRecallGuard } from "./external-wiki-guard.js";
36
36
  import { log } from "./logger.js";
37
37
  import { cloneDefaultSessionObserverBands } from "./session-observer-bands.js";
38
+ import { FALLBACK_MAX_TURNS_PER_SESSION } from "./buffer-session-cap.js";
38
39
  import { readEnvVar, resolveHomeDir } from "./runtime/env.js";
39
40
  import { normalizeEntitySchemas } from "./entity-schema.js";
40
41
  import { expandTildePath } from "./utils/path.js";
@@ -1596,7 +1597,7 @@ export function parseConfig(
1596
1597
  // Per-session retained-turn cap (#3415 bound). Far above the extraction
1597
1598
  // trigger, so healthy sessions never touch it; a full session refuses live
1598
1599
  // capture (retryable) instead of growing without bound during an outage.
1599
- bufferMaxTurnsPerSession: parsePositiveInteger(cfg.bufferMaxTurnsPerSession, "bufferMaxTurnsPerSession") ?? 200,
1600
+ bufferMaxTurnsPerSession: parsePositiveInteger(cfg.bufferMaxTurnsPerSession, "bufferMaxTurnsPerSession") ?? FALLBACK_MAX_TURNS_PER_SESSION,
1600
1601
  extractionQueueConcurrency:
1601
1602
  parsePositiveInteger(cfg.extractionQueueConcurrency, "extractionQueueConcurrency") ?? 2,
1602
1603
  bufferMaxMinutes:
@@ -4,17 +4,19 @@ import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { mkdtemp, rm } from "node:fs/promises";
6
6
  import { setImmediate } from "node:timers/promises";
7
- import { NamespaceSearchRouter, NAMESPACE_SEARCH_LEG_TIMEOUT_MS, normalizeQmdResultPath } from "./search.js";
7
+ import { NamespaceSearchRouter, NAMESPACE_SEARCH_LEG_TIMEOUT_MS, normalizeQmdResultPath, isSearchHealthDegraded } from "./search.js";
8
8
  import { MaintenanceScheduler } from "../orchestration/maintenance.js";
9
9
  import type { NamespaceCatalog } from "./catalog.js";
10
10
  import type {
11
11
  SearchBackend,
12
12
  SearchBackendStatus,
13
+ OperationalSearchHealth,
13
14
  SearchDegradation,
14
15
  SearchExecutionOptions,
15
16
  SearchQueryOptions,
16
17
  } from "../search/port.js";
17
18
  import type { QmdCapabilities, QmdVersionStatus } from "../qmd.js";
19
+ import { parseQmdStatusOutput } from "../qmd-status.js";
18
20
  import type { PluginConfig, QmdSearchResult } from "../types.js";
19
21
 
20
22
  type CollectionState = "present" | "missing" | "unknown" | "skipped";
@@ -704,16 +706,16 @@ test("clearCache releases evicted namespace backend handles before recreation",
704
706
  assert.equal(createCalls, 2);
705
707
  });
706
708
 
707
- test("legacy default namespace root auto-creates its base collection (broad root, #1929)", async () => {
709
+ test("a spelling alias of the legacy default namespace auto-creates its base collection (#1929)", async () => {
708
710
  const backend = new FakeBackend(false);
709
711
  const router = new NamespaceSearchRouter(
710
- config(),
712
+ { ...config(), defaultNamespace: "cafe\u0301" },
711
713
  { storageFor: async () => ({ dir: "/tmp/remnic" }) },
712
714
  () => backend,
713
715
  );
714
716
  const controller = new AbortController();
715
717
 
716
- const state = await router.ensureNamespaceCollection("main", {
718
+ const state = await router.ensureNamespaceCollection("caf\u00e9", {
717
719
  signal: controller.signal,
718
720
  });
719
721
 
@@ -1261,6 +1263,8 @@ test("healthForNamespace does not cache an answer whose backend status failed",
1261
1263
 
1262
1264
  const first = await router.healthForNamespace("shared");
1263
1265
  assert.equal(first.pendingEmbeddings, null);
1266
+ assert.equal(first.collectionState, "unknown");
1267
+ assert.equal(isSearchHealthDegraded(first, first.embeddingBacklogThreshold), true);
1264
1268
 
1265
1269
  const second = await router.healthForNamespace("shared");
1266
1270
  assert.equal(second.pendingEmbeddings, 10, "backlog data must be visible on the next probe");
@@ -1612,3 +1616,315 @@ test("namespace-mode maintenance is served only when a non-QMD backend's refresh
1612
1616
  }
1613
1617
  }
1614
1618
  });
1619
+
1620
+ const operationalSnapshot: OperationalSearchHealth = {
1621
+ collectionState: "present", pendingEmbeddings: 0, oldestPendingAgeMs: null,
1622
+ totalFiles: 0, embeddedFiles: null,
1623
+ };
1624
+
1625
+ test("native removal invalidates CLI readiness across equivalent namespace spellings", async t => {
1626
+ let snapshot: OperationalSearchHealth | undefined;
1627
+ let created = 0;
1628
+ const composed = "caf\u00e9";
1629
+ const decomposed = "cafe\u0301";
1630
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1631
+ live.statusResult = { ...operationalSnapshot };
1632
+ Object.assign(live, { readOperationalHealth: async () => snapshot });
1633
+ const missing = new FakeBackend(false, [], { check: "missing" });
1634
+ const present = new FakeBackend(false, [], { check: "present" });
1635
+ present.statusResult = operationalSnapshot;
1636
+ const router = new NamespaceSearchRouter(config(),
1637
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1638
+ () => ++created === 1 ? live : created === 2 ? present : missing);
1639
+ t.after(() => router.dispose());
1640
+ await router.ensureNamespaceCollection(decomposed);
1641
+ assert.equal((await router.healthForNamespace(composed)).collectionState, "present");
1642
+ assert.equal(created, 2);
1643
+ assert.equal((await router.healthForNamespace(composed)).collectionState, "present");
1644
+ assert.equal(created, 2, "absent older capability must retain the guarded diagnostic TTL");
1645
+ snapshot = { ...operationalSnapshot, collectionState: "missing", pendingEmbeddings: null };
1646
+ assert.equal((await router.healthForNamespace(decomposed)).collectionState, "missing");
1647
+ assert.equal(created, 2);
1648
+ assert.equal(live.disposed, 0);
1649
+ snapshot = undefined; // Operational metadata became unavailable after the removal.
1650
+ assert.equal((await router.healthForNamespace(composed)).collectionState, "missing");
1651
+ assert.equal(created, 3, "the native removal must have invalidated the old CLI result");
1652
+ });
1653
+
1654
+ test("an older CLI diagnostic cannot publish readiness after native removal", async t => {
1655
+ let snapshot: OperationalSearchHealth | undefined;
1656
+ let created = 0;
1657
+ const { promise: entered, resolve: statusEntered } = Promise.withResolvers<void>();
1658
+ const { promise: status, resolve: releaseStatus } = Promise.withResolvers<SearchBackendStatus>();
1659
+ t.after(() => releaseStatus(operationalSnapshot));
1660
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1661
+ t.mock.method(live, "status", () => {
1662
+ statusEntered();
1663
+ return status;
1664
+ });
1665
+ Object.assign(live, { readOperationalHealth: async () => snapshot });
1666
+ const router = new NamespaceSearchRouter(config(),
1667
+ { storageFor: async () => ({ dir: "/fixture/notes" }) }, () => {
1668
+ created++;
1669
+ return created === 1 ? live
1670
+ : new FakeBackend(false, [], { check: created === 2 ? "present" : "missing" });
1671
+ });
1672
+ t.after(() => router.dispose());
1673
+ await router.ensureNamespaceCollection("shared");
1674
+ const older = router.healthForNamespace("shared");
1675
+ await entered;
1676
+ snapshot = { ...operationalSnapshot, collectionState: "missing", pendingEmbeddings: null };
1677
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "missing");
1678
+ snapshot = undefined;
1679
+ releaseStatus(operationalSnapshot);
1680
+ const stale = await older;
1681
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "missing");
1682
+ assert.equal(created, 3);
1683
+ assert.equal(stale.collectionState, "unknown");
1684
+ assert.equal(stale.pendingEmbeddings, null);
1685
+ });
1686
+
1687
+ test("a cancelled poll does not invalidate another poll's CLI readiness", async t => {
1688
+ const { promise: entered, resolve: statusEntered } = Promise.withResolvers<void>();
1689
+ const { promise: status, resolve: releaseStatus } = Promise.withResolvers<SearchBackendStatus>();
1690
+ const { promise: storage, resolve: releaseStorage } = Promise.withResolvers<{ dir: string }>();
1691
+ const { promise: paused, resolve: storageEntered } = Promise.withResolvers<void>();
1692
+ const dir = "/fixture/notes";
1693
+ t.after(() => { releaseStatus(operationalSnapshot); releaseStorage({ dir }); });
1694
+ let pauseStorage = false;
1695
+ let created = 0;
1696
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1697
+ t.mock.method(live, "status", () => { statusEntered(); return status; });
1698
+ Object.assign(live, { readOperationalHealth: async () => undefined });
1699
+ const router = new NamespaceSearchRouter(config(), {
1700
+ storageFor: async () => {
1701
+ if (pauseStorage) { storageEntered(); return storage; }
1702
+ return { dir };
1703
+ },
1704
+ }, () => ++created === 1 ? live : new FakeBackend(false, [], { check: "present" }));
1705
+ t.after(() => router.dispose());
1706
+ await router.ensureNamespaceCollection("shared");
1707
+ const older = router.healthForNamespace("shared");
1708
+ await entered;
1709
+ pauseStorage = true;
1710
+ const controller = new AbortController();
1711
+ const cancelled = router.healthForNamespace("shared", { signal: controller.signal });
1712
+ await paused;
1713
+ controller.abort();
1714
+ assert.equal((await cancelled).collectionState, "unknown");
1715
+ pauseStorage = false;
1716
+ releaseStorage({ dir });
1717
+ releaseStatus(operationalSnapshot);
1718
+ assert.equal((await older).collectionState, "present");
1719
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "present");
1720
+ assert.equal(created, 2, "the successful diagnostic still uses the TTL");
1721
+ });
1722
+
1723
+ test("health re-probes after a cached operational backend failed startup", async t => {
1724
+ let created = 0;
1725
+ const cold = new FakeBackend(false);
1726
+ cold.available = false;
1727
+ const router = new NamespaceSearchRouter(config(),
1728
+ { storageFor: async () => ({ dir: "/fixture/notes" }) }, () => {
1729
+ if (++created === 1) return cold;
1730
+ const diagnostic = new FakeBackend(false, [], { check: "present" });
1731
+ diagnostic.statusResult = operationalSnapshot;
1732
+ return diagnostic;
1733
+ });
1734
+ t.after(() => router.dispose());
1735
+ assert.equal(await router.ensureNamespaceCollection("shared"), "unknown");
1736
+ const recovered = await router.healthForNamespace("shared");
1737
+ assert.equal(recovered.available, true);
1738
+ assert.equal(recovered.collectionState, "present");
1739
+ assert.equal(recovered.pendingEmbeddings, 0);
1740
+ assert.equal(isSearchHealthDegraded(recovered, recovered.embeddingBacklogThreshold), false);
1741
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "present");
1742
+ assert.equal(created, 2);
1743
+ });
1744
+
1745
+ test("CLI-only health caches a recognized QMD report with no pending embeddings", async t => {
1746
+ let created = 0;
1747
+ const router = new NamespaceSearchRouter(config(),
1748
+ { storageFor: async () => ({ dir: "/fixture/notes" }) }, () => {
1749
+ created++;
1750
+ const backend = new FakeBackend(false, [], { check: "present" });
1751
+ backend.statusResult = parseQmdStatusOutput(
1752
+ "QMD Status\n\nIndex: /fixture/index.sqlite\nSize: 1 KB\n\nDocuments\n Total: 1 files indexed\n Vectors: 1 embedded\n",
1753
+ );
1754
+ return backend;
1755
+ });
1756
+ t.after(() => router.dispose());
1757
+ const health = await router.healthForNamespace("shared");
1758
+ assert.equal(health.collectionState, "present");
1759
+ assert.equal(health.pendingEmbeddings, 0);
1760
+ assert.equal(isSearchHealthDegraded(health, health.embeddingBacklogThreshold), false);
1761
+ assert.equal((await router.healthForNamespace("shared")).pendingEmbeddings, 0);
1762
+ assert.equal(created, 1);
1763
+ });
1764
+
1765
+ test("operational snapshot is revalidated at the public return boundary", async t => {
1766
+ let valid = true;
1767
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1768
+ Object.assign(live, {
1769
+ readOperationalHealth: async () => ({
1770
+ ...operationalSnapshot,
1771
+ isCurrent: () => {
1772
+ queueMicrotask(() => { valid = false; });
1773
+ return valid;
1774
+ },
1775
+ }),
1776
+ });
1777
+ const router = new NamespaceSearchRouter(config(),
1778
+ { storageFor: async () => ({ dir: "/fixture/notes" }) }, () => live);
1779
+ t.after(() => router.dispose());
1780
+ await router.ensureNamespaceCollection("shared");
1781
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "unknown");
1782
+ });
1783
+
1784
+ test("operational health preserves backlog and fresh removal instead of returning old readiness", async t => {
1785
+ let snapshot: OperationalSearchHealth = { ...operationalSnapshot, pendingEmbeddings: 50_000 };
1786
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1787
+ Object.assign(live, { readOperationalHealth: async () => snapshot });
1788
+ const router = new NamespaceSearchRouter(config(),
1789
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1790
+ () => live);
1791
+ t.after(() => router.dispose());
1792
+ await router.ensureNamespaceCollection("shared");
1793
+ const backlog = await router.healthForNamespace("shared");
1794
+ assert.equal(backlog.pendingEmbeddings, 50_000);
1795
+ assert.equal(isSearchHealthDegraded(backlog, backlog.embeddingBacklogThreshold), true);
1796
+ snapshot = { ...operationalSnapshot, collectionState: "missing" };
1797
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "missing");
1798
+ });
1799
+
1800
+ test("operational health does not heal a cached missing collection using a positive snapshot", async t => {
1801
+ let created = 0;
1802
+ let metadataReads = 0;
1803
+ const live = new FakeBackend(false, [], { ensure: "missing" }, true);
1804
+ Object.assign(live, { readOperationalHealth: async () => { metadataReads++; return operationalSnapshot; } });
1805
+ const router = new NamespaceSearchRouter(config(),
1806
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1807
+ () => ++created === 1 ? live : new FakeBackend(false, [], { check: "present" }));
1808
+ t.after(() => router.dispose());
1809
+ await router.ensureNamespaceCollection("shared");
1810
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "missing");
1811
+ assert.equal(metadataReads, 0);
1812
+ });
1813
+
1814
+ test("operational health refuses a failed RPC without creating a disposable CLI diagnostic", async t => {
1815
+ let created = 0;
1816
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1817
+ Object.assign(live, { readOperationalHealth: async () => { throw new Error("Synthetic RPC failure"); } });
1818
+ const router = new NamespaceSearchRouter(config(),
1819
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1820
+ () => {
1821
+ assert.equal(++created, 1, "No second diagnostic backend after an advertised capability fails");
1822
+ return live;
1823
+ });
1824
+ t.after(() => router.dispose());
1825
+ await router.ensureNamespaceCollection("shared");
1826
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "unknown");
1827
+ });
1828
+
1829
+ test("operational health refuses a result after abort, namespace path drift, or record replacement", async t => {
1830
+ let directory = "/fixture/notes";
1831
+ let afterRead = () => {};
1832
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1833
+ Object.assign(live, { readOperationalHealth: async () => { afterRead(); return operationalSnapshot; } });
1834
+ const router = new NamespaceSearchRouter(config(),
1835
+ { storageFor: async () => ({ dir: directory }) }, () => live);
1836
+ t.after(() => router.dispose());
1837
+ await router.ensureNamespaceCollection("shared");
1838
+ const controller = new AbortController();
1839
+ afterRead = () => controller.abort();
1840
+ assert.equal((await router.healthForNamespace("shared", { signal: controller.signal })).collectionState, "unknown");
1841
+ afterRead = () => { directory = "/fixture/changed"; };
1842
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "unknown");
1843
+ directory = "/fixture/notes";
1844
+ afterRead = () => router.clearCache();
1845
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "unknown");
1846
+ });
1847
+
1848
+ test("operational record creation during a cached-health read cannot return old green", async t => {
1849
+ let created = 0;
1850
+ const cold = new FakeBackend(false, [], { check: "present" });
1851
+ cold.statusResult = { ...operationalSnapshot };
1852
+ const live = new FakeBackend(false, [], { ensure: "present" }, true);
1853
+ Object.assign(live, {
1854
+ readOperationalHealth: async () => ({
1855
+ ...operationalSnapshot, collectionState: "unknown", pendingEmbeddings: null,
1856
+ }),
1857
+ });
1858
+ const router = new NamespaceSearchRouter(config(),
1859
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1860
+ () => ++created === 1 ? cold : live);
1861
+ t.after(() => router.dispose());
1862
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "present");
1863
+ const preparing = router.ensureNamespaceCollection("shared");
1864
+ const reading = router.healthForNamespace("shared");
1865
+ await preparing;
1866
+ const health = await reading;
1867
+ assert.equal(health.collectionState, "unknown");
1868
+ assert.equal(isSearchHealthDegraded(health, health.embeddingBacklogThreshold), true);
1869
+ });
1870
+
1871
+ test("cold health refuses status errors, unknown backlog and unsupported versions without caching green", async () => {
1872
+ const failures: Array<[string, (backend: FakeBackend) => void]> = [
1873
+ ["null status", backend => {
1874
+ Object.defineProperty(backend, "status", { value: async () => null });
1875
+ }],
1876
+ ["status error", backend => {
1877
+ backend.statusResult = Object.assign({
1878
+ pendingEmbeddings: null, oldestPendingAgeMs: null, totalFiles: null, embeddedFiles: null,
1879
+ }, { error: "synthetic status failure" });
1880
+ }],
1881
+ ["unknown backlog", backend => {
1882
+ backend.statusResult = {
1883
+ pendingEmbeddings: null, oldestPendingAgeMs: null, totalFiles: 1, embeddedFiles: null,
1884
+ };
1885
+ }],
1886
+ ["unsupported version", backend => {
1887
+ Object.defineProperty(backend, "getVersionStatus", { value: () => ({
1888
+ installedVersion: "1.0.0", supportedVersion: "2.8.3", supported: false,
1889
+ newerThanSupported: false, upgradeAvailable: true, capabilities: qmdCapabilities(false),
1890
+ }) });
1891
+ }],
1892
+ ];
1893
+ for (const [name, fail] of failures) {
1894
+ const created: FakeBackend[] = [];
1895
+ const router = routerWithDegradedFirstProbe(created, "present", fail);
1896
+ try {
1897
+ const first = await router.healthForNamespace("shared");
1898
+ assert.equal(first.collectionState, "unknown", name);
1899
+ assert.equal(isSearchHealthDegraded(first, first.embeddingBacklogThreshold), true, name);
1900
+ const recovered = await router.healthForNamespace("shared");
1901
+ assert.equal(recovered.collectionState, "present", name);
1902
+ assert.equal(recovered.pendingEmbeddings, 10, name);
1903
+ assert.equal(created.length, 2, `${name} must not cache green`);
1904
+ } finally {
1905
+ await router.dispose();
1906
+ }
1907
+ }
1908
+ });
1909
+
1910
+ test("a backend without a status capability retains legitimate readiness and its diagnostic TTL", async () => {
1911
+ let created = 0;
1912
+ const router = new NamespaceSearchRouter(config(),
1913
+ { storageFor: async () => ({ dir: "/fixture/notes" }) },
1914
+ () => {
1915
+ created++;
1916
+ const backend = new FakeBackend(false, [], { check: "present" });
1917
+ Object.defineProperty(backend, "status", { value: undefined });
1918
+ return backend;
1919
+ });
1920
+ try {
1921
+ const health = await router.healthForNamespace("shared");
1922
+ assert.equal(health.collectionState, "present");
1923
+ assert.equal(health.pendingEmbeddings, null);
1924
+ assert.equal(isSearchHealthDegraded(health, health.embeddingBacklogThreshold), false);
1925
+ assert.equal((await router.healthForNamespace("shared")).collectionState, "present");
1926
+ assert.equal(created, 1);
1927
+ } finally {
1928
+ await router.dispose();
1929
+ }
1930
+ });