siyuan-note/siyuan · warning
errModelRequestTimeout
errModelRequestTimeout
Error message
model request timeout
What it means
errModelRequestTimeout is the sentinel error set when the model chat-completion request exceeds its configured requestTimeout inside createStreamWithRetry. The stream creation context is cancelled with a timer; if the provider has not returned a stream before the deadline, the agent replaces the outcome with this sentinel so classifyRetry treats it as "timeout" and applies the timeout retry/backoff policy.
Solutions
- Increase the model request timeout in the AI provider settings so slow-to-start models get enough time.
- Check the provider's status/latency; retry when the endpoint is responsive again (the agent retries automatically per maxRetries/classifyRetry).
- Reduce prompt size (shorter conversation, tighter compaction) to cut time-to-first-token.
- Verify network path (proxy/firewall) to the endpoint is not adding large latency.
Example fix
// before: requestTimeout too small for a slow reasoning model stream, _, cancel, err := createStreamWithRetry(ctx, client, req, 2, 5*time.Second, idleTimeout, retryDelay, ch) // after: raise the request timeout stream, _, cancel, err := createStreamWithRetry(ctx, client, req, 2, 120*time.Second, idleTimeout, retryDelay, ch)
Defensive patterns
Strategy: retry
Validate before calling
// before sending, sanity-check the configured timeout
if requestTimeout < 30*time.Second {
requestTimeout = 30 * time.Second // floor for slow-to-start models
} Try / catch
stream, _, cancel, err := createStreamWithRetry(ctx, client, req, maxRetries, requestTimeout, idleTimeout, retryDelay, ch)
if err != nil {
if errors.Is(err, errModelRequestTimeout) {
// classifyRetry returns "timeout"; rely on backoff retry or surface a timeout hint to the user
}
} Prevention
- Set requestTimeout generously for reasoning models with long time-to-first-token.
- Keep prompts as small as practical to reduce provider latency.
- Monitor provider status pages for slow periods.
- Ensure retry policy (maxRetries/retryDelay) is enabled for timeout-class errors.
When it happens
Trigger: In agent.go (~line 2514/2558): the OpenAI-compatible request to the model endpoint does not produce a stream within requestTimeout; requestTimedOut fires and err is set to errModelRequestTimeout, also matched later by errors.Is in classifyRetry (agent.go:2627) and in tests like TestCreateStreamRequestTimeoutAndZeroRetries.
Common situations: Slow or overloaded model provider; very long prompts (near the context limit) that take longer than the configured request timeout; network latency or VPN/proxy slowness; a requestTimeout setting that is too small for the chosen model (e.g. reasoning models with long time-to-first-token).
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.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- model request timeout
- model stream idle timeout
- agent compaction summary is empty
- agent context cannot be compacted enough
- AI editor request timeout
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/5432ca6c028b3812.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/agent.go:2514
}
e := SessionEntry{
ID: id,
Type: "assistant",
Content: m.Content,
ReasoningCont: m.ReasoningContent,
ResponseOutput: util.CloneOpenAIResponseOutput(m.ResponseOutput),
ResponseOutputTokens: m.ResponseOutputTokens,
RoundID: m.RoundID,
ToolCalls: m.ToolCalls,
}
entries = append(entries, e)
}
}
return entries
}
var (
errModelRequestTimeout = errors.New("model request timeout")
errModelStreamIdleTimeout = errors.New("model stream idle timeout")
)
func createStreamWithRetry(ctx context.Context, client *openai.Client, req openai.ChatCompletionRequest, maxRetries int,
requestTimeout, streamIdleTimeout time.Duration, retryDelay func(string, int) time.Duration,
ch chan<- AgentEvent) (*util.OpenAICompletionStream, openai.ChatCompletionStreamResponse, context.CancelFunc, error) {
return createProtocolStreamWithRetry(ctx, client, util.OpenAIProtocolChatCompletions, req, nil, maxRetries,
requestTimeout, streamIdleTimeout, retryDelay, ch)
}
func createProtocolStreamWithRetry(ctx context.Context, client *openai.Client, protocol string,
req openai.ChatCompletionRequest, responseInput []any, maxRetries int, requestTimeout, streamIdleTimeout time.Duration,
retryDelay func(string, int) time.Duration,
ch chan<- AgentEvent) (*util.OpenAICompletionStream, openai.ChatCompletionStreamResponse, context.CancelFunc, error) {
if maxRetries < 0 {
maxRetries = 0
}
View on GitHub (pinned to 9f775e8a12)