nowledge-mem 0.1.6: requestTimeoutMs and the hook budget go up to 30s (#926)
A deep Mem search can take longer than 5s, and the page refused any requestTimeoutMs over 5000 or gatewayTimeoutMs over 10000. Both now go up to 30000; the defaults (1500 and magpie's 1000) are unchanged. magpie v0.1.3538 (yetone/magpie#5890) runs a hook up to its own 30s budget; the README says an older magpie cuts anything over 10s. - validate.js, settings page and labels (en, zh, zh-TW, ja, de): 50-30000 and 100-30000. - nowledge-mem-agent checked: its 10000 ms values are fixed internal timeouts, not user options with a cap; unchanged. - slow-recall.test.mjs: a fixture server answers /memories/search after 6100 ms; requestTimeoutMs 15000 recalls it, 30001 is invalid, and a caller abort stops the fetch at once (the server sees the abort) and keeps the request as it came. Run (wsl-run, magpie-desktop): bun test packages/nowledge-mem packages/nowledge-mem-agent: 161 pass, 2 skip (live Mem and the Playwright layout check, skipped as on main), 0 fail; bun scripts/check.mjs: rc 0. The README's magpie version was filled in after that run. Not tried: a real Nowledge Mem server with a slow deep search. Reported-by: aboat0625-cpu
This commit is contained in:
@@ -120,15 +120,19 @@ derived value for all of them.
|
||||
512–32768. On the first turn the session context takes up to 45% of it, and
|
||||
the rest stays available for Memory.
|
||||
- `requestTimeoutMs`: deadline for each search, bundle or Working Memory
|
||||
request, default 1500, range 50–5000. Magpie's default 1000 ms hook
|
||||
deadline can end the request earlier. The package's example options set
|
||||
request, default 1500, range 50–30000. Magpie's default 1000 ms hook
|
||||
deadline can end the request earlier, so a longer value needs a
|
||||
`gatewayTimeoutMs` at least as long. A deep search can take 20 seconds. The package's example options set
|
||||
this to 900 when used explicitly. Thread imports keep a separate ten-second
|
||||
deadline because a completed reply's notification is not bound to the live
|
||||
request.
|
||||
- `gatewayTimeoutMs` (Magpie's own option, not this package's): the whole hook
|
||||
chain's deadline, default 1000 ms, range 100–10000. A local Mem fits the
|
||||
default; over the network, set it to 5000–10000 so the first turn's Context
|
||||
Bundle and search can finish.
|
||||
- `gatewayTimeoutMs` (Magpie's own option, not this package's): the hook's
|
||||
deadline, default 1000 ms, range 100–30000. A local Mem fits the default;
|
||||
over the network, set it to 5000–10000 so the first turn's Context Bundle
|
||||
and search can finish, and higher for a slow deep search. A budget over
|
||||
10000 ms needs Magpie 0.1.3538 or later; an older Magpie takes
|
||||
any value over 10000 as its 1000 ms default and stops the chain at 10
|
||||
seconds.
|
||||
- `recallBackoffMs`: after a connection failure, timeout or unavailable
|
||||
response, skip Mem for this endpoint/credential/Space for this long, default
|
||||
30000, range 100–300000. A failing optional bundle backs off only itself; the
|
||||
|
||||
@@ -8,7 +8,7 @@ import "./page/validate.js";
|
||||
const validateExplicitOptions = globalThis.__nowledgeMemValidateOptions;
|
||||
|
||||
// Bumped with package.json: Mem's own clients record it on imported Threads.
|
||||
export const version = "0.1.5";
|
||||
export const version = "0.1.6";
|
||||
|
||||
// The only report codes magpie's Plugins page shows; tools turn these into
|
||||
// messages, never the service's own text.
|
||||
|
||||
@@ -311,7 +311,7 @@ test("options it can't use are invalid, before anything is sent", async () => {
|
||||
{ serverUrl: "https://mem.example.com?token=x", apiKey: "k" },
|
||||
{ serverUrl: "http://127.0.0.1:14242", maxBytes: 100 },
|
||||
{ serverUrl: "http://127.0.0.1:14242", maxMemories: 0 },
|
||||
{ serverUrl: "http://127.0.0.1:14242", requestTimeoutMs: 10_000 },
|
||||
{ serverUrl: "http://127.0.0.1:14242", requestTimeoutMs: 30_001 },
|
||||
{ serverUrl: "http://127.0.0.1:14242", recallBackoffMs: 10 },
|
||||
{ serverUrl: "http://127.0.0.1:14242", capture: "yes" },
|
||||
{ serverUrl: "http://127.0.0.1:14242", recallRemote: "yes" },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/gateway-nowledge-mem",
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.6",
|
||||
"description": "Nowledge Mem recall, Context Bundle and optional conversation capture at the Magpie gateway, for every connected harness",
|
||||
"type": "module",
|
||||
"files": [
|
||||
|
||||
@@ -303,7 +303,7 @@ Object.assign(messages.en, {
|
||||
keyActionHelp: "Clearing the saved value falls back to the environment variable; it does not disable it.",
|
||||
keyEnv: "API key environment variable", keyEnvHelp: "Only NMEM_* names are accepted. Empty uses NMEM_API_KEY.",
|
||||
filterSection: "Saving and filtering", captureTools: "Include client tool results", captureCindy: "Clean recognized Cindy wrappers in human mode",
|
||||
advanced: "Advanced", maxMemories: "Maximum memories (1–20)", maxBytes: "Recall bytes (512–32768)", requestTimeout: "Request timeout ms (50–5000)", recallBackoff: "Recall backoff ms (100–300000)", gatewayTimeout: "Host hook timeout ms (100–10000)", port: "Connection-test port (1024–65535)", insecure: "Allow HTTP to a non-local server (credentials travel unencrypted)", defaultsHelp: "Empty fields inherit the environment where supported, otherwise use the shown default. Unchanged values remain as configured. The host timeout can end a request first.",
|
||||
advanced: "Advanced", maxMemories: "Maximum memories (1–20)", maxBytes: "Recall bytes (512–32768)", requestTimeout: "Request timeout ms (50–30000)", recallBackoff: "Recall backoff ms (100–300000)", gatewayTimeout: "Host hook timeout ms (100–30000)", port: "Connection-test port (1024–65535)", insecure: "Allow HTTP to a non-local server (credentials travel unencrypted)", defaultsHelp: "Empty fields inherit the environment where supported, otherwise use the shown default. Unchanged values remain as configured. The host timeout can end a request first.",
|
||||
conflict:"Configuration changed elsewhere. Your draft is kept; select Cancel, then reopen Settings to load the latest values.", invalidOption: "Check the highlighted values and ranges.",
|
||||
});
|
||||
Object.assign(messages.zh, {
|
||||
@@ -312,7 +312,7 @@ Object.assign(messages.zh, {
|
||||
useDefault: "恢复默认 / 继承",
|
||||
hostAgent: "宿主 Agent ID", hostAgentHelp: "留空时从客户端类型推导。", keyActionHelp: "清除保存值后仍会继承环境变量,不会禁用环境变量。", keyEnv: "API 密钥环境变量", keyEnvHelp: "仅接受 NMEM_* 名称;留空使用 NMEM_API_KEY。",
|
||||
filterSection: "保存与过滤", captureTools: "包含客户端工具结果", captureCindy: "在人类对话模式清理已识别的 Cindy 包装",
|
||||
advanced: "高级设置", maxMemories: "最多召回记忆数(1–20)", maxBytes: "召回字节数(512–32768)", requestTimeout: "请求超时毫秒(50–5000)", recallBackoff: "召回退避毫秒(100–300000)", gatewayTimeout: "宿主 hook 超时毫秒(100–10000)", port: "连接测试端口(1024–65535)", insecure: "允许非本机 HTTP(凭据将明文传输)", defaultsHelp: "留空时,支持环境继承的选项使用环境值,其余使用显示的默认值。未修改的值保持原样;宿主超时可能更早结束请求。",
|
||||
advanced: "高级设置", maxMemories: "最多召回记忆数(1–20)", maxBytes: "召回字节数(512–32768)", requestTimeout: "请求超时毫秒(50–30000)", recallBackoff: "召回退避毫秒(100–300000)", gatewayTimeout: "宿主 hook 超时毫秒(100–30000)", port: "连接测试端口(1024–65535)", insecure: "允许非本机 HTTP(凭据将明文传输)", defaultsHelp: "留空时,支持环境继承的选项使用环境值,其余使用显示的默认值。未修改的值保持原样;宿主超时可能更早结束请求。",
|
||||
conflict:"配置已在其他位置更改,草稿已保留。请选择“取消”,再重新打开设置以加载最新值。", invalidOption: "请检查输入及允许范围。",
|
||||
});
|
||||
Object.assign(messages["zh-TW"], {
|
||||
@@ -321,19 +321,19 @@ Object.assign(messages["zh-TW"], {
|
||||
useDefault:"恢復預設 / 繼承",
|
||||
hostAgent:"宿主 Agent ID", hostAgentHelp:"留空時從用戶端類型推導。", keyActionHelp:"清除儲存值後仍會繼承環境變數,不會停用環境變數。", keyEnv:"API 金鑰環境變數", keyEnvHelp:"僅接受 NMEM_* 名稱;留空使用 NMEM_API_KEY。",
|
||||
filterSection:"儲存與過濾", captureTools:"包含用戶端工具結果", captureCindy:"在人類對話模式清理已識別的 Cindy 包裝",
|
||||
advanced:"進階設定", maxMemories:"最多召回記憶數(1–20)", maxBytes:"召回位元組數(512–32768)", requestTimeout:"請求逾時毫秒(50–5000)", recallBackoff:"召回退避毫秒(100–300000)", gatewayTimeout:"宿主 hook 逾時毫秒(100–10000)", port:"連線測試埠(1024–65535)", insecure:"允許非本機 HTTP(憑據將明文傳輸)", defaultsHelp:"留空時,支援環境繼承的選項使用環境值,其餘使用顯示的預設值。未修改的值保持原樣;宿主逾時可能更早結束請求。", conflict:"設定已在其他位置更改,草稿已保留。請選擇「取消」,再重新開啟設定以載入最新值。", invalidOption:"請檢查輸入及允許範圍。",
|
||||
advanced:"進階設定", maxMemories:"最多召回記憶數(1–20)", maxBytes:"召回位元組數(512–32768)", requestTimeout:"請求逾時毫秒(50–30000)", recallBackoff:"召回退避毫秒(100–300000)", gatewayTimeout:"宿主 hook 逾時毫秒(100–30000)", port:"連線測試埠(1024–65535)", insecure:"允許非本機 HTTP(憑據將明文傳輸)", defaultsHelp:"留空時,支援環境繼承的選項使用環境值,其餘使用顯示的預設值。未修改的值保持原樣;宿主逾時可能更早結束請求。", conflict:"設定已在其他位置更改,草稿已保留。請選擇「取消」,再重新開啟設定以載入最新值。", invalidOption:"請檢查輸入及允許範圍。",
|
||||
});
|
||||
Object.assign(messages.ja, {
|
||||
concurrencyHelp:"保存時に変更を最新の設定に反映しますが、別の編集画面が同時に保存すると上書きされる可能性があります。一度に一つの編集画面を使ってください。非常に大きい整数は丸められる場合があります。",
|
||||
configure:"設定", dialogTitle:"Nowledge Mem の設定", settingsIntro:"接続、検索と保存を設定します。", saveHelp:"変更していない項目と一覧にない項目は保持されます。", notConfigured:"環境変数またはローカルの既定値を使用 · 未テスト",
|
||||
useDefault:"既定値 / 継承に戻す", hostAgent:"ホスト Agent ID", hostAgentHelp:"空欄の場合はハーネスから導出します。", keyActionHelp:"保存値を消すと環境変数にフォールバックします。環境変数は無効になりません。", keyEnv:"API キーの環境変数", keyEnvHelp:"NMEM_* のみ。空欄では NMEM_API_KEY を使用します。",
|
||||
filterSection:"保存とフィルター", captureTools:"クライアントのツール結果を含める", captureCindy:"人間の会話モードで既知の Cindy 包装を整理", advanced:"詳細設定", maxMemories:"記憶の最大数(1–20)", maxBytes:"検索のバイト数(512–32768)", requestTimeout:"リクエスト時間制限 ms(50–5000)", recallBackoff:"検索の再試行待ち ms(100–300000)", gatewayTimeout:"ホスト hook の時間制限 ms(100–10000)", port:"接続テストのポート(1024–65535)", insecure:"ローカル以外の HTTP を許可(認証情報は平文で送信)", defaultsHelp:"空欄は対応する環境変数、それ以外は表示された既定値を使用します。未変更の値は保持されます。ホストの時間制限が先に切れる場合があります。", conflict:"設定が別の場所で変更されました。下書きは保持されています。「キャンセル」を選び、設定を開き直してください。", invalidOption:"入力と範囲を確認してください。",
|
||||
filterSection:"保存とフィルター", captureTools:"クライアントのツール結果を含める", captureCindy:"人間の会話モードで既知の Cindy 包装を整理", advanced:"詳細設定", maxMemories:"記憶の最大数(1–20)", maxBytes:"検索のバイト数(512–32768)", requestTimeout:"リクエスト時間制限 ms(50–30000)", recallBackoff:"検索の再試行待ち ms(100–300000)", gatewayTimeout:"ホスト hook の時間制限 ms(100–30000)", port:"接続テストのポート(1024–65535)", insecure:"ローカル以外の HTTP を許可(認証情報は平文で送信)", defaultsHelp:"空欄は対応する環境変数、それ以外は表示された既定値を使用します。未変更の値は保持されます。ホストの時間制限が先に切れる場合があります。", conflict:"設定が別の場所で変更されました。下書きは保持されています。「キャンセル」を選び、設定を開き直してください。", invalidOption:"入力と範囲を確認してください。",
|
||||
});
|
||||
Object.assign(messages.de, {
|
||||
concurrencyHelp:"Beim Speichern werden deine Änderungen in die aktuellen Einstellungen übernommen; ein anderer gleichzeitig speichernder Editor kann sie dennoch überschreiben. Bitte nur einen Editor zugleich verwenden. Sehr große Ganzzahlen können gerundet werden.",
|
||||
configure:"Einstellungen", dialogTitle:"Nowledge Mem Einstellungen", settingsIntro:"Verbindung, Abruf und Speichern konfigurieren.", saveHelp:"Unveränderte und nicht aufgeführte Optionen bleiben erhalten.", notConfigured:"Umgebung oder lokaler Standard · noch nicht getestet",
|
||||
useDefault:"Standard / Erben", hostAgent:"Host-Agent-ID", hostAgentHelp:"Leer leitet die Identität aus dem Harness ab.", keyActionHelp:"Nach dem Löschen gilt weiterhin die Umgebungsvariable; sie wird nicht deaktiviert.", keyEnv:"Umgebungsvariable für API-Schlüssel", keyEnvHelp:"Nur NMEM_*; leer verwendet NMEM_API_KEY.",
|
||||
filterSection:"Speichern und filtern", captureTools:"Client-Tool-Ergebnisse einschließen", captureCindy:"Erkannte Cindy-Hüllen im Dialogmodus bereinigen", advanced:"Erweitert", maxMemories:"Maximale Erinnerungen (1–20)", maxBytes:"Abruf-Bytes (512–32768)", requestTimeout:"Anfrage-Timeout ms (50–5000)", recallBackoff:"Abruf-Wartezeit ms (100–300000)", gatewayTimeout:"Host-Hook-Timeout ms (100–10000)", port:"Verbindungstest-Port (1024–65535)", insecure:"HTTP zu fremdem Server erlauben (Zugangsdaten unverschlüsselt)", defaultsHelp:"Leer verwendet die Umgebung, wo unterstützt, sonst den angezeigten Standard. Unveränderte Werte bleiben erhalten. Das Host-Timeout kann früher enden.", conflict:"Die Konfiguration wurde anderswo geändert. Der Entwurf bleibt erhalten. Wähle „Abbrechen“ und öffne die Einstellungen erneut.", invalidOption:"Eingaben und Wertebereiche prüfen.",
|
||||
filterSection:"Speichern und filtern", captureTools:"Client-Tool-Ergebnisse einschließen", captureCindy:"Erkannte Cindy-Hüllen im Dialogmodus bereinigen", advanced:"Erweitert", maxMemories:"Maximale Erinnerungen (1–20)", maxBytes:"Abruf-Bytes (512–32768)", requestTimeout:"Anfrage-Timeout ms (50–30000)", recallBackoff:"Abruf-Wartezeit ms (100–300000)", gatewayTimeout:"Host-Hook-Timeout ms (100–30000)", port:"Verbindungstest-Port (1024–65535)", insecure:"HTTP zu fremdem Server erlauben (Zugangsdaten unverschlüsselt)", defaultsHelp:"Leer verwendet die Umgebung, wo unterstützt, sonst den angezeigten Standard. Unveränderte Werte bleiben erhalten. Das Host-Timeout kann früher enden.", conflict:"Die Konfiguration wurde anderswo geändert. Der Entwurf bleibt erhalten. Wähle „Abbrechen“ und öffne die Einstellungen erneut.", invalidOption:"Eingaben und Wertebereiche prüfen.",
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
<fieldset class="settings-section"><legend><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 17h16M8 4v6M16 14v6"/></svg><span data-t="advanced">Advanced</span></legend><div class="fields">
|
||||
<label for="max-memories"><span data-t="maxMemories">Maximum memories (1–20)</span><input id="max-memories" aria-describedby="defaults-help" type="number" min="1" max="20" placeholder="5"></label>
|
||||
<label for="max-bytes"><span data-t="maxBytes">Recall bytes (512–32768)</span><input id="max-bytes" aria-describedby="defaults-help" type="number" min="512" max="32768" placeholder="6000"></label>
|
||||
<label for="request-timeout"><span data-t="requestTimeout">Request timeout ms (50–5000)</span><input id="request-timeout" aria-describedby="defaults-help" type="number" min="50" max="5000" placeholder="1500"></label>
|
||||
<label for="request-timeout"><span data-t="requestTimeout">Request timeout ms (50–30000)</span><input id="request-timeout" aria-describedby="defaults-help" type="number" min="50" max="30000" placeholder="1500"></label>
|
||||
<label for="recall-backoff"><span data-t="recallBackoff">Recall backoff ms (100–300000)</span><input id="recall-backoff" aria-describedby="defaults-help" type="number" min="100" max="300000" placeholder="30000"></label>
|
||||
<label for="gateway-timeout"><span data-t="gatewayTimeout">Host hook timeout ms (100–10000)</span><input id="gateway-timeout" aria-describedby="defaults-help" type="number" min="100" max="10000" placeholder="1000"></label>
|
||||
<label for="gateway-timeout"><span data-t="gatewayTimeout">Host hook timeout ms (100–30000)</span><input id="gateway-timeout" aria-describedby="defaults-help" type="number" min="100" max="30000" placeholder="1000"></label>
|
||||
<label for="port"><span data-t="port">Connection-test port (1024–65535)</span><input id="port" aria-describedby="defaults-help" type="number" min="1024" max="65535" placeholder="3479"></label>
|
||||
<label class="switch-field" for="insecure"><input id="insecure" type="checkbox" aria-describedby="insecure-help"><span><strong data-t="insecure">Allow HTTP to a non-local server (credentials travel unencrypted)</strong><small id="insecure-help" data-t="insecureHelp">Use only on a trusted network.</small></span></label>
|
||||
<small id="defaults-help" data-t="defaultsHelp">Empty fields inherit the environment where supported, otherwise use the shown default. Unchanged values remain as configured. The host timeout can end a request first.</small>
|
||||
|
||||
@@ -16,8 +16,8 @@ const fields = [
|
||||
['recall','recall','bool',true], ['recall-remote','recallRemote','bool',false], ['context','contextBundle','bool',true], ['capture','capture','bool',false], ['capture-remote','captureRemote','bool',false],
|
||||
['capture-tools','captureTools','bool',true], ['capture-filter','captureFilter','filter','off'], ['capture-cindy','captureCindy','bool',false],
|
||||
['max-memories','maxMemories','number',5,1,20], ['max-bytes','maxBytes','number',6000,512,32768],
|
||||
['request-timeout','requestTimeoutMs','number',1500,50,5000], ['recall-backoff','recallBackoffMs','number',30000,100,300000],
|
||||
['gateway-timeout','gatewayTimeoutMs','number',1000,100,10000], ['port','port','number',3479,1024,65535], ['insecure','allowInsecureHttp','bool',false],
|
||||
['request-timeout','requestTimeoutMs','number',1500,50,30000], ['recall-backoff','recallBackoffMs','number',30000,100,300000],
|
||||
['gateway-timeout','gatewayTimeoutMs','number',1000,100,30000], ['port','port','number',3479,1024,65535], ['insecure','allowInsecureHttp','bool',false],
|
||||
];
|
||||
function summary() {
|
||||
if (!savedOptions) return;
|
||||
@@ -184,7 +184,7 @@ function nextOptions() {
|
||||
// Validate the explicit values before saving; environment values are
|
||||
// resolved separately by the hook.
|
||||
validateExplicitOptions(next);
|
||||
for (const [name,min,max] of [['gatewayTimeoutMs',100,10000],['port',1024,65535]]) {
|
||||
for (const [name,min,max] of [['gatewayTimeoutMs',100,30000],['port',1024,65535]]) {
|
||||
const v = next[name];
|
||||
if (v != null && (!Number.isInteger(name === 'port' ? Number(v) : v) || Number(v) < min || Number(v) > max)) throw new Error('invalidOption');
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ globalThis.__nowledgeMemValidateOptions = (raw = {}) => {
|
||||
if (skip != null && typeof skip !== 'string' && (!Array.isArray(skip) || skip.some((name) => typeof name !== 'string'))) fail();
|
||||
for (const name of ['recall','contextBundle','capture','recallRemote','captureRemote','captureTools','captureCindy'])
|
||||
if (raw[name] !== undefined && typeof raw[name] !== 'boolean') fail();
|
||||
for (const [name,fallback,min,max] of [['maxMemories',5,1,20],['maxBytes',6000,512,32768],['requestTimeoutMs',1500,50,5000],['recallBackoffMs',30000,100,300000]]) {
|
||||
for (const [name,fallback,min,max] of [['maxMemories',5,1,20],['maxBytes',6000,512,32768],['requestTimeoutMs',1500,50,30000],['recallBackoffMs',30000,100,300000]]) {
|
||||
const n = raw[name] ?? fallback;
|
||||
if (!Number.isInteger(n) || n < min || n > max) fail();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// A deep recall slower than the old 5000 ms ceiling (plugins#926,
|
||||
// aboat0625-cpu): a local fixture server answers a search after 6100 ms,
|
||||
// and a hook given requestTimeoutMs 15000 adds what it found; the caller
|
||||
// going away still cancels it at once.
|
||||
import { afterEach, beforeEach, expect, test } from "bun:test"
|
||||
import { onRequest, reset } from "./nowledge-mem.hooks.mjs"
|
||||
import { resolveOptions } from "./mem.mjs"
|
||||
|
||||
const delay = 6100
|
||||
let server, searches, aborted
|
||||
|
||||
beforeEach(() => {
|
||||
reset()
|
||||
searches = 0
|
||||
aborted = Promise.withResolvers()
|
||||
server = Bun.serve({
|
||||
hostname: "127.0.0.1", port: 0,
|
||||
async fetch(req) {
|
||||
if (new URL(req.url).pathname !== "/memories/search") return new Response("", { status: 404 })
|
||||
searches++
|
||||
req.signal.addEventListener("abort", () => aborted.resolve(), { once: true })
|
||||
await new Promise((resolve) => {
|
||||
const timer = setTimeout(resolve, delay)
|
||||
req.signal.addEventListener("abort", () => { clearTimeout(timer); resolve() }, { once: true })
|
||||
})
|
||||
return Response.json([{ memory: { id: "mem-slow", node_type: "Memory", title: "Deep recall", content: "The deep answer is QUARTZ-8413." }, similarity_score: 0.9 }])
|
||||
},
|
||||
})
|
||||
})
|
||||
afterEach(() => server.stop(true))
|
||||
|
||||
const options = () => ({ serverUrl: `http://127.0.0.1:${server.port}`, apiKey: "nmem_test", contextBundle: false, requestTimeoutMs: 15000 })
|
||||
const chat = () => ({ messages: [{ role: "user", content: "Quartz codename?" }] })
|
||||
const ctx = (signal) => ({ protocol: "chat", origin: "local", agent: "codex", query: "Quartz codename?", session: "slow", signal, options: options(), report() {} })
|
||||
|
||||
test("requestTimeoutMs takes up to 30000", () => {
|
||||
expect(resolveOptions({ serverUrl: "http://127.0.0.1:14242", requestTimeoutMs: 15000 }).requestTimeoutMs).toBe(15000)
|
||||
expect(resolveOptions({ serverUrl: "http://127.0.0.1:14242", requestTimeoutMs: 30000 }).requestTimeoutMs).toBe(30000)
|
||||
expect(() => resolveOptions({ serverUrl: "http://127.0.0.1:14242", requestTimeoutMs: 30001 })).toThrow(/invalid/)
|
||||
expect(resolveOptions({ serverUrl: "http://127.0.0.1:14242" }).requestTimeoutMs).toBe(1500)
|
||||
})
|
||||
|
||||
test("a search answered after 6100 ms is recalled with requestTimeoutMs 15000", async () => {
|
||||
const body = chat()
|
||||
const started = performance.now()
|
||||
const out = await onRequest(body, ctx(AbortSignal.timeout(20000)))
|
||||
expect(performance.now() - started).toBeGreaterThanOrEqual(delay - 100)
|
||||
expect(searches).toBe(1)
|
||||
expect(out).toBe(body)
|
||||
expect(body.messages[0].content).toContain("QUARTZ-8413")
|
||||
}, 20000)
|
||||
|
||||
test("the caller going away cancels a long recall at once", async () => {
|
||||
const caller = new AbortController()
|
||||
const body = chat()
|
||||
const run = onRequest(body, ctx(caller.signal))
|
||||
while (searches === 0) await Bun.sleep(10)
|
||||
const started = performance.now()
|
||||
caller.abort(new Error("client went away"))
|
||||
await expect(run).rejects.toThrow()
|
||||
await aborted.promise
|
||||
// the search was cut, not waited for: well under its 6100 ms
|
||||
expect(performance.now() - started).toBeLessThan(3000)
|
||||
expect(body.messages[0].content).toBe("Quartz codename?")
|
||||
}, 20000)
|
||||
Reference in New Issue
Block a user