@remnic/core 10.0.114 → 10.0.115

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 (128) hide show
  1. package/dist/access-admin-ops-surface.js +29 -29
  2. package/dist/access-cli.js +29 -29
  3. package/dist/access-extraction-force-flush.js +29 -29
  4. package/dist/access-http-briefing.js +29 -29
  5. package/dist/access-http-query.js +29 -29
  6. package/dist/access-http.js +29 -29
  7. package/dist/access-identity-continuity-surface.js +29 -29
  8. package/dist/access-lcm-surface.js +29 -29
  9. package/dist/access-mcp.js +29 -29
  10. package/dist/access-observe-write-surface.js +29 -29
  11. package/dist/access-operations-batch.js +29 -29
  12. package/dist/access-operations.js +29 -29
  13. package/dist/access-recall-concurrency.js +29 -29
  14. package/dist/access-recall-response.js +29 -29
  15. package/dist/access-recall-surface.js +29 -29
  16. package/dist/access-service.js +29 -29
  17. package/dist/active-recall.js +2 -2
  18. package/dist/briefing.js +3 -3
  19. package/dist/causal-consolidation.js +4 -4
  20. package/dist/{chunk-NRZJKDGO.js → chunk-3KPZXBZM.js} +2 -2
  21. package/dist/{chunk-SMAPUZYV.js → chunk-4RHLXYGL.js} +2 -2
  22. package/dist/{chunk-VMEFUPOM.js → chunk-67D7L5VL.js} +2 -2
  23. package/dist/{chunk-J5MBTYDO.js → chunk-BCMB7GJQ.js} +2 -2
  24. package/dist/{chunk-WP25PXBB.js → chunk-BN2TKOAJ.js} +2 -2
  25. package/dist/{chunk-4N7L2N54.js → chunk-BTXK3JBP.js} +24 -24
  26. package/dist/{chunk-O5DO5LXA.js → chunk-BWSNXJYN.js} +7 -7
  27. package/dist/{chunk-C2KBLOKE.js → chunk-CSITQG52.js} +2 -2
  28. package/dist/{chunk-C6WVKVHZ.js → chunk-D364RLLL.js} +2 -2
  29. package/dist/{chunk-RJTHGVO3.js → chunk-D52NDOOZ.js} +2 -2
  30. package/dist/{chunk-YPDUSAPH.js → chunk-DZHHXGDC.js} +2 -2
  31. package/dist/{chunk-XOCAG2LF.js → chunk-EGEUMFB2.js} +2 -2
  32. package/dist/{chunk-KPFOFT4I.js → chunk-ELYFIZHZ.js} +2 -2
  33. package/dist/{chunk-IOLFR3JJ.js → chunk-HTD75T2R.js} +2 -2
  34. package/dist/{chunk-TPAIKAT5.js → chunk-JSDKE6UY.js} +3 -3
  35. package/dist/{chunk-TS34Y2T5.js → chunk-K4Y3Y67O.js} +2 -2
  36. package/dist/{chunk-RFUL2ZIQ.js → chunk-KNT3BZZH.js} +80 -3
  37. package/dist/chunk-KNT3BZZH.js.map +1 -0
  38. package/dist/{chunk-TA6IK76H.js → chunk-KOL4H4X4.js} +2 -2
  39. package/dist/{chunk-OSYHJCLK.js → chunk-LVWGOWWC.js} +2 -2
  40. package/dist/{chunk-G6TDGYVC.js → chunk-RCAU5FB4.js} +2 -2
  41. package/dist/{chunk-VHWQGBXY.js → chunk-TNBBUN7E.js} +3 -3
  42. package/dist/{chunk-QYN6I3CG.js → chunk-TWY3T5BR.js} +2 -2
  43. package/dist/{chunk-EKWS6NCF.js → chunk-U3DAQQ3D.js} +3 -3
  44. package/dist/{chunk-T5DX6A7T.js → chunk-WXZOPHV6.js} +2 -2
  45. package/dist/{chunk-T6H5HNA6.js → chunk-YAVAQEC6.js} +2 -2
  46. package/dist/{chunk-Q7UY2CSW.js → chunk-YVYH5QSZ.js} +7 -7
  47. package/dist/{chunk-R76L66OW.js → chunk-ZFLVQNCK.js} +3 -3
  48. package/dist/{chunk-JTO63AXR.js → chunk-ZLXUTBRN.js} +2 -2
  49. package/dist/{chunk-T4FW43AG.js → chunk-ZSNH3AY6.js} +2 -2
  50. package/dist/{chunk-CTQ2XD4R.js → chunk-ZYAXJOZ5.js} +2 -2
  51. package/dist/cli.js +29 -29
  52. package/dist/coding/export-okf-codegraph.js +2 -2
  53. package/dist/compounding/engine.js +4 -4
  54. package/dist/config.js +2 -2
  55. package/dist/connectors/codex-materialize-runner.js +3 -3
  56. package/dist/connectors/index.js +3 -3
  57. package/dist/convergence-refresh.js +5 -5
  58. package/dist/corpus-watermark.js +5 -5
  59. package/dist/entity-retrieval.js +3 -3
  60. package/dist/explicit-capture.js +29 -29
  61. package/dist/extraction.js +3 -3
  62. package/dist/harmonic-retrieval.js +3 -3
  63. package/dist/index.js +29 -29
  64. package/dist/location/index.js +4 -4
  65. package/dist/maintenance/memory-governance.js +3 -3
  66. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
  67. package/dist/maintenance/rebuild-memory-projection-runner.js +5 -5
  68. package/dist/maintenance/rebuild-memory-projection.js +4 -4
  69. package/dist/namespaces/migrate.js +4 -4
  70. package/dist/namespaces/storage.js +3 -3
  71. package/dist/operator-doctor-corpus.js +6 -6
  72. package/dist/operator-toolkit.js +9 -9
  73. package/dist/orchestration/backlog-scheduler.js +30 -30
  74. package/dist/orchestration/buffer-drain-runner.js +30 -30
  75. package/dist/orchestration/maintenance.js +11 -11
  76. package/dist/orchestrator.js +29 -29
  77. package/dist/recall-navigation.js +29 -29
  78. package/dist/resume-bundles.js +2 -2
  79. package/dist/semantic-consolidation.js +4 -4
  80. package/dist/semantic-rule-promotion.js +3 -3
  81. package/dist/semantic-rule-verifier.js +3 -3
  82. package/dist/source-agent-qualifier.js +3 -3
  83. package/dist/standup/build.js +3 -3
  84. package/dist/storage/buffer-drain-claims.d.ts +3 -0
  85. package/dist/storage/buffer-drain-claims.d.ts.map +1 -1
  86. package/dist/storage/buffer-drain-claims.js +1 -1
  87. package/dist/storage/buffer-drain-handin-memo.d.ts +30 -0
  88. package/dist/storage/buffer-drain-handin-memo.d.ts.map +1 -0
  89. package/dist/storage/buffer-session-files.js +1 -1
  90. package/dist/storage.js +2 -2
  91. package/dist/transfer/export-okf.js +3 -3
  92. package/dist/verified-recall.js +3 -3
  93. package/dist/who-knows-cli.js +4 -4
  94. package/dist/who-knows.js +3 -3
  95. package/package.json +2 -2
  96. package/src/storage/buffer-drain-claims.test.ts +223 -2
  97. package/src/storage/buffer-drain-claims.ts +31 -2
  98. package/src/storage/buffer-drain-handin-memo.ts +102 -0
  99. package/dist/chunk-RFUL2ZIQ.js.map +0 -1
  100. /package/dist/{chunk-NRZJKDGO.js.map → chunk-3KPZXBZM.js.map} +0 -0
  101. /package/dist/{chunk-SMAPUZYV.js.map → chunk-4RHLXYGL.js.map} +0 -0
  102. /package/dist/{chunk-VMEFUPOM.js.map → chunk-67D7L5VL.js.map} +0 -0
  103. /package/dist/{chunk-J5MBTYDO.js.map → chunk-BCMB7GJQ.js.map} +0 -0
  104. /package/dist/{chunk-WP25PXBB.js.map → chunk-BN2TKOAJ.js.map} +0 -0
  105. /package/dist/{chunk-4N7L2N54.js.map → chunk-BTXK3JBP.js.map} +0 -0
  106. /package/dist/{chunk-O5DO5LXA.js.map → chunk-BWSNXJYN.js.map} +0 -0
  107. /package/dist/{chunk-C2KBLOKE.js.map → chunk-CSITQG52.js.map} +0 -0
  108. /package/dist/{chunk-C6WVKVHZ.js.map → chunk-D364RLLL.js.map} +0 -0
  109. /package/dist/{chunk-RJTHGVO3.js.map → chunk-D52NDOOZ.js.map} +0 -0
  110. /package/dist/{chunk-YPDUSAPH.js.map → chunk-DZHHXGDC.js.map} +0 -0
  111. /package/dist/{chunk-XOCAG2LF.js.map → chunk-EGEUMFB2.js.map} +0 -0
  112. /package/dist/{chunk-KPFOFT4I.js.map → chunk-ELYFIZHZ.js.map} +0 -0
  113. /package/dist/{chunk-IOLFR3JJ.js.map → chunk-HTD75T2R.js.map} +0 -0
  114. /package/dist/{chunk-TPAIKAT5.js.map → chunk-JSDKE6UY.js.map} +0 -0
  115. /package/dist/{chunk-TS34Y2T5.js.map → chunk-K4Y3Y67O.js.map} +0 -0
  116. /package/dist/{chunk-TA6IK76H.js.map → chunk-KOL4H4X4.js.map} +0 -0
  117. /package/dist/{chunk-OSYHJCLK.js.map → chunk-LVWGOWWC.js.map} +0 -0
  118. /package/dist/{chunk-G6TDGYVC.js.map → chunk-RCAU5FB4.js.map} +0 -0
  119. /package/dist/{chunk-VHWQGBXY.js.map → chunk-TNBBUN7E.js.map} +0 -0
  120. /package/dist/{chunk-QYN6I3CG.js.map → chunk-TWY3T5BR.js.map} +0 -0
  121. /package/dist/{chunk-EKWS6NCF.js.map → chunk-U3DAQQ3D.js.map} +0 -0
  122. /package/dist/{chunk-T5DX6A7T.js.map → chunk-WXZOPHV6.js.map} +0 -0
  123. /package/dist/{chunk-T6H5HNA6.js.map → chunk-YAVAQEC6.js.map} +0 -0
  124. /package/dist/{chunk-Q7UY2CSW.js.map → chunk-YVYH5QSZ.js.map} +0 -0
  125. /package/dist/{chunk-R76L66OW.js.map → chunk-ZFLVQNCK.js.map} +0 -0
  126. /package/dist/{chunk-JTO63AXR.js.map → chunk-ZLXUTBRN.js.map} +0 -0
  127. /package/dist/{chunk-T4FW43AG.js.map → chunk-ZSNH3AY6.js.map} +0 -0
  128. /package/dist/{chunk-CTQ2XD4R.js.map → chunk-ZYAXJOZ5.js.map} +0 -0
@@ -11,7 +11,7 @@ import "./chunk-PT4DZDJA.js";
11
11
  import "./chunk-MLAMXQAW.js";
12
12
  import "./chunk-AIYXVWUH.js";
13
13
  import "./chunk-VEWZZM3H.js";
14
- import "./chunk-J5MBTYDO.js";
14
+ import "./chunk-BCMB7GJQ.js";
15
15
  import "./chunk-3UXOZBHV.js";
16
16
  import "./chunk-AL3TCNSJ.js";
17
17
  import "./chunk-WOXO4HE6.js";
@@ -26,12 +26,12 @@ import "./chunk-236PXYG7.js";
26
26
  import "./chunk-ZCUTSMR2.js";
27
27
  import "./chunk-QDW3E4RD.js";
28
28
  import "./chunk-ZJP66Q4I.js";
29
- import "./chunk-T5DX6A7T.js";
29
+ import "./chunk-WXZOPHV6.js";
30
30
  import "./chunk-QGVCFVX6.js";
31
31
  import "./chunk-UHVXE24Y.js";
32
32
  import "./chunk-O3JG4PD3.js";
33
33
  import "./chunk-G6OFEGUR.js";
34
- import "./chunk-RFUL2ZIQ.js";
34
+ import "./chunk-KNT3BZZH.js";
35
35
  import "./chunk-GRS34Y7V.js";
