Skip to content

fix: wake session waiter timeout task on stop - #11349

Merged
zouyonghe merged 2 commits into
AstrBotDevs:masterfrom
icyaaaww:fix/session-waiter-timeout-cleanup
Nov 24, 2026
Merged

zouyonghe merged 2 commits into
AstrBotDevs:masterfrom
icyaaaww:fix/session-waiter-timeout-cleanup

Conversation

@icyaaaww

@icyaaaww icyaaaww commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Wake the active session waiter timeout task when the session stops early, so it does not remain pending until its deadline.
  • Add a regression test and an unreleased changelog entry.

Verification

  • uv run pytest tests/unit/test_session_waiter_pipeline.py -q — 8 passed.
  • uv run ruff check astrbot/core/utils/session_waiter.py tests/unit/test_session_waiter_pipeline.py — passed.
  • uv run ruff format --check astrbot/core/utils/session_waiter.py tests/unit/test_session_waiter_pipeline.py — passed.

Summary by Sourcery

Ensure stopped session waiters terminate their timeout handling promptly and cannot restart it.

Bug Fixes:

  • Wake session waiter timeout tasks immediately when sessions stop early, preventing them from remaining pending until their deadlines.
  • Prevent stopped session waiters from starting new timeout tasks when keep is called.

Tests:

  • Add regression coverage for waking timeout tasks on stop and ignoring keep requests after stopping.

- Signal the active timeout wait when a session ends early.
- Add a regression test and changelog entry.

@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 found 1 issue

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

## Individual Comments

### Comment 1
<location path="astrbot/core/utils/session_waiter.py" line_range="34-35" />
<code_context>

     def stop(self, error: Exception | None = None) -> None:
         """立即结束这个会话"""
+        if self.current_event and not self.current_event.is_set():
+            self.current_event.set()
         if not self.future.done():
             if error:
</code_context>
<issue_to_address>
**Late keep leaves timeout task pending**

When a caller invokes `keep()` after another task has stopped the controller, `keep()` does not check whether the controller's future is already done, so it creates a new timeout task after the stop signal has passed; no later stop wakes that task, which remains pending until its deadline.

Make `keep()` return without creating a task when the controller is already stopped, or otherwise ensure stop state also covers subsequently created timeout tasks.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: astrbot/core/utils/session_waiter.py:35


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

Comment thread astrbot/core/utils/session_waiter.py Resolved

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

Approved.

@zouyonghe
zouyonghe merged commit e3d8e53 into AstrBotDevs:master Nov 24, 2026
8 checks passed
Sakura520222 pushed a commit to Sakura520222/PyaBot that referenced this pull request Nov 24, 2026
* fix: wake session waiter timeout task on stop

- Signal the active timeout wait when a session ends early.
- Add a regression test and changelog entry.

* fix: ignore keep on stopped sessions

---------

Co-authored-by: 邹永赫 <1259085392@qq.com>
(cherry picked from commit e3d8e53)
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