@remnic/core 10.0.126 → 10.0.127

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 (178) hide show
  1. package/dist/access-admin-ops-surface.js +38 -38
  2. package/dist/access-cli.js +38 -38
  3. package/dist/access-extraction-force-flush.js +38 -38
  4. package/dist/access-http-briefing.js +38 -38
  5. package/dist/access-http-query.js +38 -38
  6. package/dist/access-http.js +38 -38
  7. package/dist/access-identity-continuity-surface.js +38 -38
  8. package/dist/access-lcm-surface.js +38 -38
  9. package/dist/access-mcp.js +38 -38
  10. package/dist/access-observe-write-surface.js +38 -38
  11. package/dist/access-operations-batch.js +38 -38
  12. package/dist/access-operations.js +38 -38
  13. package/dist/access-recall-concurrency.js +38 -38
  14. package/dist/access-recall-response.js +38 -38
  15. package/dist/access-recall-surface.js +38 -38
  16. package/dist/access-service.d.ts.map +1 -1
  17. package/dist/access-service.js +38 -38
  18. package/dist/active-recall.js +6 -6
  19. package/dist/briefing.js +4 -4
  20. package/dist/buffer-turn-helpers.d.ts +7 -0
  21. package/dist/buffer-turn-helpers.d.ts.map +1 -1
  22. package/dist/buffer-turn-helpers.js +3 -1
  23. package/dist/buffer-turn.d.ts +10 -0
  24. package/dist/buffer-turn.d.ts.map +1 -1
  25. package/dist/buffer.js +3 -3
  26. package/dist/causal-consolidation.js +5 -5
  27. package/dist/{chunk-BNRKSJMO.js → chunk-2BBCM2PX.js} +2 -2
  28. package/dist/{chunk-2GSPNTOU.js → chunk-2G72JBQB.js} +2 -2
  29. package/dist/{chunk-IDCZEKK6.js → chunk-34YQ7CVE.js} +3 -3
  30. package/dist/{chunk-AYWW6JEH.js → chunk-3OLHDECL.js} +115 -41
  31. package/dist/chunk-3OLHDECL.js.map +1 -0
  32. package/dist/{chunk-4VWZ4HPL.js → chunk-4DJSDH2M.js} +6 -6
  33. package/dist/{chunk-YJEOQ72B.js → chunk-6FPJPSQK.js} +2 -2
  34. package/dist/{chunk-YKUW2EZF.js → chunk-7T7I5D3F.js} +2 -2
  35. package/dist/{chunk-ERR7ZFPJ.js → chunk-7TC2PWKH.js} +2 -2
  36. package/dist/{chunk-DH2CDGAE.js → chunk-ALLI23GW.js} +2 -2
  37. package/dist/{chunk-RTIHO7AJ.js → chunk-AYBRQJXP.js} +2 -2
  38. package/dist/{chunk-UXXK523X.js → chunk-BR7CZVMO.js} +20 -16
  39. package/dist/chunk-BR7CZVMO.js.map +1 -0
  40. package/dist/{chunk-AWD36R4D.js → chunk-DURQZFVJ.js} +36 -6
  41. package/dist/chunk-DURQZFVJ.js.map +1 -0
  42. package/dist/{chunk-C7BTGSCY.js → chunk-FPBFDQZZ.js} +9 -9
  43. package/dist/{chunk-5DCCVEKT.js → chunk-GWFL6LUU.js} +2 -2
  44. package/dist/{chunk-JTY3NA3I.js → chunk-HJ7M322C.js} +2 -2
  45. package/dist/{chunk-HURBXNNB.js → chunk-JCPEXUNP.js} +2 -2
  46. package/dist/{chunk-LKGTTX74.js → chunk-JK2IVISS.js} +2 -2
  47. package/dist/{chunk-7XG7KMIW.js → chunk-LNQQEFKH.js} +2 -2
  48. package/dist/{chunk-IB4TDPCC.js → chunk-LR2X3FJM.js} +2 -2
  49. package/dist/{chunk-6IRJWKR5.js → chunk-LU2GQ4Q4.js} +2 -2
  50. package/dist/{chunk-4VCASS3Q.js → chunk-MCTGYIYN.js} +2 -2
  51. package/dist/{chunk-XN43HAIV.js → chunk-MGCV3VGC.js} +2 -2
  52. package/dist/{chunk-KWVGRNKL.js → chunk-NYZ6ZNFO.js} +2 -2
  53. package/dist/{chunk-6VAN7VZR.js → chunk-ORMJT23N.js} +7 -7
  54. package/dist/{chunk-DL7K5PMQ.js → chunk-PPPY2PCU.js} +2 -2
  55. package/dist/{chunk-5DP4GVKR.js → chunk-PXZLVFNC.js} +2 -2
  56. package/dist/{chunk-GSCIRMPR.js → chunk-QKYOMKRG.js} +2 -2
  57. package/dist/{chunk-QF64W4YM.js → chunk-QRZNVNNS.js} +2 -2
  58. package/dist/{chunk-CQMH65IP.js → chunk-TJJPT2OV.js} +2 -2
  59. package/dist/{chunk-2AVPRUML.js → chunk-TJY6AKWV.js} +2 -2
  60. package/dist/{chunk-RRHLI6VU.js → chunk-TQ5NOVMT.js} +2 -2
  61. package/dist/{chunk-KNT3BZZH.js → chunk-UWU6KEZU.js} +185 -59
  62. package/dist/chunk-UWU6KEZU.js.map +1 -0
  63. package/dist/{chunk-PUKLCFCU.js → chunk-VY3DHUL7.js} +2 -2
  64. package/dist/chunk-VY3DHUL7.js.map +1 -0
  65. package/dist/{chunk-47W3ALIS.js → chunk-XMKUABIG.js} +3 -3
  66. package/dist/{chunk-UGCLNASV.js → chunk-XUWDB53W.js} +3 -3
  67. package/dist/{chunk-XLHLZALR.js → chunk-YCJRYM3Q.js} +3 -3
  68. package/dist/{chunk-DB4THCGN.js → chunk-YFUHFPV6.js} +2 -2
  69. package/dist/{chunk-42JE2CF4.js → chunk-YPE3O5VH.js} +2 -2
  70. package/dist/{chunk-7TJMXZPO.js → chunk-ZO377APE.js} +2 -2
  71. package/dist/cli.js +38 -38
  72. package/dist/coding/export-okf-codegraph.js +3 -3
  73. package/dist/compounding/engine.js +5 -5
  74. package/dist/config.js +6 -6
  75. package/dist/connectors/codex-materialize-runner.js +4 -4
  76. package/dist/connectors/index.js +4 -4
  77. package/dist/convergence-refresh.js +6 -6
  78. package/dist/corpus-watermark.js +6 -6
  79. package/dist/entity-retrieval.js +4 -4
  80. package/dist/explicit-capture.js +38 -38
  81. package/dist/extraction-liveness.d.ts +54 -5
  82. package/dist/extraction-liveness.d.ts.map +1 -1
  83. package/dist/extraction-liveness.js +1 -1
  84. package/dist/extraction-span-config.js +2 -2
  85. package/dist/extraction.js +7 -7
  86. package/dist/harmonic-retrieval.js +4 -4
  87. package/dist/index.js +38 -38
  88. package/dist/location/index.js +5 -5
  89. package/dist/maintenance/memory-governance.js +4 -4
  90. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +4 -4
  91. package/dist/maintenance/rebuild-memory-projection-runner.js +6 -6
  92. package/dist/maintenance/rebuild-memory-projection.js +5 -5
  93. package/dist/namespaces/migrate.js +5 -5
  94. package/dist/namespaces/storage.js +4 -4
  95. package/dist/operator-doctor-corpus.js +7 -7
  96. package/dist/operator-toolkit.js +13 -13
  97. package/dist/orchestration/backlog-scheduler.js +39 -39
  98. package/dist/orchestration/buffer-drain-runner.js +39 -39
  99. package/dist/orchestration/extraction-dedupe.d.ts +46 -0
  100. package/dist/orchestration/extraction-dedupe.d.ts.map +1 -0
  101. package/dist/orchestration/extraction-drain.d.ts +12 -1
  102. package/dist/orchestration/extraction-drain.d.ts.map +1 -1
  103. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  104. package/dist/orchestration/maintenance.js +12 -12
  105. package/dist/orchestrator.js +38 -38
  106. package/dist/recall-navigation.js +38 -38
  107. package/dist/resume-bundles.js +7 -7
  108. package/dist/semantic-consolidation.js +5 -5
  109. package/dist/semantic-rule-promotion.js +4 -4
  110. package/dist/semantic-rule-verifier.js +4 -4
  111. package/dist/source-agent-qualifier.js +6 -6
  112. package/dist/standup/build.js +4 -4
  113. package/dist/storage/buffer-drain-claims.d.ts +19 -4
  114. package/dist/storage/buffer-drain-claims.d.ts.map +1 -1
  115. package/dist/storage/buffer-drain-claims.js +2 -2
  116. package/dist/storage/buffer-session-files.js +2 -2
  117. package/dist/storage/drain-claim-totals.d.ts +54 -0
  118. package/dist/storage/drain-claim-totals.d.ts.map +1 -0
  119. package/dist/storage.js +3 -3
  120. package/dist/transfer/export-okf.js +4 -4
  121. package/dist/verified-recall.js +4 -4
  122. package/dist/who-knows-cli.js +5 -5
  123. package/dist/who-knows.js +4 -4
  124. package/package.json +2 -2
  125. package/src/access-service-health.test.ts +102 -1
  126. package/src/access-service.ts +10 -1
  127. package/src/buffer-turn-helpers.ts +25 -15
  128. package/src/buffer-turn.ts +10 -0
  129. package/src/extraction-liveness.test.ts +229 -0
  130. package/src/extraction-liveness.ts +89 -6
  131. package/src/orchestration/extraction-dedupe.test.ts +101 -0
  132. package/src/orchestration/extraction-dedupe.ts +80 -0
  133. package/src/orchestration/extraction-drain-dedupe.test.ts +477 -0
  134. package/src/orchestration/extraction-drain.ts +69 -9
  135. package/src/orchestration/extraction-run.ts +2 -0
  136. package/src/storage/buffer-drain-claims.test.ts +66 -0
  137. package/src/storage/buffer-drain-claims.ts +49 -4
  138. package/src/storage/drain-claim-totals.test.ts +356 -0
  139. package/src/storage/drain-claim-totals.ts +175 -0
  140. package/dist/chunk-AWD36R4D.js.map +0 -1
  141. package/dist/chunk-AYWW6JEH.js.map +0 -1
  142. package/dist/chunk-KNT3BZZH.js.map +0 -1
  143. package/dist/chunk-PUKLCFCU.js.map +0 -1
  144. package/dist/chunk-UXXK523X.js.map +0 -1
  145. /package/dist/{chunk-BNRKSJMO.js.map → chunk-2BBCM2PX.js.map} +0 -0
  146. /package/dist/{chunk-2GSPNTOU.js.map → chunk-2G72JBQB.js.map} +0 -0
  147. /package/dist/{chunk-IDCZEKK6.js.map → chunk-34YQ7CVE.js.map} +0 -0
  148. /package/dist/{chunk-4VWZ4HPL.js.map → chunk-4DJSDH2M.js.map} +0 -0
  149. /package/dist/{chunk-YJEOQ72B.js.map → chunk-6FPJPSQK.js.map} +0 -0
  150. /package/dist/{chunk-YKUW2EZF.js.map → chunk-7T7I5D3F.js.map} +0 -0
  151. /package/dist/{chunk-ERR7ZFPJ.js.map → chunk-7TC2PWKH.js.map} +0 -0
  152. /package/dist/{chunk-DH2CDGAE.js.map → chunk-ALLI23GW.js.map} +0 -0
  153. /package/dist/{chunk-RTIHO7AJ.js.map → chunk-AYBRQJXP.js.map} +0 -0
  154. /package/dist/{chunk-C7BTGSCY.js.map → chunk-FPBFDQZZ.js.map} +0 -0
  155. /package/dist/{chunk-5DCCVEKT.js.map → chunk-GWFL6LUU.js.map} +0 -0
  156. /package/dist/{chunk-JTY3NA3I.js.map → chunk-HJ7M322C.js.map} +0 -0
  157. /package/dist/{chunk-HURBXNNB.js.map → chunk-JCPEXUNP.js.map} +0 -0
  158. /package/dist/{chunk-LKGTTX74.js.map → chunk-JK2IVISS.js.map} +0 -0
  159. /package/dist/{chunk-7XG7KMIW.js.map → chunk-LNQQEFKH.js.map} +0 -0
  160. /package/dist/{chunk-IB4TDPCC.js.map → chunk-LR2X3FJM.js.map} +0 -0
  161. /package/dist/{chunk-6IRJWKR5.js.map → chunk-LU2GQ4Q4.js.map} +0 -0
  162. /package/dist/{chunk-4VCASS3Q.js.map → chunk-MCTGYIYN.js.map} +0 -0
  163. /package/dist/{chunk-XN43HAIV.js.map → chunk-MGCV3VGC.js.map} +0 -0
  164. /package/dist/{chunk-KWVGRNKL.js.map → chunk-NYZ6ZNFO.js.map} +0 -0
  165. /package/dist/{chunk-6VAN7VZR.js.map → chunk-ORMJT23N.js.map} +0 -0
  166. /package/dist/{chunk-DL7K5PMQ.js.map → chunk-PPPY2PCU.js.map} +0 -0
  167. /package/dist/{chunk-5DP4GVKR.js.map → chunk-PXZLVFNC.js.map} +0 -0
  168. /package/dist/{chunk-GSCIRMPR.js.map → chunk-QKYOMKRG.js.map} +0 -0
  169. /package/dist/{chunk-QF64W4YM.js.map → chunk-QRZNVNNS.js.map} +0 -0
  170. /package/dist/{chunk-CQMH65IP.js.map → chunk-TJJPT2OV.js.map} +0 -0
  171. /package/dist/{chunk-2AVPRUML.js.map → chunk-TJY6AKWV.js.map} +0 -0
  172. /package/dist/{chunk-RRHLI6VU.js.map → chunk-TQ5NOVMT.js.map} +0 -0
  173. /package/dist/{chunk-47W3ALIS.js.map → chunk-XMKUABIG.js.map} +0 -0
  174. /package/dist/{chunk-UGCLNASV.js.map → chunk-XUWDB53W.js.map} +0 -0
  175. /package/dist/{chunk-XLHLZALR.js.map → chunk-YCJRYM3Q.js.map} +0 -0
  176. /package/dist/{chunk-DB4THCGN.js.map → chunk-YFUHFPV6.js.map} +0 -0
  177. /package/dist/{chunk-42JE2CF4.js.map → chunk-YPE3O5VH.js.map} +0 -0
  178. /package/dist/{chunk-7TJMXZPO.js.map → chunk-ZO377APE.js.map} +0 -0
@@ -27,10 +27,11 @@
27
27
  * inbox, so a kill between the two replays
28
28
  * nothing. A torn last line is skipped: its
29
29
  * owner never saw the append succeed.
30
- * s-<sha256(key)>.json.count cached { pending, drained } turn counts of the
31
- * body, valid while the body's size and mtime
32
- * match, so listings and the hand-over gate
33
- * never parse a body.
30
+ * s-<sha256(key)>.json.count cached { pending, drained, oldestTurnAt? }
31
+ * turn counts of the body (oldestTurnAt added by
32
+ * #3442; absent in older sidecars), valid while
33
+ * the body's size and mtime match, so listings
34
+ * and the hand-over gate never parse a body.
34
35
  *
35
36
  * Rolling back to a build that predates the inbox: run `foldAllInboxes()` (CLI:
36
37
  * `remnic buffer drain --fold-inboxes`) first; that build never reads an inbox.
@@ -53,6 +54,7 @@
53
54
  * held file lock.
54
55
  */
55
56
  import { type BufferFileIo } from "./buffer-session-files.js";
57
+ import { type DrainClaimTotals } from "./drain-claim-totals.js";
56
58
  import { type DrainedTurnSets } from "../buffer-turn-helpers.js";
57
59
  import type { BufferEntryState, BufferTurn } from "../types.js";
58
60
  /** Result of persisting one session's entry. */
@@ -113,6 +115,19 @@ export declare class BufferDrainClaims {
113
115
  private readonly io;
114
116
  constructor(stateDir: string, io: BufferFileIo);
115
117
  private readonly handIns;
118
+ /** Last `claimTotals` scan; the /health path polls per request (#3442). */
119
+ private totalsCache;
120
+ /**
121
+ * Claimed-backlog totals for liveness surfaces (#3442): sidecars only, no
122
+ * claim-body parse, bounded scan, cached for `ttlMs` (default 30s) so a
123
+ * health poll per request cannot turn into a directory storm. `ttlMs: 0`
124
+ * forces a rescan; `nowMs`/`maxClaims` are test/bounds seams.
125
+ */
126
+ claimTotals(opts?: {
127
+ ttlMs?: number;
128
+ maxClaims?: number;
129
+ nowMs?: number;
130
+ }): Promise<DrainClaimTotals>;
116
131
  private get dir();
117
132
  private fileFor;
118
133
  private leaseFileFor;
@@ -1 +1 @@
1
- {"version":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E,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAczF;;;;;OAKG;IACG,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAe9C,8FAA8F;IACxF,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,6FAA6F;YAC/E,UAAU;IAWxB;;;;;;OAMG;YACW,aAAa;IA2B3B,+DAA+D;IACzD,IAAI,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAS1C;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAuB5H;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;YA+BzB,mBAAmB;CAQlC"}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BufferDrainClaims
3
- } from "../chunk-KNT3BZZH.js";
4
- import "../chunk-UXXK523X.js";
3
+ } from "../chunk-UWU6KEZU.js";
4
+ import "../chunk-BR7CZVMO.js";
5
5
  import "../chunk-EBV6VXKF.js";
6
6
  import "../chunk-X4OZMANG.js";
7
7
  import "../chunk-R2MBW2S4.js";
@@ -2,8 +2,8 @@ import {
2
2
  BufferSessionFiles,
3
3
  bufferSessionFileName,
4
4
  legacyStateToEntries
5
- } from "../chunk-KNT3BZZH.js";
6
- import "../chunk-UXXK523X.js";
5
+ } from "../chunk-UWU6KEZU.js";
6
+ import "../chunk-BR7CZVMO.js";
7
7
  import "../chunk-EBV6VXKF.js";
