Skip to content

fix(sound-dodge): 修复模式配置并提升闪避响应稳定性#357

Open
CCYellowStar2 wants to merge 2 commits into
1bananachicken:devfrom
CCYellowStar2:fix/sound-dodge
Open

fix(sound-dodge): 修复模式配置并提升闪避响应稳定性#357
CCYellowStar2 wants to merge 2 commits into
1bananachicken:devfrom
CCYellowStar2:fix/sound-dodge

Conversation

@CCYellowStar2

@CCYellowStar2 CCYellowStar2 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

关联 Issue

Fixes #354

变更摘要

  • 修复自动闪避开关、仅闪避模式及阈值配置相互覆盖的问题
  • 支持仅闪避模式:闪避与反击提示均执行闪避
  • 根据归一化置信度处理闪避、反击同时命中的情况
  • 串行发送 MAA reverse RPC,避免并发响应串线导致按键失效
  • 将声音检测间隔由 100ms 优化至 50ms
  • 调整动作冷却计时点,避免有效触发被重复冷却丢弃
  • 将闪避第二次按键间隔限制为随机 100–200ms
  • 更新自动闪避功能文档

Summary by Sourcery

改进声音闪避配置处理方式,并基于音频检测稳定闪避/反击触发行为。

New Features:

  • 新增通过专用配置节点来配置声音闪避启用状态、模式和阈值的支持,并提供仅闪避模式选项。

Bug Fixes:

  • 修复自动闪避开关、仅闪避模式与阈值参数之间的冲突,避免它们互相覆盖。
  • 对反向 RPC 闪避/反击动作进行序列化,防止并发响应导致按键触发失败。
  • 修正闪避/反击冷却计时,避免有效触发被过早丢弃。

Enhancements:

  • 当两个音频事件同时命中时,通过比较置信度分数来规范闪避与反击的决策。
  • 通过短轮询循环队列化并处理声音触发的动作,以提升响应速度和可靠性。
  • 通过缩短监听间隔提高声音检测频率,并将闪避按键触发时间调整为更紧凑的二次按下时间窗口。

Documentation:

  • 更新中文声音闪避文档,以反映新的配置节点用法以及针对反击音效的仅闪避行为。
Original summary in English

Summary by Sourcery

Improve sound dodge configuration handling and stabilize dodge/counter trigger behavior based on audio detection.

New Features:

  • Add support for configuring sound dodge enable, mode, and thresholds via dedicated config nodes with a dodge-only mode option.

Bug Fixes:

  • Fix conflicts between auto dodge switch, dodge-only mode, and threshold parameters so they no longer override each other.
  • Serialize reverse RPC dodge/counter actions to avoid concurrent responses causing keypress failures.
  • Correct dodge/counter cooldown timing so valid triggers are not discarded prematurely.

Enhancements:

  • Normalize dodge vs counter decisions by comparing confidence scores when both audio events hit.
  • Queue and process sound-triggered actions with a short polling loop to improve responsiveness and reliability.
  • Increase sound detection frequency by reducing the listening interval and adjust dodge keypress timing to a tighter second-press window.

Documentation:

  • Update Chinese sound dodge documentation to reflect new config node usage and dodge-only behavior for counter sounds.

@sourcery-ai

sourcery-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

审阅者指南

重构声音闪避动作以支持新的配置节点,新增仅闪避模式,通过小型队列串行化声音触发的动作,并改进闪避/反击决策的时序与置信度处理,同时更新文档以保持一致。

串行化声音闪避动作的时序图

sequenceDiagram
    participant Ear
    participant Ctx
    participant Dodger

    Ear->>Ear: _check(d_score, c_score)
    alt [dodge_hit]
        Ear->>Ctx: on_dodge()
        Ctx->>Ctx: _enqueue_action("dodge")
    else [counter_hit]
        Ear->>Ctx: on_counter()
        Ctx->>Ctx: _enqueue_action("counter")
    end

    loop while not context.tasker.stopping
        Ctx->>Ctx: process_next(timeout=0.05)
        alt action == dodge
            Ctx->>Dodger: dodge()
        else action == counter
            Ctx->>Dodger: counter()
        end
    end
Loading

文件级改动

变更 详情 文件
优化声音闪避配置解析,并为启用/模式/阈值等引入集中化配置源,包括一个仅闪避模式开关。
  • 添加通用辅助方法,从上下文图中解析布尔值、JSON 参数和基于节点的配置值
  • 扩展 SoundDodgeAction.run,将 CLI/custom_action_param 设置与 SoundDodge*Config 节点值合并,并遵守整体的 enable_sound_trigger 标志
  • 引入 dodge_all_attacks 标志,在启用时将反击事件映射为闪避回调,实现仅闪避模式
  • 改进解析 custom_action_param 与配置值时的错误处理和日志记录
agent/custom/action/SoundTrigger/SoundDodgeAction.py
assets/resource/base/pipeline/SoundDodge/SoundDodge.json
assets/resource/tasks/SoundDodge.json
将闪避/反击的执行串行化以避免并发反向 RPC 问题,并依赖一个小型进程内队列配合更短的轮询间隔。
  • 向 Ctx 添加有界动作队列,将 on_dodge/on_counter 回调路由到队列中,而不是为每个事件生成新线程
  • 添加 Ctx.process_next 用于同步执行排队的闪避或反击动作,并让主运行循环以 50ms 超时轮询该方法,而非简单 sleep
  • 当队列已满时记录日志并丢弃过期动作,防止回压持续堆积
agent/custom/action/SoundTrigger/SoundDodgeAction.py
在闪避和反击得分同时命中时使用归一化置信度,并收紧监听间隔以提升响应速度。
  • 更新 Ear._check,使其按各自阈值计算每一类的置信度比例,并在两者都超过阈值时选择置信度更高的一方
  • 将声音采样间隔从 100ms 调整为 50ms,并将日志记录间隔加倍,以大致保持日志量不变
agent/custom/action/SoundTrigger/SoundListener.py
调整闪避/反击冷却时间与第二次按键间隔,以获得更准确的冷却语义和更一致的闪避输入。
  • 将 _last_dodge 和 _last_counter 时间戳的设置移动到加锁(busy lock)后、动作执行之前,避免丢失本应有效的触发
  • 减少默认闪避按键序列中的随机额外延迟,使第二次按键保持在大约 100–200ms 之间
agent/custom/action/SoundTrigger/DodgeCounterTrigger.py
使文档与新的配置节点及仅闪避模式下的阈值与模式语义保持一致。
  • 更新文档,改为描述 SoundDodgeEnableConfig/SoundDodgeModeConfig/SoundDodgeThresholdConfig/SoundCounterThresholdConfig 的 attach 字段,而不是覆盖 SoundDodgeMain 参数
  • 澄清在仅闪避模式下,反击阈值命中也会触发闪避而不是反击
docs/zh_cn/introduction/SoundDodge.md

可能关联的 Issue

  • 自动闪避问题 #354: 该 PR 修复音频闪避配置覆盖、触发与按键串线等问题,直接针对 Issue 中的失效与卡死现象。

Tips and commands

Interacting with Sourcery

  • 触发新一次审核: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub Issue: 回复审阅评论,请求 Sourcery 根据该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 描述正文任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve 来标记所有 Sourcery 评论为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 一次性忽略所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss 以忽略所有现有的 Sourcery 审阅。特别适用于你希望从一次全新的审阅开始——别忘了再评论 @sourcery-ai review 触发新审阅!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或禁用诸如 Sourcery 生成的 pull request 摘要、审阅者指南等审阅功能。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅指令。
  • 调整其他审阅设置。

Getting Help

Original review guide in English

Reviewer's Guide

