Skip to content

fix: unify plugin config source#240

Merged
EterUltimate merged 3 commits into
NickCharlie:mainfrom
EterUltimate:codex/unify-plugin-config-source
Jul 9, 2026
Merged

fix: unify plugin config source#240
EterUltimate merged 3 commits into
NickCharlie:mainfrom
EterUltimate:codex/unify-plugin-config-source

Conversation

@EterUltimate

@EterUltimate EterUltimate commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • make AstrBot plugin settings the single authoritative runtime config source
  • stop reading/writing the legacy WebUI plugin_data/config.json copy and archive it on startup
  • persist WebUI edits back into AstrBot grouped plugin config, including runtime log-level application

Tests

  • python -m pytest tests\unit\test_config.py tests\unit\test_config_service.py tests\integration\test_config_blueprint.py tests\integration\test_package_imports.py -q
  • python -m py_compile config.py main.py webui\services\config_service.py core\plugin_lifecycle.py tests\unit\test_config.py tests\unit\test_config_service.py tests\integration\test_config_blueprint.py
  • git diff --check
  • local smoke: legacy config ignored and archived

Summary by Sourcery

Unify runtime configuration to use AstrBot’s plugin settings as the single authoritative source and retire the legacy WebUI config file.

Enhancements:

  • Simplify config source synchronization so runtime settings are always refreshed from AstrBot plugin-page configuration.
  • Apply log-level and debug-mode changes via a shared helper when either source (WebUI or AstrBot) updates logging-related settings.
  • Clear one-time WebUI initial passwords from AstrBot grouped config after successful application to avoid stale secrets.
  • Archive any existing legacy WebUI plugin_data/config.json on startup so it cannot be treated as active configuration.
  • Remove shutdown-time saving of plugin_config to the legacy WebUI config file, relying solely on AstrBot configuration persistence.

Tests:

  • Update unit and integration tests around config loading, synchronization, and logging to reflect AstrBot as the sole runtime config source and the archival of the legacy WebUI config copy.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR makes AstrBot’s grouped plugin settings the single runtime configuration source, removes the legacy WebUI plugin_data/config.json read/write path, archives any existing legacy file on startup, and ensures WebUI changes (including log level/debug mode) are persisted back into the AstrBot config and applied to runtime.

Sequence diagram for WebUI config updates persisted to AstrBot and runtime log settings

sequenceDiagram
    actor WebUser as WebUIUser
    participant ConfigSvc as ConfigService
    participant PluginConfig as PluginConfig
    participant AstrBotConfig as AstrBotConfig
    participant Monitor as MonitoringInstrumentation

    WebUser->>ConfigSvc: update_config(new_config)
    ConfigSvc->>ConfigSvc: _get_astrbot_config()
    ConfigSvc->>AstrBotConfig: [AstrBot config must be available]
    ConfigSvc->>PluginConfig: [apply validated_config fields]
    ConfigSvc->>ConfigSvc: _apply_runtime_log_settings()
    ConfigSvc->>PluginConfig: log_level, debug_mode updated
    ConfigSvc->>Monitor: set_debug_mode(debug_mode)
    ConfigSvc->>Monitor: set_trace_enabled(log_level == "trace")
    ConfigSvc->>ConfigSvc: _clear_astrbot_initial_password(astrbot_config)
    ConfigSvc->>AstrBotConfig: save_config()
    ConfigSvc->>ConfigSvc: _remember_config_sync_state(astrbot_config)
    ConfigSvc-->>WebUser: (success, message, redacted_config)
Loading

File-Level Changes

Change Details Files
Make AstrBot plugin-page config the sole runtime source and stop loading legacy WebUI config.json.
  • Simplified ConfigService _config_source_signature/_last_config_source_signature to only track AstrBot payload changes.
  • Changed _sync_config_sources to always apply AstrBot config to the PluginConfig when the signature changes, removing mtime-based source preference logic.
  • Updated PluginConfig.create_from_runtime_sources to ignore legacy WebUI config.json content, logging and returning AstrBot-derived config only.
  • Adjusted unit tests in tests/unit/test_config.py and tests/unit/test_config_service.py to reflect that legacy config files are ignored and AstrBot grouped config is authoritative.
webui/services/config_service.py
config.py
tests/unit/test_config_service.py
tests/unit/test_config.py
Archive legacy WebUI plugin_data/config.json on startup instead of treating it as active config, and stop saving runtime config back to it.
  • Added _archive_legacy_config_copy helper in main.py to move plugin_data/config.json to a .legacy file (with timestamp if needed).
  • Called _archive_legacy_config_copy after PluginConfig.create_from_runtime_sources in main AstrBot initialization paths.
  • Removed plugin_lifecycle shutdown logic that wrote plugin_config.to_dict() to plugin_data/config.json.
  • Adjusted tests to assert that plugin_data/config.json is no longer created or used, and that AstrBot grouped config is updated instead.
main.py
core/plugin_lifecycle.py
tests/unit/test_config_service.py
tests/unit/test_config.py
Persist WebUI edits into AstrBot grouped config and apply runtime log-level/debug settings via a shared helper.
  • Refactored log-level/debug-mode application into ConfigService._apply_runtime_log_settings and reused it from both _apply_astrbot_config_to_plugin and update_config.
  • Ensured _apply_astrbot_config_to_plugin calls _apply_runtime_log_settings when log_level/debug_mode change and logs that config has been applied to runtime instead of saved to WebUI config.json.
  • Enhanced _sync_astrbot_group_config and related paths to require an AstrBot config source and to sync updated plugin paths, DB settings, filter thresholds, and log_level into AstrBot grouped config fields.
  • Added _clear_astrbot_initial_password to wipe webui_initial_password from AstrBot config after successful password persistence, saving back via save_config if available.
  • Introduced SaveableConfig test helper in integration tests to capture AstrBot save_config behavior and verify grouped config persistence.
  • Extended unit and integration tests to cover runtime log-level application from plugin-page config, grouped field syncing, acceptance of empty AstrBot configs, and non-propagation of transient runtime-only changes back to AstrBot.
webui/services/config_service.py
tests/unit/test_config_service.py
tests/integration/test_config_blueprint.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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 left some high level feedback:

  • The force parameter in _sync_config_sources is now effectively unused (the method always applies AstrBot config regardless of signatures); consider either reintroducing conditional behavior based on force or removing the parameter to avoid confusion.
  • The new _archive_legacy_config_copy helper is invoked in two separate initialization paths with duplicated arguments; you could centralize that call in a single place after PluginConfig.create_from_runtime_sources to avoid having to remember to update both branches in future.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `force` parameter in `_sync_config_sources` is now effectively unused (the method always applies AstrBot config regardless of signatures); consider either reintroducing conditional behavior based on `force` or removing the parameter to avoid confusion.
- The new `_archive_legacy_config_copy` helper is invoked in two separate initialization paths with duplicated arguments; you could centralize that call in a single place after `PluginConfig.create_from_runtime_sources` to avoid having to remember to update both branches in future.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@EterUltimate EterUltimate merged commit 1111d7f into NickCharlie:main Jul 9, 2026
19 checks passed
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