36
36
  import "./chunk-RLXD2L3G.js";
37
37
  import "./chunk-OVZIYLBZ.js";
@@ -3,13 +3,13 @@ import {
3
3
  parseStandupDate,
4
4
  previousActiveDate,
5
5
  standupHelp
6
- } from "../chunk-OSYHJCLK.js";
7
- import "../chunk-T5DX6A7T.js";
6
+ } from "../chunk-LVWGOWWC.js";
7
+ import "../chunk-WXZOPHV6.js";
8
8
  import "../chunk-QGVCFVX6.js";
9
9
  import "../chunk-UHVXE24Y.js";
10
10
  import "../chunk-O3JG4PD3.js";
11
11
  import "../chunk-G6OFEGUR.js";
12
- import "../chunk-RFUL2ZIQ.js";
12
+ import "../chunk-KNT3BZZH.js";
13
13
  import "../chunk-GRS34Y7V.js";
14
14
  import "../chunk-RLXD2L3G.js";
15
15
  import "../chunk-OVZIYLBZ.js";
@@ -112,6 +112,7 @@ export declare class BufferDrainClaims {
112
112
  private readonly stateDir;
113
113
  private readonly io;
114
114
  constructor(stateDir: string, io: BufferFileIo);
115
+ private readonly handIns;
115
116
  private get dir();
116
117
  private fileFor;
117
118
  private leaseFileFor;
@@ -182,6 +183,8 @@ export declare class BufferDrainClaims {
182
183
  * unlinking it. A lease whose owner died is taken over in the same call.
183
184
  */
184
185
  adopt(key: string, lease: DrainLease): Promise<AdoptOutcome>;
186
+ /** The inbox as this process last left it (identity, size, mtime); "absent" when there is none, null when unknown. */
187
+ private handInStamp;
185
188
  /**
186
189
  * Hand a live owner's in-memory entry to the claim (the path a buffer owner
187
190
  * takes instead of persisting a claimed session): ONE append to the inbox,
@@ -1 +1 @@
1
- {"version":3,"file":"buffer-drain-claims.d.ts","sourceRoot":"","sources":["../../src/storage/buffer-drain-claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AASH,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAA8C,KAAK,eAAe,E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,CAAC;YA+BzB,mBAAmB;CAQlC"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BufferDrainClaims
3
- } from "../chunk-RFUL2ZIQ.js";
3
+ } from "../chunk-KNT3BZZH.js";
4
4
  import "../chunk-UXXK523X.js";
5
5
  import "../chunk-EBV6VXKF.js";
6
6
  import "../chunk-X4OZMANG.js";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * What a live buffer owner has already handed to a drain claim's inbox, so the
3
+ * next hand-in carries only what is new (COS-666i).
4
+ *
5
+ * `mergeIntoClaim` used to append the owner's WHOLE entry on every save. For a
6
+ * claimed session that is never drained, the inbox grew by the full buffer per
7
+ * observe (quadratic), and every reader that parsed it stalled the event loop
8
+ * (a production inbox reached 799 MB). The claim fold keeps, per turn identity,
9
+ * the largest occurrence count any record holds, so a record only has to carry
10
+ * every occurrence of the identities whose count grew: folding the deltas gives
11
+ * the same claim as folding the full snapshots.
12
+ *
13
+ * The memo is only trusted while the claim is exactly as this process left it
14
+ * (`stamp`: the inbox file's identity, size and mtime, read under the claim lock). Any other
15
+ * writer, a drainer compaction (it deletes the inbox), a release or a re-claim changes the stamp, and
16
+ * the next hand-in is the whole entry again, which is always correct.
17
+ */
18
+ import type { BufferEntryState } from "../types.js";
19
+ export interface HandInPlan {
20
+ /** What to append: the whole entry, or only what grew. */
21
+ record: BufferEntryState;
22
+ /** Call after the append landed, with the claim's stamp read afterwards (null forgets the claim). */
23
+ remember(stampAfter: string | null): void;
24
+ }
25
+ export declare class HandInMemo {
26
+ private readonly byKey;
27
+ /** The hand-in to append for `incoming`, or null when the claim already holds all of it. */
28
+ plan(key: string, stamp: string | null, incoming: BufferEntryState): HandInPlan | null;
29
+ }
30
+ //# sourceMappingURL=buffer-drain-handin-memo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-drain-handin-memo.d.ts","sourceRoot":"","sources":["../../src/storage/buffer-drain-handin-memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,aAAa,CAAC;AAkChE,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,MAAM,EAAE,gBAAgB,CAAC;IACzB,qGAAqG;IACrG,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CAC3C;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IAEvD,4FAA4F;IAC5F,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,gBAAgB,GAAG,UAAU,GAAG,IAAI;CAmCvF"}
@@ -2,7 +2,7 @@ import {
2
2
  BufferSessionFiles,
3
3
  bufferSessionFileName,
4
4
  legacyStateToEntries
5
- } from "../chunk-RFUL2ZIQ.js";
5
+ } from "../chunk-KNT3BZZH.js";
6
6
  import "../chunk-UXXK523X.js";
7
7
  import "../chunk-EBV6VXKF.js";
8
8
  import "../chunk-X4OZMANG.js";
package/dist/storage.js CHANGED
@@ -14,12 +14,12 @@ import {
14
14
  parseFrontmatter,
15
15
  parseFrontmatterStringValue,
16
16
  serializeEntityFile
17
- } from "./chunk-T5DX6A7T.js";
17
+ } from "./chunk-WXZOPHV6.js";
18
18
  import "./chunk-QGVCFVX6.js";
19
19
  import "./chunk-UHVXE24Y.js";
20
20
  import "./chunk-O3JG4PD3.js";
21
21
  import "./chunk-G6OFEGUR.js";
22
- import "./chunk-RFUL2ZIQ.js";
22
+ import "./chunk-KNT3BZZH.js";
23
23
  import "./chunk-GRS34Y7V.js";
24
24
  import "./chunk-RLXD2L3G.js";
25
25
  import "./chunk-OVZIYLBZ.js";
@@ -4,18 +4,18 @@ import {
4
4
  exportOkfBundle,
5
5
  firstHeading,
6
6
  parseIncludeStatus
7
- } from "../chunk-JTO63AXR.js";
7
+ } from "../chunk-ZLXUTBRN.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-T5DX6A7T.js";
13
+ import "../chunk-WXZOPHV6.js";
14
14
  import "../chunk-QGVCFVX6.js";
15
15
  import "../chunk-UHVXE24Y.js";
16
16
  import "../chunk-O3JG4PD3.js";
17
17
  import "../chunk-G6OFEGUR.js";
18
- import "../chunk-RFUL2ZIQ.js";
18
+ import "../chunk-KNT3BZZH.js";
19
19
  import "../chunk-GRS34Y7V.js";
20
20
  import "../chunk-RLXD2L3G.js";
21
21
  import "../chunk-OVZIYLBZ.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  compareVerifiedEpisodeResults,
3
3
  searchVerifiedEpisodes
4
- } from "./chunk-TA6IK76H.js";
4
+ } from "./chunk-KOL4H4X4.js";
5
5
  import "./chunk-B7RWBZXW.js";
6
- import "./chunk-T5DX6A7T.js";
6
+ import "./chunk-WXZOPHV6.js";
7
7
  import "./chunk-QGVCFVX6.js";
8
8
  import "./chunk-UHVXE24Y.js";
9
9
  import "./chunk-O3JG4PD3.js";
10
10
  import "./chunk-G6OFEGUR.js";
11
- import "./chunk-RFUL2ZIQ.js";
11
+ import "./chunk-KNT3BZZH.js";
12
12
  import "./chunk-GRS34Y7V.js";
13
13
  import "./chunk-RLXD2L3G.js";
14
14
  import "./chunk-OVZIYLBZ.js";
