Skip to content

0.2.22 规则正则匹配对无效正则容错,告警跳过而非中断整条回复链 - #40

Merged
lunzhiPenxil merged 3 commits into
OlivOS-Team:mainfrom
Desom-fu:main
Oct 8, 2026
Merged

lunzhiPenxil merged 3 commits into
OlivOS-Team:mainfrom
Desom-fu:main

Conversation

@Desom-fu

@Desom-fu Desom-fu commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary by Sourcery

为自定义回复规则增加无效正则容错,确保异常规则不会阻断后续回复处理。

Bug Fixes:

  • 使无效正则规则被记录并跳过,避免中断整条回复处理链。

Chores:

  • 更新插件版本号至 0.2.24(SVN 39)。

@sourcery-ai

sourcery-ai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

本次更新将版本升级至 0.2.22(37),并在正则规则匹配处捕获无效表达式异常、记录告警后跳过该规则,从而保证后续回复规则仍能继续执行。

Sequence diagram for invalid regex rule handling

sequenceDiagram
    participant Event as PluginEvent
    participant Runtime as reply_runtime
    participant Regex as re.match
    participant Logger as Proc.log

    Event->>Runtime: reply_runtime(plugin_event, Proc)
    Runtime->>Regex: re.match(pattern, tmp_message)
    alt Invalid regular expression
        Regex-->>Runtime: re.error
        Runtime->>Logger: Proc.log(1, warning)
        Runtime-->>Runtime: continue to next rule
    else Valid regular expression
        Regex-->>Runtime: match result
        Runtime-->>Runtime: Continue normal reply processing
    end
Loading

File-Level Changes

Change Details Files
为规则正则匹配增加无效表达式容错,避免单条错误规则中断整条回复处理链。
  • 捕获 Python 正则编译/匹配产生的 re.error 异常。
  • 记录包含规则内容和异常原因的告警日志。
  • 跳过无效规则并继续处理后续规则。
ChanceCustom/replyCore.py
将插件版本和 SVN 构建号升级至 0.2.22(37)。
  • 同步更新应用元数据中的版本与 SVN 字段。
  • 同步更新主程序运行时版本常量。
ChanceCustom/app.json
ChanceCustom/main.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

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="ChanceCustom/replyCore.py" line_range="305" />
<code_context>
-                        res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+                        try:
+                            res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+                        except re.error as e:
+                            Proc.log(
+                                1,
</code_context>
<issue_to_address>
**Regex errors stop reply processing**

When a configured regex is deeply nested enough to raise `RecursionError` or uses a repetition count beyond the regex engine's limit, `re.match` raises `RecursionError` or `OverflowError`, but the handler catches only `re.error`; the exception escapes `reply_runtime` and `unity_reply` instead of skipping the rule, stopping the reply chain.

Catch `RecursionError` and `OverflowError` alongside `re.error` so these patterns are logged and skipped.

Also at `ChanceCustom/replyCore.py:304`.
</issue_to_address>

### Comment 2
<location path="ChanceCustom/replyCore.py" line_range="306-310" />
<code_context>
+                        try:
+                            res_re = re.match('^%s$' % tmp_dictCustomData_this[key_this]['key'], tmp_message)
+                        except re.error as e:
+                            Proc.log(
+                                1,
+                                'ChanceCustom 规则[%s]的正则表达式无效,已跳过: %s'
+                                % (tmp_dictCustomData_this[key_this]['key'], e)
+                            )
+                            continue
                         if res_re is not None:
</code_context>
<issue_to_address>
**Invalid rules flood operator logs**

When an invalid regex rule remains configured while incoming messages continue in a busy chat, `reply_runtime` calls `Proc.log` with the same warning on every evaluation, including evaluations triggered by group and private messages; the repeated warnings overwhelm useful diagnostics and can consume log storage.

Deduplicate or rate-limit the warning per invalid rule instead of logging it on every evaluation.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: ChanceCustom/replyCore.py:305, ChanceCustom/replyCore.py:310


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

Comment thread ChanceCustom/replyCore.py Resolved
Comment thread ChanceCustom/replyCore.py Resolved

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@lunzhiPenxil
lunzhiPenxil merged commit 6f2deef into OlivOS-Team:main Oct 8, 2026
3 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.

2 participants