magpie icon indicating copy to clipboard operation
magpie copied to clipboard

gateway hooks: 10s chain / 11s RPC caps silently drop slow memory recall

Open aboat0625-cpu opened this issue 3 weeks ago • 1 comments

magpie version

v0.1.3435, source revision 7e5cebb86c92ce754b50d475ff461575d98b6a23. The same deadline limits are still present in main at e7fe52fdc30fde5740a51c94790b0130946d5965 (source inspected; the tests below were run on the installed-version base).

Where

GUI / asynchronous gateway request hooks.

OS

macOS, Apple Silicon (arm64), Go 1.26.8, Bun 1.4.4.

Agent, provider and model

A client routed through Magpie with the Nowledge Mem asynchronous recall hook. Provider/model choice is not needed to reproduce: a synthetic hook with a 12-second delay is sufficient.

What happened, and what was expected

A healthy memory backend can finish a deep search after more than ten seconds. One bounded live check returned HTTP 200 and relevant results after 20.833 seconds; no memory content or private query is included here.

The request still reaches the language model, but recall has been discarded. Increasing the plugin's own request timeout cannot fix the host's limits:

  • internal/plugin/host.js: gatewayTimeoutMs accepts only 100–10000 ms; an explicit larger value falls back to 1000 ms.
  • gatewayBudget() caps the entire hook chain at 10000 ms.
  • internal/plugin/gateway.go: GatewayBegin shares an 11-second context across startup and the request RPC. Completion RPCs also have an 11-second limit.

Expected: permit an explicitly configured, bounded longer I/O budget for slow recall, consistently across the per-hook timer, chain timer and Go RPC. Preserve the existing default, rollback/fail-open behavior, request-state limits and immediate caller cancellation. Startup need not become unbounded.

Sources:

Steps to reproduce

Add this synthetic test beside the existing tests in internal/plugin. It uses the repository's existing sandbox and hook fixture helpers, without contacting a model or memory server:

func TestGatewayHookSlowRecallUsesConfiguredBudget(t *testing.T) {
    sandbox(t)
    spec := gatewayFixture(t, `export async function onRequest(body, ctx) {
      await new Promise(resolve => setTimeout(resolve, 12000));
      ctx.report("ready", 12);
      return {...body, note: "recalled"};
    }`)
    if err := SetOptions(spec, map[string]any{"gatewayTimeoutMs": 130000}); err != nil {
        t.Fatal(err)
    }
    ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
    defer cancel()
    out := gatewayRequest(ctx, []byte(`{"note":"original"}`), GatewayContext{})
    if !strings.Contains(string(out), `"recalled"`) {
        t.Fatalf("slow recall was dropped despite its configured budget: %s", out)
    }
}

Imports: context, strings, testing, time.

Run with the project's isolated-home/Bun test setup:

go test -tags nogui ./internal/plugin -run '^TestGatewayHookSlowRecallUsesConfiguredBudget$' -count=1 -v

Error text / observed regression

On the unmodified installed-version base:

gateway request hook failed or timed out; keeping request
slow recall was dropped despite its configured budget: {"note":"original"}
--- FAIL: TestGatewayHookSlowRecallUsesConfiguredBudget (1.07s)

The roughly one-second failure is the invalid-large-option fallback. Keeping the option within its allowed range does not solve a 12-second recall either, because the chain is capped at ten seconds.

Local validation and limits

An isolated candidate that raises the explicit hook/chain ceiling, keeps startup bounded separately, and aligns the RPC deadline completed the 12-second regression. A second test confirmed that a caller cancelled after 100 ms still returns the original body promptly.

Targeted race checks passed for:

  • ./internal/plugin -run '^TestGateway|^TestAsyncGateway'
  • ./internal/gateway -run '^TestAsyncGateway'

The full upstream suite has not been run. The candidate has not replaced the official signed application. The timeout ceiling/policy should be chosen by maintainers; a client-side setting alone cannot address the current host cap.

The companion Nowledge plugin also has a separate 5000 ms request-timeout validation ceiling, so both sides need compatible budgets.

Companion plugin report: https://github.com/magpie-community/plugins/issues/926

aboat0625-cpu avatar Nov 10 '26 06:11 aboat0625-cpu

Fixed in v0.1.3538 (86825005e). Thanks @aboat0625-cpu.

  • gatewayTimeoutMs now takes 100 to 30000 ms. A value outside that range is clamped to the nearer bound instead of falling back to the 1 s default.
  • The chain budget follows the longest hook's own timeout, up to 30 s. When no hook asks for more than 10 s, the budget is the same as before.
  • The request and completion RPCs wait for that budget plus 1 s, never less than the old 11 s.
  • The defaults haven't changed. Cancelling the request still stops the hook at once, and a failing hook still keeps the request as it came.

On the Nowledge Mem side, requestTimeoutMs goes up to 30000 in @magpie-community/gateway-nowledge-mem 0.1.6 (magpie-community/plugins#926). Set gatewayTimeoutMs at least as long as requestTimeoutMs.

I'll leave this open until it works for you.

yetone avatar Nov 10 '26 07:11 yetone