fix: task 结束时清理残留 pending runtime mode,避免下次工作插入错误通知
场景:模型最后一次输出(无工具调用)后、task 仍 running 时切换权限/执行环境, 进入 queue_*_change 只设置 pending,task 随即结束未进入工具循环, pending 残留到下次工作首次工具调用时才被应用并插入变更通知。 修复:在 handle_task_with_sender 末尾调用 apply_pending_runtime_mode_changes 立即应用并清空 pending,丢弃生成的 notices(等同空闲期切换语义)。
This commit is contained in:
parent
f44c09a7ce
commit
f03446a3bb
@ -1695,6 +1695,25 @@ async def handle_task_with_sender(
|
||||
socketio.start_background_task(run_bg_poll)
|
||||
|
||||
has_running_completion_jobs = has_running_sub_agents or has_running_background_commands
|
||||
|
||||
# 任务结束时清理残留的 pending runtime mode(权限/执行环境/网络权限)。
|
||||
# 场景:用户在模型最后一次输出(无工具调用)后、task 仍为 running 状态时切换了
|
||||
# 权限/执行环境,此时会进入 queue_*_change 路径只设置 pending,但 task 随即自然
|
||||
# 结束,不会进入 execute_tool_calls → apply_pending_runtime_mode_changes。
|
||||
# 若不在此清理,pending 会残留到下一次工作首次工具调用时才被应用,
|
||||
# 并把"变更通知"作为 user 消息注入到新一轮对话中(bug)。
|
||||
# 正确行为:task 结束时立即应用 pending(等同空闲期切换),但不生成通知。
|
||||
try:
|
||||
if hasattr(web_terminal, "apply_pending_runtime_mode_changes"):
|
||||
residual_notices = web_terminal.apply_pending_runtime_mode_changes() or []
|
||||
if residual_notices:
|
||||
debug_log(
|
||||
"[RuntimeMode] task 结束时应用残留 pending runtime mode,丢弃通知: "
|
||||
f"{[n.get('source') if isinstance(n, dict) else n for n in residual_notices]}"
|
||||
)
|
||||
except Exception as exc:
|
||||
debug_log(f"[RuntimeMode] task 结束时清理 pending runtime mode 失败: {exc}")
|
||||
|
||||
pending_runtime_guidance_messages: List[str] = []
|
||||
try:
|
||||
from .tasks import task_manager
|
||||
|
||||
Loading…
Reference in New Issue
Block a user