Refactors the sound dodge action to honor new config nodes, add a dodge-only mode, serialize sound-triggered actions through a small queue, and improve timing and confidence handling for dodge/counter decisions, while updating docs to match.

Sequence diagram for serialized sound dodge actions

sequenceDiagram
    participant Ear
    participant Ctx
    participant Dodger

    Ear->>Ear: _check(d_score, c_score)
    alt [dodge_hit]
        Ear->>Ctx: on_dodge()
        Ctx->>Ctx: _enqueue_action("dodge")
    else [counter_hit]
        Ear->>Ctx: on_counter()
        Ctx->>Ctx: _enqueue_action("counter")
    end

    loop while not context.tasker.stopping
        Ctx->>Ctx: process_next(timeout=0.05)
        alt action == dodge
            Ctx->>Dodger: dodge()
        else action == counter
            Ctx->>Dodger: counter()
        end
    end
Loading

File-Level Changes

Change Details Files
Refine sound dodge configuration parsing and introduce centralized config sources for enable/mode/thresholds, including a dodge-only mode toggle.
  • Add generic helpers to parse booleans, JSON params, and node-based configuration values from the context graph
  • Extend SoundDodgeAction.run to merge CLI/custom_action_param settings with SoundDodge*Config node values and to respect an overall enable_sound_trigger flag
  • Introduce a dodge_all_attacks flag that maps counter events to dodge callbacks when enabled, implementing a dodge-only mode
  • Improve error handling and logging when parsing custom_action_param and config values
agent/custom/action/SoundTrigger/SoundDodgeAction.py
assets/resource/base/pipeline/SoundDodge/SoundDodge.json
assets/resource/tasks/SoundDodge.json
Serialize dodge/counter execution to avoid concurrent reverse-RPC issues and rely on a small in-process queue with shorter polling intervals.
  • Add a bounded action queue to Ctx and route on_dodge/on_counter callbacks into the queue instead of spawning new threads per event
  • Add Ctx.process_next to synchronously execute queued dodge or counter actions and wire the main run loop to poll this with a 50ms timeout instead of sleeping
  • Log and drop stale actions when the queue is full, preventing backpressure from piling up
agent/custom/action/SoundTrigger/SoundDodgeAction.py
Use normalized confidence when both dodge and counter scores hit, and tighten listening intervals for better responsiveness.
  • Update Ear._check to compute per-class confidence ratios against their thresholds and choose the higher-confidence action when both exceed their thresholds
  • Adjust sound sampling interval from 100ms to 50ms and double the logging interval to keep log volume roughly constant
agent/custom/action/SoundTrigger/SoundListener.py
Adjust dodge/counter cooldown timing and second keypress interval for more accurate cooldown semantics and more consistent dodge input.
  • Move _last_dodge and _last_counter timestamps to be set under the busy lock before executing actions to avoid losing valid triggers
  • Reduce the random extra delay in the default dodge key sequence to keep the second keypress between approximately 100–200ms
agent/custom/action/SoundTrigger/DodgeCounterTrigger.py
Align documentation with the new configuration nodes and dodge-only semantics for thresholds and modes.
  • Update docs to describe SoundDodgeEnableConfig/SoundDodgeModeConfig/SoundDodgeThresholdConfig/SoundCounterThresholdConfig attach fields instead of overriding SoundDodgeMain params
  • Clarify that in dodge-only mode, counter threshold hits still trigger dodge rather than counter
docs/zh_cn/introduction/SoundDodge.md

Possibly linked issues

  • 自动闪避问题 #354: 该 PR 修复音频闪避配置覆盖、触发与按键串线等问题,直接针对 Issue 中的失效与卡死现象。

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.

嗨,我已经审阅了你的修改,看起来非常不错!


Sourcery 对开源项目是免费的——如果你喜欢我们的审查结果,请考虑分享它们 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进审查质量。
Original comment in English

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


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.

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