feat(referee): integrate referee state and sentry commands into decision#17
feat(referee): integrate referee state and sentry commands into decision#17gqsdjhh wants to merge 3 commits into
Conversation
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough该PR在导航模块中添加并注册哨兵决策相关输入与输出,实现在 Command 层的 exchange/switch/confirm 控制与 ~800ms 的自动清除逻辑,重构 lua_sync 为安全读取 Context,扩展 Lua 黑板与 API 并将命令生命周期集成到 Navigation 更新循环。 变更哨兵决策与游戏状态集成
代码审查工作量估计🎯 3 (中等) | ⏱️ ~25 分钟 诗
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/cxx/component.cc (2)
191-193: 💤 Low valueLambda 风格与同段其他 lambda 不一致。
同一
make_api_injection中其他 lambda 都未显式书写返回类型,这里的[this]()-> void { ... }显式写出-> void略显不齐整。统一为隐式返回即可。♻️ 风格统一
- api.set_function("confirm_revive", [this]()-> void { - command.confirm_revive(); - }); + api.set_function("confirm_revive", [this] { command.confirm_revive(); });🤖 Prompt for 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. In `@src/cxx/component.cc` around lines 191 - 193, 在 make_api_injection 中的 api.set_function("confirm_revive", [this]()-> void { command.confirm_revive(); }); 与同段其他 lambda 风格不一致:请将该 lambda 的显式返回类型移除,改为与同组一致的隐式返回形式(即使用 [this]() { command.confirm_revive(); }),以保持代码风格统一并保留对 this 的捕获;定位标识符参考 api.set_function("confirm_revive") 和 command.confirm_revive().
99-106: ⚡ Quick win
switch_mode对非法mode静默返回,建议加日志便于排查。
mode来自 Lua 调用方,越界时直接return不会触发任何反馈,调试时很难定位“为什么没切换”。建议至少warn一行,并保持其他决策状态不变(不调用reset_all_decisions,与现有实现一致)。♻️ 建议改动
auto switch_mode(int mode) -> void { - if (mode < 1 || mode > 3) - return; + if (mode < 1 || mode > 3) { + // 上层 Lua 传入越界值,记录后忽略,保留既有决策 + return; + }(如果
Command能拿到 logger,请把return前替换为warn(...)调用;否则在调用api.set_function("switch_mode", ...)处统一打日志。)🤖 Prompt for 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. In `@src/cxx/component.cc` around lines 99 - 106, The switch_mode function currently returns silently on an out-of-range mode; update it to emit a warning when mode < 1 || mode > 3 (but keep the current behavior of not calling reset_all_decisions or changing state) by logging a clear message that includes the invalid mode value; if the Command class (or the surrounding object that owns switch_mode) exposes a logger, call its warn(...) before returning from switch_mode, otherwise add a warning log at the place where api.set_function("switch_mode", ...) is registered so callers and logs show why the switch was ignored; keep references to reset_all_decisions, requested_mode and activate_decision unchanged.
🤖 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/cxx/component.cc`:
- Around line 114-120: Command::update() reads sentry_decision_clear_at which
other Lua API callbacks (e.g., exchange_17mm_bullet, switch_mode,
confirm_revive) modify under io_mutex, so call command.update() while holding
the same io_mutex to prevent data races; specifically, acquire io_mutex before
invoking command.update() (the call site that currently precedes lua_sync() and
lua_tick()) or, alternatively, add a clear comment on the component specifying
it must run in a mutually exclusive callback group / single-threaded executor
(e.g., MultiThreadedExecutor with non-Reentrant callbacks) so maintainers know
the required synchronization.
In `@src/lua/blackboard.lua`:
- Line 9: The local variable last_our_dart_nmber_of_hits is misspelled (nmber)
and the PR also introduced a duplicated field our_dart_nmber_of_hits alongside
the correct our_dart_number_of_hits; rename the local variable
last_our_dart_nmber_of_hits to last_our_dart_number_of_hits and remove the newly
added misspelled field usage in this file, ensuring all references (lines around
initialization and 185-192) use last_our_dart_number_of_hits and
our_dart_number_of_hits; if C++ (component.cc lua_sync) still writes the
misspelled key, keep only the correct key in Lua and optionally add a temporary
alias read-from fallback from our_dart_nmber_of_hits -> our_dart_number_of_hits
(without introducing new persistent misspelled fields) so existing callers
continue to work until they migrate.
---
Nitpick comments:
In `@src/cxx/component.cc`:
- Around line 191-193: 在 make_api_injection 中的
api.set_function("confirm_revive", [this]()-> void { command.confirm_revive();
}); 与同段其他 lambda 风格不一致:请将该 lambda 的显式返回类型移除,改为与同组一致的隐式返回形式(即使用 [this]() {
command.confirm_revive(); }),以保持代码风格统一并保留对 this 的捕获;定位标识符参考
api.set_function("confirm_revive") 和 command.confirm_revive().
- Around line 99-106: The switch_mode function currently returns silently on an
out-of-range mode; update it to emit a warning when mode < 1 || mode > 3 (but
keep the current behavior of not calling reset_all_decisions or changing state)
by logging a clear message that includes the invalid mode value; if the Command
class (or the surrounding object that owns switch_mode) exposes a logger, call
its warn(...) before returning from switch_mode, otherwise add a warning log at
the place where api.set_function("switch_mode", ...) is registered so callers
and logs show why the switch was ignored; keep references to
reset_all_decisions, requested_mode and activate_decision unchanged.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3fc6475e-0ec3-4adc-bf46-ff22df44d826
📒 Files selected for processing (6)
src/cxx/component.ccsrc/cxx/context.ccsrc/cxx/context.hhsrc/lua/action.luasrc/lua/api.luasrc/lua/blackboard.lua
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/cxx/component.cc (3)
129-133: 💤 Low value800ms 魔法数字建议提取为命名常量。
std::chrono::milliseconds{800}是哨兵决策的自动清除窗口,与裁判系统下行刷新节奏强相关。建议提升为Command的static constexpr命名常量(如decision_hold_duration),便于后续调参、统一注释来源,并避免在update()中读取clear_at与此处写入逻辑分离时产生不一致。🔧 建议的修复
+ static constexpr auto decision_hold_duration = std::chrono::milliseconds{800}; + auto activate_decision() -> void { *sentry_decision_enabled = true; - sentry_decision_clear_at = - std::chrono::steady_clock::now() + std::chrono::milliseconds{800}; + sentry_decision_clear_at = std::chrono::steady_clock::now() + decision_hold_duration; }🤖 Prompt for 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. In `@src/cxx/component.cc` around lines 129 - 133, The hard-coded 800ms duration in activate_decision() (std::chrono::milliseconds{800}) should be extracted to a named constant on the Command type to centralize tuning and avoid mismatches with other places that read/write sentry_decision_clear_at; add a static constexpr std::chrono::milliseconds decision_hold_duration (or similarly named) to Command and replace std::chrono::milliseconds{800} in activate_decision() with Command::decision_hold_duration, and update any other places that set or compare sentry_decision_clear_at to use that constant.
191-193: 💤 Low valueLambda 风格不一致:多余的尾置返回类型。
第 185、188 行的回调均省略
-> void,而第 191 行的confirm_revive显式写出-> void,建议统一风格。🔧 建议的修复
- api.set_function("confirm_revive", [this]()-> void { + api.set_function("confirm_revive", [this]() { command.confirm_revive(); });🤖 Prompt for 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. In `@src/cxx/component.cc` around lines 191 - 193, 回调 lambda 风格不一致:在 api.set_function("confirm_revive", ...) 的 lambda 中移除多余的尾置返回类型 `-> void` 以与其它回调(例如前面对其他命令的 set_function 回调)保持一致;定位到使用 api.set_function("confirm_revive", [this]()-> void { command.confirm_revive(); }); 并将其改为省略返回类型的形式(保持捕获和主体不变)。
99-106: ⚡ Quick win
switch_mode静默忽略非法 mode 值,建议至少打日志。当
mode不在[1, 3]范围内时函数直接return,调用方(Lua 侧)无法感知错误,调试时也难以定位为何决策未生效。建议至少打一条warn日志,或返回 bool 让 Lua 侧可判断。🔧 示例修复
auto switch_mode(int mode) -> void { - if (mode < 1 || mode > 3) - return; + if (mode < 1 || mode > 3) { + // 仅接受 1..3,超出范围视为非法请求 + return; + } reset_all_decisions(); *requested_mode = static_cast<std::uint8_t>(mode); activate_decision(); }若组件持有日志接口,可改为
warn("switch_mode: invalid mode {}", mode);。🤖 Prompt for 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. In `@src/cxx/component.cc` around lines 99 - 106, The function switch_mode currently returns silently for invalid mode values (mode < 1 || mode > 3), which hides errors from callers; update switch_mode to either log a warning (e.g., using the component's logger with a message like "switch_mode: invalid mode {}" including the mode) before returning, or change its signature to return a bool indicating success/failure so the Lua side can detect the error; ensure the modified logic still calls reset_all_decisions(), updates *requested_mode, and calls activate_decision() only on valid modes, and reference switch_mode, requested_mode, reset_all_decisions, and activate_decision when making the change.
🤖 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/cxx/component.cc`:
- Around line 285-286: 修复 game 对象中拼写错误的键:将重复写入的
our_dart_nmber_of_hits(拼写错误)移除,仅保留正确的 our_dart_number_of_hits;如果必须保留旧键做兼容(即保留
our_dart_nmber_of_hits),在该位置添加明确的 TODO: deprecated 注释并记录移除时间表以避免脏 API
长期存在。定位标识符:game、our_dart_number_of_hits、our_dart_nmber_of_hits。
---
Nitpick comments:
In `@src/cxx/component.cc`:
- Around line 129-133: The hard-coded 800ms duration in activate_decision()
(std::chrono::milliseconds{800}) should be extracted to a named constant on the
Command type to centralize tuning and avoid mismatches with other places that
read/write sentry_decision_clear_at; add a static constexpr
std::chrono::milliseconds decision_hold_duration (or similarly named) to Command
and replace std::chrono::milliseconds{800} in activate_decision() with
Command::decision_hold_duration, and update any other places that set or compare
sentry_decision_clear_at to use that constant.
- Around line 191-193: 回调 lambda 风格不一致:在 api.set_function("confirm_revive", ...)
的 lambda 中移除多余的尾置返回类型 `-> void` 以与其它回调(例如前面对其他命令的 set_function 回调)保持一致;定位到使用
api.set_function("confirm_revive", [this]()-> void { command.confirm_revive();
}); 并将其改为省略返回类型的形式(保持捕获和主体不变)。
- Around line 99-106: The function switch_mode currently returns silently for
invalid mode values (mode < 1 || mode > 3), which hides errors from callers;
update switch_mode to either log a warning (e.g., using the component's logger
with a message like "switch_mode: invalid mode {}" including the mode) before
returning, or change its signature to return a bool indicating success/failure
so the Lua side can detect the error; ensure the modified logic still calls
reset_all_decisions(), updates *requested_mode, and calls activate_decision()
only on valid modes, and reference switch_mode, requested_mode,
reset_all_decisions, and activate_decision when making the change.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0496a083-b2ec-4fa2-8769-aaf15ab924cd
📒 Files selected for processing (1)
src/cxx/component.cc
Summary
This PR integrates referee-system state and sentry control commands into the decision layer.
It adds the C++ to Lua data path for referee-related fields, exposes sentry control commands to Lua, and extends the decision blackboard so upper-layer logic can read referee state and issue sentry-related actions.
Changes
exchange_17mm_bulletswitch_modeconfirm_reviveScope
This PR focuses on communication and decision-layer integration only.
PR 摘要
本 PR 将裁判系统状态与哨兵(sentry)控制命令集成到决策层,建立从 C++ 到 Lua 的裁判相关数据通路,并在决策黑板中暴露哨兵控制命令,供上层 Lua 逻辑读取裁判状态并发出哨兵相关动作。变更范围限定在通信与决策层集成。
主要变更
导航组件集成(src/cxx/component.cc)
上下文输入扩展(src/cxx/context.cc / src/cxx/context.hh)
决策黑板扩展(src/lua/blackboard.lua)
Lua API 与封装(src/lua/action.lua / src/lua/api.lua)
并发修复
影响范围与兼容性