@remnic/core 10.0.193 → 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-UAEJKURK.js → chunk-ME63JKWJ.js} +61 -59
- package/dist/{chunk-UAEJKURK.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-ODI4K32P.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-persist-failure.d.ts +0 -2
- package/dist/orchestration/extraction-persist-failure.d.ts.map +1 -1
- package/dist/orchestration/extraction-persist.d.ts +6 -2
- package/dist/orchestration/extraction-persist.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-persist-declaration.test.ts +35 -0
- package/src/orchestration/extraction-persist-failure.ts +0 -3
- package/src/orchestration/extraction-persist.ts +3 -3
- 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-ODI4K32P.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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtractionFailureClass, ExtractionResult } from "./types.js";
|
|
2
|
-
import { isTransientHttpError } from "./connectors/live/transient-errors.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Read a numeric HTTP status off a thrown error without re-implementing the
|
|
@@ -16,22 +15,91 @@ function httpStatusFromError(err: unknown): number | undefined {
|
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Map a thrown extraction error to a coarse failure class for the retry/breaker
|
|
19
|
-
* layer.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* layer. Never throws.
|
|
19
|
+
*
|
|
20
|
+
* - 401/403 → `auth_config` (misconfigured provider, open the breaker).
|
|
21
|
+
* - transient (429/5xx/network, per the shared `isTransientHttpError`) →
|
|
22
|
+
* `provider_retryable` (back off; a provider that comes back drains the window).
|
|
23
|
+
* - a terminal status that refuses THIS input (400/413/422 — the same droppable
|
|
24
|
+
* set `localRejectionStatus` uses) → `provider_permanent`: a resend of the
|
|
25
|
+
* identical request can never succeed, so the fingerprint dead-letters after
|
|
26
|
+
* `extractionProviderPermanentMaxAttempts` instead of looping the drain forever.
|
|
27
|
+
* EXCEPTION: a 400 that refuses a request PARAMETER (`unsupported parameter:
|
|
28
|
+
* temperature`, `unknown field`, `…not supported with this model`) is the
|
|
29
|
+
* setup's problem — the identical request fails for every future window, so
|
|
30
|
+
* it is `auth_config` (retained), not the chunk's.
|
|
31
|
+
* - any other terminal status (404/405/410/…) → `auth_config`: a missing route or
|
|
32
|
+
* model is the endpoint setup's problem, not the chunk's — innocent windows are
|
|
33
|
+
* never dropped for it.
|
|
34
|
+
* - no status and not transient → `provider_retryable` (unknown failure; fail
|
|
35
|
+
* open toward retry rather than silently dead-lettering a buffered window).
|
|
23
36
|
*/
|
|
24
37
|
export function classifyExtractionThrownError(err: unknown): ExtractionFailureClass {
|
|
25
38
|
try {
|
|
26
39
|
const status = httpStatusFromError(err);
|
|
27
40
|
if (status === 401 || status === 403) return "auth_config";
|
|
28
|
-
|
|
41
|
+
// A recognized status resolves retryability directly: `isTransientHttpError`
|
|
42
|
+
// cannot read every status property name (e.g. `statusCode`), so deferring to
|
|
43
|
+
// it would mis-bucket terminal local statuses (404/405/410) as retryable.
|
|
44
|
+
if (status !== undefined) {
|
|
45
|
+
if (status === 400 && isParameterConfigRejection(err)) return "auth_config";
|
|
46
|
+
if (status === 400 || status === 413 || status === 422) {
|
|
47
|
+
// A permanent-looking refusal alongside a transient sibling attempt is
|
|
48
|
+
// not conclusive proof the window is unextractable — retry under the
|
|
49
|
+
// drain's own bound instead of dead-lettering (#3757).
|
|
50
|
+
return err instanceof Object && "transientAttemptSeen" in err && err.transientAttemptSeen === true
|
|
51
|
+
? "provider_retryable"
|
|
52
|
+
: "provider_permanent";
|
|
53
|
+
}
|
|
54
|
+
return status === 408 || status === 429 || status >= 500 ? "provider_retryable" : "auth_config";
|
|
55
|
+
}
|
|
29
56
|
return "provider_retryable";
|
|
30
57
|
} catch {
|
|
31
58
|
return "provider_retryable";
|
|
32
59
|
}
|
|
33
60
|
}
|
|
34
61
|
|
|
62
|
+
/**
|
|
63
|
+
* A refusal that classifies `provider_permanent` is inconclusive when a
|
|
64
|
+
* transient attempt was seen elsewhere in the request chain (a timeout/5xx
|
|
65
|
+
* primary before a 400 gateway refusal proves nothing about the window) —
|
|
66
|
+
* downgrade it to `provider_retryable` so the drain's own bound applies
|
|
67
|
+
* instead of the dead-letter cap (#3757).
|
|
68
|
+
*/
|
|
69
|
+
export function downgradePermanentOnTransientAttempt(cls: ExtractionFailureClass, transientAttemptSeen: boolean): ExtractionFailureClass {
|
|
70
|
+
return transientAttemptSeen && cls === "provider_permanent" ? "provider_retryable" : cls;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Provider error codes that name a rejected request parameter rather than the payload. `http_4xx_parameter` is the fallback transport's own token. */
|
|
74
|
+
const PARAMETER_CONFIG_CODE =
|
|
75
|
+
/^(?:unsupported_parameter|unsupported_value|unknown_parameter|invalid_parameter|parameter_not_supported|http_4xx_parameter)$/i;
|
|
76
|
+
/** Provider message shapes that blame the request shape/setup, not the content. `value` is deliberately not a subject — a content refusal like `unexpected value in messages[0].content` must stay an input refusal, not park the window as a config problem (#3757). */
|
|
77
|
+
const PARAMETER_CONFIG_MESSAGE =
|
|
78
|
+
/(?:unsupported|unknown|unexpected|unrecognized) (?:parameter|param|field|option)\b|not supported (?:with|for|by) this model|additional propert(?:y|ies) (?:are )?not allowed/i;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* True when a provider 400 refuses the request's configuration — an unsupported
|
|
82
|
+
* or unknown parameter/field (`temperature` on a model that forbids it, an
|
|
83
|
+
* extra property the schema rejects) — rather than this input. Reads `code`,
|
|
84
|
+
* `type`, `errorClass`, a nested `error.code`, and the message; never throws.
|
|
85
|
+
* An ambiguous 400 stays an input refusal, so genuinely refused content still
|
|
86
|
+
* dead-letters instead of parking the drain forever.
|
|
87
|
+
*/
|
|
88
|
+
export function isParameterConfigRejection(cause: unknown): boolean {
|
|
89
|
+
try {
|
|
90
|
+
if (!(cause instanceof Object)) return false;
|
|
91
|
+
if ("code" in cause && PARAMETER_CONFIG_CODE.test(String(cause.code))) return true;
|
|
92
|
+
if ("type" in cause && PARAMETER_CONFIG_CODE.test(String(cause.type))) return true;
|
|
93
|
+
if ("errorClass" in cause && PARAMETER_CONFIG_CODE.test(String(cause.errorClass))) return true;
|
|
94
|
+
const nested = "error" in cause && cause.error instanceof Object ? cause.error : undefined;
|
|
95
|
+
if (nested && "code" in nested && PARAMETER_CONFIG_CODE.test(String(nested.code))) return true;
|
|
96
|
+
const msg = "message" in cause ? String(cause.message) : undefined;
|
|
97
|
+
return msg !== undefined && PARAMETER_CONFIG_MESSAGE.test(msg);
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
35
103
|
const CONTEXT_LIMIT_MESSAGE = /maximum context|context length|context window|request entity/i;
|
|
36
104
|
const SIZE_LIMIT_PHRASE = /too large|too long|exceed/i;
|
|
37
105
|
const INPUT_SUBJECT_TERM =
|
|
@@ -153,7 +221,7 @@ export function formatExtractionParseFailureLog(input: {
|
|
|
153
221
|
* chunk that keeps drawing it is dropped after its recovery copy is saved.
|
|
154
222
|
*/
|
|
155
223
|
export class LocalLlmRejectedError extends Error {
|
|
156
|
-
constructor(readonly httpStatus?: number, readonly finishReason?: string) {
|
|
224
|
+
constructor(readonly httpStatus?: number, readonly finishReason?: string, readonly parameterRefusal?: boolean, readonly sawTransientAttempt?: boolean) {
|
|
157
225
|
super(httpStatus === undefined ? "local LLM answered with unusable content" : `local LLM rejected the input (HTTP ${httpStatus})`);
|
|
158
226
|
this.name = "LocalLlmRejectedError";
|
|
159
227
|
}
|
|
@@ -166,7 +234,17 @@ export class LocalLlmRejectedError extends Error {
|
|
|
166
234
|
* or refused reply stays `parse_empty`.
|
|
167
235
|
*/
|
|
168
236
|
export function classifyLocalLlmRejected(err: LocalLlmRejectedError): ExtractionFailureClass {
|
|
169
|
-
|
|
237
|
+
if (err.finishReason === "length") return "output_truncated";
|
|
238
|
+
// A 400 that refuses a request PARAMETER is the endpoint setup's problem, not
|
|
239
|
+
// the chunk's — retain it parked instead of dead-lettering valid turns.
|
|
240
|
+
if (err.parameterRefusal) return "auth_config";
|
|
241
|
+
// A status-bearing rejection after a transient sibling attempt is inconclusive:
|
|
242
|
+
// the window is not proven unextractable, so it stays retryable (#3757).
|
|
243
|
+
if (err.sawTransientAttempt === true && err.httpStatus !== undefined) return "provider_retryable";
|
|
244
|
+
// A status-bearing rejection refuses THIS input (400/413/422 — `localRejectionStatus`
|
|
245
|
+
// already filtered the droppable set): dead-letter at the permanent cap instead
|
|
246
|
+
// of parking at the parse_empty cap. Only the statusless unusable reply stays parse_empty.
|
|
247
|
+
return err.httpStatus !== undefined ? "provider_permanent" : "parse_empty";
|
|
170
248
|
}
|
|
171
249
|
|
|
172
250
|
/** What the local client recorded about a failed call (`failureDiag`). */
|
|
@@ -174,6 +252,8 @@ export interface LocalFailureDiag {
|
|
|
174
252
|
lastError?: unknown;
|
|
175
253
|
/** The completion's `finish_reason` as the client received it (validated before it is logged). */
|
|
176
254
|
finishReason?: string;
|
|
255
|
+
/** A transient attempt (timeout, network error, 408/429/5xx) was consumed inside the local retry loop before the final failure. */
|
|
256
|
+
sawTransientAttempt?: boolean;
|
|
177
257
|
}
|
|
178
258
|
|
|
179
259
|
/** The HTTP status when the local endpoint answered and refuses this input (400, 413, 422); else undefined. A wrong model name or route (404, 405, 410), auth, timeout and rate limiting are the setup's problem, not the chunk's. */
|
|
@@ -3,6 +3,7 @@ import test from "node:test";
|
|
|
3
3
|
|
|
4
4
|
import { parseConfig } from "./config.js";
|
|
5
5
|
import { ExtractionEngine } from "./extraction.js";
|
|
6
|
+
import { LocalLlmRejectedError } from "./extraction-error-classification.js";
|
|
6
7
|
import type { BufferTurn } from "./types.js";
|
|
7
8
|
|
|
8
9
|
// Follow-up to #3266: the trigger drain drops a chunk after N failures, but not for an outage. Whether a local-model failure
|
|
@@ -13,7 +14,7 @@ const TURNS: BufferTurn[] = [
|
|
|
13
14
|
];
|
|
14
15
|
|
|
15
16
|
type LocalMessages = Array<{ role: string; content: string }>;
|
|
16
|
-
type LocalStub = (messages: LocalMessages, options: { failureDiag?: { lastError?: Error } }) => Promise<{ content: string } | null>;
|
|
17
|
+
type LocalStub = (messages: LocalMessages, options: { failureDiag?: { lastError?: Error; sawTransientAttempt?: boolean } }) => Promise<{ content: string } | null>;
|
|
17
18
|
|
|
18
19
|
async function extractWith(local: LocalStub) {
|
|
19
20
|
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: false }));
|
|
@@ -31,13 +32,15 @@ test("a local endpoint that answers with something unusable rejects the chunk: p
|
|
|
31
32
|
assert.equal(result.extractionFailureClass, "parse_empty");
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
test("a local endpoint that answers with a client error rejects the chunk:
|
|
35
|
+
test("a local endpoint that answers with a client error rejects the chunk: provider_permanent", async () => {
|
|
36
|
+
// Status-bearing rejections (400/413/422 — the droppable set) dead-letter at
|
|
37
|
+
// the permanent cap instead of parking at the parse_empty cap (#3757).
|
|
35
38
|
for (const status of [400, 413, 422]) {
|
|
36
39
|
const result = await extractWith(async (_messages, options) => {
|
|
37
40
|
if (options.failureDiag) options.failureDiag.lastError = withStatus(status);
|
|
38
41
|
return null;
|
|
39
42
|
});
|
|
40
|
-
assert.equal(result.extractionFailureClass, "
|
|
43
|
+
assert.equal(result.extractionFailureClass, "provider_permanent", `HTTP ${status}`);
|
|
41
44
|
}
|
|
42
45
|
});
|
|
43
46
|
|
|
@@ -53,3 +56,114 @@ test("not the chunk's fault: unreachable, timeout, 5xx, 429, auth and a wrong mo
|
|
|
53
56
|
assert.equal(result.extractionFailureClass, "provider_retryable", `HTTP ${status}`);
|
|
54
57
|
}
|
|
55
58
|
});
|
|
59
|
+
|
|
60
|
+
const GATEWAY_400 = { result: null, failureReason: "http_error" as const, httpStatus: 400, errorClass: "http_4xx", sawTransientAttempt: false };
|
|
61
|
+
|
|
62
|
+
// A transient primary failure (timeout/5xx/429) makes a later terminal-looking
|
|
63
|
+
// gateway refusal inconclusive — the window must stay retryable under the
|
|
64
|
+
// drain's own bound instead of dead-lettering (#3757, codex P1).
|
|
65
|
+
test("transient primary + terminal-looking gateway refusal stays provider_retryable", async () => {
|
|
66
|
+
for (const status of [408, 429, 500, 503]) {
|
|
67
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
68
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
69
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
70
|
+
assert.equal(Reflect.set(engine, "localLlm", { async chatCompletion() { throw withStatus(status); } }), true);
|
|
71
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
72
|
+
const result = await engine.extract(TURNS);
|
|
73
|
+
assert.equal(result.extractionFailure, "fallback_no_parsed_output", `HTTP ${status}`);
|
|
74
|
+
assert.equal(result.extractionFailureClass, "provider_retryable", `HTTP ${status}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("transient direct-client failure + terminal-looking gateway refusal stays provider_retryable", async () => {
|
|
79
|
+
const engine = new ExtractionEngine(parseConfig({ openaiApiKey: "fixture-key" }));
|
|
80
|
+
const client = { chat: { completions: { async create() { throw withStatus(503); } } } };
|
|
81
|
+
assert.equal(Reflect.set(engine, "client", client), true);
|
|
82
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
83
|
+
const result = await engine.extract(TURNS);
|
|
84
|
+
assert.equal(result.extractionFailureClass, "provider_retryable");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a permanent primary refusal does not rescue a terminal gateway refusal", async () => {
|
|
88
|
+
// A droppable-status local rejection is permanent evidence about the window
|
|
89
|
+
// itself — two refusals agree, so the class stays provider_permanent.
|
|
90
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
91
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
92
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
93
|
+
assert.equal(Reflect.set(engine, "localLlm", { async chatCompletion() { throw new LocalLlmRejectedError(400); } }), true);
|
|
94
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
95
|
+
const result = await engine.extract(TURNS);
|
|
96
|
+
assert.equal(result.extractionFailureClass, "provider_permanent");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// The null-return path carries the same evidence as a throw: LocalLlmClient
|
|
100
|
+
// records transient attempts on failureDiag.sawTransientAttempt and returns
|
|
101
|
+
// null (#3757).
|
|
102
|
+
test("a null local reply carrying transient diag evidence keeps a terminal gateway refusal retryable", async () => {
|
|
103
|
+
for (const status of [429, 500, 503]) {
|
|
104
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
105
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
106
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
107
|
+
const local = {
|
|
108
|
+
async chatCompletion(_messages: LocalMessages, options: { failureDiag?: { lastError?: Error; sawTransientAttempt?: boolean } }) {
|
|
109
|
+
if (options.failureDiag) {
|
|
110
|
+
options.failureDiag.lastError = withStatus(status);
|
|
111
|
+
options.failureDiag.sawTransientAttempt = true;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
assert.equal(Reflect.set(engine, "localLlm", local), true);
|
|
117
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
118
|
+
const result = await engine.extract(TURNS);
|
|
119
|
+
assert.equal(result.extractionFailureClass, "provider_retryable", `HTTP ${status}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("an empty local reply with no diag evidence keeps a gateway refusal permanent", async () => {
|
|
124
|
+
// An HTTP-200 empty completion records nothing on the diagnostic — an absent
|
|
125
|
+
// lastError is NOT a transient attempt, so the refusal dead-letters (#3757).
|
|
126
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
127
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
128
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
129
|
+
assert.equal(Reflect.set(engine, "localLlm", { async chatCompletion() { return null; } }), true);
|
|
130
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
131
|
+
const result = await engine.extract(TURNS);
|
|
132
|
+
assert.equal(result.extractionFailureClass, "provider_permanent");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a throw after a recorded transient attempt keeps a gateway refusal retryable", async () => {
|
|
136
|
+
// A retried 5xx followed by an unusable reply throws a statusless rejection:
|
|
137
|
+
// the class is parse_empty but the diagnostic flag still proves the attempt.
|
|
138
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
139
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
140
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
141
|
+
const local = {
|
|
142
|
+
async chatCompletion(_messages: LocalMessages, options: { failureDiag?: { sawTransientAttempt?: boolean } }) {
|
|
143
|
+
if (options.failureDiag) options.failureDiag.sawTransientAttempt = true;
|
|
144
|
+
throw new LocalLlmRejectedError(undefined);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
assert.equal(Reflect.set(engine, "localLlm", local), true);
|
|
148
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
149
|
+
const result = await engine.extract(TURNS);
|
|
150
|
+
assert.equal(result.extractionFailureClass, "provider_retryable");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("a null local reply carrying non-transient diag evidence keeps the refusal permanent", async () => {
|
|
154
|
+
// A missing route/model (404) is the endpoint setup's problem, not a
|
|
155
|
+
// transient attempt — the gateway refusal must still dead-letter.
|
|
156
|
+
const engine = new ExtractionEngine(parseConfig({ localLlmEnabled: true, localLlmModel: "fixture-local", localLlmFallback: true, openaiApiKey: false }));
|
|
157
|
+
const modelRegistry = { calculateContextSizes: () => ({ maxInputChars: 8_000, maxOutputTokens: 1_000, description: "fixture" }) };
|
|
158
|
+
assert.equal(Reflect.set(engine, "modelRegistry", modelRegistry), true);
|
|
159
|
+
const local = {
|
|
160
|
+
async chatCompletion(_messages: LocalMessages, options: { failureDiag?: { lastError?: Error } }) {
|
|
161
|
+
if (options.failureDiag) options.failureDiag.lastError = withStatus(404);
|
|
162
|
+
return null;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
assert.equal(Reflect.set(engine, "localLlm", local), true);
|
|
166
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", { async parseWithSchemaDetailed() { return GATEWAY_400; } }), true);
|
|
167
|
+
const result = await engine.extract(TURNS);
|
|
168
|
+
assert.equal(result.extractionFailureClass, "provider_permanent");
|
|
169
|
+
});
|
|
@@ -79,7 +79,9 @@ test("a rejected request (HTTP 400, no reply) logs the same diagnostic once and
|
|
|
79
79
|
if (options.failureDiag) options.failureDiag.lastError = Object.assign(new Error("local LLM http failure"), { status: 400 });
|
|
80
80
|
return null;
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
// A status-bearing refusal is provider_permanent (#3757): the status still
|
|
83
|
+
// classifies the window even though no reply text arrived to parse.
|
|
84
|
+
assert.equal(result.extractionFailureClass, "provider_permanent");
|
|
83
85
|
const lines = warns.filter((w) => w.includes(MARKER));
|
|
84
86
|
assert.equal(lines.length, 1);
|
|
85
87
|
assert.match(lines[0]!, /replyChars=0 /);
|
package/src/extraction.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import assert from "node:assert/strict";
|
|
|
11
11
|
import test from "node:test";
|
|
12
12
|
|
|
13
13
|
import { classifyExtractionThrownError, classifyFallbackParseFailure, formatExtractionParseFailureLog } from "./extraction.js";
|
|
14
|
+
import { classifyLocalLlmRejected, LocalLlmRejectedError } from "./extraction-error-classification.js";
|
|
14
15
|
|
|
15
16
|
test("classifyExtractionThrownError: 401/403 → auth_config", () => {
|
|
16
17
|
assert.equal(classifyExtractionThrownError({ status: 401 }), "auth_config");
|
|
@@ -24,14 +25,83 @@ test("classifyExtractionThrownError: 429/5xx → provider_retryable", () => {
|
|
|
24
25
|
assert.equal(classifyExtractionThrownError({ status: 503 }), "provider_retryable");
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
test("classifyExtractionThrownError: bare network error /
|
|
28
|
+
test("classifyExtractionThrownError: bare network error / statusless failure → provider_retryable (fail-open toward retry)", () => {
|
|
28
29
|
assert.equal(classifyExtractionThrownError(new Error("socket hang up")), "provider_retryable");
|
|
29
|
-
// A
|
|
30
|
-
|
|
30
|
+
// A bare Error carries no status — the shared classifier treats it as a plain
|
|
31
|
+
// network failure (a local endpoint coming back up drains it).
|
|
32
|
+
assert.equal(classifyExtractionThrownError(new Error("model produced unparseable output")), "provider_retryable");
|
|
33
|
+
// Unknown non-HTTP failures stay retryable: an innocent buffered window is
|
|
34
|
+
// never silently dead-lettered for a failure shape nobody classified.
|
|
31
35
|
assert.equal(classifyExtractionThrownError(null), "provider_retryable");
|
|
32
36
|
assert.equal(classifyExtractionThrownError("not an object"), "provider_retryable");
|
|
33
37
|
});
|
|
34
38
|
|
|
39
|
+
test("classifyExtractionThrownError: input-refusing terminal status → provider_permanent", () => {
|
|
40
|
+
// 400/413/422 refuse THIS request — a resend of the identical payload can
|
|
41
|
+
// never succeed, so the fingerprint dead-letters at its attempt cap.
|
|
42
|
+
assert.equal(classifyExtractionThrownError({ status: 400 }), "provider_permanent");
|
|
43
|
+
assert.equal(classifyExtractionThrownError({ status: 413 }), "provider_permanent");
|
|
44
|
+
assert.equal(classifyExtractionThrownError({ status: 422 }), "provider_permanent");
|
|
45
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 400 }), "provider_permanent");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("classifyExtractionThrownError: other terminal status → auth_config (setup problem, not the chunk's)", () => {
|
|
49
|
+
// A missing route or model is the endpoint setup's problem — the breaker
|
|
50
|
+
// opens instead of dropping innocent windows.
|
|
51
|
+
assert.equal(classifyExtractionThrownError({ status: 404 }), "auth_config");
|
|
52
|
+
assert.equal(classifyExtractionThrownError({ status: 405 }), "auth_config");
|
|
53
|
+
assert.equal(classifyExtractionThrownError({ status: 410 }), "auth_config");
|
|
54
|
+
// `statusCode` spellings resolve the same way: the recognized status — not a
|
|
55
|
+
// statusless transient fallback — decides retryability (405/410 included).
|
|
56
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 404 }), "auth_config");
|
|
57
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 405 }), "auth_config");
|
|
58
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 410 }), "auth_config");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("classifyExtractionThrownError: statusCode transient statuses stay provider_retryable", () => {
|
|
62
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 429 }), "provider_retryable");
|
|
63
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 503 }), "provider_retryable");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("classifyExtractionThrownError: parameter/config 400 stays auth_config; input-refusal 400 stays provider_permanent", () => {
|
|
67
|
+
// The fallback-llm unsupported-`temperature` shape — a setup failure, retained.
|
|
68
|
+
assert.equal(
|
|
69
|
+
classifyExtractionThrownError({ status: 400, message: "Unsupported parameter: 'temperature' is not supported with this model." }),
|
|
70
|
+
"auth_config",
|
|
71
|
+
);
|
|
72
|
+
assert.equal(classifyExtractionThrownError({ statusCode: 400, message: "unknown parameter: 'top_k'" }), "auth_config");
|
|
73
|
+
assert.equal(classifyExtractionThrownError({ status: 400, code: "unsupported_parameter", param: "temperature" }), "auth_config");
|
|
74
|
+
assert.equal(classifyExtractionThrownError({ status: 400, code: "http_4xx_parameter" }), "auth_config");
|
|
75
|
+
assert.equal(classifyExtractionThrownError({ status: 400, error: { code: "unknown_parameter" } }), "auth_config");
|
|
76
|
+
// Ambiguous and content-refusing 400s still dead-letter as input refusals —
|
|
77
|
+
// including a bare `unexpected value` phrase that names the payload, not a
|
|
78
|
+
// request parameter (#3757).
|
|
79
|
+
assert.equal(classifyExtractionThrownError({ status: 400, message: "content violates the provider usage policy" }), "provider_permanent");
|
|
80
|
+
assert.equal(classifyExtractionThrownError({ status: 400, message: "Input content rejected: unexpected value in messages[0].content" }), "provider_permanent");
|
|
81
|
+
assert.equal(classifyExtractionThrownError({ status: 400 }), "provider_permanent");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("classifyExtractionThrownError: a refusal beside a transient sibling attempt stays retryable", () => {
|
|
85
|
+
// Model-chain exhaustion where an earlier attempt failed transiently is not
|
|
86
|
+
// conclusive proof the window is unextractable — the drain's own bound governs.
|
|
87
|
+
assert.equal(classifyExtractionThrownError({ status: 413, transientAttemptSeen: true }), "provider_retryable");
|
|
88
|
+
assert.equal(classifyExtractionThrownError({ status: 422, transientAttemptSeen: true }), "provider_retryable");
|
|
89
|
+
assert.equal(classifyExtractionThrownError({ status: 413, transientAttemptSeen: false }), "provider_permanent");
|
|
90
|
+
assert.equal(classifyExtractionThrownError({ status: 413 }), "provider_permanent");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("classifyLocalLlmRejected: status-bearing rejections dead-letter, statusless stays parse_empty", () => {
|
|
94
|
+
// 400/413/422 refuse THIS input (localRejectionStatus already filtered the set):
|
|
95
|
+
// bounded by the permanent cap, not by the parse_empty long-park.
|
|
96
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(400)), "provider_permanent");
|
|
97
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(413)), "provider_permanent");
|
|
98
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(422)), "provider_permanent");
|
|
99
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(undefined)), "parse_empty");
|
|
100
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(400, "length")), "output_truncated");
|
|
101
|
+
// A parameter-refusing 400 is the endpoint setup's problem: retained, never dropped.
|
|
102
|
+
assert.equal(classifyLocalLlmRejected(new LocalLlmRejectedError(400, undefined, true)), "auth_config");
|
|
103
|
+
});
|
|
104
|
+
|
|
35
105
|
test("classifyFallbackParseFailure: maps the gateway parse-failure reasons", () => {
|
|
36
106
|
assert.equal(classifyFallbackParseFailure("no_models"), "auth_config");
|
|
37
107
|
assert.equal(classifyFallbackParseFailure("http_error"), "provider_retryable");
|
package/src/extraction.ts
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
import { applyGroundingWithConnector, headerConnector, renderExtractionConversation, resolveSourceConnector, type ExtractionGroundingContext } from "./source-agent-qualifier.js";
|
|
39
39
|
import { isMemoryCategory } from "./write-envelope.js";
|
|
40
40
|
export { classifyExtractionThrownError, classifyFallbackParseFailure, formatExtractionParseFailureLog } from "./extraction-error-classification.js";
|
|
41
|
-
import { LocalLlmRejectedError, classifyExtractionThrownError, classifyFallbackParseFailure, classifyLocalLlmRejected, formatExtractionParseFailureLog, directInputTooLargeResult, formatDirectInputTooLargeLog, isRequestTooLargeError, localRejectionStatus, type LocalFailureDiag } from "./extraction-error-classification.js";
|
|
41
|
+
import { LocalLlmRejectedError, classifyExtractionThrownError, classifyFallbackParseFailure, classifyLocalLlmRejected, downgradePermanentOnTransientAttempt, formatExtractionParseFailureLog, directInputTooLargeResult, formatDirectInputTooLargeLog, isParameterConfigRejection, isRequestTooLargeError, localRejectionStatus, type LocalFailureDiag } from "./extraction-error-classification.js";
|
|
42
42
|
import { buildUnusableReplyDiagnostic, formatUnusableReplyDiagnostic, looksLikeExtractionResultPayload } from "./extraction-reply-diagnostic.js";
|
|
43
43
|
import { AMBIENT_CAPTURE_PROMPT_SECTION_COMPACT, clampAmbientCaptureConfidence } from "./ambient-provenance.js";
|
|
44
44
|
import {
|
|
@@ -810,9 +810,8 @@ export class ExtractionEngine {
|
|
|
810
810
|
? '- Source quotes: For each fact, include a "quote" field with the EXACT verbatim words from the conversation that support the fact (a contiguous span from a single turn, not a paraphrase). Cap at ~300 chars.'
|
|
811
811
|
: "",
|
|
812
812
|
// #1578: emit the same event-time guidance as the primary extraction
|
|
813
|
-
// paths so proactive-recovered facts also carry an optional eventTime
|
|
814
|
-
//
|
|
815
|
-
// bi-temporal gate is off, keeping the prompt unchanged by default.
|
|
813
|
+
// paths so proactive-recovered facts also carry an optional eventTime.
|
|
814
|
+
// Returns "" when the bi-temporal gate is off.
|
|
816
815
|
eventTimePromptInstruction(this.config),
|
|
817
816
|
headerConnector(sourceConnector) !== undefined && resolveMemoryLifecycleCapabilities(this.config).extractionScopeClassification
|
|
818
817
|
? `Tool, command, or CLI-flag instructions tied to the ${sourceConnector} agent are "project" scope; when you recover one, begin the fact with a leading "In ${sourceConnector}, " clause naming that agent (e.g. "In ${sourceConnector}, use the search tool with a repository path.").`
|
|
@@ -1091,10 +1090,9 @@ export class ExtractionEngine {
|
|
|
1091
1090
|
: turn.content,
|
|
1092
1091
|
}))
|
|
1093
1092
|
.filter((turn) => turn.content.trim().length > 0);
|
|
1094
|
-
// One derivation
|
|
1095
|
-
//
|
|
1096
|
-
//
|
|
1097
|
-
// orchestrator does not recompute over a different turn set (#2183).
|
|
1093
|
+
// One derivation over the turns the model sees (boundedTurns) — the same
|
|
1094
|
+
// set the qualifier, grounding source, and telemetry filter use. Carried
|
|
1095
|
+
// to persistence via result.sourceConnector (#2183).
|
|
1098
1096
|
const resolvedConnector = resolveSourceConnector(boundedTurns);
|
|
1099
1097
|
// Ambient-capture provenance (issue #2294): true when any contributing turn
|
|
1100
1098
|
// came from an always-on recorder, so the prompt warns about media audio
|
|
@@ -1179,10 +1177,10 @@ export class ExtractionEngine {
|
|
|
1179
1177
|
localLlm: resolveLocalLlmCapabilities(this.config).localLlm,
|
|
1180
1178
|
});
|
|
1181
1179
|
this.profiler.startSpan("total", extractionTraceId);
|
|
1182
|
-
// True when a
|
|
1183
|
-
//
|
|
1184
|
-
// primary
|
|
1185
|
-
let primaryExtractorAttempted = false;
|
|
1180
|
+
// True when a primary extractor ran before the gateway fallback: a gateway
|
|
1181
|
+
// "no models" isn't auth_config then (codex review), and a transient
|
|
1182
|
+
// primary attempt makes a terminal-looking refusal inconclusive (#3757).
|
|
1183
|
+
let primaryExtractorAttempted = false, primaryTransientAttemptSeen = false;
|
|
1186
1184
|
// Direct client refused the request as too large (#3531): report that if the gateway fails too.
|
|
1187
1185
|
let directInputTooLarge = false;
|
|
1188
1186
|
|
|
@@ -1191,8 +1189,9 @@ export class ExtractionEngine {
|
|
|
1191
1189
|
if (this.shouldUseLocalLlm) {
|
|
1192
1190
|
this.profiler.startSpan("local-llm", extractionTraceId);
|
|
1193
1191
|
primaryExtractorAttempted = true;
|
|
1192
|
+
const localDiag: LocalFailureDiag = {};
|
|
1194
1193
|
try {
|
|
1195
|
-
const localResult = await this.extractWithLocalLlm(conversation, signal, ambientCapture);
|
|
1194
|
+
const localResult = await this.extractWithLocalLlm(conversation, signal, ambientCapture, localDiag);
|
|
1196
1195
|
throwIfExtractionAborted(signal);
|
|
1197
1196
|
if (localResult) {
|
|
1198
1197
|
const durationMs = Date.now() - startTime;
|
|
@@ -1225,6 +1224,7 @@ export class ExtractionEngine {
|
|
|
1225
1224
|
extractionFailureClass: "provider_retryable",
|
|
1226
1225
|
};
|
|
1227
1226
|
}
|
|
1227
|
+
primaryTransientAttemptSeen ||= localDiag.sawTransientAttempt === true;
|
|
1228
1228
|
log.info("extraction: local LLM unavailable, falling back to gateway default AI");
|
|
1229
1229
|
} catch (err) {
|
|
1230
1230
|
if (signal?.aborted) throw err;
|
|
@@ -1239,6 +1239,7 @@ export class ExtractionEngine {
|
|
|
1239
1239
|
extractionFailureClass: err instanceof LocalLlmRejectedError ? classifyLocalLlmRejected(err) : classifyExtractionThrownError(err),
|
|
1240
1240
|
};
|
|
1241
1241
|
}
|
|
1242
|
+
primaryTransientAttemptSeen ||= localDiag.sawTransientAttempt === true || (err instanceof LocalLlmRejectedError ? classifyLocalLlmRejected(err) : classifyExtractionThrownError(err)) === "provider_retryable";
|
|
1242
1243
|
log.info("extraction: local LLM error, falling back to gateway default AI:", err);
|
|
1243
1244
|
} finally {
|
|
1244
1245
|
// End local-llm span if it wasn't ended on the success path
|
|
@@ -1262,8 +1263,7 @@ export class ExtractionEngine {
|
|
|
1262
1263
|
const finalResult = await this.applyProactiveQuestionPass(conversation, grounded, groundingContext, signal);
|
|
1263
1264
|
return this.finalizeExtractionResult(finalResult, boundedTurns, resolvedConnector, ambientCapture);
|
|
1264
1265
|
}
|
|
1265
|
-
// Emit
|
|
1266
|
-
// Wrapped in try/catch so a subscriber error doesn't break the fallback path.
|
|
1266
|
+
// Emit llm_error for Opik before fallback; a subscriber error must not break it.
|
|
1267
1267
|
try {
|
|
1268
1268
|
this.emit({
|
|
1269
1269
|
kind: "llm_error", traceId, model: this.config.model, operation: "extraction",
|
|
@@ -1283,6 +1283,7 @@ export class ExtractionEngine {
|
|
|
1283
1283
|
closedDirectTrace = true;
|
|
1284
1284
|
directInputTooLarge = err instanceof Object && isRequestTooLargeError(err);
|
|
1285
1285
|
if (directInputTooLarge) log.warn(formatDirectInputTooLargeLog(conversation.length));
|
|
1286
|
+
primaryTransientAttemptSeen ||= classifyExtractionThrownError(err) === "provider_retryable";
|
|
1286
1287
|
log.info("extraction: direct client failed, falling back to gateway AI:", err);
|
|
1287
1288
|
} finally {
|
|
1288
1289
|
try { this.profiler.endSpan("direct-client", extractionTraceId); } catch { /* span may already be closed */ }
|
|
@@ -1299,10 +1300,7 @@ export class ExtractionEngine {
|
|
|
1299
1300
|
} catch { /* trace emit must not block fallback */ }
|
|
1300
1301
|
}
|
|
1301
1302
|
|
|
1302
|
-
//
|
|
1303
|
-
// final fallback after local/direct attempts fail. Emit a fresh llm_start so the
|
|
1304
|
-
// gateway-backed call gets its own trace rather than being orphaned under the
|
|
1305
|
-
// direct-client traceId.
|
|
1303
|
+
// Gateway mode: primary path; plugin mode: final fallback — a fresh llm_start gives the gateway call its own trace.
|
|
1306
1304
|
const fallbackTraceId = crypto.randomUUID();
|
|
1307
1305
|
const fallbackStartTime = Date.now();
|
|
1308
1306
|
if (this.useGatewayModelSource) {
|
|
@@ -1386,10 +1384,12 @@ export class ExtractionEngine {
|
|
|
1386
1384
|
const fallbackParseFailureClass: ExtractionFailureClass =
|
|
1387
1385
|
detailed.result === null
|
|
1388
1386
|
? detailed.failureReason === "no_models" && primaryExtractorAttempted
|
|
1389
|
-
? //
|
|
1390
|
-
// the root cause is the primary (transient), not gateway auth/config.
|
|
1387
|
+
? // The root cause is the primary's failure, not gateway auth/config.
|
|
1391
1388
|
"provider_retryable"
|
|
1392
|
-
:
|
|
1389
|
+
: // Status-bearing refusals classify via the thrown-error classifier — no unbounded retry (#3757).
|
|
1390
|
+
detailed.failureReason === "http_error" && detailed.httpStatus !== undefined
|
|
1391
|
+
? classifyExtractionThrownError({ status: detailed.httpStatus, code: detailed.errorClass, transientAttemptSeen: detailed.sawTransientAttempt === true || primaryTransientAttemptSeen })
|
|
1392
|
+
: classifyFallbackParseFailure(detailed.failureReason)
|
|
1393
1393
|
: "parse_empty";
|
|
1394
1394
|
if (directInputTooLarge) return directInputTooLargeResult();
|
|
1395
1395
|
return {
|
|
@@ -1414,7 +1414,7 @@ export class ExtractionEngine {
|
|
|
1414
1414
|
entities: [],
|
|
1415
1415
|
questions: [],
|
|
1416
1416
|
extractionFailure: "fallback_failed",
|
|
1417
|
-
extractionFailureClass: classifyExtractionThrownError(err),
|
|
1417
|
+
extractionFailureClass: downgradePermanentOnTransientAttempt(classifyExtractionThrownError(err), primaryTransientAttemptSeen),
|
|
1418
1418
|
};
|
|
1419
1419
|
} finally {
|
|
1420
1420
|
try { this.profiler.endSpan("gateway-fallback", extractionTraceId); } catch { /* span may already be closed */ }
|
|
@@ -1435,6 +1435,7 @@ export class ExtractionEngine {
|
|
|
1435
1435
|
conversation: string,
|
|
1436
1436
|
signal?: AbortSignal,
|
|
1437
1437
|
ambientCapture = false,
|
|
1438
|
+
diag?: LocalFailureDiag,
|
|
1438
1439
|
): Promise<ExtractionResult | null> {
|
|
1439
1440
|
const lifecycleCaps = resolveMemoryLifecycleCapabilities(this.config);
|
|
1440
1441
|
log.debug(
|
|
@@ -1490,7 +1491,7 @@ Conversation:
|
|
|
1490
1491
|
${truncatedConversation}`;
|
|
1491
1492
|
|
|
1492
1493
|
log.debug(`extractWithLocalLlm: calling localLlm.chatCompletion with prompt length ${localPrompt.length}...`);
|
|
1493
|
-
const failureDiag: LocalFailureDiag = {};
|
|
1494
|
+
const failureDiag: LocalFailureDiag = diag ?? {};
|
|
1494
1495
|
const response = await this.localLlm.chatCompletion(
|
|
1495
1496
|
[
|
|
1496
1497
|
{ role: "system", content: "You are a memory extraction system. Output valid JSON only." },
|
|
@@ -1513,7 +1514,7 @@ ${truncatedConversation}`;
|
|
|
1513
1514
|
const rejected = localRejectionStatus(failureDiag);
|
|
1514
1515
|
if (rejected !== undefined) {
|
|
1515
1516
|
log.warn(formatUnusableReplyDiagnostic(buildUnusableReplyDiagnostic("", failureDiag.finishReason, 0, contextSizes.maxOutputTokens)));
|
|
1516
|
-
throw new LocalLlmRejectedError(rejected, failureDiag.finishReason); // the endpoint is up and refuses this input
|
|
1517
|
+
throw new LocalLlmRejectedError(rejected, failureDiag.finishReason, rejected === 400 && isParameterConfigRejection(failureDiag.lastError), failureDiag.sawTransientAttempt); // the endpoint is up and refuses this input
|
|
1517
1518
|
}
|
|
1518
1519
|
log.debug("extractWithLocalLlm: chatCompletion returned null or empty content");
|
|
1519
1520
|
return null;
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getCodexSubscriptionShutdownSignal,
|
|
20
20
|
isDefaultRegisteredCodexSubscriptionRunner,
|
|
21
21
|
} from "./providers/codex-subscription.js";
|
|
22
|
+
import { isParameterConfigRejection } from "./extraction-error-classification.js";
|
|
22
23
|
import type { GetRuntimeAuthForModelFn, ResolveApiKeyFn } from "./resolve-provider-secret.js";
|
|
23
24
|
import { resolveHomeDir } from "./runtime/env.js";
|
|
24
25
|
import type { GatewayConfig, ModelProviderConfig } from "./types.js";
|
|
@@ -267,8 +268,10 @@ export interface StructuredParseFailure {
|
|
|
267
268
|
attemptedModel?: string;
|
|
268
269
|
/** HTTP status when known. Never a response body. */
|
|
269
270
|
httpStatus?: number;
|
|
270
|
-
/** Coarse class: http_4xx / http_5xx / timeout / network / empty / schema_rejection / no_models. */
|
|
271
|
+
/** Coarse class: http_4xx / http_4xx_parameter / http_5xx / timeout / network / empty / schema_rejection / no_models. */
|
|
271
272
|
errorClass?: string;
|
|
273
|
+
/** An earlier model in the chain failed transiently (5xx/408/429/timeout/network) — the last-attempt refusal is not conclusive proof the window is unextractable. */
|
|
274
|
+
sawTransientAttempt?: boolean;
|
|
272
275
|
}
|
|
273
276
|
|
|
274
277
|
export type StructuredParseResult<T> =
|
|
@@ -306,7 +309,14 @@ export function fallbackLlmRuntimeContextFromConfig(
|
|
|
306
309
|
};
|
|
307
310
|
}
|
|
308
311
|
|
|
309
|
-
|
|
312
|
+
// Only trust a status token at the message start (`400 {...}` SDK shape) or
|
|
313
|
+
// beside an HTTP/status keyword — a bare 3-digit token elsewhere is usually
|
|
314
|
+
// part of prose (e.g. "after 400 attempts") and must not masquerade as an
|
|
315
|
+
// HTTP refusal (#3757). No status → `provider_retryable`, the safe direction.
|
|
316
|
+
// Every quantifier is bounded so the scan stays linear on hostile messages
|
|
317
|
+
// (CodeQL polynomial-regex alert on uncontrolled data).
|
|
318
|
+
const HTTP_STATUS_IN_MESSAGE =
|
|
319
|
+
/(?:^\s{0,4}\(?\s{0,4}|(?:https?[\w./]{0,16}|status\s{0,4}code|status|error)\b\s{0,4}[:=]?\s{0,4}\(?\s{0,4})([1-5]\d{2})\b/i;
|
|
310
320
|
|
|
311
321
|
export function isTimeoutError(err: unknown): boolean {
|
|
312
322
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -359,7 +369,11 @@ export function classifyThrownProviderError(err: unknown): Omit<StructuredParseF
|
|
|
359
369
|
return {
|
|
360
370
|
failureReason: "http_error",
|
|
361
371
|
httpStatus,
|
|
362
|
-
|
|
372
|
+
// A 400 that refuses a request parameter (unsupported `temperature`,
|
|
373
|
+
// unknown field) is a setup failure — tag it so the failure-class
|
|
374
|
+
// mapping retains the window instead of dead-lettering it.
|
|
375
|
+
errorClass:
|
|
376
|
+
httpStatus === 400 && isParameterConfigRejection(err) ? "http_4xx_parameter" : errorClassForHttpStatus(httpStatus),
|
|
363
377
|
};
|
|
364
378
|
}
|
|
365
379
|
return { failureReason: "http_error", errorClass: "network" };
|