Skip to content

fix: reject providers missing adapter type - #9404

Open
EterUltimate wants to merge 1 commit into
AstrBotDevs:masterfrom
EterUltimate:codex/automation-4-provider-config-20260726
Open

fix: reject providers missing adapter type#9404
EterUltimate wants to merge 1 commit into
AstrBotDevs:masterfrom
EterUltimate:codex/automation-4-provider-config-20260726

Conversation

@EterUltimate

@EterUltimate EterUltimate commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #9399.

Evidence

  • Issue [Bug] 填写provider配置时,出现状态不一致问题 #9399 includes a dashboard stack trace for POST /api/v1/provider-sources/providers ending in KeyError('type') at astrbot/core/provider/manager.py inside load_provider.
  • Current ProviderManager.create_provider appends the new provider to config["provider"], saves config, and only then calls load_provider; a missing merged type therefore both raises and leaves a bad provider persisted.
  • The reported path matches the current code path: astrbot/dashboard/api/providers.py -> ProviderConfigService.create_provider -> ProviderManager.create_provider -> load_provider.

Changes

  • Validate enabled provider configs after provider-source merge and before create/update saves.
  • Skip already-corrupt enabled provider configs missing adapter type during load_provider instead of raising KeyError.
  • Move the PersonaManager annotation import behind TYPE_CHECKING to avoid the circular import exposed by the new core regression test.
  • Add regression coverage for no-save-on-invalid-provider and no-KeyError loading behavior.

Merge plan

Verification

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run pytest tests/unit/test_provider_manager_config_validation.py tests/test_fastapi_v1_dashboard.py -q -> 74 passed
  • uv run pytest tests/unit/test_provider_manager_config_validation.py tests/test_fastapi_v1_dashboard.py::test_v1_safe_provider_routes_accept_slash_ids tests/test_chat_route.py -q -> 12 passed
  • uv run astrbot --help
  • cd dashboard && bunx pnpm@10.28.2 install --frozen-lockfile
  • cd dashboard && bunx pnpm@10.28.2 run build

Full local Windows pytest was also run with uv run pytest --cov=astrbot tests/ -q: 1841 passed, 28 failed. The failures are existing Windows path/newline/sandbox/file-uri/local-shell cases outside the provider files touched here; targeted provider/API tests passed. tests/test_code_quality_typing.py is not present on current origin/master, so it could not be run.

  • This is NOT a breaking change. / 这不是一个破坏性变更。
  • I have ensured that no new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Validate provider configurations for a valid adapter type before persisting them and ensure loading skips invalid providers instead of raising errors.

Bug Fixes:

  • Prevent saving new or updated providers whose merged configuration is missing a valid adapter type field.
  • Avoid KeyError and other crashes when loading enabled providers that lack a valid adapter type by skipping them instead.

Enhancements:

  • Guard provider creation and update with a centralized provider config validation helper.
  • Adjust PersonaManager typing to avoid circular import issues exposed by tests.

Tests:

  • Add unit tests covering rejection of invalid provider configs before save and safe skipping of missing-type providers during load.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 填写provider配置时,出现状态不一致问题

1 participant