8
8
  import "../chunk-X4OZMANG.js";
9
9
  import "../chunk-R2MBW2S4.js";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Cheap drain-claim totals for liveness surfaces (`/health.extraction`, #3442).
3
+ *
4
+ * The in-memory buffer snapshot misses every turn handed to a drain claim, so
5
+ * health can report a tiny backlog while hundreds of thousands of turns sit in
6
+ * `<stateDir>/buffer/drain/`. This reader answers "how much is claimed?" from
7
+ * the `*.json.count` sidecars ALONE: it stats each claim body to validate the
8
+ * sidecar's cached identity (size + mtime, the same rule `readSummary` uses)
9
+ * and never parses a claim body — on the health path a body parse is exactly
10
+ * the multi-GB cost we are avoiding, and stale/missing sidecars count as
11
+ * `unverifiedClaims` instead of triggering one. It also never WRITES: summary
12
+ * refreshes stay owned by the drain path (`readSummary`).
13
+ *
14
+ * Bounded: the sidecar scan stops after `maxClaims` bodies (`truncated: true`),
15
+ * while `claimedSessions` still counts every body from the single readdir, so
16
+ * the session count stays exact even when the scan is capped. Callers cache the
17
+ * result (`BufferDrainClaims.claimTotals`) rather than re-scanning per request.
18
+ */
19
+ /** How the reported oldest claimed age was derived. */
20
+ export type DrainClaimAgeBasis = "turn" | "claim-mtime-lower-bound";
21
+ export interface DrainClaimTotals {
22
+ /** Claim bodies in the drain directory: every session handed to a drainer. */
23
+ claimedSessions: number;
24
+ /** Sum of `pending` over sidecars that still match their body's identity. */
25
+ claimedPendingTurns: number;
26
+ /**
27
+ * Oldest oldest-turn candidate over claims with pending > 0; null when none
28
+ * report one. Legacy sidecars (pre-#3442) contribute their BODY MTIME, which
29
+ * is a true LOWER BOUND on the oldest turn's age: every claim-body mutation
30
+ * is a whole-file rewrite, so mtime >= newest turn >= oldest turn.
31
+ */
32
+ oldestClaimedTurnAt: string | null;
33
+ /** How `oldestClaimedTurnAt` was derived (see the field doc above). */
34
+ oldestClaimedAgeBasis: DrainClaimAgeBasis | null;
35
+ /** Sidecars read and identity-verified this scan. */
36
+ verifiedSidecars: number;
37
+ /** Bodies whose sidecar is missing, unparsable, or stale — excluded from the sums, never parsed to recover. */
38
+ unverifiedClaims: number;
39
+ /**
40
+ * Claims with a non-empty pending-hand-in inbox (`.inbox.jsonl`): their
41
+ * turns are pending but NOT in `claimedPendingTurns` (the sidecar counts
42
+ * only the body), so the pending sum UNDERCOUNTS by this many claims'
43
+ * worth. Each contributes its inbox mtime as a lower-bound age candidate:
44
+ * appends only ever add content, so every inbox turn predates the last
45
+ * append (mtime >= newest inbox turn >= oldest inbox turn).
46
+ */
47
+ claimsPendingInbox: number;
48
+ /** The sidecar scan stopped at `maxClaims`; bodies past the cap are not summed. */
49
+ truncated: boolean;
50
+ }
51
+ export declare function readDrainClaimTotals(claimsDir: string, opts?: {
52
+ maxClaims?: number;
53
+ }): Promise<DrainClaimTotals>;
54
+ //# sourceMappingURL=drain-claim-totals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drain-claim-totals.d.ts","sourceRoot":"","sources":["../../src/storage/drain-claim-totals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,uDAAuD;AACvD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,yBAAyB,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,eAAe,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,uEAAuE;IACvE,qBAAqB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjD,qDAAqD;IACrD,gBAAgB,EAAE,MAAM,CAAC;IACzB,+GAA+G;IAC/G,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mFAAmF;IACnF,SAAS,EAAE,OAAO,CAAC;CACpB;AAkCD,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAkF3B"}
package/dist/storage.js CHANGED
@@ -14,11 +14,11 @@ import {
14
14
  parseFrontmatter,
15
15
  parseFrontmatterStringValue,
16
16
  serializeEntityFile
17
- } from "./chunk-IB4TDPCC.js";
17
+ } from "./chunk-LR2X3FJM.js";
18
18
  import "./chunk-QGVCFVX6.js";
19
19
  import "./chunk-UHVXE24Y.js";
20
20
  import "./chunk-O3JG4PD3.js";
21
- import "./chunk-KNT3BZZH.js";
21
+ import "./chunk-UWU6KEZU.js";
22
22
  import "./chunk-G6OFEGUR.js";
23
23
  import "./chunk-BFDXJHYG.js";
24
24
  import "./chunk-J6U6KUMK.js";
@@ -69,7 +69,7 @@ import "./chunk-AF2XMJKD.js";
69
69
  import "./chunk-OR42ZI54.js";
70
70
  import "./chunk-IUM3VSHI.js";
71
71
  import "./chunk-23G5P7TA.js";
72
- import "./chunk-UXXK523X.js";
72
+ import "./chunk-BR7CZVMO.js";
73
73
  import "./chunk-MMRTPH3J.js";
74
74
  import "./chunk-I55KAVET.js";
75
75
  import "./chunk-L2EXJQJP.js";
@@ -4,17 +4,17 @@ import {
4
4
  exportOkfBundle,
5
5
  firstHeading,
6
6
  parseIncludeStatus
7
- } from "../chunk-5DCCVEKT.js";
7
+ } from "../chunk-GWFL6LUU.js";
8
8
  import {
9
9
  OKF_EXPORT_VERSION
10
10
  } from "../chunk-I7TR2OCU.js";
11
11
  import "../chunk-D24OXEPB.js";
12
12
  import "../chunk-3UXOZBHV.js";
13
- import "../chunk-IB4TDPCC.js";
13
+ import "../chunk-LR2X3FJM.js";
14
14
  import "../chunk-QGVCFVX6.js";
15
15
  import "../chunk-UHVXE24Y.js";
16
16
  import "../chunk-O3JG4PD3.js";
17
- import "../chunk-KNT3BZZH.js";
17
+ import "../chunk-UWU6KEZU.js";
18
18
  import "../chunk-G6OFEGUR.js";
19
19
  import "../chunk-BFDXJHYG.js";
20
20
  import "../chunk-J6U6KUMK.js";
@@ -63,7 +63,7 @@ import "../chunk-AF2XMJKD.js";
63
63
  import "../chunk-OR42ZI54.js";
64
64
  import "../chunk-IUM3VSHI.js";
65
65
  import "../chunk-23G5P7TA.js";
66
- import "../chunk-UXXK523X.js";
66
+ import "../chunk-BR7CZVMO.js";
67
67
  import "../chunk-MMRTPH3J.js";
68
68
  import "../chunk-I55KAVET.js";
69
69
  import "../chunk-L2EXJQJP.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  compareVerifiedEpisodeResults,
3
3
  searchVerifiedEpisodes
4
- } from "./chunk-5DP4GVKR.js";
4
+ } from "./chunk-PXZLVFNC.js";
5
5
  import "./chunk-B7RWBZXW.js";
6
- import "./chunk-IB4TDPCC.js";
6
+ import "./chunk-LR2X3FJM.js";
7
7
  import "./chunk-QGVCFVX6.js";
8
8
  import "./chunk-UHVXE24Y.js";
9
9
  import "./chunk-O3JG4PD3.js";
10
- import "./chunk-KNT3BZZH.js";
10
+ import "./chunk-UWU6KEZU.js";
11
11
  import "./chunk-G6OFEGUR.js";
12
12
  import "./chunk-BFDXJHYG.js";
13
13
  import "./chunk-J6U6KUMK.js";
@@ -56,7 +56,7 @@ import "./chunk-AF2XMJKD.js";
56
56
  import "./chunk-OR42ZI54.js";
57
57
  import "./chunk-IUM3VSHI.js";
58
58
  import "./chunk-23G5P7TA.js";
59
- import "./chunk-UXXK523X.js";
59
+ import "./chunk-BR7CZVMO.js";
60
60
  import "./chunk-MMRTPH3J.js";
61
61
  import "./chunk-I55KAVET.js";
62
62
  import "./chunk-L2EXJQJP.js";
@@ -4,13 +4,13 @@ import {
4
4
  renderWhoKnows,
5
5
  renderWhoKnowsJson,
6
6
  renderWhoKnowsText
7
- } from "./chunk-2AVPRUML.js";
8
- import "./chunk-JTY3NA3I.js";
9
- import "./chunk-IB4TDPCC.js";
7
+ } from "./chunk-TJY6AKWV.js";
8
+ import "./chunk-HJ7M322C.js";
9
+ import "./chunk-LR2X3FJM.js";
10
10
  import "./chunk-QGVCFVX6.js";
11
11
  import "./chunk-UHVXE24Y.js";
12
12
  import "./chunk-O3JG4PD3.js";
13
- import "./chunk-KNT3BZZH.js";
13
+ import "./chunk-UWU6KEZU.js";
14
14
  import "./chunk-G6OFEGUR.js";
15
15
  import "./chunk-BFDXJHYG.js";
16
16
  import "./chunk-J6U6KUMK.js";
@@ -59,7 +59,7 @@ import "./chunk-AF2XMJKD.js";
59
59
  import "./chunk-OR42ZI54.js";
60
60
  import "./chunk-IUM3VSHI.js";
61
61
  import "./chunk-23G5P7TA.js";
62
- import "./chunk-UXXK523X.js";
62
+ import "./chunk-BR7CZVMO.js";
63
63
  import "./chunk-MMRTPH3J.js";
64
64
  import "./chunk-I55KAVET.js";
65
65
  import "./chunk-L2EXJQJP.js";
package/dist/who-knows.js CHANGED
@@ -9,12 +9,12 @@ import {
9
9
  loadWhoKnowsEntities,
10
10
  tokenizeTopic,
11
11
  validateWhoKnowsInput
12
- } from "./chunk-JTY3NA3I.js";
13
- import "./chunk-IB4TDPCC.js";
12
+ } from "./chunk-HJ7M322C.js";
13
+ import "./chunk-LR2X3FJM.js";
14
14
  import "./chunk-QGVCFVX6.js";
15
15
  import "./chunk-UHVXE24Y.js";
16
16
  import "./chunk-O3JG4PD3.js";
17
- import "./chunk-KNT3BZZH.js";
17
+ import "./chunk-UWU6KEZU.js";
18
18
  import "./chunk-G6OFEGUR.js";
19
19
  import "./chunk-BFDXJHYG.js";
20
20
  import "./chunk-J6U6KUMK.js";
@@ -63,7 +63,7 @@ import "./chunk-AF2XMJKD.js";
63
63
  import "./chunk-OR42ZI54.js";
64
64
  import "./chunk-IUM3VSHI.js";
65
65
  import "./chunk-23G5P7TA.js";
66
- import "./chunk-UXXK523X.js";
66
+ import "./chunk-BR7CZVMO.js";
67
67
  import "./chunk-MMRTPH3J.js";
68
68
  import "./chunk-I55KAVET.js";
69
69
  import "./chunk-L2EXJQJP.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.126",
3
+ "version": "10.0.127",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3396,7 +3396,7 @@
3396
3396
  "core"
3397
3397
  ],
3398
3398
  "peerDependencies": {
3399
- "@remnic/coding-graph": "^10.0.126"
3399
+ "@remnic/coding-graph": "^10.0.127"
3400
3400
  },
3401
3401
  "peerDependenciesMeta": {
3402
3402
  "@remnic/coding-graph": {
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { mkdir, mkdtemp, rm } from "node:fs/promises";
2
+ import { mkdir, mkdtemp, rm, stat, writeFile } from "node:fs/promises";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
  import test from "node:test";
@@ -8,6 +8,8 @@ import { EngramAccessService } from "./access-service.js";
8
8
  import { parseConfig } from "./config.js";
9
9
  import { TOKEN_CAPABILITIES_VERSION, tokenCapabilityStore } from "./access-token-capabilities.js";
10
10
  import { namespaceCollectionName } from "./namespaces/search.js";
11
+ import { NamespaceStorageRouter } from "./namespaces/storage.js";
12
+ import { SmartBuffer } from "./buffer.js";
11
13
  import type { Orchestrator } from "./orchestrator.js";
12
14
  import type { SearchBackend } from "./search/port.js";
13
15
 
@@ -767,3 +769,102 @@ test("health surfaces extraction-LLM availability and last failure reason (#3140
767
769
  await rm(memoryDir, { recursive: true, force: true });
768
770
  }
769
771
  });
772
+
773
+ // ── #3442: claimed drain backlog in the extraction block ─────────────────────
774
+
775
+ test("health reports claimed drain backlog totals and degrades when the oldest claimed turn is stale", async (t) => {
776
+ const nowMs = Date.parse("2026-07-30T12:00:00.000Z");
777
+ t.mock.timers.enable({ apis: ["Date"], now: nowMs });
778
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-claims-"));
779
+ try {
780
+ const config = parseConfig({ memoryDir, qmdEnabled: false, extractionLiveness: { staleWindowMs: 1000 } });
781
+ const router = new NamespaceStorageRouter(config);
782
+ // Seed REAL claims so the provider's sidecar scan sees them: one stuck
783
+ // (oldest 10s > 1s window) and one fresh. Claims live under <baseDir>/state.
784
+ const drainDir = path.join(memoryDir, "state", "buffer", "drain");
785
+ await mkdir(drainDir, { recursive: true });
786
+ const writeClaim = async (n: number, pending: number, oldestTurnAt: string) => {
787
+ const body = path.join(drainDir, `s-${String(n).padStart(64, "0")}.json`);
788
+ await writeFile(body, JSON.stringify({ key: `k${n}`, entry: { turns: [] } }));
789
+ const identity = await stat(body);
790
+ await writeFile(`${body}.count`, JSON.stringify({ key: `k${n}`, size: identity.size, mtimeMs: identity.mtimeMs, pending, drained: 0, oldestTurnAt }));
791
+ };
792
+ await writeClaim(1, 5, new Date(nowMs - 10_000).toISOString());
793
+ await writeClaim(2, 7, new Date(nowMs - 100).toISOString());
794
+ // SAFETY: /health reads only buffer.getBufferSnapshot; the rest of SmartBuffer is unused by this path.
795
+ const buffer = {
796
+ getBufferSnapshot: async () => ({ bufferedSessionCount: 0, pendingTurnCount: 0, oldestTurnTimestamp: null }),
797
+ } as SmartBuffer;
798
+ const fake = {
799
+ config,
800
+ qmd: makeQmd({}),
801
+ // In-memory buffer is EMPTY: every pending turn lives in drain claims.
802
+ buffer,
803
+ storage: await router.storageFor(config.defaultNamespace),
804
+ getStorage: (namespace?: string) => router.storageFor(namespace ?? config.defaultNamespace),
805
+ };
806
+ // SAFETY: /health touches only config, qmd, buffer.getBufferSnapshot, storage.loadMeta, storage.bufferDrainClaims and getStorage; the rest of the Orchestrator is unused here.
807
+ const service = new EngramAccessService(fake as Orchestrator);
808
+
809
+ const health = await service.health();
810
+ assert.equal(health.extraction.degraded, true, "an old claimed backlog degrades even with a fresh watermark");
811
+ assert.equal(health.extraction.claimedSessionCount, 2);
812
+ assert.equal(health.extraction.claimedPendingTurnCount, 12);
813
+ assert.equal(health.extraction.oldestClaimedTurnAgeMs, 10_000);
814
+ assert.equal(health.extraction.oldestClaimedAgeBasis, "turn");
815
+ assert.equal(health.extraction.claimedBacklogTruncated, false);
816
+ assert.equal(health.extraction.claimedBacklogUnverified, 0);
817
+ assert.equal(health.extraction.claimedBacklogPendingInbox, 0);
818
+ assert.match(health.extraction.degradedReason ?? "", /claimed drain backlog/);
819
+ assert.match(health.extraction.degradedReason ?? "", /12 claimed turn/);
820
+
821
+ const scopedHealth = await tokenCapabilityStore.run(
822
+ { version: TOKEN_CAPABILITIES_VERSION, namespaces: ["default"] },
823
+ () => service.health()
824
+ );
825
+ assert.equal(scopedHealth.extraction.degraded, true);
826
+ assert.match(scopedHealth.extraction.degradedReason ?? "", /claimed drain backlog|claimed turn/);
827
+ assert.doesNotMatch(scopedHealth.extraction.degradedReason ?? "", /0 buffered session/);
828
+ } finally {
829
+ t.mock.timers.reset();
830
+ await rm(memoryDir, { recursive: true, force: true });
831
+ }
832
+ });
833
+
834
+ test("health reports claim totals without degrading while the oldest claimed turn is inside the window", async (t) => {
835
+ const nowMs = Date.parse("2026-07-30T12:00:00.000Z");
836
+ t.mock.timers.enable({ apis: ["Date"], now: nowMs });
837
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-claims-fresh-"));
838
+ try {
839
+ const config = parseConfig({ memoryDir, qmdEnabled: false, extractionLiveness: { staleWindowMs: 1000 } });
840
+ const router = new NamespaceStorageRouter(config);
841
+ const drainDir = path.join(memoryDir, "state", "buffer", "drain");
842
+ await mkdir(drainDir, { recursive: true });
843
+ const body = path.join(drainDir, `s-${"0".repeat(64)}.json`);
844
+ await writeFile(body, JSON.stringify({ key: "k1", entry: { turns: [] } }));
845
+ const identity = await stat(body);
846
+ await writeFile(`${body}.count`, JSON.stringify({ key: "k1", size: identity.size, mtimeMs: identity.mtimeMs, pending: 12, drained: 0, oldestTurnAt: new Date(nowMs - 100).toISOString() }));
847
+ // SAFETY: /health reads only buffer.getBufferSnapshot; the rest of SmartBuffer is unused by this path.
848
+ const buffer = {
849
+ getBufferSnapshot: async () => ({ bufferedSessionCount: 0, pendingTurnCount: 0, oldestTurnTimestamp: null }),
850
+ } as SmartBuffer;
851
+ const fake = {
852
+ config,
853
+ qmd: makeQmd({}),
854
+ buffer,
855
+ storage: await router.storageFor(config.defaultNamespace),
856
+ getStorage: (namespace?: string) => router.storageFor(namespace ?? config.defaultNamespace),
857
+ };
858
+ // SAFETY: /health touches only config, qmd, buffer.getBufferSnapshot, storage.loadMeta, storage.bufferDrainClaims and getStorage; the rest of the Orchestrator is unused here.
859
+ const service = new EngramAccessService(fake as Orchestrator);
860
+
861
+ const health = await service.health();
862
+ assert.equal(health.extraction.degraded, false);
863
+ assert.equal(health.extraction.claimedSessionCount, 1);
864
+ assert.equal(health.extraction.claimedPendingTurnCount, 12);
865
+ assert.equal(health.extraction.degradedReason, null);
866
+ } finally {
867
+ t.mock.timers.reset();
868
+ await rm(memoryDir, { recursive: true, force: true });
869
+ }
870
+ });
@@ -2331,7 +2331,12 @@ export class EngramAccessService extends SupportPassportAccessServiceBase {
2331
2331
  const extraction = await computeExtractionLivenessStatus(
2332
2332
  this.orchestrator,
2333
2333
  extractionWatermark,
2334
- caps?.namespaces !== undefined ? undefined : this.extractionLivenessWarn
2334
+ caps?.namespaces !== undefined ? undefined : this.extractionLivenessWarn,
2335
+ undefined,
2336
+ // #3442: claimed drain backlog from the root storage's sidecar scan —
2337
+ // cheap by contract (no claim-body parse, TTL-cached). Throwing is
2338
+ // surfaced inside the reader as a distinct degradation, not swallowed.
2339
+ () => this.orchestrator.storage.bufferDrainClaims().claimTotals()
2335
2340
  );
2336
2341
  let scopedDegradedReason: string | null = null;
2337
2342
  if (extraction.degraded) {
@@ -2339,6 +2344,10 @@ export class EngramAccessService extends SupportPassportAccessServiceBase {
2339
2344
  scopedDegradedReason = "daemon extraction pipeline degraded; extraction watermark unreadable";
2340
2345
  } else if (extraction.degradedReason?.includes("buffer unreadable")) {
2341
2346
  scopedDegradedReason = "daemon extraction pipeline degraded; extraction buffer unreadable";
2347
+ } else if (extraction.degradedReason?.includes("claimed drain backlog")) {
2348
+ scopedDegradedReason =
2349
+ `${extraction.claimedSessionCount ?? 0} claimed session(s), ` +
2350
+ `${extraction.claimedPendingTurnCount ?? 0} claimed turn(s) pending extraction`;
2342
2351
  } else {
2343
2352
  scopedDegradedReason =
2344
2353
  `${extraction.bufferedSessionCount} buffered session(s), ` +
@@ -273,6 +273,30 @@ export interface ExtractionScopeGroup {
273
273
  turns: BufferTurn[];
274
274
  }
275
275
 
276
+ /**
277
+ * Scope-group identity for one turn (#3251): the durable pins that decide
278
+ * which extraction scope a turn belongs to. Shared by
279
+ * `groupTurnsByExtractionScope` and the #3443 duplicate collapse so both use
280
+ * ONE definition of "same scope".
281
+ */
282
+ export function extractionScopeGroupKey(turn: BufferTurn): string {
283
+ return [
284
+ turn.writeNamespaceOverride ?? "",
285
+ turn.principalOverride ?? "",
286
+ scopeProfilePlanIdentity(turn.scopeProfileWritePlan),
287
+ // Accepted captures are deliberately accepted content: they must never
288
+ // share a scope group with ordinary turns, or a group-level capture
289
+ // policy (the explicit-mode gate, the planless-accepted null pin) is
290
+ // applied to ordinary conversation turns because `.some(acceptedCapture)`
291
+ // only looked at the merged group.
292
+ turn.acceptedCapture === true ? "accepted" : "",
293
+ turn.codingContext?.projectId ?? "",
294
+ turn.codingContext?.rootPath ?? "",
295
+ turn.codingContext?.branch ?? "",
296
+ turn.codingContext?.defaultBranch ?? "",
297
+ ].join("\u0000");
298
+ }
299
+
276
300
  /**
277
301
  * Partition extraction turns by their durable scope pins (#3251). Turns
278
302
  * captured under different namespaces / principals / scope profiles /
@@ -283,21 +307,7 @@ export interface ExtractionScopeGroup {
283
307
  export function groupTurnsByExtractionScope(turns: BufferTurn[]): ExtractionScopeGroup[] {
284
308
  const groups = new Map<string, ExtractionScopeGroup>();
285
309
  for (const turn of turns) {
286
- const key = [
287
- turn.writeNamespaceOverride ?? "",
288
- turn.principalOverride ?? "",
289
- scopeProfilePlanIdentity(turn.scopeProfileWritePlan),
290
- // Accepted captures are deliberately accepted content: they must never
291
- // share a scope group with ordinary turns, or a group-level capture
292
- // policy (the explicit-mode gate, the planless-accepted null pin) is
293
- // applied to ordinary conversation turns because `.some(acceptedCapture)`
294
- // only looked at the merged group.
295
- turn.acceptedCapture === true ? "accepted" : "",
296
- turn.codingContext?.projectId ?? "",
297
- turn.codingContext?.rootPath ?? "",
298
- turn.codingContext?.branch ?? "",
299
- turn.codingContext?.defaultBranch ?? "",
300
- ].join("\u0000");
310
+ const key = extractionScopeGroupKey(turn);
301
311
  const group = groups.get(key);
302
312
  if (group) {
303
313
  group.turns.push(turn);
@@ -47,4 +47,14 @@ export interface BufferTurn extends SourceConnectorProvenance, BufferTurnOwner,
47
47
  * re-applied at the execution boundary.
48
48
  */
49
49
  codingContext?: import("./types.js").CodingContext;
50
+ /**
51
+ * In-flight drain marker (#3443): this turn is an exact duplicate (same
52
+ * role AND content) of an earlier turn in the SAME extraction window and
53
+ * scope, and its first occurrence represents it. The drain's chunk carries
54
+ * a marked COPY so buffer/claim clearing and chunk drops remove every
55
+ * identity together, while the extraction run keeps the duplicate text out
56
+ * of the model conversation. Never persisted: the marker is set only on
57
+ * the drain's in-memory chunk copies, never on buffered or claimed turns.
58
+ */
59
+ extractionDuplicateOf?: true;
50
60
  }