@@ -4,14 +4,14 @@ import {
4
4
  renderWhoKnows,
5
5
  renderWhoKnowsJson,
6
6
  renderWhoKnowsText
7
- } from "./chunk-RJTHGVO3.js";
8
- import "./chunk-C2KBLOKE.js";
9
- import "./chunk-T5DX6A7T.js";
7
+ } from "./chunk-D52NDOOZ.js";
8
+ import "./chunk-CSITQG52.js";
9
+ import "./chunk-WXZOPHV6.js";
10
10
  import "./chunk-QGVCFVX6.js";
11
11
  import "./chunk-UHVXE24Y.js";
12
12
  import "./chunk-O3JG4PD3.js";
13
13
  import "./chunk-G6OFEGUR.js";
14
- import "./chunk-RFUL2ZIQ.js";
14
+ import "./chunk-KNT3BZZH.js";
15
15
  import "./chunk-GRS34Y7V.js";
16
16
  import "./chunk-RLXD2L3G.js";
17
17
  import "./chunk-OVZIYLBZ.js";
package/dist/who-knows.js CHANGED
@@ -9,13 +9,13 @@ import {
9
9
  loadWhoKnowsEntities,
10
10
  tokenizeTopic,
11
11
  validateWhoKnowsInput
12
- } from "./chunk-C2KBLOKE.js";
13
- import "./chunk-T5DX6A7T.js";
12
+ } from "./chunk-CSITQG52.js";
13
+ import "./chunk-WXZOPHV6.js";
14
14
  import "./chunk-QGVCFVX6.js";
15
15
  import "./chunk-UHVXE24Y.js";
16
16
  import "./chunk-O3JG4PD3.js";
17
17
  import "./chunk-G6OFEGUR.js";
18
- import "./chunk-RFUL2ZIQ.js";
18
+ import "./chunk-KNT3BZZH.js";
19
19
  import "./chunk-GRS34Y7V.js";
20
20
  import "./chunk-RLXD2L3G.js";
21
21
  import "./chunk-OVZIYLBZ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.114",
3
+ "version": "10.0.115",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3386,7 +3386,7 @@
3386
3386
  "core"
3387
3387
  ],
3388
3388
  "peerDependencies": {
3389
- "@remnic/coding-graph": "^10.0.114"
3389
+ "@remnic/coding-graph": "^10.0.115"
3390
3390
  },
