Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions astrbot/core/utils/session_waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self) -> None:

def stop(self, error: Exception | None = None) -> None:
"""立即结束这个会话"""
if self.current_event and not self.current_event.is_set():
self.current_event.set()
Comment thread
zouyonghe marked this conversation as resolved.
Resolved
if not self.future.done():
if error:
self.future.set_exception(error)
Expand All @@ -46,6 +48,9 @@ def keep(self, timeout: float = 0, reset_timeout=False) -> None:
当 reset_timeout 设置为 False 时, 代表继续维持原来的超时时间, 新 timeout = 原来剩余的timeout + timeout (可以 < 0)
"""
if self.future.done():
return

new_ts = time.time()

if reset_timeout:
Expand Down
2 changes: 2 additions & 0 deletions changelogs/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- QQ Official: failed image uploads no longer log base64 payloads, avoiding dashboard freezes from oversized log entries. Retry attempts decrease from five to three, with one summary warning.

- Session waiters now wake their timeout task immediately when completed early, avoiding stale asyncio tasks for the remainder of the configured timeout.

- 「插件 → 管理行为 → 函数工具」现在只列出插件工具。Agent 运行时工具由配置文件的 AI 功能设置控制,MCP 工具可在「插件 → MCP」查看。
- Extensions → Handlers → Function Tools now lists plugin tools. Configure Agent runtime tools in the profile's AI capability settings and view MCP tools under Extensions → MCP Servers.

Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_session_waiter_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Session waiters are dispatched by the core pipeline after access checks."""

import asyncio
import copy
from types import SimpleNamespace
from unittest.mock import AsyncMock
Expand All @@ -19,11 +20,47 @@
from astrbot.core.utils.session_waiter import (
USER_SESSIONS,
DefaultSessionFilter,
SessionController,
SessionFilter,
SessionWaiter,
)


@pytest.mark.asyncio
async def test_stopping_session_waiter_wakes_timeout_task():
controller = SessionController()
holding_started = asyncio.Event()
holding_finished = asyncio.Event()
original_holding = controller._holding

async def track_holding(event, timeout):
holding_started.set()
try:
await original_holding(event, timeout)
finally:
holding_finished.set()

controller._holding = track_holding
controller.keep(timeout=60, reset_timeout=True)
await holding_started.wait()
controller.stop()

await asyncio.wait_for(holding_finished.wait(), timeout=1)
assert controller.future.done()


@pytest.mark.asyncio
async def test_keep_after_stop_does_not_start_timeout_task():
controller = SessionController()
controller.stop()

try:
controller.keep(timeout=60, reset_timeout=True)
assert controller.current_event is None
finally:
controller.stop()


@pytest.mark.asyncio
@pytest.mark.parametrize(
("private", "state"),
Expand Down
Loading