Skip to content

fix: talk_value=0 时真正跳过回复判断,仅保留表达学习#1667

Closed
hsd221 wants to merge 2 commits into
Mai-with-u:devfrom
hsd221:fix/talk-value-zero-skip-reply
Closed

fix: talk_value=0 时真正跳过回复判断,仅保留表达学习#1667
hsd221 wants to merge 2 commits into
Mai-with-u:devfrom
hsd221:fix/talk-value-zero-skip-reply

Conversation

@hsd221
Copy link
Copy Markdown
Contributor

@hsd221 hsd221 commented May 9, 2026

问题

WebUI 中将群聊 talk_value 配置为 0 后,消息仍会频繁进入 Timing Gate 产生 LLM 调用。根因有三个:

  1. _get_effective_reply_frequency() 将频率钳位在 max(0.01, ...),导致 talk_value=0 实际生效为 0.01
  2. 空闲补偿机制 _should_trigger_message_turn_by_idle_compensation() 可将空窗时间折算为等效消息数,绕过阈值
  3. get_talk_value()time=""(WebUI 显示「全天」)被 parse_range() 丢弃,导致会话专属规则静默失效。用户将群聊频率设为 0,但因规则被跳过而回退到基础 talk_value=0.8,频率检查 <=0 从未触发

修复

  • 移除 _get_effective_reply_frequency()adjust_talk_frequency() 中的 0.01 钳位
  • _get_message_trigger_threshold() 频率为 0 时返回 _EFFECTIVELY_INFINITE_THRESHOLD 避免除零
  • _schedule_message_turn() 频率为 0 时仅在学习条件满足时调度 turn
  • run_loop() 频率为 0 且非强制触发时,学习完成后跳过 Timing Gate 和 Planner
  • _is_time_in_range(): time 为空视为全时段生效,修复 WebUI「全天」规则被跳过的问题
  • 提取 _is_expression_learning_due() 消除调度与执行阶段的守卫重复
  • 提取 _transition_to_idle() 消除 run_loop 两处相同的状态重置代码
  • @强制回复不受 talk_value=0 影响

测试

  • 现有 12 个 timing gate 测试全部通过
  • ruff 检查通过

🤖 Generated with Claude Code

Summary by CodeRabbit

发布说明

  • 新功能

    • 新增完全静默模式,当对话频率设置为零时,Agent 可正确进入静默状态。
  • 改进

    • 优化消息处理流程,缓存消息检测时跳过不必要的处理步骤,提升效率。
    • 重构对话时间触发逻辑,统一处理时间范围判断。

Review Change Stack

移除 _get_effective_reply_frequency 和 adjust_talk_frequency 中的
0.01 硬钳位,使 talk_value=0 的语义从"最低频率"修正为"仅学习不回复"。
提取 _is_expression_learning_due 共享守卫消除调度与执行阶段的重复检查。
@强制回复不受 talk_value=0 影响,仍可正常触发。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 43989c6c-8871-4477-b115-b2d5879ff045

📥 Commits

Reviewing files that changed from the base of the PR and between a0a5b77 and 31da969.

📒 Files selected for processing (3)
  • src/common/utils/utils_config.py
  • src/maisaka/reasoning_engine.py
  • src/maisaka/runtime.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/maisaka/reasoning_engine.py
  • src/maisaka/runtime.py

Walkthrough

移除回复频率的非零下限以支持完全静默(有效频率 ≤ 0);在调度中短路常规回复但保留表达式学习触发;提取聊天规则的时间窗判断为辅助方法;推理引擎在静默且有缓存消息时跳过内部循环并切换空闲。

变更内容

完全静默模式支持与时间窗抽取重构

Layer / File(s) Summary
常量与频率调整
src/maisaka/runtime.py
添加 _EFFECTIVELY_INFINITE_THRESHOLD 常量;adjust_talk_frequency() 直接保存传入倍数,移除最小非零限制。
频率计算与触发阈值
src/maisaka/runtime.py
_get_effective_reply_frequency() 不再强制非零下限,允许返回 0;_get_message_trigger_threshold() 将有效频率 ≤ 0 映射为 _EFFECTIVELY_INFINITE_THRESHOLD,否则计算 ceil(1.0 / frequency)
消息调度逻辑
src/maisaka/runtime.py
_schedule_message_turn() 在有效频率 ≤ 0 时短路:仅在表达式学习到期时调度,否则返回跳过正常内部处理。
学习触发逻辑重构
src/maisaka/runtime.py
新增 _is_expression_learning_due() 封装学习触发判断;_trigger_expression_learning() 使用该方法进行早期返回决策。
聊天配置时间窗判定
src/common/utils/utils_config.py
新增 ChatConfigUtils._is_time_in_range(time_str, now_min),在 get_talk_value 的会话规则与全局回退规则中复用该方法以判断规则时间窗(支持空串与跨午夜)。
推理引擎集成
src/maisaka/reasoning_engine.py
run_loop 添加早期继续守护:当有缓存消息且有效频率 ≤ 0 且无强制计时触发时,记录调试信息并切换到空闲后继续外层循环;finally 路径调用 _transition_to_idle()

🎯 3 (中等复杂度) | ⏱️ ~20 分钟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR标题准确概括了主要变更:当talk_value=0时跳过回复判断,仅保留表达学习。标题清晰具体,直接反映了此次修复的核心内容。
Description check ✅ Passed PR描述结构完整,详细说明了问题根因、修复方案和测试情况。相比模板虽未完全填写全部复选框,但核心内容(问题、修复、测试)已充分阐述。
Docstring Coverage ✅ Passed Docstring coverage is 94.74% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/maisaka/reasoning_engine.py`:
- Around line 456-464: The fast-path early `continue` when cached_messages and
runtime timing conditions are met skips the later cleanup that sets
`_agent_state` back from "running" (which causes `register_message()` to treat
subsequent messages as still-in-progress and incorrectly trigger debounce/quiet
windows); fix by performing the same state reset/phase update before returning
from this branch (or move this timing-gate branch into the shared try/finally
cleanup so the post-run cleanup always runs). Update the branch that checks
`cached_messages` / `_runtime._get_effective_reply_frequency()` /
`_runtime._has_forced_timing_trigger()` to either call the same reset routine
used after the run or ensure `_agent_state` is cleared and any debounce/phase
flags are updated before `continue`, and keep `register_message`/debounce
behaviour consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db85c620-c075-4648-a18b-b684e310dfd4

📥 Commits

Reviewing files that changed from the base of the PR and between 09eeefc and a0a5b77.

📒 Files selected for processing (2)
  • src/maisaka/reasoning_engine.py
  • src/maisaka/runtime.py

Comment thread src/maisaka/reasoning_engine.py
- _is_time_in_range(): time 为空视为全时段生效,修复 WebUI「全天」规则被 parse_range 丢弃的 bug
- 将频率<=0的跳过检查提前到 cached_messages 判断之前,覆盖 timeout 路径
- 提取 _transition_to_idle(),消除 run_loop 内两处相同的状态重置代码

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
hsd221 added a commit to hsd221/MaiBot that referenced this pull request May 10, 2026
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