Skip to content

[Bug] OpenAI-compatible streaming request returns 502 when upstream proxy reports EOF #8945

@DolphinZZZZZ

Description

@DolphinZZZZZ

What happened / 发生了什么

When using an OpenAI-compatible provider with gpt-5.5, AstrBot sometimes receives a 502 error during streaming chat completion.

The upstream proxy/server log shows that the actual upstream request failed with EOF when forwarding to:

https://chatgpt.com/backend-api/codex/responses

AstrBot only receives:

Error code: 502 - {'error': {'message': 'Upstream request failed', 'type': 'upstream_error'}}

Provider configuration names, account names, API key names, session IDs, and message contents are redacted. The involved models are gpt-5.5 and gpt-5.4.

Reproduce / 如何复现?

  1. Configure an OpenAI-compatible provider using gpt-5.5.
  2. Enable streaming output.
  3. Send a normal chat request from the QQ official adapter.
  4. The upstream proxy occasionally returns EOF and AstrBot logs a 502 request error.

In the observed case, the request body was small, around 23 KB, so this does not look like a large-context request failure.

AstrBot version / AstrBot 版本

v4.26.0-beta.1

OS / 系统

Windows

Message platform / 消息平台

The failing request came from the QQ official adapter.

Relevant AstrBot log, with session ID and message content redacted:

[2026-06-21 23:47:11.041] [Core] [INFO] [core.event_bus:79]:
[default] [AstrBot (qq_official)] [redacted-session-id]: [At:qq_official] [redacted-message-content]

The response path also shows the QQ official C2C sender:

[qqofficial.qqofficial_message_event:437]:
Message sent to C2C: {...}

So the observed message channel was qq_official / QQ official C2C.

AstrBot logs / AstrBot 日志

[2026-06-21 23:48:31.645] [Core]
[WARN]
[v4.26.0-beta.1] [runners.tool_loop_agent_runner:554]:
Chat Model [redacted-provider]/gpt-5.5 request error: Error code: 502 - {'error': {'message': 'Upstream request failed', 'type': 'upstream_error'}}

Traceback (most recent call last):
  File "<ASTRBOT_ROOT>/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 509, in _iter_llm_responses_with_fallback
    async for attempt in retrying:
  File "<PYTHON_ENV>/site-packages/tenacity/asyncio/__init__.py", line 170, in __anext__
    do = await self.iter(retry_state=self._retry_state)
  File "<PYTHON_ENV>/site-packages/tenacity/asyncio/__init__.py", line 157, in iter
    result = await action(retry_state)
  File "<PYTHON_ENV>/site-packages/tenacity/_utils.py", line 111, in inner
    return call(*args, **kwargs)
  File "<PYTHON_ENV>/site-packages/tenacity/__init__.py", line 393, in <lambda>
    self._add_action_func(lambda rs: rs.outcome.result())
  File "<PYTHON_ENV>/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
  File "<PYTHON_ENV>/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "<ASTRBOT_ROOT>/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 513, in _iter_llm_responses_with_fallback
    async for resp in self._iter_llm_responses(
  File "<ASTRBOT_ROOT>/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 473, in _iter_llm_responses
    async for resp in stream:
  File "<ASTRBOT_ROOT>/astrbot/core/provider/sources/openai_source.py", line 1218, in text_chat_stream
    ) = await self._handle_api_error(
  File "<ASTRBOT_ROOT>/astrbot/core/provider/sources/openai_source.py", line 1092, in _handle_api_error
    raise e
  File "<ASTRBOT_ROOT>/astrbot/core/provider/sources/openai_source.py", line 1205, in text_chat_stream
    async for response in self._query_stream(payloads, func_tool):
  File "<ASTRBOT_ROOT>/astrbot/core/provider/sources/openai_source.py", line 551, in _query_stream
    stream = await self.client.chat.completions.create(
  File "<PYTHON_ENV>/site-packages/openai/resources/chat/completions/completions.py", line 2814, in create
    return await self._post(
  File "<PYTHON_ENV>/site-packages/openai/_base_client.py", line 1931, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
  File "<PYTHON_ENV>/site-packages/openai/_base_client.py", line 1716, in request
    raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: Error code: 502 - {'error': {'message': 'Upstream request failed', 'type': 'upstream_error'}}

Upstream server/proxy logs / 上游服务器日志

Sensitive account fields have been redacted.

{
  "kind": "request_error",
  "message": "Post \"https://chatgpt.com/backend-api/codex/responses\": EOF",
  "platform": "openai",
  "model": "gpt-5.5"
}

Related HTTP response returned to AstrBot:

request error: Error code: 502 - {'error': {'message': 'Upstream request failed', 'type': 'upstream_error'}}

Expected behavior / 期望行为

If this is considered an upstream/provider-side failure, AstrBot should ideally surface a clearer error message or retry/fail over more gracefully during streaming requests.

For example:

  • Preserve the upstream EOF information if available.
  • Make it clearer that the 502 came from the upstream provider/proxy.
  • Avoid losing useful error context during streaming fallback handling.

Additional context / 补充信息

The same provider setup also uses gpt-5.4 in related model configuration, but provider names, account names, API key names, session IDs, and message contents are intentionally omitted from this report.

We tested whether the issue was caused by an overlong conversation context. After enabling AstrBot context compression/truncation, the request size was reduced significantly, but the EOF/502 error could still occur. In one observed failed request, the request body was only around 23 KB. Therefore, this report is not about an input-too-large failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions