{"record":{"id":"e704236803979d36","repo":"siyuan-note/siyuan","slug":"model-request-timeout","errorCode":null,"errorMessage":"model request timeout","messagePattern":"model request timeout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/agent.go","lineNumber":2444,"sourceCode":"\t\t\t}\n\t\t\te := SessionEntry{\n\t\t\t\tID:                   id,\n\t\t\t\tType:                 \"assistant\",\n\t\t\t\tContent:              m.Content,\n\t\t\t\tReasoningCont:        m.ReasoningContent,\n\t\t\t\tResponseOutput:       util.CloneOpenAIResponseOutput(m.ResponseOutput),\n\t\t\t\tResponseOutputTokens: m.ResponseOutputTokens,\n\t\t\t\tRoundID:              m.RoundID,\n\t\t\t\tToolCalls:            m.ToolCalls,\n\t\t\t}\n\t\t\tentries = append(entries, e)\n\t\t}\n\t}\n\treturn entries\n}\n\nvar (\n\terrModelRequestTimeout    = errors.New(\"model request timeout\")\n\terrModelStreamIdleTimeout = errors.New(\"model stream idle timeout\")\n)\n\nfunc createStreamWithRetry(ctx context.Context, client *openai.Client, req openai.ChatCompletionRequest, maxRetries int,\n\trequestTimeout, streamIdleTimeout time.Duration, retryDelay func(string, int) time.Duration,\n\tch chan<- AgentEvent) (*util.OpenAICompletionStream, openai.ChatCompletionStreamResponse, context.CancelFunc, error) {\n\treturn createProtocolStreamWithRetry(ctx, client, util.OpenAIProtocolChatCompletions, req, nil, maxRetries,\n\t\trequestTimeout, streamIdleTimeout, retryDelay, ch)\n}\n\nfunc createProtocolStreamWithRetry(ctx context.Context, client *openai.Client, protocol string,\n\treq openai.ChatCompletionRequest, responseInput []any, maxRetries int, requestTimeout, streamIdleTimeout time.Duration,\n\tretryDelay func(string, int) time.Duration,\n\tch chan<- AgentEvent) (*util.OpenAICompletionStream, openai.ChatCompletionStreamResponse, context.CancelFunc, error) {\n\tif maxRetries < 0 {\n\t\tmaxRetries = 0\n\t}\n","sourceCodeStart":2426,"sourceCodeEnd":2462,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/agent.go#L2426-L2462","documentation":"errModelRequestTimeout is a sentinel error indicating the HTTP request to the model provider exceeded the configured request timeout. createStreamWithRetry maps a timer expiration onto this sentinel (optionally overriding the transport error) and classifyRetry labels it \"timeout\" so the retry logic can back off and retry.","triggerScenarios":"In createStreamWithRetry/createProtocolStreamWithRetry, the per-request context timer fires before the stream is established (requestTimedOut is true), so err is replaced with errModelRequestTimeout; also returned by createResponseCompaction and covered by TestCreateStreamRequestTimeoutAndZeroRetries.","commonSituations":"Slow or overloaded model provider endpoints; requestTimeout configured too aggressively low; network latency/proxy delays; very large prompts taking longer than the timeout to be accepted.","solutions":["Increase the model request timeout configuration","Check provider status/network connectivity and proxy settings","Retry — the built-in retry loop already classifies this as retryable (\"timeout\")","Reduce prompt size so the request completes within the timeout","Verify maxRetries is not 0 if automatic retries are desired"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if errors.Is(err, errModelRequestTimeout) {\n    // back off and retry; also consider raising the request timeout\n}","preventionTips":["Set requestTimeout generously relative to prompt size","Keep maxRetries > 0 so timeout classification triggers automatic retries","Monitor provider status pages and configure sane retry delays"],"tags":["agent","timeout","network","retry"],"backgroundTag":"request-timeout","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}