3391
3391
  "peerDependenciesMeta": {
3392
3392
  "@remnic/coding-graph": {
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { mkdtempSync, readdirSync, existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync, rmSync, statSync, utimesSync } from "node:fs";
2
+ import { mkdtempSync, readdirSync, existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync, rmSync, statSync, truncateSync, utimesSync } from "node:fs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import os from "node:os";
5
5
  import { hostname } from "node:os";
@@ -10,7 +10,7 @@ import test from "node:test";
10
10
  import { BufferDrainClaims, type AckOutcome, type DrainLease } from "./buffer-drain-claims.js";
11
11
  import { BufferSessionFiles, bufferSessionFileName } from "./buffer-session-files.js";
12
12
  import { ClaimBufferStorage } from "../orchestration/buffer-drain-runner.js";
13
- import type { BufferEntryState } from "../types.js";
13
+ import type { BufferEntryState, BufferTurn } from "../types.js";
14
14
  import { withHeldFileLock } from "../utils/serialize-mutations.js";
15
15
  /** Plain-file BufferFileIo double: claims logic is file-atomic, not crypto-aware. */
16
16
  function plainIo() {
@@ -1154,3 +1154,224 @@ test("a finished drain is verified with one real read before it reads as drained
1154
1154
  s.cleanup();
1155
1155
  }
1156
1156
  });
1157
+
1158
+ /** The turn contents of each inbox record, in file order. */
1159
+ function inboxRecords(stateDir: string, key: string): string[][] {
1160
+ const lines = readFileSync(inboxFile(stateDir, key), "utf8").split("\n").filter((line) => line.length > 0);
1161
+ return lines.map((line) =>
1162
+ z.object({ turns: z.array(z.object({ content: z.string() })) }).parse(JSON.parse(line)).turns.map((t) => t.content),
1163
+ );
1164
+ }
1165
+
1166
+ const at = (minute: number): string => `2026-11-01T00:${String(minute).padStart(2, "0")}:00.000Z`;
1167
+
1168
+ test("a hand-in appends only the turns the claim does not hold yet", async () => {
1169
+ const s = setup();
1170
+ try {
1171
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1172
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1173
+ const turns = [turn("a", at(0)), turn("b", at(1))];
1174
+ await s.claims.mergeIntoClaim("sess-1", entry(turns));
1175
+ turns.push(turn("c", at(2)));
1176
+ await s.claims.mergeIntoClaim("sess-1", entry(turns));
1177
+ turns.push(turn("d", at(3)));
1178
+ await s.claims.mergeIntoClaim("sess-1", entry(turns));
1179
+
1180
+ assert.deepEqual(inboxRecords(s.stateDir, "sess-1"), [["a", "b"], ["c"], ["d"]], "records after the first carry only new turns");
1181
+ const claim = await s.claims.load("sess-1");
1182
+ assert.deepEqual(claim?.entry.turns.map((t) => t.content), ["a", "b", "c", "d"]);
1183
+ } finally {
1184
+ s.cleanup();
1185
+ }
1186
+ });
1187
+
1188
+ test("a hand-in that changes nothing appends nothing", async () => {
1189
+ const s = setup();
1190
+ try {
1191
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1192
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1193
+ const same = entry([turn("a", at(0)), turn("b", at(1))]);
1194
+ await s.claims.mergeIntoClaim("sess-1", same);
1195
+ const before = statSync(inboxFile(s.stateDir, "sess-1")).size;
1196
+ await s.claims.mergeIntoClaim("sess-1", same);
1197
+ assert.equal(statSync(inboxFile(s.stateDir, "sess-1")).size, before, "no second record");
1198
+ } finally {
1199
+ s.cleanup();
1200
+ }
1201
+ });
1202
+
1203
+ test("a hand-in still carries a new occurrence of a turn the claim already holds", async () => {
1204
+ const s = setup();
1205
+ try {
1206
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1207
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1208
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("x", at(1))]));
1209
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("x", at(1)), turn("x", at(1))]));
1210
+ const claim = await s.claims.load("sess-1");
1211
+ assert.deepEqual(claim?.entry.turns.map((t) => t.content), ["a", "x", "x"], "the second equal turn is not lost");
1212
+ } finally {
1213
+ s.cleanup();
1214
+ }
1215
+ });
1216
+
1217
+ test("delta hand-ins fold to exactly what full snapshots fold to", async () => {
1218
+ let seed = 7;
1219
+ const next = (n: number): number => {
1220
+ seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
1221
+ return (seed >>> 16) % n;
1222
+ };
1223
+ let sawRetained = 0;
1224
+ let sawDuplicate = 0;
1225
+ for (let round = 0; round < 25; round += 1) {
1226
+ const delta = setup();
1227
+ const full = setup();
1228
+ try {
1229
+ const base = entry([turn("a", at(0))]);
1230
+ delta.seedSession("sess-1", base);
1231
+ full.seedSession("sess-1", base);
1232
+ await delta.claims.claimFromSessionFile("sess-1", makeLease());
1233
+ await full.claims.claimFromSessionFile("sess-1", makeLease());
1234
+ let active: BufferTurn[] = [turn("a", at(0))];
1235
+ let retained: BufferTurn[] = [];
1236
+ for (let step = 0; step < 8; step += 1) {
1237
+ const move = next(4);
1238
+ if (move === 0) active = [...active, turn(`t${next(3)}`, at(next(3)))];
1239
+ else if (move === 1 && active.length > 1) {
1240
+ const [moved] = active.splice(next(active.length), 1);
1241
+ if (moved) retained = [...retained, moved];
1242
+ } else if (move === 2 && retained.length > 0) active = [...active, ...retained.splice(0, 1)];
1243
+ else active = active.slice(1).concat(turn(`u${next(2)}`, at(3 + next(2))));
1244
+ const snapshot: BufferEntryState = { turns: [...active], lastExtractionAt: null, extractionCount: step };
1245
+ if (retained.length > 0) snapshot.retainedTurns = [...retained];
1246
+ if (retained.length > 0) sawRetained += 1;
1247
+ if (new Set(active.map((t) => `${t.content}|${t.timestamp}`)).size < active.length) sawDuplicate += 1;
1248
+ await delta.claims.mergeIntoClaim("sess-1", snapshot);
1249
+ mkdirSync(path.dirname(inboxFile(full.stateDir, "sess-1")), { recursive: true });
1250
+ appendFileSync(inboxFile(full.stateDir, "sess-1"), record("sess-1", snapshot));
1251
+ }
1252
+ const got = await delta.claims.load("sess-1");
1253
+ const want = await full.claims.load("sess-1");
1254
+ assert.deepEqual(got?.entry.turns, want?.entry.turns, `round ${round}: active turns`);
1255
+ assert.deepEqual(got?.entry.retainedTurns, want?.entry.retainedTurns, `round ${round}: retained turns`);
1256
+ assert.equal(got?.entry.extractionCount, want?.entry.extractionCount, `round ${round}: extraction count`);
1257
+ } finally {
1258
+ delta.cleanup();
1259
+ full.cleanup();
1260
+ }
1261
+ }
1262
+ assert.ok(sawRetained > 10, "the sequences really move turns to retained");
1263
+ assert.ok(sawDuplicate > 10, "the sequences really hold duplicate occurrences");
1264
+ });
1265
+
1266
+ test("a hand-in sends the whole entry again when the inbox changed behind its back", async () => {
1267
+ const s = setup();
1268
+ try {
1269
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1270
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1271
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1))]));
1272
+ // Another process compacted or removed the inbox; "b" is no longer anywhere.
1273
+ rmSync(inboxFile(s.stateDir, "sess-1"));
1274
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1)), turn("c", at(2))]));
1275
+ const claim = await s.claims.load("sess-1");
1276
+ assert.deepEqual(claim?.entry.turns.map((t) => t.content), ["a", "b", "c"], "b is handed in again, not lost");
1277
+ } finally {
1278
+ s.cleanup();
1279
+ }
1280
+ });
1281
+
1282
+ test("a hand-in after a drain progress write sends the whole entry again", async () => {
1283
+ const s = setup();
1284
+ try {
1285
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1286
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1287
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1))]));
1288
+ const loaded = await s.claims.load("sess-1");
1289
+ assert.ok(loaded);
1290
+ // The drainer extracts "a" and compacts the inbox into the body.
1291
+ await s.claims.writeEntry("sess-1", "worker-1", entry([turn("b", at(1))]), loaded.entry);
1292
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1)), turn("c", at(2))]));
1293
+ const claim = await s.claims.load("sess-1");
1294
+ assert.deepEqual(claim?.entry.turns.map((t) => t.content), ["b", "c"], "b stays, c arrives, the drained a does not return");
1295
+ } finally {
1296
+ s.cleanup();
1297
+ }
1298
+ });
1299
+
1300
+ test("a listing does not read a large inbox while the body still has pending turns", async () => {
1301
+ const s = setup();
1302
+ try {
1303
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1304
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1305
+ const filler = "x".repeat(1_100_000);
1306
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn(filler, at(1))]));
1307
+ assert.ok(statSync(inboxFile(s.stateDir, "sess-1")).size > 1_048_576, "fixture: the inbox is over 1 MiB");
1308
+
1309
+ const spied = spyIo();
1310
+ const claims = new BufferDrainClaims(s.stateDir, spied.io);
1311
+ const page = await claims.listPage(undefined, 10);
1312
+ assert.deepEqual(page.entries.map((e) => e.key), ["sess-1"], "the claim is still listed");
1313
+ assert.ok((page.entries[0]?.turnCount ?? 0) >= 1, "with at least its body count");
1314
+ assert.equal(spied.readPaths.filter((p) => p === inboxFile(s.stateDir, "sess-1")).length, 0, "the inbox is not read");
1315
+ } finally {
1316
+ s.cleanup();
1317
+ }
1318
+ });
1319
+
1320
+ test("a listing skips an inbox too long to read as one string, without reading it", async () => {
1321
+ const s = setup();
1322
+ try {
1323
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1324
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1325
+ await s.claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1))]));
1326
+ truncateSync(inboxFile(s.stateDir, "sess-1"), 0x1fffffe9);
1327
+
1328
+ const spied = spyIo();
1329
+ const claims = new BufferDrainClaims(s.stateDir, spied.io);
1330
+ assert.deepEqual((await claims.listPage(undefined, 10)).entries, [], "an unreadable claim is skipped, as before");
1331
+ assert.equal(spied.readPaths.filter((p) => p === inboxFile(s.stateDir, "sess-1")).length, 0, "and never read");
1332
+ } finally {
1333
+ s.cleanup();
1334
+ }
1335
+ });
1336
+
1337
+ /** A claim whose body has nothing pending (the drainer extracted it) but whose inbox holds a hand-in. */
1338
+ async function drainedBodyClaimWithInbox(s: ReturnType<typeof setup>, handIn: BufferEntryState): Promise<void> {
1339
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1340
+ await s.claims.claimFromSessionFile("sess-1", makeLease());
1341
+ const loaded = await s.claims.load("sess-1");
1342
+ assert.ok(loaded);
1343
+ await s.claims.writeEntry("sess-1", "worker-1", entry([]), loaded.entry);
1344
+ await s.claims.releaseLease("sess-1", "worker-1");
1345
+ await s.claims.mergeIntoClaim("sess-1", handIn);
1346
+ }
1347
+
1348
+ test("a listing does not read a large inbox beside a drained body, and keeps the claim a candidate", async () => {
1349
+ const s = setup();
1350
+ try {
1351
+ await drainedBodyClaimWithInbox(s, entry([turn("x".repeat(1_100_000), at(1))]));
1352
+ assert.ok(statSync(inboxFile(s.stateDir, "sess-1")).size > 1_048_576, "fixture: the inbox is over 1 MiB");
1353
+
1354
+ const spied = spyIo();
1355
+ const claims = new BufferDrainClaims(s.stateDir, spied.io);
1356
+ const page = await claims.listPage(undefined, 10);
1357
+ assert.deepEqual(page.entries.map((e) => e.key), ["sess-1"], "the claim is still a candidate");
1358
+ assert.equal(spied.readPaths.filter((p) => p === inboxFile(s.stateDir, "sess-1")).length, 0, "the inbox is not read");
1359
+ } finally {
1360
+ s.cleanup();
1361
+ }
1362
+ });
1363
+
1364
+ test("a listing skips an unreadably long inbox beside a drained body without reading it", async () => {
1365
+ const s = setup();
1366
+ try {
1367
+ await drainedBodyClaimWithInbox(s, entry([turn("b", at(1))]));
1368
+ truncateSync(inboxFile(s.stateDir, "sess-1"), 0x1fffffe9);
1369
+
1370
+ const spied = spyIo();
1371
+ const claims = new BufferDrainClaims(s.stateDir, spied.io);
1372
+ assert.deepEqual((await claims.listPage(undefined, 10)).entries, []);
1373
+ assert.equal(spied.readPaths.filter((p) => p === inboxFile(s.stateDir, "sess-1")).length, 0, "and never read");
1374
+ } finally {
1375
+ s.cleanup();
1376
+ }
1377
+ });
@@ -61,6 +61,7 @@ import { mkdir, readdir, readFile, rename, stat, unlink, writeFile } from "node:
61
61
  import path from "node:path";
62
62
 
63
63
  import { bufferSessionFileName, type BufferFileIo } from "./buffer-session-files.js";
64
+ import { HandInMemo } from "./buffer-drain-handin-memo.js";
64
65
  import { bufferTurnIdentityKey, subtractBufferTurns, type DrainedTurnSets } from "../buffer-turn-helpers.js";
65
66
  import { log } from "../logger.js";
66
67
  import { isErrnoCode } from "../utils/errno.js";
@@ -426,6 +427,11 @@ function leaseBelongsToProcess(lease: DrainLease | null, ownerId: string): boole
426
427
  const INBOX_SUFFIX = ".inbox.jsonl";
427
428
  /** Cached turn counts beside a claim body (see `ClaimSummary`). */
428
429
  const COUNT_SUFFIX = ".count";
430
+ /** Above this, a listing does not parse an inbox while the body still has pending turns (COS-666i). */
431
+ const INBOX_LISTING_PARSE_LIMIT = 1_048_576;
432
+ /** Node cannot build a string longer than this; an inbox this big can never be read. */
433
+ // shortcut: counts bytes, so a multi-byte-heavy inbox just over this is skipped though readable; fold it by hand then.
434
+ const INBOX_UNREADABLE_BYTES = 0x1fffffe8;
429
435
 
