mnemon icon indicating copy to clipboard operation
mnemon copied to clipboard

OpenAI-compat availability fallback probe inherits the 2s discovery deadline — slow remote providers (e.g. Cloudflare Workers AI) are permanently reported "unavailable"

Open Easthq opened this issue 6 days ago • 1 comments

Environment

  • mnemon 0.2.15 (npm @mnemon-dev/mnemon, win32-x64 binary)
  • Windows 10 (22631), Git Bash
  • Embedding provider: Cloudflare Workers AI OpenAI-compatible endpoint https://api.cloudflare.com/client/v4/accounts/<account-id>/ai/v1
  • Model: @cf/qwen/qwen3-embedding-0.6b (works: returns 1024-dim vectors)
  • Line numbers below refer to internal/memory/embed/ollama.go and cmd/memory/embed.go on the default branch as of 2026-11-25 (behavior confirmed identical in the 0.2.15 binary).

Summary

Providers that don't serve GET /models are supposed to be handled by the embed round-trip fallback in Available(), but the fallback shares the same 2-second context as the models probe. On a remote endpoint whose round-trip exceeds 2s (Cloudflare from our network: ~5.7s cold, measured), the fallback can never succeed, so such providers are permanently reported unavailable — even though the real embed path (30s client timeout, ollama.go:117) works perfectly.

Reproduction

  1. Set MNEMON_EMBED_ENDPOINT to the Cloudflare URL above, MNEMON_EMBED_MODEL=@cf/qwen/qwen3-embedding-0.6b, MNEMON_EMBED_API_KEY=<valid Workers AI token>.
  2. Raw curl against the endpoint (same machine):
    • GET {base}/models → 405 (route not offered)
    • POST {base}/embeddings → 200 with a valid embedding, 5.74s cold, 0.4–1.6s on a warm keep-alive connection
  3. mnemon embed --status → "embedding_available": false
  4. mnemon embed <id> → Error: OpenAI-compatible embedding provider not available at <endpoint>

Root cause

Available(), internal/memory/embed/ollama.go:172-190:

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) // :173
...
status, ok := c.probeStatus(ctx, route)                                 // :182
if ok {
    return true
}
if c.protocol == ProtocolOpenAI && (status == 404 || status == 405 || status == 501) {
    return c.probeEmbed(ctx)                                            // :187 — same 2s ctx!
}

probeEmbed (:215-216) does a full HTTPS + TLS + inference round trip via embedWithContext(ctx, ...) under that 2s deadline. The comment at :164 says the 2s budget exists "to avoid blocking the CLI on unresponsive servers" — but for providers without a /models route the current behavior isn't a fast fail, it's an always fail. The fallback introduced for Voyage AI (per the comment at :167-171) is defeated by its own budget whenever latency is high.

Notably, cmd/memory/embed.go:53 already runs a full ec.Embed("availability probe") in --status mode with no 2s cap (bounded only by the 30s client timeout) — so the codebase elsewhere treats a full-length embed probe as acceptable; Available()'s fallback just isn't given the same budget.

Suggested fix

Give the fallback its own budget instead of inheriting the discovery deadline. The 30s http.Client.Timeout still bounds it:

--- a/internal/memory/embed/ollama.go
+++ b/internal/memory/embed/olama.go
@@ func (c *Client) Available() bool {
 	status, ok := c.probeStatus(ctx, route)
 	if ok {
 		return true
 	}
 	if c.protocol == ProtocolOpenAI && (status == 404 || status == 405 || status == 501) {
-		return c.probeEmbed(ctx)
+		// No /models route (Voyage AI, Cloudflare Workers AI, ...): the
+		// fallback is a real embed round-trip and must not inherit the 2s
+		// discovery deadline — remote inference regularly exceeds it, which
+		// makes such providers permanently "unavailable". The 30s
+		// http.Client timeout still bounds this probe.
+		return c.probeEmbed(context.Background())
 	}
 	return false
 }

If you'd rather keep a tighter bound on the recall hot path, a hard cap of ~10s (or an env knob like MNEMON_EMBED_PROBE_TIMEOUT) would also fix the observed case. Note the fallback only triggers when the models route is genuinely absent (404/405/501), so local llama.cpp/vLLM/LM Studio servers still take the fast GET /models → 200 path and see no behavior change.

Easthq avatar Nov 25 '26 14:11 Easthq

dsh‑mnemon suffers from the same issue.

Easthq avatar Nov 25 '26 14:11 Easthq