Skip to content

fix(openai): keep a cleared provider timeout from disabling every request - #10364

Open
Lesereingrape wants to merge 1 commit into
AstrBotDevs:masterfrom
Lesereingrape:fix/openai-provider-timeout-floor
Open

Lesereingrape wants to merge 1 commit into
AstrBotDevs:masterfrom
Lesereingrape:fix/openai-provider-timeout-floor

Conversation

@Lesereingrape

@Lesereingrape Lesereingrape commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

ProviderOpenAIOfficial hands the provider timeout field straight to the OpenAI SDK:

self.timeout = provider_config.get("timeout", 120)
self.custom_headers = self.request_headers
if isinstance(self.timeout, str):
    self.timeout = int(self.timeout)

timeout is a dashboard numeric field declared as a plain "type": "int" with no slider and no
minimum (astrbot/core/config/default.py:2822-2826), and clearing such a field writes 0 —
toNumber() maps parseFloat('') to 0
(dashboard/src/components/shared/ConfigItemRenderer.vue:361-364). httpx reads 0 as "expire
immediately", so every request of that provider dies before it leaves. A non-numeric value
("" from a cleared timeout: in a hand-edited data/config.json, or a quoted string) raises
ValueError inside __init__, which ProviderManager.initialize logs as a bare
Failed to load provider adapter ... Unknown cause. (astrbot/core/provider/manager.py:688)
before skipping the provider, so the model silently disappears from the selection.

Measured against a local OpenAI-compatible server that answers after 3 s, on master @ ac4df996:

provider_config["timeout"] before this change after this change
absent client.timeout=120 → replies in 3.16 s unchanged
120 replies in 3.02 s unchanged
0 APITimeoutError: Request timed out. after 0.00 s replies in 3.02 s
-5 APITimeoutError after 0.00 s clamped to the shared 1 s floor, warns
"" ValueError: invalid literal for int() with base 10: '' → provider dropped replies in 3.02 s
"abc" same ValueError replies in 3.02 s

The same __init__ is shared by 10 OpenAI-compatible adapters (groq, longcat, mirarouter,
aihubmix, openai_responses, openrouter, ssycloud, xai, xiaomi, zhipu), so one cleared box breaks
all of them.

Modifications / 改动点

  • Route the field through coerce_int_config (astrbot/core/utils/config_number.py), the helper
    the repo already uses for exactly this class of field — including its own guard for the same
    timeout key in deerflow_agent_runner.py:197 — instead of adding a bespoke normalizer, so the
    behaviour matches the DeerFlow runner: a cleared, None or non-numeric value behaves like an
    absent one (documented default 120), a usable value is kept, and anything below the shared
    min_value=1 floor is clamped with a warning that names the field and the provider config.
  • Add tests to the existing tests/test_openai_source.py covering the default, a tuned value, the
    numeric string, 0/negative/""/"abc"/None, and one OpenAI-compatible subclass inheriting
    the fallback.

No dependencies added, no signature or config schema change, no behaviour change for a valid
timeout.

Screenshots or Test Results / 运行截图或测试结果

Before the change (RED, the seven timeout cases against master @ ac4df996):

6 failed, 4 passed

After the change (GREEN):

10 passed
76 passed in 11.74s        # whole tests/test_openai_source.py

The gate CI runs for these paths, and the full suite:

ruff format --check astrbot/core/provider/sources/openai_source.py tests/test_openai_source.py   # 2 files already formatted
ruff check astrbot/core/provider/sources/openai_source.py tests/test_openai_source.py            # All checks passed!
3605 passed, 82 skipped in 453.99s        # full tests/ on master @ ac4df996 + this change

Two notes for the reviewer:

检查清单未勾选,是因为这些第一条人称声明需由账号本人确认;本 PR 由自动化 agent 会话代为准备、测试并提交,实测证据已附于上文。


Disclosure: this PR was prepared, tested and submitted by an AI agent working on behalf of the account owner.

Summary by Sourcery

Ensure OpenAI-compatible providers resolve malformed or cleared timeout settings to a usable request timeout.

Bug Fixes:

  • Prevent cleared, invalid, zero, and negative OpenAI provider timeout values from disabling requests or causing the provider to be dropped during initialization.

Enhancements:

  • Apply shared integer configuration coercion with a default timeout and minimum supported value across OpenAI-compatible providers.

Tests:

  • Add coverage for default, valid, string, invalid, empty, null, zero, negative, and inherited OpenAI-compatible provider timeout values.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant