siyuan-note/siyuan · error

AI editor request timeout

Error message

AI editor request timeout

What it means

NewAIEditorChatStream (kernel/model/ai.go:193) arms a timer of prov.RequestTimeout seconds around util.CreateOpenAICompletionStream, which must dial the provider, authenticate, and receive the streaming response headers. If that whole setup exceeds the configured RequestTimeout, the timer cancels the context and the error is replaced with this message. It bounds how long the kernel waits for a stream to be established.

Source

Thrown at kernel/model/ai.go:193

	}

	messages := buildAIEditorMessages(prompt, history, editing.MaxHistoryMessages)

	req := openai.ChatCompletionRequest{
		Model:               m.Name,
		MaxCompletionTokens: editing.MaxCompletionTokens,
		Temperature:         float32(editing.Temperature),
		Messages:            messages,
		Stream:              true,
	}
	streamCtx, cancel := context.WithCancel(ctx)
	requestTimeout := time.Duration(prov.RequestTimeout) * time.Second
	requestTimer, requestTimerDone := startAIEditorCancelTimer(requestTimeout, cancel)
	client := util.NewOpenAIClientWithModel(prov.APIKey, prov.BaseURL, m.Name)
	completionStream, err := util.CreateOpenAICompletionStream(streamCtx, client, prov.Protocol, req, nil)
	requestTimedOut := stopAIEditorCancelTimer(requestTimer, requestTimerDone)
	if requestTimedOut {
		err = errors.New("AI editor request timeout")
	}
	if nil != err {
		cancel()
		return nil, err
	}
	if nil == completionStream {
		cancel()
		return nil, errors.New("AI editor model returned nil stream")
	}
	return &AIEditorChatStream{
		stream:      completionStream,
		cancel:      cancel,
		idleTimeout: 120 * time.Second,
	}, nil
}

func startAIEditorCancelTimer(timeout time.Duration, cancel context.CancelFunc) (*time.Timer, <-chan struct{}) {
	if 0 >= timeout {

View on GitHub (pinned to afa823b6b4)

Solutions

  1. Verify the provider endpoint responds quickly outside SiYuan (curl a minimal streaming request with the same key and URL)
  2. Increase the provider's RequestTimeout in 设置 - 人工智能 (e.g. 120 s or more for slow self-hosted models)
  3. Fix the BaseURL (scheme, port, path) and check proxy/firewall rules for the kernel process
  4. If the provider cold-starts, send a warm-up request before long editing sessions, or switch to a lower-latency endpoint

Example fix

// before: provider config {"requestTimeout": 30} -> "AI editor request timeout"
// after: provider config {"requestTimeout": 180}, or fix baseUrl from "https://llm.local/v3" to "https://llm.local/v1"
Defensive patterns

Strategy: retry

Validate before calling

// smoke-test the endpoint before a long editing session
curl -N -m 10 -H "Authorization: Bearer $KEY" "$BASE_URL/chat/completions" \
  -d '{"model":"...","stream":true,"messages":[{"role":"user","content":"hi"}]}'
// if headers do not arrive within RequestTimeout, raise the timeout or fix the URL

Try / catch

if err != nil && err.Error() == "AI editor request timeout" {
    if attempt < maxAttempts {
        attempt++
        continue // transient slow start; back off before retrying
    }
    suggestUserIncreaseRequestTimeout(prov.Name)
    return err
}

Prevention

When it happens

Trigger: Provider endpoint unreachable (wrong BaseURL, DNS failure, TLS hang) so connection setup never completes; or a reachable but slow provider (cold-start self-hosted model, queued service) that takes longer than RequestTimeout seconds to return the first SSE response.

Common situations: Small RequestTimeout (e.g. 30 s) with a distant or overloaded self-hosted LLM; wrong or unreachable BaseURL in provider settings; proxies/firewalls that stall outbound HTTPS; first-request cold start of a serverless model endpoint.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/66f91e8c81f32330. Report an issue: GitHub.