430
436
  /** Claim bodies `listPage` may read per requested entry: bounds one scan's
431
437
  * I/O even when the directory is mostly empty tombstones. */
@@ -437,6 +443,8 @@ export class BufferDrainClaims {
437
443
  private readonly io: BufferFileIo,
438
444
  ) {}
439
445
 
446
+ private readonly handIns = new HandInMemo();
447
+
440
448
  private get dir(): string {
441
449
  return path.join(this.stateDir, "buffer", "drain");
442
450
  }
@@ -695,6 +703,16 @@ export class BufferDrainClaims {
695
703
  );
696
704
  }
697
705
 
706
+ /** The inbox as this process last left it (identity, size, mtime); "absent" when there is none, null when unknown. */
707
+ private async handInStamp(key: string): Promise<string | null> {
708
+ try {
709
+ const inbox = await stat(this.inboxFor(key));
710
+ return `${inbox.ino}:${inbox.size}:${inbox.mtimeMs}`;
711
+ } catch (err) {
712
+ return isErrnoCode(err, "ENOENT") ? "absent" : null;
713
+ }
714
+ }
715
+
698
716
  /**
699
717
  * Hand a live owner's in-memory entry to the claim (the path a buffer owner
700
718
  * takes instead of persisting a claimed session): ONE append to the inbox,
@@ -716,7 +734,10 @@ export class BufferDrainClaims {
716
734
  if (!this.isClaimed(key)) return;
717
735
  // Leading newline: a torn tail from a kill mid-append ends at this
718
736
  // record's newline instead of fusing into it.
719
- await this.io.append(this.inboxFor(key), `\n${JSON.stringify({ id: randomUUID(), key, ...incoming })}`);
737
+ const plan = this.handIns.plan(key, await this.handInStamp(key), incoming);
738
+ if (plan === null) return;
739
+ await this.io.append(this.inboxFor(key), `\n${JSON.stringify({ id: randomUUID(), key, ...plan.record })}`);
740
+ plan.remember(await this.handInStamp(key));
720
741
  });
721
742
  }
722
743
 
@@ -964,7 +985,15 @@ export class BufferDrainClaims {
964
985
  if (!summary) return null;
965
986
  let inboxTurns = 0;
966
987
  try {
967
- for (const record of await this.readInbox(summary.key)) inboxTurns += pendingTurns(record.entry);
988
+ const inboxBytes = (await stat(this.inboxFor(summary.key)).catch(() => null))?.size ?? 0;
989
+ if (inboxBytes > INBOX_UNREADABLE_BYTES) throw new Error(`inbox is ${inboxBytes} bytes, too long to read`);
990
+ if (inboxBytes <= INBOX_LISTING_PARSE_LIMIT) {
991
+ for (const record of await this.readInbox(summary.key)) inboxTurns += pendingTurns(record.entry);
992
+ } else if (summary.pending === 0) {
993
+ // Unknown but positive: the claim stays a candidate, and the drain counts the inbox exactly.
994
+ inboxTurns = 1;
995
+ }
996
+ // A large inbox beside a pending body adds nothing here: the body already makes the claim a candidate.
968
997
  } catch (err) {
969
998
  log.debug(`buffer drain: skipping claim ${name} with an unreadable inbox: ${err instanceof Error ? err.message : String(err)}`);
970
999
  return null;