Files
yetone dda4afdc36 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
2026-11-10 15:31:40 +08:00

66 lines
3.1 KiB
JavaScript

// 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)