Skip to content

fix: accept extra after-message hook args#239

Merged
EterUltimate merged 1 commit into
NickCharlie:mainfrom
EterUltimate:codex/compat-after-message-extra-args
Jul 9, 2026
Merged

fix: accept extra after-message hook args#239
EterUltimate merged 1 commit into
NickCharlie:mainfrom
EterUltimate:codex/compat-after-message-extra-args

Conversation

@EterUltimate

@EterUltimate EterUltimate commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Accept extra positional arguments in the selflearning after_message_sent hook.
  • Add a package-path import regression test that verifies the hook signature remains compatible.

Evidence

  • lxfight-s-Astrbot-Plugins/astrbot_plugin_livingmemory PR [Feature] 自动清理注入到user prompt的提示 #196 / merge e2ac45d4bdb09a42def646be21cc6292a2b02736 fixed the same AstrBot v4.26.5 hook dispatcher issue.
  • Related LivingMemory issue Fix high-frequency disabled realtime learning calls #195 shows AstrBot v4.26.5 calling after_message_sent as event, *args, **kwargs, producing TypeError: ... takes 2 positional arguments but 3 were given for single-argument plugin hooks.
  • Local selflearning main.py had SelfLearningPlugin.on_bot_message_sent(self, event) under @filter.after_message_sent().

Validation

  • python -m pytest tests/integration/test_package_imports.py -q
  • python -m py_compile main.py tests\integration\test_package_imports.py
  • git diff --check
  • AstrBot local smoke test in C:\Users\zacza\Desktop\x\AstrBot\data\plugins\astrbot_plugin_self_learning: imported plugin and called on_bot_message_sent(event, extra_arg) successfully.

Summary by Sourcery

Allow the self-learning plugin’s after-message hook to accept extra positional arguments while ensuring its signature remains compatible with AstrBot’s framework calls.

Bug Fixes:

  • Prevent TypeError when AstrBot passes extra positional arguments to the self-learning plugin’s after_message_sent hook.

Enhancements:

  • Add an integration test that validates the after_message_sent hook’s signature supports additional positional arguments.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR updates the self-learning plugin’s after-message hook to accept extra positional arguments passed by AstrBot and adds an integration test to ensure the hook’s signature remains compatible when imported via the AstrBot package path.

Sequence diagram for AstrBot calling the updated after_message_sent hook

sequenceDiagram
    participant AstrBotCore
    participant SelfLearningPlugin

    AstrBotCore->>SelfLearningPlugin: on_bot_message_sent(event, extra_arg)
    activate SelfLearningPlugin
    SelfLearningPlugin->>SelfLearningPlugin: reset_trace_context()
    SelfLearningPlugin->>SelfLearningPlugin: [store message in database]
    deactivate SelfLearningPlugin
Loading

File-Level Changes

Change Details Files
Allow the self-learning plugin after_message_sent hook to accept extra positional arguments from the framework.
  • Extend on_bot_message_sent signature to include a variadic positional parameter after the event object
  • Preserve existing monitored and filter.after_message_sent decorators and behavior around trace context and database writes
main.py
Add an integration test that verifies the plugin’s after_message_sent hook signature supports extra positional arguments when imported via the AstrBot package path.
  • Import inspect to introspect the hook method signature
  • Load the plugin via a package-path alias consistent with AstrBot plugin loading
  • Assert that on_bot_message_sent defines a VAR_POSITIONAL (*args) parameter and clean up the alias before and after the test
tests/integration/test_package_imports.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:

  • In test_after_message_sent_hook_accepts_framework_extra_args, consider tightening the assertion to verify the position of the *args parameter (e.g., that it is the second parameter after event) rather than only checking that a VAR_POSITIONAL parameter exists somewhere in the signature.
  • In on_bot_message_sent, the extra positional args are intentionally unused; adding a brief inline comment explaining that they are accepted solely for AstrBot hook compatibility would help prevent future refactors from mistakenly removing them.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_after_message_sent_hook_accepts_framework_extra_args`, consider tightening the assertion to verify the position of the `*args` parameter (e.g., that it is the second parameter after `event`) rather than only checking that a VAR_POSITIONAL parameter exists somewhere in the signature.
- In `on_bot_message_sent`, the extra positional args are intentionally unused; adding a brief inline comment explaining that they are accepted solely for AstrBot hook compatibility would help prevent future refactors from mistakenly removing them.

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 cc11986 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