Skip to content

fix: check OnWaitingLLMRequestEvent stop signal before acquiring session lock#8935

Open
Foolllll-J wants to merge 1 commit into
AstrBotDevs:masterfrom
Foolllll-J:fix/stop-event-on-waiting-llm-request
Open

fix: check OnWaitingLLMRequestEvent stop signal before acquiring session lock#8935
Foolllll-J wants to merge 1 commit into
AstrBotDevs:masterfrom
Foolllll-J:fix/stop-event-on-waiting-llm-request

Conversation

@Foolllll-J

@Foolllll-J Foolllll-J commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

修复 OnWaitingLLMRequestEvent hook 的返回值和 event.is_stopped() 未被检查的问题,导致插件在该 hook 中调用 event.stop_event() 后,pipeline 仍然继续获取会话锁并执行 LLM 请求。

Modifications / 改动点

  • astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py:213 — 将 await call_event_hook(event, EventType.OnWaitingLLMRequestEvent) 的返回值改为条件检查:如果 hook 返回 True(事件被停止),直接 return 终止 pipeline,与同文件中 OnLLMRequestEvent 的处理方式保持一致。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • ruff check . — All checks passed
  • tests/unit/test_astr_message_event.py — 78 passed

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Prevent the pipeline from acquiring the session lock and issuing an LLM request when OnWaitingLLMRequestEvent indicates the event has been stopped.

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@Foolllll-J is attempting to deploy a commit to the soulter's projects Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 21, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the internal agent sub-stage processing logic to check the return value of the OnWaitingLLMRequestEvent event hook. If the hook returns a truthy value, the process returns early, preventing further execution and the acquisition of the session lock. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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:

  • Since call_event_hook is now used as a gate to short-circuit the pipeline, consider making its return contract explicitly boolean (or explicitly checking is True) and documenting that True means the request was stopped, to avoid accidental truthy values changing control flow.
  • It may be helpful to add a debug-level log right before the return when OnWaitingLLMRequestEvent stops the pipeline so that it’s easier to trace why a particular LLM request never acquired the session lock.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `call_event_hook` is now used as a gate to short-circuit the pipeline, consider making its return contract explicitly boolean (or explicitly checking `is True`) and documenting that `True` means the request was stopped, to avoid accidental truthy values changing control flow.
- It may be helpful to add a debug-level log right before the `return` when `OnWaitingLLMRequestEvent` stops the pipeline so that it’s easier to trace why a particular LLM request never acquired the session lock.

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

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant