Skip to content

fix(tui): release agent workers on close - #735

Merged
lsdefine merged 1 commit into
lsdefine:mainfrom
nianyucatfish:fix/tui-agent-worker-cleanup
Aug 6, 2026
Merged

fix(tui): release agent workers on close#735
lsdefine merged 1 commit into
lsdefine:mainfrom
nianyucatfish:fix/tui-agent-worker-cleanup

Conversation

@nianyucatfish

@nianyucatfish nianyucatfish commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

背景

本 PR 基于 @JeanStory#734 中发现并说明的 TUI session 关闭后 Agent worker 线程泄露问题。

GenericAgent.run() 在空闲时阻塞于 task_queue.get();仅从前端 session 列表移除对象不会唤醒该 worker。abort() 只能中止正在运行的任务,也不能让空闲 worker 从队列等待中返回。

修改

  • tuiapp.py/close 在移除 session 前中止任务、发送现有字符串退出信号并等待 worker 退出。
  • tuiapp_v2.py/close 与 Ctrl+D 复用相同的 worker 清理路径;停止并 join 后释放日志锁、清理空 task directory,再移除 session。
  • tui_v3.py:v3 为单 AgentBridge 架构而非多 session;在整体 TUI 退出的 finally 中统一停止并 join 唯一的 Agent runner,同时释放其日志锁。

不修改 agentmain.py:其现有 run() 循环已将字符串任务作为退出 sentinel 处理。

验证

  • python -m py_compile frontends/tuiapp.py frontends/tuiapp_v2.py frontends/tui_v3.py
  • git diff --check
  • 手动 v2 线程测试:
    • 5 个 session:29 threads;关闭至 1 个 session:25 threads。
    • 7 个 session:33 threads;关闭至 1 个 session:25 threads。
    • 重复 Ctrl+N / Ctrl+D 后线程数从 26 回落到 25。
    • 退出整个 TUI 后,tuiapp_v2.pyga_cli tui2 相关进程均已退出。

@lsdefine
lsdefine merged commit 2757bdd into lsdefine:main Aug 6, 2026
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