@remnic/core 10.0.162 → 10.0.164
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 +39 -39
- package/dist/access-cli.js +39 -39
- package/dist/access-extraction-force-flush-preempt.js +39 -39
- package/dist/access-extraction-force-flush.js +39 -39
- package/dist/access-http-briefing.js +39 -39
- package/dist/access-http-query.js +39 -39
- package/dist/access-http.js +39 -39
- package/dist/access-identity-continuity-surface.js +39 -39
- package/dist/access-lcm-surface.js +39 -39
- package/dist/access-mcp.js +39 -39
- package/dist/access-observe-write-surface.js +39 -39
- package/dist/access-operations-batch.js +39 -39
- package/dist/access-operations.js +39 -39
- package/dist/access-recall-concurrency.js +39 -39
- package/dist/access-recall-diagnostics.js +2 -2
- package/dist/access-recall-response.js +39 -39
- package/dist/access-recall-surface.js +39 -39
- package/dist/access-service.js +39 -39
- package/dist/active-recall.js +3 -3
- package/dist/briefing.js +3 -3
- package/dist/causal-consolidation.js +4 -4
- package/dist/{chunk-D2EJNBZS.js → chunk-22VXXA67.js} +2 -2
- package/dist/{chunk-23ODHEVS.js → chunk-3QLAOYBL.js} +2 -2
- package/dist/{chunk-HG4OCRKD.js → chunk-4HKK5HUI.js} +2 -2
- package/dist/{chunk-6POF4N2J.js → chunk-4LPTSB5V.js} +2 -2
- package/dist/{chunk-6HGN4OEA.js → chunk-5D4NBANY.js} +2 -2
- package/dist/{chunk-6HGN4OEA.js.map → chunk-5D4NBANY.js.map} +1 -1
- package/dist/{chunk-FDR5YW6B.js → chunk-5LTXYM7D.js} +2 -2
- package/dist/{chunk-ZZZT6OR2.js → chunk-6ARSFTLD.js} +2 -2
- package/dist/{chunk-SC7GUUGO.js → chunk-6S4DM53Y.js} +3 -3
- package/dist/{chunk-ZVK6TWGF.js → chunk-ARJ3KCX4.js} +2 -2
- package/dist/{chunk-LW5MFJBC.js → chunk-AU6AEUFD.js} +2 -2
- package/dist/{chunk-A6E54ILI.js → chunk-DBVSU3HE.js} +8 -8
- package/dist/{chunk-PZSVAVQW.js → chunk-E5RJPLNL.js} +2 -2
- package/dist/{chunk-S3QTZMSD.js → chunk-EI2M2CFJ.js} +2 -2
- package/dist/{chunk-6RW6I6X4.js → chunk-FSI45NUK.js} +2 -2
- package/dist/{chunk-IF5YAXBY.js → chunk-IHOKB3L3.js} +34 -34
- package/dist/{chunk-IF5YAXBY.js.map → chunk-IHOKB3L3.js.map} +1 -1
- package/dist/{chunk-MATBXHXU.js → chunk-JJEQRSYU.js} +2 -2
- package/dist/{chunk-SHFN2RW5.js → chunk-JVIWVJ2A.js} +2 -2
- package/dist/{chunk-Q2WMKMMX.js → chunk-KR6PEAM4.js} +7 -7
- package/dist/{chunk-R4HZOXUY.js → chunk-L6BLTV4D.js} +2 -2
- package/dist/{chunk-2S3M2GLC.js → chunk-M7Q7Z6V5.js} +34 -1
- package/dist/chunk-M7Q7Z6V5.js.map +1 -0
- package/dist/{chunk-T4V3GVX3.js → chunk-OAGTKS73.js} +2 -2
- package/dist/{chunk-FEHCP2ZN.js → chunk-PCUDFWX5.js} +2 -2
- package/dist/{chunk-DQATNC34.js → chunk-QBREZ4QL.js} +2 -2
- package/dist/{chunk-WE7WPSUA.js → chunk-RDO6AMDL.js} +2 -2
- package/dist/{chunk-UGTLRFN4.js → chunk-RH6XWXMA.js} +3 -3
- package/dist/{chunk-QRGJLMH7.js → chunk-SBU5GDOT.js} +3 -3
- package/dist/{chunk-YCOHRQWO.js → chunk-SOGOHLWN.js} +1 -1
- package/dist/chunk-SOGOHLWN.js.map +1 -0
- package/dist/{chunk-SHLEP3HN.js → chunk-SRN5M4LQ.js} +3 -3
- package/dist/{chunk-JAPUF4X7.js → chunk-TFNZXOXK.js} +2 -2
- package/dist/{chunk-6CXSNIEP.js → chunk-UGQEJWR3.js} +2 -2
- package/dist/{chunk-QUC4S2D2.js → chunk-V4ASAWRP.js} +10 -2
- package/dist/chunk-V4ASAWRP.js.map +1 -0
- package/dist/{chunk-VEPXXXTO.js → chunk-V6M6N3EE.js} +2 -2
- package/dist/{chunk-QQPXWVRX.js → chunk-VXMWTRQX.js} +2 -2
- package/dist/{chunk-SMAXKFKS.js → chunk-WAJL65KW.js} +3 -3
- package/dist/{chunk-SOO75MET.js → chunk-WRAK5LLB.js} +2 -2
- package/dist/{chunk-IVZNNRBF.js → chunk-XE4UYWW3.js} +2 -2
- package/dist/{chunk-JGIRGWS6.js → chunk-YMC4AYJK.js} +2 -2
- package/dist/{chunk-D67DA4DI.js → chunk-YWPCDR3I.js} +2 -2
- package/dist/{chunk-UVEHXFSC.js → chunk-Z3SXC3MP.js} +2 -2
- package/dist/{chunk-NFL4LC22.js → chunk-ZRLTQ2Y7.js} +2 -2
- package/dist/cli.js +39 -39
- package/dist/coding/export-okf-codegraph.js +2 -2
- package/dist/compounding/engine.js +4 -4
- package/dist/config.js +3 -3
- package/dist/connectors/codex-materialize-runner.js +3 -3
- package/dist/connectors/index.js +3 -3
- package/dist/convergence-refresh.js +5 -5
- package/dist/corpus-watermark.js +5 -5
- package/dist/entity-retrieval.js +3 -3
- package/dist/explicit-capture.js +39 -39
- package/dist/extraction-error-classification.d.ts +23 -1
- package/dist/extraction-error-classification.d.ts.map +1 -1
- package/dist/extraction-error-classification.js +7 -1
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +5 -5
- package/dist/harmonic-retrieval.js +3 -3
- package/dist/index.js +39 -39
- package/dist/location/index.js +4 -4
- package/dist/maintenance/memory-governance.js +3 -3
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
- package/dist/maintenance/rebuild-memory-projection-runner.js +5 -5
- package/dist/maintenance/rebuild-memory-projection.js +4 -4
- package/dist/namespaces/migrate.js +4 -4
- package/dist/namespaces/storage.js +3 -3
- package/dist/operator-doctor-corpus.js +6 -6
- package/dist/operator-toolkit.js +10 -10
- package/dist/orchestration/backlog-scheduler.js +40 -40
- package/dist/orchestration/buffer-drain-runner.js +40 -40
- package/dist/orchestration/maintenance.js +11 -11
- package/dist/orchestrator.js +39 -39
- 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 +39 -39
- 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 +4 -4
- package/dist/semantic-consolidation.js +4 -4
- package/dist/semantic-rule-promotion.js +3 -3
- package/dist/semantic-rule-verifier.js +3 -3
- package/dist/source-agent-qualifier.js +3 -3
- package/dist/standup/build.js +3 -3
- package/dist/storage.js +2 -2
- package/dist/transfer/export-okf.js +3 -3
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +3 -3
- package/dist/who-knows-cli.js +4 -4
- package/dist/who-knows.js +3 -3
- package/package.json +2 -2
- package/src/access-observe-replay-durability.test.ts +23 -3
- package/src/buffer-admission-idempotency.test.ts +1 -1
- package/src/buffer-ingress-invariant.test.ts +1 -1
- package/src/config.test.ts +3 -2
- package/src/config.ts +1 -1
- package/src/extraction-direct-input-too-large.test.ts +141 -0
- package/src/extraction-error-classification.ts +61 -1
- package/src/extraction-queue-concurrency-default.test.ts +107 -0
- package/src/extraction.ts +7 -1
- package/src/orchestration/extraction-queue-coordinator.ts +1 -1
- package/src/orchestrator-extraction-queue.test.ts +3 -3
- package/src/orchestrator-flush.test.ts +12 -12
- package/src/types.ts +1 -1
- package/dist/chunk-2S3M2GLC.js.map +0 -1
- package/dist/chunk-QUC4S2D2.js.map +0 -1
- package/dist/chunk-YCOHRQWO.js.map +0 -1
- /package/dist/{chunk-D2EJNBZS.js.map → chunk-22VXXA67.js.map} +0 -0
- /package/dist/{chunk-23ODHEVS.js.map → chunk-3QLAOYBL.js.map} +0 -0
- /package/dist/{chunk-HG4OCRKD.js.map → chunk-4HKK5HUI.js.map} +0 -0
- /package/dist/{chunk-6POF4N2J.js.map → chunk-4LPTSB5V.js.map} +0 -0
- /package/dist/{chunk-FDR5YW6B.js.map → chunk-5LTXYM7D.js.map} +0 -0
- /package/dist/{chunk-ZZZT6OR2.js.map → chunk-6ARSFTLD.js.map} +0 -0
- /package/dist/{chunk-SC7GUUGO.js.map → chunk-6S4DM53Y.js.map} +0 -0
- /package/dist/{chunk-ZVK6TWGF.js.map → chunk-ARJ3KCX4.js.map} +0 -0
- /package/dist/{chunk-LW5MFJBC.js.map → chunk-AU6AEUFD.js.map} +0 -0
- /package/dist/{chunk-A6E54ILI.js.map → chunk-DBVSU3HE.js.map} +0 -0
- /package/dist/{chunk-PZSVAVQW.js.map → chunk-E5RJPLNL.js.map} +0 -0
- /package/dist/{chunk-S3QTZMSD.js.map → chunk-EI2M2CFJ.js.map} +0 -0
- /package/dist/{chunk-6RW6I6X4.js.map → chunk-FSI45NUK.js.map} +0 -0
- /package/dist/{chunk-MATBXHXU.js.map → chunk-JJEQRSYU.js.map} +0 -0
- /package/dist/{chunk-SHFN2RW5.js.map → chunk-JVIWVJ2A.js.map} +0 -0
- /package/dist/{chunk-Q2WMKMMX.js.map → chunk-KR6PEAM4.js.map} +0 -0
- /package/dist/{chunk-R4HZOXUY.js.map → chunk-L6BLTV4D.js.map} +0 -0
- /package/dist/{chunk-T4V3GVX3.js.map → chunk-OAGTKS73.js.map} +0 -0
- /package/dist/{chunk-FEHCP2ZN.js.map → chunk-PCUDFWX5.js.map} +0 -0
- /package/dist/{chunk-DQATNC34.js.map → chunk-QBREZ4QL.js.map} +0 -0
- /package/dist/{chunk-WE7WPSUA.js.map → chunk-RDO6AMDL.js.map} +0 -0
- /package/dist/{chunk-UGTLRFN4.js.map → chunk-RH6XWXMA.js.map} +0 -0
- /package/dist/{chunk-QRGJLMH7.js.map → chunk-SBU5GDOT.js.map} +0 -0
- /package/dist/{chunk-SHLEP3HN.js.map → chunk-SRN5M4LQ.js.map} +0 -0
- /package/dist/{chunk-JAPUF4X7.js.map → chunk-TFNZXOXK.js.map} +0 -0
- /package/dist/{chunk-6CXSNIEP.js.map → chunk-UGQEJWR3.js.map} +0 -0
- /package/dist/{chunk-VEPXXXTO.js.map → chunk-V6M6N3EE.js.map} +0 -0
- /package/dist/{chunk-QQPXWVRX.js.map → chunk-VXMWTRQX.js.map} +0 -0
- /package/dist/{chunk-SMAXKFKS.js.map → chunk-WAJL65KW.js.map} +0 -0
- /package/dist/{chunk-SOO75MET.js.map → chunk-WRAK5LLB.js.map} +0 -0
- /package/dist/{chunk-IVZNNRBF.js.map → chunk-XE4UYWW3.js.map} +0 -0
- /package/dist/{chunk-JGIRGWS6.js.map → chunk-YMC4AYJK.js.map} +0 -0
- /package/dist/{chunk-D67DA4DI.js.map → chunk-YWPCDR3I.js.map} +0 -0
- /package/dist/{chunk-UVEHXFSC.js.map → chunk-Z3SXC3MP.js.map} +0 -0
- /package/dist/{chunk-NFL4LC22.js.map → chunk-ZRLTQ2Y7.js.map} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { parseConfig } from "./config.js";
|
|
5
|
+
import { isRequestTooLargeError } from "./extraction-error-classification.js";
|
|
6
|
+
import { ExtractionEngine } from "./extraction.js";
|
|
7
|
+
import type { StructuredParseResult } from "./fallback-llm-codex-subscription.js";
|
|
8
|
+
import type { BufferTurn, ExtractionResult } from "./types.js";
|
|
9
|
+
|
|
10
|
+
// Issue #3531: forced and fail-closed flushes send the whole window as one
|
|
11
|
+
// atomic direct-client request. When the provider refuses it as too large, the
|
|
12
|
+
// failure must say so instead of surfacing as a gateway "no parsed output", and
|
|
13
|
+
// it must stay retryable so the retained turns are never parked or dropped.
|
|
14
|
+
|
|
15
|
+
const SENTENCE = "Moonlight's theme color is green, not blue. ";
|
|
16
|
+
|
|
17
|
+
// A synthetic window far over the 12,000-char per-call budget.
|
|
18
|
+
const OVERSIZED_WINDOW: BufferTurn[] = Array.from({ length: 40 }, (_, index) => ({
|
|
19
|
+
role: index % 2 === 0 ? "user" : "assistant",
|
|
20
|
+
content: SENTENCE.repeat(250),
|
|
21
|
+
timestamp: `2026-11-20T12:${String(index).padStart(2, "0")}:00.000Z`,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
class FakeBadRequestError extends Error {
|
|
25
|
+
readonly status: number;
|
|
26
|
+
constructor(status: number, message: string) {
|
|
27
|
+
super(`${status} ${message}`);
|
|
28
|
+
this.status = status;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function engineWithDirectFailure(
|
|
33
|
+
err: Error,
|
|
34
|
+
gatewayResult: StructuredParseResult<ExtractionResult> = {
|
|
35
|
+
result: null,
|
|
36
|
+
failureReason: "no_models",
|
|
37
|
+
errorClass: "no_models",
|
|
38
|
+
},
|
|
39
|
+
) {
|
|
40
|
+
const engine = new ExtractionEngine(parseConfig({ openaiApiKey: "fixture-key" }));
|
|
41
|
+
let direct = 0;
|
|
42
|
+
let gateway = 0;
|
|
43
|
+
const client = {
|
|
44
|
+
chat: {
|
|
45
|
+
completions: {
|
|
46
|
+
async create() {
|
|
47
|
+
direct += 1;
|
|
48
|
+
throw err;
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const fallbackLlm = {
|
|
54
|
+
async parseWithSchemaDetailed() {
|
|
55
|
+
gateway += 1;
|
|
56
|
+
return gatewayResult;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
assert.equal(Reflect.set(engine, "client", client), true);
|
|
60
|
+
assert.equal(Reflect.set(engine, "fallbackLlm", fallbackLlm), true);
|
|
61
|
+
return { engine, directCalls: () => direct, gatewayCalls: () => gateway };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test("an oversized atomic direct request fails as direct_input_too_large and stays retryable", async () => {
|
|
65
|
+
const { engine, directCalls } = engineWithDirectFailure(
|
|
66
|
+
new FakeBadRequestError(400, "The total text input size exceeds 8 MB"),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const result = await engine.extract(OVERSIZED_WINDOW);
|
|
70
|
+
|
|
71
|
+
assert.equal(directCalls(), 1);
|
|
72
|
+
assert.equal(result.extractionFailure, "direct_input_too_large");
|
|
73
|
+
// provider_retryable keeps the window: the drain never counts it toward a drop
|
|
74
|
+
// and the retry layer never long-parks it as a parse failure.
|
|
75
|
+
assert.equal(result.extractionFailureClass, "provider_retryable");
|
|
76
|
+
assert.deepEqual(result.facts, []);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("an HTTP 413 from the direct client is a size rejection too", async () => {
|
|
80
|
+
const { engine } = engineWithDirectFailure(new FakeBadRequestError(413, "Request Entity Too Large"));
|
|
81
|
+
const result = await engine.extract(OVERSIZED_WINDOW);
|
|
82
|
+
assert.equal(result.extractionFailure, "direct_input_too_large");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("the gateway fallback still runs and wins after a direct size rejection", async () => {
|
|
86
|
+
const { engine, gatewayCalls } = engineWithDirectFailure(
|
|
87
|
+
new FakeBadRequestError(400, "This model's maximum context length is 128000 tokens"),
|
|
88
|
+
{
|
|
89
|
+
modelUsed: "fixture-gateway",
|
|
90
|
+
result: {
|
|
91
|
+
facts: [{ category: "fact", content: SENTENCE.trim(), confidence: 0.95, tags: [] }],
|
|
92
|
+
profileUpdates: [],
|
|
93
|
+
entities: [],
|
|
94
|
+
questions: [],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const result = await engine.extract(OVERSIZED_WINDOW);
|
|
100
|
+
|
|
101
|
+
assert.equal(gatewayCalls(), 1);
|
|
102
|
+
assert.equal(result.extractionFailure, undefined);
|
|
103
|
+
assert.equal(result.facts[0]?.content, SENTENCE.trim());
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("a direct 400 that is not about size keeps the gateway failure", async () => {
|
|
107
|
+
const { engine } = engineWithDirectFailure(new FakeBadRequestError(400, "invalid model id"));
|
|
108
|
+
const result = await engine.extract(OVERSIZED_WINDOW);
|
|
109
|
+
assert.equal(result.extractionFailure, "fallback_no_parsed_output");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("isRequestTooLargeError rejects 400s whose 'exceed' is not about input size", () => {
|
|
113
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "max_tokens exceeds maximum allowed")), false);
|
|
114
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "temperature exceeds 2.0")), false);
|
|
115
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "quota exceeded")), false);
|
|
116
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "spending limit exceeded")), false);
|
|
117
|
+
assert.equal(
|
|
118
|
+
isRequestTooLargeError(new FakeBadRequestError(400, "You exceeded your current quota, please check your plan")),
|
|
119
|
+
false,
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("isRequestTooLargeError matches size rejections only", () => {
|
|
124
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(413, "Payload Too Large")), true);
|
|
125
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "The total text input size exceeds 8 MB")), true);
|
|
126
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "maximum context length is 8192 tokens")), true);
|
|
127
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "prompt is too long")), true);
|
|
128
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "invalid model id")), false);
|
|
129
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(500, "upstream payload too large")), false);
|
|
130
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(429, "rate limit exceeded")), false);
|
|
131
|
+
assert.equal(isRequestTooLargeError(new Error("input too large")), false);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("isRequestTooLargeError needs an input subject for 'too large' and 'too long' (#3533)", () => {
|
|
135
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "temperature is too large")), false);
|
|
136
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "max_tokens is too large: 9000")), false);
|
|
137
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "top_k value is too large")), false);
|
|
138
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "stop sequence is too long")), false);
|
|
139
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "Request too large for model")), true);
|
|
140
|
+
assert.equal(isRequestTooLargeError(new FakeBadRequestError(400, "prompt is too long")), true);
|
|
141
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtractionFailureClass } from "./types.js";
|
|
1
|
+
import type { ExtractionFailureClass, ExtractionResult } from "./types.js";
|
|
2
2
|
import { isTransientHttpError } from "./connectors/live/transient-errors.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -32,6 +32,66 @@ export function classifyExtractionThrownError(err: unknown): ExtractionFailureCl
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const CONTEXT_LIMIT_MESSAGE = /maximum context|context length|context window|request entity/i;
|
|
36
|
+
const SIZE_LIMIT_PHRASE = /too large|too long|exceed/i;
|
|
37
|
+
const INPUT_SUBJECT_TERM =
|
|
38
|
+
/\b(?:input|prompt|request|payload|body|messages?|content|context|size|length|tokens?)\b/i;
|
|
39
|
+
const REQUEST_TOO_LARGE_EXCLUDE =
|
|
40
|
+
/\b(?:max_tokens|max_completion_tokens|temperature|top_p|quota|rate limit|spending|billing)\b/i;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* True when a provider refused the request because the input is too big: HTTP
|
|
44
|
+
* 413, or HTTP 400 whose message names a size or context limit (OpenAI-style
|
|
45
|
+
* "maximum context length", "total text input size exceeds 8 MB"). "too large",
|
|
46
|
+
* "too long" and "exceed" count only beside an input subject and never beside
|
|
47
|
+
* an output, quota or sampling term (`max_tokens exceeds limit`,
|
|
48
|
+
* `temperature is too large`, `quota exceeded` are different failures).
|
|
49
|
+
* Resending the same atomic request can never succeed (#3531). Never throws.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/** An Error or SDK error object; the HTTP status is sniffed off it when present. */
|
|
53
|
+
export interface HttpThrowable {
|
|
54
|
+
readonly status?: number;
|
|
55
|
+
readonly message?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isRequestTooLargeError(err: HttpThrowable): boolean {
|
|
59
|
+
try {
|
|
60
|
+
const status = httpStatusFromError(err);
|
|
61
|
+
if (status === 413) return true;
|
|
62
|
+
if (status !== 400 || !(err instanceof Error)) return false;
|
|
63
|
+
const message = err.message;
|
|
64
|
+
if (CONTEXT_LIMIT_MESSAGE.test(message)) return true;
|
|
65
|
+
if (REQUEST_TOO_LARGE_EXCLUDE.test(message)) return false;
|
|
66
|
+
return SIZE_LIMIT_PHRASE.test(message) && INPUT_SUBJECT_TERM.test(message);
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Result when the provider refused the window as too large (#3531). Retryable
|
|
74
|
+
* on purpose: the retained turns are never parked or dropped, and
|
|
75
|
+
* `remnic buffer drain` can still extract them in budget-sized chunks.
|
|
76
|
+
*/
|
|
77
|
+
export function directInputTooLargeResult(): ExtractionResult {
|
|
78
|
+
return {
|
|
79
|
+
facts: [],
|
|
80
|
+
profileUpdates: [],
|
|
81
|
+
entities: [],
|
|
82
|
+
questions: [],
|
|
83
|
+
extractionFailure: "direct_input_too_large",
|
|
84
|
+
extractionFailureClass: "provider_retryable",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function formatDirectInputTooLargeLog(chars: number): string {
|
|
89
|
+
return (
|
|
90
|
+
`extraction: direct client refused a ${chars}-char request as too large; an atomic flush is never ` +
|
|
91
|
+
"split, so any turns the gateway fallback does not extract stay buffered for `remnic buffer drain`"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
35
95
|
/**
|
|
36
96
|
* Map the gateway fallback's discriminated parse-failure reason to a coarse
|
|
37
97
|
* extraction failure class. "no models configured" is an auth/config problem;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { parseConfig } from "./config.js";
|
|
5
|
+
import {
|
|
6
|
+
ExtractionQueueCoordinator,
|
|
7
|
+
type ExtractionQueueTask,
|
|
8
|
+
} from "./orchestration/extraction-queue-coordinator.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Bounded-concurrency default regressions: the extraction queue ships
|
|
12
|
+
* bounded-parallel instead of serial, an explicit operator value — including
|
|
13
|
+
* a deployed serial `1` — always wins over the default, and the default
|
|
14
|
+
* limit still serializes work sharing a session key.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Parked queue task with deterministic start/release handles. */
|
|
18
|
+
function makeParkedTask() {
|
|
19
|
+
const started = Promise.withResolvers<void>();
|
|
20
|
+
const release = Promise.withResolvers<void>();
|
|
21
|
+
let didStart = false;
|
|
22
|
+
const task: ExtractionQueueTask = async () => {
|
|
23
|
+
didStart = true;
|
|
24
|
+
started.resolve();
|
|
25
|
+
await release.promise;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
task,
|
|
29
|
+
startedPromise: started.promise,
|
|
30
|
+
release: () => release.resolve(),
|
|
31
|
+
get started() {
|
|
32
|
+
return didStart;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function startedWithin(promise: Promise<void>, timeoutMs = 1_000): Promise<boolean> {
|
|
38
|
+
const result = Promise.withResolvers<boolean>();
|
|
39
|
+
const timeout = setTimeout(() => result.resolve(false), timeoutMs);
|
|
40
|
+
void promise.then(() => result.resolve(true));
|
|
41
|
+
try {
|
|
42
|
+
return await result.promise;
|
|
43
|
+
} finally {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test("parseConfig: extractionQueueConcurrency defaults to bounded-parallel 2", () => {
|
|
49
|
+
assert.equal(parseConfig({}).extractionQueueConcurrency, 2);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("parseConfig: an explicit operator value wins over the default (serial 1 stays serial)", () => {
|
|
53
|
+
assert.equal(parseConfig({ extractionQueueConcurrency: 1 }).extractionQueueConcurrency, 1);
|
|
54
|
+
assert.equal(parseConfig({ extractionQueueConcurrency: 4 }).extractionQueueConcurrency, 4);
|
|
55
|
+
for (const invalid of [0, -1, 1.5, "two"]) {
|
|
56
|
+
assert.throws(
|
|
57
|
+
() => parseConfig({ extractionQueueConcurrency: invalid }),
|
|
58
|
+
/extractionQueueConcurrency must be a positive integer/,
|
|
59
|
+
`expected rejection for ${JSON.stringify(invalid)}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("default coordinator limit is 2", () => {
|
|
65
|
+
assert.equal(new ExtractionQueueCoordinator().maxConcurrency, 2);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("default coordinator runs two distinct sessions concurrently, not three", async () => {
|
|
69
|
+
const coordinator = new ExtractionQueueCoordinator();
|
|
70
|
+
const first = makeParkedTask();
|
|
71
|
+
const second = makeParkedTask();
|
|
72
|
+
const third = makeParkedTask();
|
|
73
|
+
coordinator.enqueue(first.task, { key: "session-a" });
|
|
74
|
+
coordinator.enqueue(second.task, { key: "session-b" });
|
|
75
|
+
coordinator.enqueue(third.task, { key: "session-c" });
|
|
76
|
+
try {
|
|
77
|
+
assert.equal(await startedWithin(first.startedPromise), true, "first session should start");
|
|
78
|
+
assert.equal(await startedWithin(second.startedPromise), true, "second session should start in parallel");
|
|
79
|
+
assert.equal(third.started, false, "the third task must stay queued: the default limit is 2, not unbounded");
|
|
80
|
+
first.release();
|
|
81
|
+
assert.equal(await startedWithin(third.startedPromise), true, "a freed slot should start the third task");
|
|
82
|
+
} finally {
|
|
83
|
+
first.release();
|
|
84
|
+
second.release();
|
|
85
|
+
third.release();
|
|
86
|
+
assert.equal(await coordinator.waitForIdle(5_000), true);
|
|
87
|
+
}
|
|
88
|
+
assert.equal(coordinator.isProcessing, false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("default coordinator still serializes tasks sharing a session key", async () => {
|
|
92
|
+
const coordinator = new ExtractionQueueCoordinator();
|
|
93
|
+
const busy = makeParkedTask();
|
|
94
|
+
const sameKey = makeParkedTask();
|
|
95
|
+
coordinator.enqueue(busy.task, { key: "s1" });
|
|
96
|
+
await busy.startedPromise;
|
|
97
|
+
coordinator.enqueue(sameKey.task, { key: "s1" });
|
|
98
|
+
assert.equal(
|
|
99
|
+
sameKey.started,
|
|
100
|
+
false,
|
|
101
|
+
"same-session work must never run concurrently, even under the default limit",
|
|
102
|
+
);
|
|
103
|
+
busy.release();
|
|
104
|
+
await sameKey.startedPromise;
|
|
105
|
+
sameKey.release();
|
|
106
|
+
assert.equal(await coordinator.waitForIdle(5_000), true);
|
|
107
|
+
});
|
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, localRejectionStatus, type LocalFailureDiag } from "./extraction-error-classification.js";
|
|
41
|
+
import { LocalLlmRejectedError, classifyExtractionThrownError, classifyFallbackParseFailure, classifyLocalLlmRejected, formatExtractionParseFailureLog, directInputTooLargeResult, formatDirectInputTooLargeLog, 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 {
|
|
@@ -1179,6 +1179,8 @@ export class ExtractionEngine {
|
|
|
1179
1179
|
// fallback, so a gateway "no models" result doesn't re-classify a real
|
|
1180
1180
|
// primary failure as auth_config (codex review: preserve direct/local failures).
|
|
1181
1181
|
let primaryExtractorAttempted = false;
|
|
1182
|
+
// Direct client refused the request as too large (#3531): report that if the gateway fails too.
|
|
1183
|
+
let directInputTooLarge = false;
|
|
1182
1184
|
|
|
1183
1185
|
try {
|
|
1184
1186
|
// Try local LLM first if enabled
|
|
@@ -1275,6 +1277,8 @@ export class ExtractionEngine {
|
|
|
1275
1277
|
});
|
|
1276
1278
|
} catch { /* trace emit must not block fallback */ }
|
|
1277
1279
|
closedDirectTrace = true;
|
|
1280
|
+
directInputTooLarge = err instanceof Object && isRequestTooLargeError(err);
|
|
1281
|
+
if (directInputTooLarge) log.warn(formatDirectInputTooLargeLog(conversation.length));
|
|
1278
1282
|
log.info("extraction: direct client failed, falling back to gateway AI:", err);
|
|
1279
1283
|
} finally {
|
|
1280
1284
|
try { this.profiler.endSpan("direct-client", extractionTraceId); } catch { /* span may already be closed */ }
|
|
@@ -1383,6 +1387,7 @@ export class ExtractionEngine {
|
|
|
1383
1387
|
"provider_retryable"
|
|
1384
1388
|
: classifyFallbackParseFailure(detailed.failureReason)
|
|
1385
1389
|
: "parse_empty";
|
|
1390
|
+
if (directInputTooLarge) return directInputTooLargeResult();
|
|
1386
1391
|
return {
|
|
1387
1392
|
facts: [],
|
|
1388
1393
|
profileUpdates: [],
|
|
@@ -1398,6 +1403,7 @@ export class ExtractionEngine {
|
|
|
1398
1403
|
durationMs: Date.now() - fallbackStartTime, error: String(err),
|
|
1399
1404
|
});
|
|
1400
1405
|
log.error("extraction fallback failed", err);
|
|
1406
|
+
if (directInputTooLarge) return directInputTooLargeResult();
|
|
1401
1407
|
return {
|
|
1402
1408
|
facts: [],
|
|
1403
1409
|
profileUpdates: [],
|
|
@@ -92,7 +92,7 @@ export class ExtractionQueueCoordinator {
|
|
|
92
92
|
/** Resolves the processor's park while a new task arrives mid-drain. */
|
|
93
93
|
private wake?: () => void;
|
|
94
94
|
|
|
95
|
-
constructor(concurrency =
|
|
95
|
+
constructor(concurrency = 2) {
|
|
96
96
|
this.concurrency = Number.isInteger(concurrency) && concurrency >= 1 ? concurrency : 1;
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -35,7 +35,7 @@ function installCapturingLogger(): { entries: LogEntry[] } {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function createCoordinator(): ExtractionQueueCoordinator {
|
|
38
|
-
return new ExtractionQueueCoordinator();
|
|
38
|
+
return new ExtractionQueueCoordinator(1);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// ── Per-key FIFO: queued tasks retain their own captured scope and settlement ─
|
|
@@ -495,8 +495,8 @@ test("tasks sharing a buffer key never run concurrently even with free capacity"
|
|
|
495
495
|
assert.equal(otherKey.outcome, "finished");
|
|
496
496
|
});
|
|
497
497
|
|
|
498
|
-
test("
|
|
499
|
-
const coordinator =
|
|
498
|
+
test("an explicit limit of 1 keeps the queue serial", async () => {
|
|
499
|
+
const coordinator = createParallelCoordinator(1);
|
|
500
500
|
assert.equal(coordinator.maxConcurrency, 1);
|
|
501
501
|
const first = makeParkedTask(false);
|
|
502
502
|
const second = makeParkedTask(false);
|
|
@@ -379,7 +379,7 @@ test("flushSession waits for queued extraction task completion", async () => {
|
|
|
379
379
|
return [makeTurn("thread-a", "remember alpha")];
|
|
380
380
|
},
|
|
381
381
|
};
|
|
382
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
382
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
383
383
|
orchestrator.runExtraction = async () => {
|
|
384
384
|
extractionStarted = true;
|
|
385
385
|
await new Promise<void>((resolve) => {
|
|
@@ -475,7 +475,7 @@ test("flushSession flushes the pending debounced buffer save before extraction,
|
|
|
475
475
|
assert.equal(entryTurns[0]?.content, "remember alpha");
|
|
476
476
|
});
|
|
477
477
|
test("queued extraction settles immediately when its caller aborts while waiting", async () => {
|
|
478
|
-
const queue = new ExtractionQueueCoordinator();
|
|
478
|
+
const queue = new ExtractionQueueCoordinator(1);
|
|
479
479
|
let extractionStarted = false;
|
|
480
480
|
let releaseExtraction!: () => void;
|
|
481
481
|
// SAFETY: fixture deps stub — only the queued-extraction path fields are exercised.
|
|
@@ -658,7 +658,7 @@ test("flushSession rejects and skips extraction when the durable buffer save fai
|
|
|
658
658
|
test("ingestBulkImportBatch rejects when the extraction deadline expires in the queue", async () => {
|
|
659
659
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
660
660
|
orchestrator.config = parseConfig({});
|
|
661
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
661
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
662
662
|
orchestrator.extractionQueueCoordinator.setProcessingForTest(true);
|
|
663
663
|
let runExtractionCalls = 0;
|
|
664
664
|
orchestrator.runExtraction = async () => {
|
|
@@ -709,7 +709,7 @@ test("ingestBulkImportBatch rejects when the extraction deadline expires in the
|
|
|
709
709
|
test("queued extraction clamps long deadline timers to the Node setTimeout limit", async () => {
|
|
710
710
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
711
711
|
orchestrator.config = parseConfig({});
|
|
712
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
712
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
713
713
|
orchestrator.extractionQueueCoordinator.setProcessingForTest(true);
|
|
714
714
|
orchestrator.runExtraction = async () => ({
|
|
715
715
|
status: "completed",
|
|
@@ -742,7 +742,7 @@ test("queued extraction clamps long deadline timers to the Node setTimeout limit
|
|
|
742
742
|
test("ingestBulkImportBatch does not report queue wait timeout after extraction starts", async () => {
|
|
743
743
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
744
744
|
orchestrator.config = parseConfig({});
|
|
745
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
745
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
746
746
|
let runExtractionCalls = 0;
|
|
747
747
|
orchestrator.runExtraction = async () => {
|
|
748
748
|
runExtractionCalls += 1;
|
|
@@ -777,7 +777,7 @@ test("ingestBulkImportBatch does not report queue wait timeout after extraction
|
|
|
777
777
|
test("ingestBulkImportBatch reports post-persist metadata failures separately", async () => {
|
|
778
778
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
779
779
|
orchestrator.config = parseConfig({});
|
|
780
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
780
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
781
781
|
orchestrator.runExtraction = async () => ({
|
|
782
782
|
status: "completed",
|
|
783
783
|
persistedCount: 1,
|
|
@@ -809,7 +809,7 @@ test("ingestBulkImportBatch reports post-persist metadata failures separately",
|
|
|
809
809
|
test("ingestBulkImportBatch can disable source-valid-at replay context", async () => {
|
|
810
810
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
811
811
|
orchestrator.config = parseConfig({});
|
|
812
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
812
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
813
813
|
const capturedSlices: BufferTurn[][] = [];
|
|
814
814
|
orchestrator.runExtraction = async (turns: BufferTurn[]) => {
|
|
815
815
|
capturedSlices.push(turns);
|
|
@@ -862,7 +862,7 @@ test("ingestBulkImportBatch can disable source-valid-at replay context", async (
|
|
|
862
862
|
test("ingestBulkImportBatch skips LCM observation for flush-plan recovery batches (issue #2457)", async () => {
|
|
863
863
|
const orchestrator = Object.create(Orchestrator.prototype) as unknown as BulkImportTestDouble;
|
|
864
864
|
orchestrator.config = parseConfig({});
|
|
865
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
865
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
866
866
|
const observedSessionKeys: string[] = [];
|
|
867
867
|
orchestrator.lcmEngine = {
|
|
868
868
|
enabled: true,
|
|
@@ -907,7 +907,7 @@ test("ingestBulkImportBatch skips LCM observation for flush-plan recovery batche
|
|
|
907
907
|
test("ingestBulkImportBatch still observes ordinary bulk imports through LCM (issue #2457)", async () => {
|
|
908
908
|
const orchestrator = Object.create(Orchestrator.prototype) as unknown as BulkImportTestDouble;
|
|
909
909
|
orchestrator.config = parseConfig({});
|
|
910
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
910
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
911
911
|
const observed: { sessionKey: string; turnCount: number }[] = [];
|
|
912
912
|
orchestrator.lcmEngine = {
|
|
913
913
|
enabled: true,
|
|
@@ -946,7 +946,7 @@ test("ingestBulkImportBatch still observes ordinary bulk imports through LCM (is
|
|
|
946
946
|
test("ingestBulkImportBatch observes mixed batches that contain flush-plan turns (issue #2457)", async () => {
|
|
947
947
|
const orchestrator = Object.create(Orchestrator.prototype) as unknown as BulkImportTestDouble;
|
|
948
948
|
orchestrator.config = parseConfig({});
|
|
949
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
949
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
950
950
|
const observed: number[] = [];
|
|
951
951
|
orchestrator.lcmEngine = {
|
|
952
952
|
enabled: true,
|
|
@@ -985,7 +985,7 @@ test("ingestBulkImportBatch observes mixed batches that contain flush-plan turns
|
|
|
985
985
|
test("ingestBulkImportBatch preserves partial metadata failure before a later slice rejects", async () => {
|
|
986
986
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
987
987
|
orchestrator.config = parseConfig({});
|
|
988
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
988
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
989
989
|
let runExtractionCalls = 0;
|
|
990
990
|
orchestrator.runExtraction = async () => {
|
|
991
991
|
runExtractionCalls += 1;
|
|
@@ -1047,7 +1047,7 @@ test("ingestBulkImportBatch preserves partial metadata failure before a later sl
|
|
|
1047
1047
|
test("ingestBulkImportBatch stops after the first failed source-valid-at slice", async () => {
|
|
1048
1048
|
const orchestrator = Object.create(Orchestrator.prototype) as any;
|
|
1049
1049
|
orchestrator.config = parseConfig({});
|
|
1050
|
-
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator();
|
|
1050
|
+
orchestrator.extractionQueueCoordinator = new ExtractionQueueCoordinator(1);
|
|
1051
1051
|
let runExtractionCalls = 0;
|
|
1052
1052
|
orchestrator.runExtraction = async () => {
|
|
1053
1053
|
runExtractionCalls += 1;
|
package/src/types.ts
CHANGED
|
@@ -725,7 +725,7 @@ export interface PluginConfig
|
|
|
725
725
|
/** Retained turns admitted per session before live backpressure (#3415 bound). */
|
|
726
726
|
bufferMaxTurnsPerSession: number;
|
|
727
727
|
bufferMaxMinutes: number;
|
|
728
|
-
/**
|
|
728
|
+
/** Background extraction concurrency; defaults to 2. Same-buffer tasks never overlap. Applies at daemon start. */
|
|
729
729
|
extractionQueueConcurrency: number;
|
|
730
730
|
/**
|
|
731
731
|
* Debounce window (ms) for persisting the smart buffer to `state/buffer.json`
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/extraction-error-classification.ts"],"sourcesContent":["import type { ExtractionFailureClass } from \"./types.js\";\nimport { isTransientHttpError } from \"./connectors/live/transient-errors.js\";\n\n/**\n * Read a numeric HTTP status off a thrown error without re-implementing the\n * shared transient classifier. Uses `in`/typeof narrowing (no inline casts).\n */\nfunction httpStatusFromError(err: unknown): number | undefined {\n if (!err || typeof err !== \"object\") return undefined;\n if (\"status\" in err && typeof err.status === \"number\" && Number.isFinite(err.status)) return err.status;\n if (\"statusCode\" in err && typeof err.statusCode === \"number\" && Number.isFinite(err.statusCode)) {\n return err.statusCode;\n }\n return undefined;\n}\n\n/**\n * Map a thrown extraction error to a coarse failure class for the retry/breaker\n * layer. 401/403 → `auth_config` (misconfigured provider, open the breaker);\n * transient (429/5xx/network, per the shared `isTransientHttpError`) → back off;\n * anything else defaults to `provider_retryable` (fail-open toward retry, but\n * capped by the per-fingerprint attempt budget). Never throws.\n */\nexport function classifyExtractionThrownError(err: unknown): ExtractionFailureClass {\n try {\n const status = httpStatusFromError(err);\n if (status === 401 || status === 403) return \"auth_config\";\n if (isTransientHttpError(err)) return \"provider_retryable\";\n return \"provider_retryable\";\n } catch {\n return \"provider_retryable\";\n }\n}\n\n/**\n * Map the gateway fallback's discriminated parse-failure reason to a coarse\n * extraction failure class. \"no models configured\" is an auth/config problem;\n * an HTTP/transport failure backs off; an unparseable-but-present response is a\n * genuine empty-parse.\n */\nexport function classifyFallbackParseFailure(\n reason: \"no_models\" | \"empty\" | \"http_error\" | \"schema_rejection\" | \"timeout\",\n): ExtractionFailureClass {\n switch (reason) {\n case \"no_models\":\n return \"auth_config\";\n case \"http_error\":\n case \"timeout\":\n return \"provider_retryable\";\n case \"empty\":\n case \"schema_rejection\":\n return \"parse_empty\";\n }\n}\n\n/**\n * Operator-visible extraction parse-failure line. Keeps the historical\n * greppable prefix and appends the fields that used to live only at debug.\n */\nexport function formatExtractionParseFailureLog(input: {\n failureReason: string;\n attemptedModel?: string;\n httpStatus?: number;\n errorClass?: string;\n traceId: string;\n}): string {\n const modelUsed =\n typeof input.attemptedModel === \"string\" && input.attemptedModel.length > 0\n ? input.attemptedModel\n : \"unknown\";\n const errorClass =\n typeof input.errorClass === \"string\" && input.errorClass.length > 0\n ? input.errorClass\n : \"none\";\n const httpStatus =\n typeof input.httpStatus === \"number\" && Number.isFinite(input.httpStatus)\n ? String(input.httpStatus)\n : \"none\";\n return [\n \"extraction fallback returned no parsed output\",\n `failureReason=${input.failureReason}`,\n `modelUsed=${modelUsed}`,\n `errorClass=${errorClass}`,\n `httpStatus=${httpStatus}`,\n `traceId=${input.traceId}`,\n ].join(\" \");\n}\n\n/**\n * The local endpoint answered, and what it said rejects this input (unusable content, or a client error that is not\n * auth, timeout or rate limiting): the chunk's problem, not an outage. A `finish_reason=length` reply classifies as\n * `output_truncated` (#3521); every other rejection retries like an empty parse, and a trigger-drain\n * chunk that keeps drawing it is dropped after its recovery copy is saved.\n */\nexport class LocalLlmRejectedError extends Error {\n constructor(readonly httpStatus?: number, readonly finishReason?: string) {\n super(httpStatus === undefined ? \"local LLM answered with unusable content\" : `local LLM rejected the input (HTTP ${httpStatus})`);\n this.name = \"LocalLlmRejectedError\";\n }\n}\n\n/**\n * Map a local-endpoint rejection to its failure class: a reply cut off at the\n * output ceiling (`finish_reason=length`) is `output_truncated` — retries at\n * the same `maxOutputTokens` can never complete (#3521). Every other unusable\n * or refused reply stays `parse_empty`.\n */\nexport function classifyLocalLlmRejected(err: LocalLlmRejectedError): ExtractionFailureClass {\n return err.finishReason === \"length\" ? \"output_truncated\" : \"parse_empty\";\n}\n\n/** What the local client recorded about a failed call (`failureDiag`). */\nexport interface LocalFailureDiag {\n lastError?: unknown;\n /** The completion's `finish_reason` as the client received it (validated before it is logged). */\n finishReason?: string;\n}\n\n/** 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. */\nexport function localRejectionStatus(diag: LocalFailureDiag): number | undefined {\n const status = httpStatusFromError(diag.lastError);\n return status !== undefined && [400, 413, 422].includes(status) ? status : undefined;\n}\n"],"mappings":";;;;;AAOA,SAAS,oBAAoB,KAAkC;AAC7D,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;AAC5C,MAAI,YAAY,OAAO,OAAO,IAAI,WAAW,YAAY,OAAO,SAAS,IAAI,MAAM,EAAG,QAAO,IAAI;AACjG,MAAI,gBAAgB,OAAO,OAAO,IAAI,eAAe,YAAY,OAAO,SAAS,IAAI,UAAU,GAAG;AAChG,WAAO,IAAI;AAAA,EACb;AACA,SAAO;AACT;AASO,SAAS,8BAA8B,KAAsC;AAClF,MAAI;AACF,UAAM,SAAS,oBAAoB,GAAG;AACtC,QAAI,WAAW,OAAO,WAAW,IAAK,QAAO;AAC7C,QAAI,qBAAqB,GAAG,EAAG,QAAO;AACtC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQO,SAAS,6BACd,QACwB;AACxB,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAMO,SAAS,gCAAgC,OAMrC;AACT,QAAM,YACJ,OAAO,MAAM,mBAAmB,YAAY,MAAM,eAAe,SAAS,IACtE,MAAM,iBACN;AACN,QAAM,aACJ,OAAO,MAAM,eAAe,YAAY,MAAM,WAAW,SAAS,IAC9D,MAAM,aACN;AACN,QAAM,aACJ,OAAO,MAAM,eAAe,YAAY,OAAO,SAAS,MAAM,UAAU,IACpE,OAAO,MAAM,UAAU,IACvB;AACN,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB,MAAM,aAAa;AAAA,IACpC,aAAa,SAAS;AAAA,IACtB,cAAc,UAAU;AAAA,IACxB,cAAc,UAAU;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B,EAAE,KAAK,GAAG;AACZ;AAQO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAC/C,YAAqB,YAA8B,cAAuB;AACxE,UAAM,eAAe,SAAY,6CAA6C,sCAAsC,UAAU,GAAG;AAD9G;AAA8B;AAEjD,SAAK,OAAO;AAAA,EACd;AAAA,EAHqB;AAAA,EAA8B;AAIrD;AAQO,SAAS,yBAAyB,KAAoD;AAC3F,SAAO,IAAI,iBAAiB,WAAW,qBAAqB;AAC9D;AAUO,SAAS,qBAAqB,MAA4C;AAC/E,QAAM,SAAS,oBAAoB,KAAK,SAAS;AACjD,SAAO,WAAW,UAAa,CAAC,KAAK,KAAK,GAAG,EAAE,SAAS,MAAM,IAAI,SAAS;AAC7E;","names":[]}
|