@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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/extraction-liveness.ts"],"sourcesContent":["/**\n * Extraction-pipeline liveness (issue #2151).\n *\n * A daemon's implicit extraction can fail continuously for months while\n * `/health` stays green and recall keeps serving: every individual failure is\n * logged (timeouts, fallback-no-parsed-output), but nothing aggregates them\n * into a checkable status. This module surfaces a liveness *watermark* — the\n * last successful extraction plus the current buffer backlog — and decides when\n * that watermark is stale enough to call the pipeline degraded.\n *\n * The §22 error-vs-empty principle applies at the pipeline level: \"no\n * extraction succeeded for 90 days\" (a non-empty buffer with a stale/absent\n * watermark) must be distinguishable from \"nothing to extract\" (an empty\n * buffer). Degradation therefore requires a NON-EMPTY buffer — an idle daemon\n * with nothing buffered is healthy, not degraded.\n *\n * The core decision (`evaluateExtractionLiveness`) is a pure function shared by\n * every surface (authenticated `/health`, `remnic doctor`, `remnic stats`) so\n * the verdict never diverges across code paths.\n */\nimport { coerceBool, coerceNumber } from \"./connectors/coerce.js\";\nimport { getExtractionLlmHealth } from \"./extraction-llm-health.js\";\nimport { log } from \"./logger.js\";\nimport type { OperatorDoctorCheck } from \"./operator-doctor-types.js\";\nimport type { PluginConfig } from \"./types.js\";\n\n/** Default staleness window: 24h. A watermark older than this with a non-empty buffer is degraded. */\nconst DEFAULT_STALE_WINDOW_MS = 86_400_000;\n\nexport interface ExtractionLivenessConfig {\n /** Master gate. When false, liveness is never reported degraded. Default true. */\n enabled: boolean;\n /**\n * How stale the last-successful-extraction watermark may get (ms) before a\n * non-empty buffer flags the pipeline degraded. Default 24h.\n */\n staleWindowMs: number;\n}\n\n/**\n * A read-only snapshot of buffered, not-yet-extracted work. Structurally\n * satisfied by `SmartBuffer.getBufferSnapshot()` so callers can pass the live\n * buffer without this module depending on the buffer implementation.\n */\nexport interface ExtractionBufferSnapshot {\n bufferedSessionCount: number;\n pendingTurnCount: number;\n oldestTurnTimestamp: string | null;\n /**\n * Set by the liveness reader (never by `SmartBuffer`) when the buffer exists\n * but its snapshot read threw. An unreadable buffer is a pipeline fault, not\n * an empty queue (§22): it degrades the pipeline with a distinct reason\n * instead of masquerading as a zero-backlog (healthy) snapshot.\n */\n readFailed?: boolean;\n /** Read-failure detail, surfaced in the degraded reason when `readFailed`. */\n readError?: string;\n}\n\nexport interface ExtractionBufferSource {\n getBufferSnapshot(): Promise<ExtractionBufferSnapshot>;\n}\n\nexport interface ExtractionRootStats {\n extractionCount?: number;\n lastConsolidationAt?: string | null;\n}\n\nexport interface ExtractionWatermarkRead {\n lastExtractionAt: string | null;\n readFailed: boolean;\n readError?: string;\n pending?: boolean;\n rootStats?: ExtractionRootStats;\n}\n\nexport type ExtractionWatermarkOrStorage =\n | ExtractionWatermarkRead\n | { readMetadata(): Promise<{ lastExtractionAt?: string | null } | null> }\n | { loadMeta(): Promise<{ lastExtractionAt?: string | null }> };\n\nexport async function coerceExtractionWatermark(\n watermark: ExtractionWatermarkOrStorage,\n): Promise<ExtractionWatermarkRead> {\n if (watermark && \"readFailed\" in watermark && typeof watermark.readFailed === \"boolean\") {\n return watermark as ExtractionWatermarkRead;\n }\n try {\n let lastExtractionAt: string | null = null;\n if (\"loadMeta\" in watermark && typeof watermark.loadMeta === \"function\") {\n const meta = await watermark.loadMeta();\n lastExtractionAt = meta?.lastExtractionAt ?? null;\n } else if (\"readMetadata\" in watermark && typeof watermark.readMetadata === \"function\") {\n const meta = await watermark.readMetadata();\n lastExtractionAt = meta?.lastExtractionAt ?? null;\n }\n return {\n lastExtractionAt,\n readFailed: true,\n readError: \"aggregate watermark unavailable from legacy root-store-only storage argument\",\n };\n } catch (error) {\n return {\n lastExtractionAt: null,\n readFailed: true,\n readError: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n/**\n * The daemon-scoped liveness payload surfaced on `/health.extraction` and in\n * doctor/stats details. Its watermark is the maximum successful extraction\n * across every distinct namespace store, matching the daemon-wide buffer scope.\n */\nexport interface ExtractionLivenessStatus {\n lastExtractionAt: string | null;\n bufferedSessionCount: number;\n pendingTurnCount: number;\n oldestBufferedTurnAgeMs: number | null;\n degraded: boolean;\n degradedReason: string | null;\n watermarkPending?: boolean;\n watermarkScope: \"aggregate\";\n /**\n * Extraction-LLM availability (issue #3140): outcome of the last extraction\n * attempt. `lastFailureReason` is non-null exactly while `llmReachable` is\n * false. Populated by the daemon-wide status readers (`/health`, doctor,\n * stats), not by the pure evaluators below.\n */\n llmReachable?: boolean;\n lastFailureReason?: string | null;\n lastFailureAt?: string | null;\n}\n\ninterface ExtractionLivenessOrchestratorLike {\n config: Pick<PluginConfig, \"extractionLiveness\">;\n buffer?: ExtractionBufferSource;\n}\n\n/**\n * Parse the `extractionLiveness` config block. Follows the nested-block shape\n * validation used elsewhere in `config.ts` and coerces string booleans (§24:\n * CLI/JSON deliver `\"false\"`/`\"0\"` as strings, which must read as falsy).\n */\nexport function parseExtractionLivenessConfig(\n cfg: Record<string, unknown>,\n): ExtractionLivenessConfig {\n const raw = cfg.extractionLiveness;\n if (raw !== undefined && (raw === null || typeof raw !== \"object\" || Array.isArray(raw))) {\n throw new Error(`extractionLiveness must be a plain object (got ${JSON.stringify(raw)})`);\n }\n const block = (raw ?? {}) as Record<string, unknown>;\n return {\n // `?? true` keeps the default on when the key is absent while honoring\n // explicit \"false\"/\"0\"/false opt-outs (coerceBool handles the string forms).\n enabled: coerceBool(block.enabled) ?? true,\n staleWindowMs: parseStaleWindowMs(block.staleWindowMs),\n };\n}\n\n/**\n * Parse `extractionLiveness.staleWindowMs`. Absent (`undefined`) → the 24h\n * default; any PRESENT value (including an explicit `null`) must coerce to a\n * positive INTEGER of milliseconds, else THROW. A fractional or non-positive\n * value (\"0.5\" would floor to 0, making every backlog instantly stale; 1.9 would\n * floor to 1) is rejected, never floored/reinterpreted (§1/§17/§39). Mirrors\n * config.ts's `parseIntegerInClosedRange` (round 9 finding 1): only an absent key\n * falls back; an explicit `null` is invalid input, not \"use the default\".\n * Inlined rather than imported because config.ts already imports this module\n * (importing back would be circular), the same reason `recall-concurrency-config.ts`\n * inlines its numeric validation.\n */\nfunction parseStaleWindowMs(value: unknown): number {\n // Only an absent key (undefined) falls back to the default; an explicit `null`\n // is invalid input and proceeds to validation → throw (mirrors\n // parseIntegerInClosedRange, round 9 finding 1).\n if (value === undefined) return DEFAULT_STALE_WINDOW_MS;\n const coerced = coerceNumber(value);\n if (coerced === undefined || !Number.isFinite(coerced) || !Number.isInteger(coerced) || coerced < 1) {\n throw new Error(\n `extractionLiveness.staleWindowMs must be an integer greater than or equal to 1; got ${JSON.stringify(value)}`,\n );\n }\n return coerced;\n}\n\n/** Milliseconds between `timestamp` and `nowMs`, clamped at 0; null when unparsable/absent. */\nfunction ageMsFrom(timestamp: string | null, nowMs: number): number | null {\n if (typeof timestamp !== \"string\") return null;\n const parsed = Date.parse(timestamp);\n if (!Number.isFinite(parsed)) return null;\n return Math.max(0, nowMs - parsed);\n}\n\n/** Compact human-readable duration (\"3d\", \"5h\", \"12m\", \"45s\") for logs and CLI output. */\nexport function formatAgeMs(ms: number): string {\n const s = Math.max(0, Math.floor(ms / 1000));\n if (s >= 86_400) return `${Math.floor(s / 86_400)}d`;\n if (s >= 3_600) return `${Math.floor(s / 3_600)}h`;\n if (s >= 60) return `${Math.floor(s / 60)}m`;\n return `${s}s`;\n}\n\n/**\n * Pure liveness verdict. Degraded when the feature is enabled AND any of: the\n * last-extraction watermark could not be READ (a storage fault, §22), the buffer\n * read failed (a pipeline fault, §22), or the buffer is non-empty and the\n * watermark is absent or stale. Each cause yields a DISTINCT reason so an\n * operator can tell a meta-read failure from a buffer-read failure from a\n * pipeline that has genuinely never extracted.\n *\n * Staleness uses a half-open freshness window (§23): an extraction is fresh\n * while its age is in `[0, staleWindowMs)`, so an age of EXACTLY `staleWindowMs`\n * is stale (the upper bound on \"fresh\" is exclusive). A null/unparsable watermark\n * means \"never succeeded\" and is treated as stale — as is a FUTURE watermark (a\n * clock-skewed or corrupt timestamp ahead of now must not read as a fresh\n * extraction and hide a real backlog stall).\n */\nexport function evaluateExtractionLiveness(input: {\n config: ExtractionLivenessConfig;\n lastExtractionAt: string | null;\n snapshot: ExtractionBufferSnapshot;\n nowMs: number;\n metaReadFailed?: boolean;\n metaReadError?: string;\n watermarkPending?: boolean;\n}): ExtractionLivenessStatus {\n const { config, lastExtractionAt, snapshot, nowMs } = input;\n const lastMs = lastExtractionAt !== null ? Date.parse(lastExtractionAt) : Number.NaN;\n const hasWatermark = Number.isFinite(lastMs);\n const ageMs = nowMs - lastMs;\n // A future watermark (negative age) is clock-skewed or corrupt data, not a\n // fresh extraction: treat it as stale so a real backlog stall is not hidden.\n const stale = !hasWatermark || ageMs < 0 || ageMs >= config.staleWindowMs;\n const hasBacklog = snapshot.bufferedSessionCount > 0;\n // A watermark or buffer that cannot be READ is a fault, not an empty queue\n // (§22): a storage/pipeline outage must not read as healthy, and must stay\n // distinct from a pipeline that has genuinely never extracted.\n const metaReadFailed = input.metaReadFailed === true;\n const watermarkPending = input.watermarkPending === true;\n const readFailed = snapshot.readFailed === true;\n const degraded =\n config.enabled && (metaReadFailed || readFailed || (!watermarkPending && hasBacklog && stale));\n\n let degradedReason: string | null = null;\n if (degraded) {\n if (metaReadFailed) {\n degradedReason = `extraction watermark unreadable: ${input.metaReadError ?? \"meta read failed\"}`;\n } else if (readFailed) {\n degradedReason = `extraction buffer unreadable: ${snapshot.readError ?? \"buffer snapshot read failed\"}`;\n } else {\n const watermark = hasWatermark\n ? `last succeeded ${formatAgeMs(nowMs - lastMs)} ago`\n : \"no successful extraction on record\";\n degradedReason =\n `${watermark}; ${snapshot.bufferedSessionCount} buffered session(s), ` +\n `${snapshot.pendingTurnCount} turn(s) pending extraction`;\n }\n }\n\n return {\n lastExtractionAt,\n bufferedSessionCount: snapshot.bufferedSessionCount,\n pendingTurnCount: snapshot.pendingTurnCount,\n oldestBufferedTurnAgeMs: ageMsFrom(snapshot.oldestTurnTimestamp, nowMs),\n degraded,\n degradedReason,\n ...(watermarkPending ? { watermarkPending: true } : {}),\n watermarkScope: \"aggregate\",\n };\n}\n\nconst EMPTY_SNAPSHOT: ExtractionBufferSnapshot = {\n bufferedSessionCount: 0,\n pendingTurnCount: 0,\n oldestTurnTimestamp: null,\n};\n\n/**\n * Read a buffer snapshot without throwing. An ABSENT buffer degrades to an empty\n * (healthy) snapshot — some service constructions have no orchestrator buffer. A\n * buffer that EXISTS but whose read throws yields a `readFailed` snapshot so the\n * verdict can distinguish a pipeline fault from an empty queue (§22).\n */\nasync function readBufferSnapshot(\n buffer: ExtractionBufferSource | undefined,\n): Promise<ExtractionBufferSnapshot> {\n if (!buffer || typeof buffer.getBufferSnapshot !== \"function\") return EMPTY_SNAPSHOT;\n try {\n return await buffer.getBufferSnapshot();\n } catch (err) {\n return {\n ...EMPTY_SNAPSHOT,\n readFailed: true,\n readError: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\n/**\n * Gather the liveness status from an aggregate watermark read and an optional\n * buffer. A read failure on either side is surfaced as a degraded status with a\n * distinct reason rather than swallowed into a healthy-looking verdict.\n */\nexport async function gatherExtractionLivenessStatus(input: {\n config: ExtractionLivenessConfig;\n watermark: ExtractionWatermarkOrStorage;\n buffer: ExtractionBufferSource | undefined;\n nowMs: number;\n}): Promise<ExtractionLivenessStatus> {\n const { config, buffer, nowMs } = input;\n const watermarkRead = await coerceExtractionWatermark(input.watermark);\n const snapshot = await readBufferSnapshot(buffer);\n return evaluateExtractionLiveness({\n config,\n lastExtractionAt: watermarkRead.lastExtractionAt,\n snapshot,\n nowMs,\n metaReadFailed: watermarkRead.readFailed,\n metaReadError: watermarkRead.readError,\n watermarkPending: watermarkRead.pending,\n });\n}\n\n/**\n * Aggregated-WARN throttle (issue #2151): emit at most ONE warning per\n * staleness window while degraded — not one line per failed extraction attempt.\n * State is instance-scoped (held by the owning service), never a module global\n * (§5), so multiple service instances throttle independently.\n */\nexport class ExtractionLivenessWarnThrottle {\n private lastWarnAtMs: number | null = null;\n\n /** Warn if degraded and outside the throttle window; returns whether a WARN was emitted. */\n maybeWarn(status: ExtractionLivenessStatus, staleWindowMs: number, nowMs: number): boolean {\n if (!status.degraded) {\n // Recovered (or never degraded): reset so a fresh episode warns at once.\n this.lastWarnAtMs = null;\n return false;\n }\n if (this.lastWarnAtMs !== null && nowMs - this.lastWarnAtMs < staleWindowMs) return false;\n this.lastWarnAtMs = nowMs;\n log.warn(\n `extraction pipeline liveness degraded: ${status.degradedReason ?? \"buffered turns are not being extracted\"}`,\n );\n return true;\n }\n}\n\n/**\n * Normalize the `extractionLiveness` block at the read boundary. `parseConfig`\n * always populates it, but a host adapter, an older persisted config, or a\n * hand-built `PluginConfig` can hand us an absent, partial, or loosely-typed\n * block - and every liveness surface (/health, doctor, stats) must degrade to\n * the documented default (enabled, 24h window) rather than throw. Both fields\n * are coerced with the same rules as `parseExtractionLivenessConfig` (§24:\n * `\"false\"`/`\"0\"` read as falsy; a numeric string like `\"5000\"` parses), except a\n * present but non-integer or non-positive `staleWindowMs` falls back to the\n * default here rather than throwing.\n */\nexport function resolveExtractionLivenessConfig(\n block: { enabled?: unknown; staleWindowMs?: unknown } | undefined,\n): ExtractionLivenessConfig {\n const staleWindowMs = coerceNumber(block?.staleWindowMs);\n return {\n enabled: coerceBool(block?.enabled) ?? true,\n staleWindowMs:\n staleWindowMs !== undefined && Number.isInteger(staleWindowMs) && staleWindowMs >= 1\n ? staleWindowMs\n : DEFAULT_STALE_WINDOW_MS,\n };\n}\n\n/**\n * Compute the daemon-wide liveness status for the authenticated `/health`\n * payload and emit the throttled aggregate warning.\n */\nexport async function computeExtractionLivenessStatus(\n orchestrator: ExtractionLivenessOrchestratorLike,\n watermark: ExtractionWatermarkOrStorage,\n throttle?: ExtractionLivenessWarnThrottle,\n nowMs: number = Date.now(),\n): Promise<ExtractionLivenessStatus> {\n const config = resolveExtractionLivenessConfig(orchestrator.config.extractionLiveness);\n const status = await gatherExtractionLivenessStatus({\n config,\n watermark,\n buffer: orchestrator.buffer,\n nowMs,\n });\n throttle?.maybeWarn(status, config.staleWindowMs, nowMs);\n // Extraction-LLM availability (#3140): a silent no_models / LLM-unreachable\n // outage must be visible on /health (and doctor/stats) without debug logs.\n return { ...status, ...getExtractionLlmHealth() };\n}\n\n/**\n * `remnic doctor` check for extraction-pipeline liveness. Status `warn` when\n * degraded (with a remediation hint), `ok` otherwise.\n */\nexport async function summarizeExtractionLiveness(\n config: Pick<PluginConfig, \"extractionLiveness\">,\n watermark: ExtractionWatermarkOrStorage,\n buffer?: ExtractionBufferSource,\n nowMs: number = Date.now(),\n): Promise<OperatorDoctorCheck> {\n const livenessConfig = resolveExtractionLivenessConfig(config.extractionLiveness);\n const status = await gatherExtractionLivenessStatus({\n config: livenessConfig,\n watermark,\n buffer,\n nowMs,\n });\n const scopeNote = ` Watermark scope: ${status.watermarkScope}.`;\n const summary =\n (status.degraded\n ? `Extraction pipeline degraded: ${status.degradedReason}.`\n : `Extraction pipeline healthy: last extraction ${status.lastExtractionAt ?? \"never\"}, ` +\n `${status.bufferedSessionCount} buffered session(s), ${status.pendingTurnCount} turn(s) pending` +\n `${livenessConfig.enabled ? \"\" : \" (liveness check disabled)\"}.`) + scopeNote;\n return {\n key: \"extraction_liveness\",\n status: status.degraded ? \"warn\" : \"ok\",\n summary,\n remediation: status.degraded\n ? \"Extraction has stalled while turns are buffered. Inspect daemon logs for extraction \" +\n \"timeouts or fallback-no-parsed-output errors, verify the extraction model/provider is \" +\n \"reachable, then force a flush (e.g. `remnic flush`).\"\n : undefined,\n details: { ...status, staleWindowMs: livenessConfig.staleWindowMs, enabled: livenessConfig.enabled },\n };\n}\n\n/**\n * Lines for `remnic stats`: the aggregate extraction watermark, root metadata\n * counters, buffer backlog, and liveness verdict. Root counter failures render\n * those counters unavailable; the injected aggregate read alone determines\n * watermark liveness so stats cannot diverge from health and doctor.\n */\nexport async function renderExtractionLivenessStats(\n orchestrator: ExtractionLivenessOrchestratorLike,\n watermark: ExtractionWatermarkRead,\n nowMs: number = Date.now(),\n): Promise<string[]> {\n const status = evaluateExtractionLiveness({\n config: resolveExtractionLivenessConfig(orchestrator.config.extractionLiveness),\n lastExtractionAt: watermark.lastExtractionAt,\n snapshot: await readBufferSnapshot(orchestrator.buffer),\n nowMs,\n metaReadFailed: watermark.readFailed,\n metaReadError: watermark.readError,\n watermarkPending: watermark.pending,\n });\n const oldestAge =\n status.oldestBufferedTurnAgeMs !== null ? formatAgeMs(status.oldestBufferedTurnAgeMs) : \"n/a\";\n const rootStats = watermark.rootStats;\n const watermarkDisplay = watermark.readFailed\n ? \"unavailable\"\n : watermark.pending\n ? \"pending\"\n : status.lastExtractionAt ?? \"never\";\n return [\n `Extractions: ${rootStats?.extractionCount ?? \"unavailable\"}`,\n `Last extraction: ${watermarkDisplay}`,\n `Last consolidation: ${rootStats ? rootStats.lastConsolidationAt ?? \"never\" : \"unavailable\"}`,\n `Buffered sessions: ${status.bufferedSessionCount} (${status.pendingTurnCount} turns pending)`,\n `Oldest buffered turn age: ${oldestAge}`,\n `Extraction watermark scope: ${status.watermarkScope}`,\n `Extraction liveness: ${status.degraded ? `DEGRADED — ${status.degradedReason}` : \"ok\"}`,\n ];\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,IAAM,0BAA0B;AAsDhC,eAAsB,0BACpB,WACkC;AAClC,MAAI,aAAa,gBAAgB,aAAa,OAAO,UAAU,eAAe,WAAW;AACvF,WAAO;AAAA,EACT;AACA,MAAI;AACF,QAAI,mBAAkC;AACtC,QAAI,cAAc,aAAa,OAAO,UAAU,aAAa,YAAY;AACvE,YAAM,OAAO,MAAM,UAAU,SAAS;AACtC,yBAAmB,MAAM,oBAAoB;AAAA,IAC/C,WAAW,kBAAkB,aAAa,OAAO,UAAU,iBAAiB,YAAY;AACtF,YAAM,OAAO,MAAM,UAAU,aAAa;AAC1C,yBAAmB,MAAM,oBAAoB;AAAA,IAC/C;AACA,WAAO;AAAA,MACL;AAAA,MACA,YAAY;AAAA,MACZ,WAAW;AAAA,IACb;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