@remnic/core 10.0.194 → 10.0.195
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.
- package/dist/access-admin-ops-surface.js +58 -59
- package/dist/access-cli.js +58 -59
- package/dist/access-cli.js.map +1 -1
- package/dist/access-extraction-force-flush-preempt.js +58 -59
- package/dist/access-extraction-force-flush.js +58 -59
- package/dist/access-http-briefing.js +58 -59
- package/dist/access-http-query.js +58 -59
- package/dist/access-http.js +58 -59
- package/dist/access-identity-continuity-surface.js +58 -59
- package/dist/access-lcm-surface.js +58 -59
- package/dist/access-mcp.js +58 -59
- package/dist/access-observe-write-surface.js +58 -59
- package/dist/access-operations-batch.js +58 -59
- package/dist/access-operations.js +58 -59
- package/dist/access-recall-concurrency.js +58 -59
- package/dist/access-recall-diagnostics.js +2 -2
- package/dist/access-recall-response.js +58 -59
- package/dist/access-recall-surface.js +58 -59
- package/dist/access-service.js +58 -59
- package/dist/active-recall.js +7 -6
- package/dist/active-recall.js.map +1 -1
- package/dist/{auto-sync-BJUAGKI5.js → auto-sync-BEW65FDT.js} +6 -5
- package/dist/{auto-sync-BJUAGKI5.js.map → auto-sync-BEW65FDT.js.map} +1 -1
- package/dist/briefing.js +7 -6
- package/dist/buffer.d.ts +1 -0
- package/dist/buffer.d.ts.map +1 -1
- package/dist/buffer.js +3 -3
- package/dist/calibration.js +5 -4
- package/dist/calibration.js.map +1 -1
- package/dist/causal-consolidation.js +8 -7
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/{chunk-FZU62GIV.js → chunk-2X5I5C3M.js} +27 -10
- package/dist/chunk-2X5I5C3M.js.map +1 -0
- package/dist/{chunk-DYUPSTCV.js → chunk-3EXG2KPK.js} +3 -3
- package/dist/{chunk-FGFU6J26.js → chunk-4FTYKZ77.js} +3 -3
- package/dist/{chunk-4EAVEDLG.js → chunk-4GVSMPBP.js} +8 -8
- package/dist/{chunk-QIPRDRGM.js → chunk-4HEJDVPU.js} +1 -1
- package/dist/chunk-4HEJDVPU.js.map +1 -0
- package/dist/{chunk-EEA2RM4B.js → chunk-4I6A3SDL.js} +2 -2
- package/dist/{chunk-SKJM4PKE.js → chunk-4JI5PPFW.js} +2 -2
- package/dist/{chunk-TDG5NZAZ.js → chunk-65JA7LWV.js} +2 -2
- package/dist/{chunk-3YID7KZ6.js → chunk-6QMKUWXH.js} +2 -2
- package/dist/{chunk-7SOKOEAZ.js → chunk-6RRHTHKQ.js} +2 -2
- package/dist/{chunk-VHQNJW4Q.js → chunk-6W62D4MC.js} +2 -2
- package/dist/{chunk-2QW5HPKU.js → chunk-76LBLH62.js} +35 -28
- package/dist/chunk-76LBLH62.js.map +1 -0
- package/dist/{chunk-NN3LMWKA.js → chunk-7TQ3EDQ3.js} +1 -1
- package/dist/chunk-7TQ3EDQ3.js.map +1 -0
- package/dist/{chunk-KJ65WZHB.js → chunk-A7DIZOTF.js} +2 -2
- package/dist/{chunk-TZ7ZA2LM.js → chunk-AD3JOG2Q.js} +2 -2
- package/dist/{chunk-KZ4BJRGQ.js → chunk-BD26CK6T.js} +2 -2
- package/dist/{chunk-BDFSVUUZ.js → chunk-C3H2QZOZ.js} +2 -1
- package/dist/chunk-C3H2QZOZ.js.map +1 -0
- package/dist/{chunk-7EP4FURO.js → chunk-C72YQM7E.js} +2 -2
- package/dist/{chunk-CJSTQNE5.js → chunk-CTOMDCCA.js} +2 -2
- package/dist/{chunk-PSQ347YP.js → chunk-DSKII2W4.js} +3 -3
- package/dist/{chunk-KOVQZJ27.js → chunk-E7LDTUWK.js} +2 -2
- package/dist/{chunk-SPAKBUJY.js → chunk-EWLMEYLF.js} +2 -2
- package/dist/{chunk-3BICT225.js → chunk-FGNBUUPX.js} +2 -2
- package/dist/{chunk-QZMGZBTF.js → chunk-HBG6CQEX.js} +2 -2
- package/dist/{chunk-FKHXXL42.js → chunk-HD7M55OI.js} +2 -2
- package/dist/{chunk-7V6GNQC2.js → chunk-HINQENZG.js} +2 -2
- package/dist/{chunk-WRVKI6ZO.js → chunk-HLQXSX4F.js} +2 -2
- package/dist/{chunk-T765HQ5U.js → chunk-IIDAN7XJ.js} +2 -2
- package/dist/{chunk-G2MS56KM.js → chunk-IT4G6HTG.js} +2 -2
- package/dist/{chunk-M7Q7Z6V5.js → chunk-JDZ5JPYG.js} +38 -8
- package/dist/chunk-JDZ5JPYG.js.map +1 -0
- package/dist/{chunk-MMRTPH3J.js → chunk-KQYGUFMQ.js} +5 -3
- package/dist/chunk-KQYGUFMQ.js.map +1 -0
- package/dist/{chunk-TWYYUMYO.js → chunk-KXAGZRJV.js} +2 -2
- package/dist/{chunk-JITK24KX.js → chunk-LJNCJK7B.js} +10 -10
- package/dist/{chunk-Z6EFSXU3.js → chunk-LMM2LRVQ.js} +2 -2
- package/dist/{chunk-V65H7MI6.js → chunk-M42UFQZY.js} +51 -4
- package/dist/chunk-M42UFQZY.js.map +1 -0
- package/dist/{chunk-VSLV3EEP.js → chunk-ME63JKWJ.js} +59 -57
- package/dist/{chunk-VSLV3EEP.js.map → chunk-ME63JKWJ.js.map} +1 -1
- package/dist/{chunk-AALJHIKH.js → chunk-OHJ5PNYB.js} +3 -3
- package/dist/{chunk-XZMQLON4.js → chunk-OK726OF4.js} +7 -5
- package/dist/chunk-OK726OF4.js.map +1 -0
- package/dist/{chunk-Q6S67LHR.js → chunk-OOMFFMX3.js} +2 -2
- package/dist/{chunk-VMNX2UV7.js → chunk-Q2GDUJSK.js} +5 -5
- package/dist/{chunk-JNDMIAJ4.js → chunk-QEVZKJM6.js} +2 -2
- package/dist/{chunk-ZNCCX7P6.js → chunk-QW5LZTKA.js} +2 -2
- package/dist/{chunk-5GIYIYJI.js → chunk-QZPAOOU7.js} +2 -2
- package/dist/{chunk-NKHRIDYP.js → chunk-RTXW6E6X.js} +3 -3
- package/dist/{chunk-5WDUY2ZZ.js → chunk-S4QWAWR6.js} +4 -4
- package/dist/{chunk-STSORBX5.js → chunk-SFUS2V2V.js} +1 -1
- package/dist/{chunk-HEJFE3BC.js → chunk-SJCN7ESG.js} +2 -2
- package/dist/{chunk-AJ7JHHRY.js → chunk-SPPWVMP4.js} +2 -2
- package/dist/{chunk-QSF5SJAM.js → chunk-STQNKDKZ.js} +9 -3
- package/dist/chunk-STQNKDKZ.js.map +1 -0
- package/dist/{chunk-QFKNIKUF.js → chunk-SXR7L57Z.js} +2 -2
- package/dist/{chunk-GYCUX3N4.js → chunk-TGMIJABS.js} +2 -2
- package/dist/{chunk-GH7IKABD.js → chunk-UFJJMQDV.js} +2 -2
- package/dist/{chunk-UH2VY2QQ.js → chunk-WCW7I7ZM.js} +2 -2
- package/dist/{chunk-3RZ4GDOH.js → chunk-XDNVWY7I.js} +93 -23
- package/dist/chunk-XDNVWY7I.js.map +1 -0
- package/dist/{chunk-LR6LWX33.js → chunk-XXDIPAUE.js} +2 -2
- package/dist/{chunk-YCJJODER.js → chunk-YCTD3XET.js} +10 -3
- package/dist/chunk-YCTD3XET.js.map +1 -0
- package/dist/{chunk-WEI6HEUX.js → chunk-YXAH5TSN.js} +2 -2
- package/dist/{chunk-75K6DRPN.js → chunk-ZAVFAGBE.js} +2 -2
- package/dist/{chunk-7KTORRIK.js → chunk-ZNJU3NBJ.js} +2 -2
- package/dist/cli.js +58 -59
- package/dist/coding/export-okf-codegraph.js +6 -5
- package/dist/coding/export-okf-codegraph.js.map +1 -1
- package/dist/compounding/engine.js +8 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -6
- package/dist/connectors/codex-materialize-runner.js +7 -6
- package/dist/connectors/index.js +7 -6
- package/dist/convergence-refresh.js +9 -8
- package/dist/corpus-watermark.js +9 -8
- package/dist/deep-recall-policy-llm.js +4 -3
- package/dist/entity-retrieval.js +7 -6
- package/dist/explicit-capture.js +58 -59
- package/dist/extraction-error-classification.d.ts +40 -5
- package/dist/extraction-error-classification.d.ts.map +1 -1
- package/dist/extraction-error-classification.js +5 -2
- package/dist/extraction-faithfulness.js +4 -3
- package/dist/extraction-judge.js +4 -3
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +17 -18
- package/dist/fallback-llm-codex-subscription.d.ts +3 -1
- package/dist/fallback-llm-codex-subscription.d.ts.map +1 -1
- package/dist/fallback-llm-codex-subscription.js +2 -1
- package/dist/fallback-llm.d.ts.map +1 -1
- package/dist/fallback-llm.js +3 -2
- package/dist/harmonic-retrieval.js +7 -6
- package/dist/index.js +58 -59
- package/dist/live-connectors-runner.js +1 -2
- package/dist/local-llm-helpers.d.ts +1 -0
- package/dist/local-llm-helpers.d.ts.map +1 -1
- package/dist/local-llm-helpers.js +1 -1
- package/dist/local-llm.d.ts.map +1 -1
- package/dist/local-llm.js +4 -3
- package/dist/location/index.js +8 -7
- package/dist/maintenance/memory-governance.js +7 -6
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -6
- package/dist/maintenance/rebuild-memory-projection-runner.js +9 -8
- package/dist/maintenance/rebuild-memory-projection.js +8 -7
- package/dist/memory-browse.js +3 -3
- package/dist/namespaces/migrate.js +8 -7
- package/dist/namespaces/storage.js +7 -6
- package/dist/operator-doctor-corpus.js +10 -9
- package/dist/operator-toolkit.js +14 -13
- package/dist/orchestration/backlog-scheduler.js +59 -60
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +59 -60
- package/dist/orchestration/extraction-drain.d.ts +1 -0
- package/dist/orchestration/extraction-drain.d.ts.map +1 -1
- package/dist/orchestration/extraction-run-helpers.d.ts +41 -4
- package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
- package/dist/orchestration/extraction-run.d.ts +4 -0
- package/dist/orchestration/extraction-run.d.ts.map +1 -1
- package/dist/orchestration/maintenance.js +17 -16
- package/dist/orchestrator.js +58 -59
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-navigate-access.js +2 -2
- package/dist/recall-navigate-disclosure.js +2 -2
- package/dist/recall-navigate.js +2 -2
- package/dist/recall-navigation.js +58 -59
- package/dist/recall-planner-llm.js +3 -2
- package/dist/recall-planner-llm.js.map +1 -1
- package/dist/recall-state-view-admission.js +3 -3
- package/dist/recall-why-service.js +3 -3
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.js +2 -2
- package/dist/resume-bundles.js +8 -7
- package/dist/semantic-consolidation.js +8 -7
- package/dist/semantic-rule-promotion.js +7 -6
- package/dist/semantic-rule-verifier.js +7 -6
- package/dist/source-agent-qualifier.js +10 -9
- package/dist/standup/build.js +7 -6
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +6 -5
- package/dist/summarizer.js +6 -5
- package/dist/support-passport/index.js +6 -5
- package/dist/transfer/export-okf.js +7 -6
- package/dist/types-extraction-failure.d.ts +7 -1
- package/dist/types-extraction-failure.d.ts.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +7 -6
- package/dist/who-knows-cli.js +8 -7
- package/dist/who-knows.js +7 -6
- package/package.json +2 -2
- package/src/buffer-incremental-persistence.test.ts +23 -0
- package/src/buffer.ts +30 -28
- package/src/config.ts +2 -0
- package/src/extraction-error-classification.ts +88 -8
- package/src/extraction-local-failure-class.test.ts +117 -3
- package/src/extraction-reply-diagnostic-wiring.test.ts +3 -1
- package/src/extraction.test.ts +73 -3
- package/src/extraction.ts +26 -25
- package/src/fallback-llm-codex-subscription.ts +17 -3
- package/src/fallback-llm.test.ts +70 -0
- package/src/fallback-llm.ts +17 -18
- package/src/local-llm-headers-timeout.test.ts +151 -0
- package/src/local-llm-helpers.ts +1 -1
- package/src/local-llm.ts +44 -43
- package/src/orchestration/extraction-drain.ts +11 -5
- package/src/orchestration/extraction-run-helpers.ts +110 -4
- package/src/orchestration/extraction-run.test.ts +408 -3
- package/src/orchestration/extraction-run.ts +75 -75
- package/src/storage.ts +5 -4
- package/src/types-extraction-failure.ts +12 -1
- package/src/types.ts +6 -6
- package/dist/chunk-2QW5HPKU.js.map +0 -1
- package/dist/chunk-3RZ4GDOH.js.map +0 -1
- package/dist/chunk-BDFSVUUZ.js.map +0 -1
- package/dist/chunk-C7SRUWBW.js +0 -54
- package/dist/chunk-C7SRUWBW.js.map +0 -1
- package/dist/chunk-FZU62GIV.js.map +0 -1
- package/dist/chunk-M7Q7Z6V5.js.map +0 -1
- package/dist/chunk-MMRTPH3J.js.map +0 -1
- package/dist/chunk-NN3LMWKA.js.map +0 -1
- package/dist/chunk-QIPRDRGM.js.map +0 -1
- package/dist/chunk-QSF5SJAM.js.map +0 -1
- package/dist/chunk-V65H7MI6.js.map +0 -1
- package/dist/chunk-XZMQLON4.js.map +0 -1
- package/dist/chunk-YCJJODER.js.map +0 -1
- /package/dist/{chunk-DYUPSTCV.js.map → chunk-3EXG2KPK.js.map} +0 -0
- /package/dist/{chunk-FGFU6J26.js.map → chunk-4FTYKZ77.js.map} +0 -0
- /package/dist/{chunk-4EAVEDLG.js.map → chunk-4GVSMPBP.js.map} +0 -0
- /package/dist/{chunk-EEA2RM4B.js.map → chunk-4I6A3SDL.js.map} +0 -0
- /package/dist/{chunk-SKJM4PKE.js.map → chunk-4JI5PPFW.js.map} +0 -0
- /package/dist/{chunk-TDG5NZAZ.js.map → chunk-65JA7LWV.js.map} +0 -0
- /package/dist/{chunk-3YID7KZ6.js.map → chunk-6QMKUWXH.js.map} +0 -0
- /package/dist/{chunk-7SOKOEAZ.js.map → chunk-6RRHTHKQ.js.map} +0 -0
- /package/dist/{chunk-VHQNJW4Q.js.map → chunk-6W62D4MC.js.map} +0 -0
- /package/dist/{chunk-KJ65WZHB.js.map → chunk-A7DIZOTF.js.map} +0 -0
- /package/dist/{chunk-TZ7ZA2LM.js.map → chunk-AD3JOG2Q.js.map} +0 -0
- /package/dist/{chunk-KZ4BJRGQ.js.map → chunk-BD26CK6T.js.map} +0 -0
- /package/dist/{chunk-7EP4FURO.js.map → chunk-C72YQM7E.js.map} +0 -0
- /package/dist/{chunk-CJSTQNE5.js.map → chunk-CTOMDCCA.js.map} +0 -0
- /package/dist/{chunk-PSQ347YP.js.map → chunk-DSKII2W4.js.map} +0 -0
- /package/dist/{chunk-KOVQZJ27.js.map → chunk-E7LDTUWK.js.map} +0 -0
- /package/dist/{chunk-SPAKBUJY.js.map → chunk-EWLMEYLF.js.map} +0 -0
- /package/dist/{chunk-3BICT225.js.map → chunk-FGNBUUPX.js.map} +0 -0
- /package/dist/{chunk-QZMGZBTF.js.map → chunk-HBG6CQEX.js.map} +0 -0
- /package/dist/{chunk-FKHXXL42.js.map → chunk-HD7M55OI.js.map} +0 -0
- /package/dist/{chunk-7V6GNQC2.js.map → chunk-HINQENZG.js.map} +0 -0
- /package/dist/{chunk-WRVKI6ZO.js.map → chunk-HLQXSX4F.js.map} +0 -0
- /package/dist/{chunk-T765HQ5U.js.map → chunk-IIDAN7XJ.js.map} +0 -0
- /package/dist/{chunk-G2MS56KM.js.map → chunk-IT4G6HTG.js.map} +0 -0
- /package/dist/{chunk-TWYYUMYO.js.map → chunk-KXAGZRJV.js.map} +0 -0
- /package/dist/{chunk-JITK24KX.js.map → chunk-LJNCJK7B.js.map} +0 -0
- /package/dist/{chunk-Z6EFSXU3.js.map → chunk-LMM2LRVQ.js.map} +0 -0
- /package/dist/{chunk-AALJHIKH.js.map → chunk-OHJ5PNYB.js.map} +0 -0
- /package/dist/{chunk-Q6S67LHR.js.map → chunk-OOMFFMX3.js.map} +0 -0
- /package/dist/{chunk-VMNX2UV7.js.map → chunk-Q2GDUJSK.js.map} +0 -0
- /package/dist/{chunk-JNDMIAJ4.js.map → chunk-QEVZKJM6.js.map} +0 -0
- /package/dist/{chunk-ZNCCX7P6.js.map → chunk-QW5LZTKA.js.map} +0 -0
- /package/dist/{chunk-5GIYIYJI.js.map → chunk-QZPAOOU7.js.map} +0 -0
- /package/dist/{chunk-NKHRIDYP.js.map → chunk-RTXW6E6X.js.map} +0 -0
- /package/dist/{chunk-5WDUY2ZZ.js.map → chunk-S4QWAWR6.js.map} +0 -0
- /package/dist/{chunk-STSORBX5.js.map → chunk-SFUS2V2V.js.map} +0 -0
- /package/dist/{chunk-HEJFE3BC.js.map → chunk-SJCN7ESG.js.map} +0 -0
- /package/dist/{chunk-AJ7JHHRY.js.map → chunk-SPPWVMP4.js.map} +0 -0
- /package/dist/{chunk-QFKNIKUF.js.map → chunk-SXR7L57Z.js.map} +0 -0
- /package/dist/{chunk-GYCUX3N4.js.map → chunk-TGMIJABS.js.map} +0 -0
- /package/dist/{chunk-GH7IKABD.js.map → chunk-UFJJMQDV.js.map} +0 -0
- /package/dist/{chunk-UH2VY2QQ.js.map → chunk-WCW7I7ZM.js.map} +0 -0
- /package/dist/{chunk-LR6LWX33.js.map → chunk-XXDIPAUE.js.map} +0 -0
- /package/dist/{chunk-WEI6HEUX.js.map → chunk-YXAH5TSN.js.map} +0 -0
- /package/dist/{chunk-75K6DRPN.js.map → chunk-ZAVFAGBE.js.map} +0 -0
- /package/dist/{chunk-7KTORRIK.js.map → chunk-ZNJU3NBJ.js.map} +0 -0
|
@@ -81,6 +81,9 @@ export interface ExtractionRetryStateEntry {
|
|
|
81
81
|
nextEligibleAtMs: number;
|
|
82
82
|
firstFailedAtMs: number;
|
|
83
83
|
lastFailureClass: ExtractionFailureClass;
|
|
84
|
+
/** Only `provider_permanent` failures count here — transient/setup failures
|
|
85
|
+
* must not consume the terminal-refusal allowance (issue #3757). */
|
|
86
|
+
permanentAttempts?: number;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
export interface ExtractionResilienceStatus {
|
|
@@ -135,16 +138,23 @@ export function computeExtractionRetryNextEligibleMs(
|
|
|
135
138
|
|
|
136
139
|
/**
|
|
137
140
|
* Whether a recorded failure long-parks the fingerprint: `output_truncated`
|
|
138
|
-
* can never succeed at the same output ceiling,
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
+
* can never succeed at the same output ceiling, `parse_empty` past its attempt
|
|
142
|
+
* cap has shown this window unparseable, and `provider_permanent` past its cap
|
|
143
|
+
* normally dead-letters — the park is the fallback when the dead-letter's
|
|
144
|
+
* recovery copy could not be written. The retained window still drains under a
|
|
145
|
+
* raised ceiling (#3521).
|
|
141
146
|
*/
|
|
142
147
|
export function extractionFailureLongParks(
|
|
143
148
|
cls: ExtractionFailureClass,
|
|
144
149
|
attempts: number,
|
|
145
150
|
parseEmptyMaxAttempts: number,
|
|
151
|
+
providerPermanentMaxAttempts: number = parseEmptyMaxAttempts,
|
|
146
152
|
): boolean {
|
|
147
|
-
return
|
|
153
|
+
return (
|
|
154
|
+
cls === "output_truncated" ||
|
|
155
|
+
(cls === "parse_empty" && attempts > parseEmptyMaxAttempts) ||
|
|
156
|
+
(cls === "provider_permanent" && attempts >= providerPermanentMaxAttempts)
|
|
157
|
+
);
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
/**
|
|
@@ -487,3 +497,99 @@ export async function extractChunkedExtraction(
|
|
|
487
497
|
);
|
|
488
498
|
return merged;
|
|
489
499
|
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Dead-letter bound for `provider_permanent` failures (the unbounded
|
|
503
|
+
* remnic-buffer-drain loop): once a fingerprint fails `permanentMaxAttempts`
|
|
504
|
+
* times with a terminal input refusal that a resend can never fix, the retry
|
|
505
|
+
* loop must END — the fingerprint is marked processed so later attempts
|
|
506
|
+
* short-circuit. Same rule as the drain's drop path: a dropped-chunk recovery
|
|
507
|
+
* copy under `state/dropped/` is written first, and if the copy cannot be
|
|
508
|
+
* written the window stays buffered and parked instead of being silently lost.
|
|
509
|
+
* Never throws on a storage failure — the run already holds its failure result.
|
|
510
|
+
*/
|
|
511
|
+
export async function maybeDeadLetterPermanentExtractionFailure(args: {
|
|
512
|
+
readonly recorded: boolean;
|
|
513
|
+
readonly dropAllowed: boolean;
|
|
514
|
+
readonly failureClass: ExtractionFailureClass;
|
|
515
|
+
/** Permanent-refusal count only — transient/setup failures never consume the allowance. */
|
|
516
|
+
readonly permanentAttempts: number;
|
|
517
|
+
readonly permanentMaxAttempts: number;
|
|
518
|
+
readonly storage: StorageManager;
|
|
519
|
+
readonly bufferKey: string;
|
|
520
|
+
readonly turns: readonly BufferTurn[];
|
|
521
|
+
/** In-flight part copy → its buffered source turn (`extractionPartOf` splits). */
|
|
522
|
+
readonly partParents?: ReadonlyMap<BufferTurn, BufferTurn>;
|
|
523
|
+
readonly fingerprint: string;
|
|
524
|
+
readonly clearBufferedTurns: (dropTurns: readonly BufferTurn[]) => Promise<void>;
|
|
525
|
+
readonly recordProcessed: (
|
|
526
|
+
storage: StorageManager,
|
|
527
|
+
fingerprint: string,
|
|
528
|
+
meta: MetaState,
|
|
529
|
+
) => Promise<void>;
|
|
530
|
+
/** Drop the fingerprint from persisted retry state only (inside the meta mutator). */
|
|
531
|
+
readonly clearPersistedRetryEntry: (meta: MetaState) => boolean;
|
|
532
|
+
/** Drop the fingerprint from the in-memory mirror — called only after the save lands. */
|
|
533
|
+
readonly clearRetryMirror: () => void;
|
|
534
|
+
readonly isDeadlineError: (err: Error) => boolean;
|
|
535
|
+
readonly runDeadlineAware: <T>(
|
|
536
|
+
operation: () => Promise<T>,
|
|
537
|
+
phase: string,
|
|
538
|
+
clearTimerOnError?: boolean,
|
|
539
|
+
) => Promise<T>;
|
|
540
|
+
}): Promise<boolean> {
|
|
541
|
+
// No-drop callers (fail-closed flushes, claim drains) retain the window: the
|
|
542
|
+
// permanent failure stays parked for replay rather than silently processed.
|
|
543
|
+
if (!args.recorded || !args.dropAllowed || args.failureClass !== "provider_permanent") return false;
|
|
544
|
+
if (args.permanentAttempts < Math.max(1, args.permanentMaxAttempts)) return false;
|
|
545
|
+
// Split turns: slice copies match nothing buffered, so the drop set is the
|
|
546
|
+
// parents — same rule as the drain's drop path. Dropping only the copies
|
|
547
|
+
// would strand the parent and re-enter the retry cycle forever.
|
|
548
|
+
const dropTurns =
|
|
549
|
+
args.partParents === undefined
|
|
550
|
+
? args.turns
|
|
551
|
+
: [...new Set(args.turns.map((t) => args.partParents?.get(t) ?? t))];
|
|
552
|
+
const reason =
|
|
553
|
+
`dead-lettered after ${args.permanentAttempts} provider_permanent extraction failures ` +
|
|
554
|
+
"(a resend of the identical request cannot succeed)";
|
|
555
|
+
let copyPath: string | null = null;
|
|
556
|
+
try {
|
|
557
|
+
copyPath = await args.runDeadlineAware(
|
|
558
|
+
() => args.storage.saveDroppedExtractionChunk(args.bufferKey, reason, dropTurns),
|
|
559
|
+
"during_dead_letter_copy",
|
|
560
|
+
false,
|
|
561
|
+
);
|
|
562
|
+
} catch (err) {
|
|
563
|
+
if (err instanceof Error && args.isDeadlineError(err)) throw err;
|
|
564
|
+
log.warn(
|
|
565
|
+
"runExtraction: could not save the dead-letter recovery copy; keeping the window buffered and parked",
|
|
566
|
+
err,
|
|
567
|
+
);
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
await args.runDeadlineAware(
|
|
572
|
+
() =>
|
|
573
|
+
args.storage.updateMeta(async (freshMeta) => {
|
|
574
|
+
await args.recordProcessed(args.storage, args.fingerprint, freshMeta);
|
|
575
|
+
args.clearPersistedRetryEntry(freshMeta);
|
|
576
|
+
}),
|
|
577
|
+
"during_dead_letter_mark",
|
|
578
|
+
false,
|
|
579
|
+
);
|
|
580
|
+
// The mirror entry clears only after the save lands: a failed save would
|
|
581
|
+
// otherwise restart the permanent-attempt count at zero in this process
|
|
582
|
+
// while the persisted entry stayed at the cap.
|
|
583
|
+
args.clearRetryMirror();
|
|
584
|
+
} catch (err) {
|
|
585
|
+
if (err instanceof Error && args.isDeadlineError(err)) throw err;
|
|
586
|
+
// Without a durable processed mark the window must stay buffered: clearing
|
|
587
|
+
// it here would let recaptured content reach the provider again after a
|
|
588
|
+
// restart instead of being skipped as processed_fingerprint.
|
|
589
|
+
log.warn("runExtraction: failed to mark dead-lettered fingerprint processed; keeping the window parked", err);
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
log.warn(`runExtraction: ${reason}; recovery copy saved to ${copyPath}`);
|
|
593
|
+
await args.runDeadlineAware(() => args.clearBufferedTurns(dropTurns), "during_dead_letter_clear");
|
|
594
|
+
return true;
|
|
595
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import assert from "node:assert/strict";
|
|
11
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
11
|
+
import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import test from "node:test";
|
|
@@ -88,6 +88,7 @@ const migrationSummary: TierMigrationCycleSummary = {
|
|
|
88
88
|
// ---------------------------------------------------------------------------
|
|
89
89
|
|
|
90
90
|
interface Harness {
|
|
91
|
+
baseDir: string;
|
|
91
92
|
config: PluginConfig;
|
|
92
93
|
buffer: SmartBuffer;
|
|
93
94
|
storageForNs: (ns: string) => Promise<StorageManager>;
|
|
@@ -107,7 +108,7 @@ interface Harness {
|
|
|
107
108
|
run: (
|
|
108
109
|
coord: ExtractionRunCoordinator,
|
|
109
110
|
content: string,
|
|
110
|
-
opts?: { force?: boolean; failClosed?: boolean; writeNamespaceOverride?: string },
|
|
111
|
+
opts?: { force?: boolean; failClosed?: boolean; writeNamespaceOverride?: string; dropFailedChunks?: boolean },
|
|
111
112
|
) => Promise<{ status: string; reason?: string; failureClass?: string; retainedBuffer?: boolean }>;
|
|
112
113
|
cleanup: () => Promise<void>;
|
|
113
114
|
passiveCapture: () => { principal?: string; namespace?: string } | null;
|
|
@@ -202,6 +203,7 @@ async function makeHarness(overrides: Record<string, unknown> = {}): Promise<Har
|
|
|
202
203
|
});
|
|
203
204
|
|
|
204
205
|
return {
|
|
206
|
+
baseDir,
|
|
205
207
|
config,
|
|
206
208
|
buffer,
|
|
207
209
|
storageForNs,
|
|
@@ -246,6 +248,7 @@ async function makeHarness(overrides: Record<string, unknown> = {}): Promise<Har
|
|
|
246
248
|
failOnExtractionFailure: opts.failClosed === true,
|
|
247
249
|
forceExtractionAttempt: opts.force === true,
|
|
248
250
|
writeNamespaceOverride: opts.writeNamespaceOverride,
|
|
251
|
+
dropFailedChunks: opts.dropFailedChunks,
|
|
249
252
|
});
|
|
250
253
|
return { status: result.status, reason: result.reason, failureClass: result.failureClass, retainedBuffer: result.retainedBuffer };
|
|
251
254
|
},
|
|
@@ -943,11 +946,413 @@ test("output_truncated: long-parks on the first failure — a retry at the same
|
|
|
943
946
|
}
|
|
944
947
|
});
|
|
945
948
|
|
|
949
|
+
test("provider_permanent: dead-letters the fingerprint at extractionProviderPermanentMaxAttempts", async () => {
|
|
950
|
+
const h = await makeHarness({
|
|
951
|
+
extractionRetryScheduleMs: [1000],
|
|
952
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
953
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
954
|
+
extractionBreakerFailureThreshold: 100,
|
|
955
|
+
extractionRetryJitterRatio: 0,
|
|
956
|
+
});
|
|
957
|
+
try {
|
|
958
|
+
// Record processed fingerprints into meta so the processed-skip path is exercised.
|
|
959
|
+
h.setFingerprintRecorder(async (_storage, fingerprint, meta) => {
|
|
960
|
+
if (meta === undefined) return; // the dead-letter path always passes a loaded meta
|
|
961
|
+
meta.processedExtractionFingerprints = [
|
|
962
|
+
...(meta.processedExtractionFingerprints ?? []),
|
|
963
|
+
{ fingerprint, observedAt: new Date().toISOString() },
|
|
964
|
+
];
|
|
965
|
+
});
|
|
966
|
+
const coord = h.newCoordinator();
|
|
967
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
968
|
+
await h.run(coord, "fp-1", { force: true }); // attempt 1
|
|
969
|
+
const deadLettered = await h.run(coord, "fp-1", { force: true }); // attempt 2 hits the cap → dead-letter
|
|
970
|
+
assert.notEqual(
|
|
971
|
+
deadLettered.retainedBuffer,
|
|
972
|
+
true,
|
|
973
|
+
"a consumed window is not reported as retained — the drain treats it as drained",
|
|
974
|
+
);
|
|
975
|
+
|
|
976
|
+
const storage = await h.storageForNs("default");
|
|
977
|
+
const meta = await storage.loadMeta();
|
|
978
|
+
assert.equal(
|
|
979
|
+
h.recordedProcessedCount(),
|
|
980
|
+
1,
|
|
981
|
+
"permanent failure past its cap marks the fingerprint processed",
|
|
982
|
+
);
|
|
983
|
+
assert.ok(
|
|
984
|
+
(meta.processedExtractionFingerprints ?? []).length > 0,
|
|
985
|
+
"processed fingerprint persisted to meta",
|
|
986
|
+
);
|
|
987
|
+
assert.equal(
|
|
988
|
+
(meta.extractionRetryState ?? []).length,
|
|
989
|
+
0,
|
|
990
|
+
"a dead-lettered fingerprint leaves no retry entry to resume",
|
|
991
|
+
);
|
|
992
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
993
|
+
const dropped = await readdir(path.join(h.baseDir, "ns-default", "state", "dropped")).catch(
|
|
994
|
+
() => [] as string[],
|
|
995
|
+
);
|
|
996
|
+
assert.ok(dropped.length > 0, "dead-letter saved a dropped-chunk recovery copy");
|
|
997
|
+
// With clearBufferAfterExtraction=false the window stays buffered for the
|
|
998
|
+
// drain's own drop path to remove — termination comes from the processed
|
|
999
|
+
// mark, which the next call observes.
|
|
1000
|
+
const calls = h.engineCalls();
|
|
1001
|
+
const skipped = await h.run(coord, "fp-1");
|
|
1002
|
+
assert.equal(skipped.reason, "processed_fingerprint");
|
|
1003
|
+
assert.equal(h.engineCalls(), calls, "a processed fingerprint never calls extract() again");
|
|
1004
|
+
} finally {
|
|
1005
|
+
await h.cleanup();
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
test("provider_permanent: no-drop callers retain the window — no processed mark, no clear, no copy", async () => {
|
|
1010
|
+
const h = await makeHarness({
|
|
1011
|
+
extractionRetryScheduleMs: [1000],
|
|
1012
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1013
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1014
|
+
extractionBreakerFailureThreshold: 100,
|
|
1015
|
+
extractionRetryJitterRatio: 0,
|
|
1016
|
+
});
|
|
1017
|
+
try {
|
|
1018
|
+
h.setFingerprintRecorder(async (_storage, fingerprint, meta) => {
|
|
1019
|
+
if (meta === undefined) return;
|
|
1020
|
+
meta.processedExtractionFingerprints = [
|
|
1021
|
+
...(meta.processedExtractionFingerprints ?? []),
|
|
1022
|
+
{ fingerprint, observedAt: new Date().toISOString() },
|
|
1023
|
+
];
|
|
1024
|
+
});
|
|
1025
|
+
const coord = h.newCoordinator();
|
|
1026
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1027
|
+
const droppedDir = path.join(h.baseDir, "ns-default", "state", "dropped");
|
|
1028
|
+
|
|
1029
|
+
// Claim-drain policy (dropFailedChunks:false): the cap must NOT dead-letter.
|
|
1030
|
+
await h.run(coord, "fp-nodrop", { force: true, dropFailedChunks: false });
|
|
1031
|
+
const retained = await h.run(coord, "fp-nodrop", { force: true, dropFailedChunks: false });
|
|
1032
|
+
assert.equal(retained.retainedBuffer, true, "no-drop run retains the failed window");
|
|
1033
|
+
assert.equal(h.recordedProcessedCount(), 0, "no-drop path never marks the fingerprint processed");
|
|
1034
|
+
const storage = await h.storageForNs("default");
|
|
1035
|
+
const meta = await storage.loadMeta();
|
|
1036
|
+
assert.ok(
|
|
1037
|
+
(meta.extractionRetryState ?? []).length > 0,
|
|
1038
|
+
"the parked retry entry survives — a retained window keeps retrying per policy",
|
|
1039
|
+
);
|
|
1040
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
1041
|
+
assert.deepEqual(
|
|
1042
|
+
await readdir(droppedDir).catch(() => [] as string[]),
|
|
1043
|
+
[],
|
|
1044
|
+
"no drop happened, so no recovery copy is written",
|
|
1045
|
+
);
|
|
1046
|
+
|
|
1047
|
+
// Fail-closed flush (failOnExtractionFailure): throws after recording; the
|
|
1048
|
+
// window must stay for the caller's replay, never dead-lettered.
|
|
1049
|
+
await assert.rejects(() => h.run(coord, "fp-closed", { force: true, failClosed: true }));
|
|
1050
|
+
await assert.rejects(() => h.run(coord, "fp-closed", { force: true, failClosed: true }));
|
|
1051
|
+
assert.equal(h.recordedProcessedCount(), 0, "fail-closed path never marks the fingerprint processed");
|
|
1052
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
1053
|
+
assert.deepEqual(
|
|
1054
|
+
await readdir(droppedDir).catch(() => [] as string[]),
|
|
1055
|
+
[],
|
|
1056
|
+
"fail-closed path writes no recovery copy — the caller still owns the window",
|
|
1057
|
+
);
|
|
1058
|
+
} finally {
|
|
1059
|
+
await h.cleanup();
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
test("provider_permanent: dead-letter recovery copy preserves the original cleared turns", async () => {
|
|
1064
|
+
const h = await makeHarness({
|
|
1065
|
+
extractionRetryScheduleMs: [1000],
|
|
1066
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1067
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1068
|
+
extractionBreakerFailureThreshold: 100,
|
|
1069
|
+
extractionRetryJitterRatio: 0,
|
|
1070
|
+
extractionMaxTurnChars: 20,
|
|
1071
|
+
});
|
|
1072
|
+
try {
|
|
1073
|
+
h.setFingerprintRecorder(async (_storage, fingerprint, meta) => {
|
|
1074
|
+
if (meta === undefined) return;
|
|
1075
|
+
meta.processedExtractionFingerprints = [
|
|
1076
|
+
...(meta.processedExtractionFingerprints ?? []),
|
|
1077
|
+
{ fingerprint, observedAt: new Date().toISOString() },
|
|
1078
|
+
];
|
|
1079
|
+
});
|
|
1080
|
+
const coord = h.newCoordinator();
|
|
1081
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1082
|
+
const tail = "x".repeat(200); // trimmed to 20 chars for extraction, but cleared in full
|
|
1083
|
+
// SAFETY: the literal turns satisfy BufferTurn's structural fields for this harness.
|
|
1084
|
+
const turns = [
|
|
1085
|
+
{ role: "user", content: `u:fp-full-${tail}`, timestamp: "2026-07-15T00:00:00Z", persistProcessedFingerprint: true },
|
|
1086
|
+
{ role: "assistant", content: `a:fp-full-${tail}`, timestamp: "2026-07-15T00:00:01Z", persistProcessedFingerprint: true },
|
|
1087
|
+
{ role: "user", content: "context-only turn", timestamp: "2026-07-15T00:00:02Z", extractionContextOnly: true, persistProcessedFingerprint: true },
|
|
1088
|
+
] as BufferTurn[];
|
|
1089
|
+
const runOpts = {
|
|
1090
|
+
skipCharThreshold: true, skipUserTurnThreshold: true, clearBufferAfterExtraction: false,
|
|
1091
|
+
bufferKey: "fp-full", failOnExtractionFailure: false, forceExtractionAttempt: true,
|
|
1092
|
+
};
|
|
1093
|
+
await coord.runExtraction(turns, runOpts);
|
|
1094
|
+
await coord.runExtraction(turns, runOpts); // attempt 2 hits the cap → dead-letter
|
|
1095
|
+
|
|
1096
|
+
const droppedDir = path.join(h.baseDir, "ns-default", "state", "dropped");
|
|
1097
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
1098
|
+
const dropped = await readdir(droppedDir).catch(() => [] as string[]);
|
|
1099
|
+
assert.equal(dropped.length, 1, "exactly one recovery copy was written");
|
|
1100
|
+
const payload = JSON.parse(await readFile(path.join(droppedDir, dropped[0]), "utf8"));
|
|
1101
|
+
assert.equal(payload.turns.length, 3, "recovery copy keeps every cleared turn — context-only included");
|
|
1102
|
+
assert.ok(
|
|
1103
|
+
payload.turns[0].content.endsWith(tail),
|
|
1104
|
+
"recovery copy keeps the untrimmed tail beyond extractionMaxTurnChars",
|
|
1105
|
+
);
|
|
1106
|
+
assert.ok(
|
|
1107
|
+
payload.turns.some((t: BufferTurn) => t.extractionContextOnly === true),
|
|
1108
|
+
"context-only turns are preserved in the recovery copy",
|
|
1109
|
+
);
|
|
1110
|
+
} finally {
|
|
1111
|
+
await h.cleanup();
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
test("provider_permanent: transient attempts never consume the permanent-refusal allowance", async () => {
|
|
1116
|
+
const h = await makeHarness({
|
|
1117
|
+
extractionRetryScheduleMs: [1000],
|
|
1118
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1119
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1120
|
+
extractionBreakerFailureThreshold: 100,
|
|
1121
|
+
extractionRetryJitterRatio: 0,
|
|
1122
|
+
});
|
|
1123
|
+
try {
|
|
1124
|
+
h.setFingerprintRecorder(async (_storage, fingerprint, meta) => {
|
|
1125
|
+
if (meta === undefined) return;
|
|
1126
|
+
meta.processedExtractionFingerprints = [
|
|
1127
|
+
...(meta.processedExtractionFingerprints ?? []),
|
|
1128
|
+
{ fingerprint, observedAt: new Date().toISOString() },
|
|
1129
|
+
];
|
|
1130
|
+
});
|
|
1131
|
+
const coord = h.newCoordinator();
|
|
1132
|
+
// Two transient failures first — total attempts reach the cap early, but
|
|
1133
|
+
// only provider_permanent failures may consume the dead-letter allowance.
|
|
1134
|
+
h.setRespond(() => failureResult("provider_retryable"));
|
|
1135
|
+
await h.run(coord, "fp-mix", { force: true });
|
|
1136
|
+
await h.run(coord, "fp-mix", { force: true });
|
|
1137
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1138
|
+
await h.run(coord, "fp-mix", { force: true }); // total attempts 3 > cap 2, permanentAttempts 1
|
|
1139
|
+
assert.equal(h.recordedProcessedCount(), 0, "one permanent refusal never dead-letters at the cap");
|
|
1140
|
+
const storage = await h.storageForNs("default");
|
|
1141
|
+
const meta = await storage.loadMeta();
|
|
1142
|
+
assert.equal(
|
|
1143
|
+
(meta.extractionRetryState ?? [])[0]?.permanentAttempts,
|
|
1144
|
+
1,
|
|
1145
|
+
"the persisted entry counts permanent refusals separately",
|
|
1146
|
+
);
|
|
1147
|
+
await h.run(coord, "fp-mix", { force: true }); // permanentAttempts 2 hits the cap → dead-letter
|
|
1148
|
+
assert.equal(h.recordedProcessedCount(), 1, "the second permanent refusal dead-letters");
|
|
1149
|
+
} finally {
|
|
1150
|
+
await h.cleanup();
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
test("provider_permanent: the cap-reaching failure long-parks when the recovery copy cannot be written", async () => {
|
|
1155
|
+
const h = await makeHarness({
|
|
1156
|
+
extractionRetryScheduleMs: [1000],
|
|
1157
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1158
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1159
|
+
extractionBreakerFailureThreshold: 100,
|
|
1160
|
+
extractionRetryJitterRatio: 0,
|
|
1161
|
+
});
|
|
1162
|
+
try {
|
|
1163
|
+
const coord = h.newCoordinator();
|
|
1164
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1165
|
+
const storage = await h.storageForNs("default");
|
|
1166
|
+
storage.saveDroppedExtractionChunk = async () => {
|
|
1167
|
+
throw new Error("disk full");
|
|
1168
|
+
};
|
|
1169
|
+
await h.run(coord, "fp-nocopy", { force: true });
|
|
1170
|
+
await h.run(coord, "fp-nocopy", { force: true }); // permanentAttempts 2 = cap: long-park even though the copy failed
|
|
1171
|
+
const meta = await storage.loadMeta();
|
|
1172
|
+
const entry = (meta.extractionRetryState ?? [])[0];
|
|
1173
|
+
assert.ok(entry, "the retry entry survives a failed recovery copy");
|
|
1174
|
+
const delta = Date.parse(entry.nextEligibleAt) - Date.now();
|
|
1175
|
+
assert.ok(
|
|
1176
|
+
delta > 8_000_000,
|
|
1177
|
+
`cap-reaching failure long-parks (~maxBackoff), got ${Math.round(delta / 1000)}s`,
|
|
1178
|
+
);
|
|
1179
|
+
const calls = h.engineCalls();
|
|
1180
|
+
await h.run(coord, "fp-nocopy");
|
|
1181
|
+
assert.equal(h.engineCalls(), calls, "the parked window suppresses provider calls");
|
|
1182
|
+
} finally {
|
|
1183
|
+
await h.cleanup();
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
test("provider_permanent: a failed processed-mark save keeps the retry cap in memory", async () => {
|
|
1188
|
+
const h = await makeHarness({
|
|
1189
|
+
extractionRetryScheduleMs: [1000],
|
|
1190
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1191
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1192
|
+
extractionBreakerFailureThreshold: 100,
|
|
1193
|
+
extractionRetryJitterRatio: 0,
|
|
1194
|
+
});
|
|
1195
|
+
try {
|
|
1196
|
+
const coord = h.newCoordinator();
|
|
1197
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1198
|
+
const storage = await h.storageForNs("default");
|
|
1199
|
+
const realUpdateMeta = storage.updateMeta.bind(storage);
|
|
1200
|
+
let updateCalls = 0;
|
|
1201
|
+
// The third meta write is the dead-letter mark: run the mutator, then fail
|
|
1202
|
+
// the save — the mirror entry must survive so the cap still applies.
|
|
1203
|
+
storage.updateMeta = async (mutate) => {
|
|
1204
|
+
updateCalls += 1;
|
|
1205
|
+
if (updateCalls === 3) {
|
|
1206
|
+
await mutate(await storage.loadMeta());
|
|
1207
|
+
throw new Error("disk full");
|
|
1208
|
+
}
|
|
1209
|
+
return realUpdateMeta(mutate);
|
|
1210
|
+
};
|
|
1211
|
+
await h.run(coord, "fp-save", { force: true });
|
|
1212
|
+
await h.run(coord, "fp-save", { force: true }); // cap → dead-letter; mark save fails
|
|
1213
|
+
const calls = h.engineCalls();
|
|
1214
|
+
await h.run(coord, "fp-save");
|
|
1215
|
+
assert.equal(
|
|
1216
|
+
h.engineCalls(),
|
|
1217
|
+
calls,
|
|
1218
|
+
"the cap survives a failed mark save — the attempt count does not restart at zero",
|
|
1219
|
+
);
|
|
1220
|
+
} finally {
|
|
1221
|
+
await h.cleanup();
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
test("provider_permanent: a dead-lettered split chunk drops its buffered parent turn", async () => {
|
|
1226
|
+
const h = await makeHarness({
|
|
1227
|
+
extractionRetryScheduleMs: [1000],
|
|
1228
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1229
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1230
|
+
extractionBreakerFailureThreshold: 100,
|
|
1231
|
+
extractionRetryJitterRatio: 0,
|
|
1232
|
+
});
|
|
1233
|
+
try {
|
|
1234
|
+
const coord = h.newCoordinator();
|
|
1235
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1236
|
+
// SAFETY: the literal turns satisfy BufferTurn's structural fields for this harness.
|
|
1237
|
+
const parent = {
|
|
1238
|
+
role: "user", content: `parent-full-content-${"p".repeat(300)}`,
|
|
1239
|
+
timestamp: "2026-07-15T00:00:00Z", persistProcessedFingerprint: true,
|
|
1240
|
+
} as BufferTurn;
|
|
1241
|
+
// SAFETY: the literal slice turn satisfies BufferTurn's structural fields for this harness.
|
|
1242
|
+
const slice = {
|
|
1243
|
+
role: "user", content: "parent-full-content-ppppp",
|
|
1244
|
+
timestamp: "2026-07-15T00:00:00Z",
|
|
1245
|
+
extractionPartOf: { part: 1, of: 1 }, persistProcessedFingerprint: true,
|
|
1246
|
+
} as BufferTurn;
|
|
1247
|
+
const partParents = new Map<BufferTurn, BufferTurn>([[slice, parent]]);
|
|
1248
|
+
const clearedSets: BufferTurn[][] = [];
|
|
1249
|
+
h.buffer.clearAfterExtraction = async (_key, ts) => {
|
|
1250
|
+
clearedSets.push([...(ts ?? [])]);
|
|
1251
|
+
};
|
|
1252
|
+
const runOpts = {
|
|
1253
|
+
skipCharThreshold: true, skipUserTurnThreshold: true, clearBufferAfterExtraction: true,
|
|
1254
|
+
bufferKey: "fp-split", forceExtractionAttempt: true, partParents,
|
|
1255
|
+
};
|
|
1256
|
+
await coord.runExtraction([slice], runOpts);
|
|
1257
|
+
await coord.runExtraction([slice], runOpts); // permanentAttempts 2 → dead-letter
|
|
1258
|
+
const lastClear = clearedSets.at(-1);
|
|
1259
|
+
assert.equal(lastClear?.length, 1, "the dead-letter clears exactly one buffered turn");
|
|
1260
|
+
assert.equal(
|
|
1261
|
+
lastClear?.[0],
|
|
1262
|
+
parent,
|
|
1263
|
+
"the drop set is the buffered parent — slice copies match nothing and would strand it",
|
|
1264
|
+
);
|
|
1265
|
+
const droppedDir = path.join(h.baseDir, "ns-default", "state", "dropped");
|
|
1266
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
1267
|
+
const dropped = await readdir(droppedDir).catch(() => [] as string[]);
|
|
1268
|
+
assert.equal(dropped.length, 1, "one recovery copy written for the dead-lettered parent");
|
|
1269
|
+
const payload = JSON.parse(await readFile(path.join(droppedDir, dropped[0]), "utf8"));
|
|
1270
|
+
assert.equal(
|
|
1271
|
+
payload.turns[0]?.content,
|
|
1272
|
+
parent.content,
|
|
1273
|
+
"the recovery copy holds the parent's full content, not the slice",
|
|
1274
|
+
);
|
|
1275
|
+
} finally {
|
|
1276
|
+
await h.cleanup();
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
|
|
1280
|
+
test("provider_permanent: dead-letter clears pass dropRetainedTurns so deferred copies die with the window", async () => {
|
|
1281
|
+
const h = await makeHarness({
|
|
1282
|
+
extractionRetryScheduleMs: [1000],
|
|
1283
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1284
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1285
|
+
extractionBreakerFailureThreshold: 100,
|
|
1286
|
+
extractionRetryJitterRatio: 0,
|
|
1287
|
+
});
|
|
1288
|
+
try {
|
|
1289
|
+
const coord = h.newCoordinator();
|
|
1290
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1291
|
+
const clearOpts: Array<{ dropRetainedTurns?: boolean } | undefined> = [];
|
|
1292
|
+
h.buffer.clearAfterExtraction = async (_key, _ts, opts) => {
|
|
1293
|
+
clearOpts.push(opts);
|
|
1294
|
+
};
|
|
1295
|
+
const runOpts = {
|
|
1296
|
+
skipCharThreshold: true, skipUserTurnThreshold: true, clearBufferAfterExtraction: true,
|
|
1297
|
+
bufferKey: "fp-retained", forceExtractionAttempt: true,
|
|
1298
|
+
};
|
|
1299
|
+
// SAFETY: the literal turn satisfies BufferTurn's structural fields for this harness.
|
|
1300
|
+
const turn = { role: "user", content: "x", timestamp: "2026-07-15T00:00:00Z" } as BufferTurn;
|
|
1301
|
+
await coord.runExtraction([turn], runOpts);
|
|
1302
|
+
await coord.runExtraction([turn], runOpts); // permanentAttempts 2 → dead-letter
|
|
1303
|
+
const last = clearOpts.at(-1);
|
|
1304
|
+
assert.ok(last !== undefined, "the dead-letter ran a buffer clear");
|
|
1305
|
+
assert.equal(last.dropRetainedTurns, true, "the dead-letter also drops retained (judge-deferred) turns");
|
|
1306
|
+
} finally {
|
|
1307
|
+
await h.cleanup();
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
test("provider_permanent: a failed processed-mark keeps the window parked — no clear, still retained", async () => {
|
|
1312
|
+
const h = await makeHarness({
|
|
1313
|
+
extractionRetryScheduleMs: [1000],
|
|
1314
|
+
extractionRetryMaxBackoffMs: 9_000_000,
|
|
1315
|
+
extractionProviderPermanentMaxAttempts: 2,
|
|
1316
|
+
extractionBreakerFailureThreshold: 100,
|
|
1317
|
+
extractionRetryJitterRatio: 0,
|
|
1318
|
+
});
|
|
1319
|
+
try {
|
|
1320
|
+
h.setFingerprintRecorder(() => {
|
|
1321
|
+
throw new Error("meta save failed");
|
|
1322
|
+
});
|
|
1323
|
+
const coord = h.newCoordinator();
|
|
1324
|
+
h.setRespond(() => failureResult("provider_permanent"));
|
|
1325
|
+
const clearSets: BufferTurn[][] = [];
|
|
1326
|
+
h.buffer.clearAfterExtraction = async (_key, ts) => {
|
|
1327
|
+
clearSets.push([...(ts ?? [])]);
|
|
1328
|
+
};
|
|
1329
|
+
await h.run(coord, "fp-unsaved", { force: true }); // attempt 1
|
|
1330
|
+
const res = await h.run(coord, "fp-unsaved", { force: true }); // attempt 2 → copy saved, meta mark fails
|
|
1331
|
+
assert.equal(res.retainedBuffer, true, "an unsaved processed mark keeps the window parked for a later pass");
|
|
1332
|
+
assert.equal(clearSets.length, 0, "no buffer clear without a durable processed mark");
|
|
1333
|
+
assert.equal(h.recordedProcessedCount(), 1, "the dead-letter attempted the processed mark");
|
|
1334
|
+
const meta = await (await h.storageForNs("default")).loadMeta();
|
|
1335
|
+
assert.equal(
|
|
1336
|
+
(meta.processedExtractionFingerprints ?? []).length,
|
|
1337
|
+
0,
|
|
1338
|
+
"the failed mark left nothing persisted in meta",
|
|
1339
|
+
);
|
|
1340
|
+
// The recovery copy still landed — the next dead-letter pass rewrites it.
|
|
1341
|
+
// SAFETY: a missing dropped/ dir reads as an empty name list.
|
|
1342
|
+
const dropped = await readdir(path.join(h.baseDir, "ns-default", "state", "dropped")).catch(
|
|
1343
|
+
() => [] as string[],
|
|
1344
|
+
);
|
|
1345
|
+
assert.equal(dropped.length, 1, "recovery copy saved even though the processed mark failed");
|
|
1346
|
+
} finally {
|
|
1347
|
+
await h.cleanup();
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
|
|
946
1351
|
test("invariant: a failing extraction never records a processed fingerprint", async () => {
|
|
947
1352
|
const h = await makeHarness({ extractionBreakerFailureThreshold: 100 });
|
|
948
1353
|
try {
|
|
949
1354
|
const coord = h.newCoordinator();
|
|
950
|
-
for (const cls of ["provider_retryable", "parse_empty", "output_truncated", "auth_config"] as const) {
|
|
1355
|
+
for (const cls of ["provider_retryable", "parse_empty", "output_truncated", "auth_config", "provider_permanent"] as const) {
|
|
951
1356
|
h.setRespond(() => failureResult(cls));
|
|
952
1357
|
await h.run(coord, `fp-${cls}`, { force: true });
|
|
953
1358
|
}
|