#3958·chatbox

[BUG] Work mode: run_command never returns when the command leaves a long-running child process; Stop and Retry are dead until the app is restarted

Author: smgcdCreated Sep 28, 2026Updated Sep 29, 2026

Environment

  • Chatbox Desktop 1.23.5 (Windows installer), Windows 11 x64
  • Session type: Work / Agent mode, run_command enabled, Full Access (no per-command approval)
  • Long sessions with many commands; hit this repeatedly (20+ times) in one evening
  • File paths below are from the sourcemaps shipped inside resources/app.asar of 1.23.5, so line references may shift slightly, but the behaviour is easy to verify

Summary

When a run_command tool call starts a process that outlives the wrapper shell (a proxy core, a dev server, a watcher, a tunnel — anything daemon-like), the tool call never returns:

  • the UI keeps showing the command as still running (for 10+ minutes),
  • clicking Stop does not help,
  • Retry / "retry from the last step" does nothing at all except a ~2.5 s toast Wait for the current replies to finish, and the composer stays blocked,
  • only quitting and restarting Chatbox recovers the session — after which the very same command finishes in seconds (the work had already been done in the background).

Steps to reproduce

  1. Open a Work mode session with Full Access so commands run without approval.
  2. Let the agent run a command that launches a long-running child and then exits, e.g.
powershell
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "$env:SystemRoot\System32\ping.exe"   # stand-in for any daemon
$psi.Arguments = '-t 127.0.0.1'
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
[System.Diagnostics.Process]::Start($psi) | Out-Null
'started'
  1. The wrapper PowerShell exits immediately, but the tool call stays running forever.
  2. Click Stop → the tool call still never returns.
  3. Click Retry / retry from the last step → nothing happens (only the toast above).
  4. Restart the app → retry works immediately.

Evidence from %APPDATA%\\\xyz.chatboxapp.app\logs\main.log

  • 1242 [skills:user-exec] agent_operation start entries, of which 20 have no matching finish — even though timeoutMs=118000 expired hours ago and the timeout path is supposed to produce a finish log. All 20 are commands that launch long-lived processes.
  • Orphans from stopped sessions were still alive hours later (measured: 3 headless Chrome instances, 1 sandbox script, 1 proxy core — all with dead parent PIDs). Those are exactly the processes holding the stdio pipes open.

Root cause (from reading the shipped sources)

  1. src/main/skills/user-exec-runner.ts resolves the exec promise only in child.on('close'). Node emits close only after all stdio streams are closed, and a leaked grandchild that inherited the stdio handles keeps them open → close never fires. child.on('exit') (which does fire as soon as PowerShell exits) is not used to settle the call.
  2. The timeout/cancel path calls killProcessTree(child) → taskkill /PID <pid> /T /F. By the time it runs, the wrapper PowerShell has already exited, so taskkill matches nothing and the orphan survives → the pipes stay open forever. SIGKILL cannot help either.
  3. The renderer awaits that IPC promise (src/renderer/.../packages/tools/run-command.ts: await skillsController.userExec(...)). The abort signal only fires cancelUserExec; it never abandons the await. So the agent loop never leaves the tool call.
  4. The session lock therefore stays engaged: getSessionActionGate('regenerate', locks) (packages/chatbox-core/src/session/action-gates.ts) blocks while generatingReplyCount > 0, which requires an active generation runtime. Stop leaves the runtime in stopping (it is only cleared once the stop pipeline finishes), so retry stays blocked. Restarting the app empties the runtime registry and unblocks it. User-visible feedback is a single 2.5 s toast (notifySessionLockBlocked), which reads as "the button does nothing".

Measured: which spawn patterns leak the handle

Same 7-second child process, launched from a parent that owns pipes (exactly like the tool runner). The metric is the delay between the wrapper's exit and close:

launch technique close delay verdict
.NET ProcessStartInfo, UseShellExecute=$false, no redirect +7.10 s (= child lifetime) leaks
Start-Process -RedirectStandardOutput/-Error -WindowStyle Hidden +7.08 s leaks — redirecting stdout/stderr of the child is not enough, the child still inherits the caller's other handles
Start-Process -WindowStyle Hidden (ShellExecute path) +0.00 s safe
Invoke-CimMethod Win32_Process Create +0.00 s safe

Chatbox-side confirmation of row 2: a command spawning ping -n 20 logged durationMs=19453, i.e. the tool call returned only when the leaked child exited.

Suggested fixes

  1. Settle the tool call on exit/error as well (optionally with a short drain grace period), and resolve a cancellation immediately with cancelled: true instead of waiting for stdio to drain. close is not a reliable "the command has finished" signal when the command spawns daemons.
  2. Make Stop actually terminal: record the descendants at spawn time, or run the child in a Windows Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, so daemons that have left the process tree can still be killed. taskkill /T on an already-exited PID is a silent no-op today.
  3. Consider spawning tools with handle inheritance disabled, so a daemon started by a command cannot hold the tool's pipes at all.
  4. On Stop, clear the generation runtime unconditionally (including the stopping phase) so Retry is not gated by a runtime that can never finish, and make a blocked action more visible than a 2.5 s toast.

Impact

Any Work-mode session that uses a daemon-like command (dev server, proxy, tunnel, file watcher — very common) can become permanently stuck: the turn is lost, Stop does nothing, Retry does nothing, and the app must be restarted. In my case this happened 20+ times in a single evening.

Workaround (user side)

  • Launch daemons with Start-Process -WindowStyle Hidden (ShellExecute path) or Invoke-CimMethod Win32_Process Create — not with ProcessStartInfo(UseShellExecute=$false) and not relying on -RedirectStandardOutput (verified above).
  • If a session is already stuck, killing the leaked background process releases the pipes, the hung tool call returns immediately as cancelled, and Retry starts working again without restarting Chatbox.

中文摘要(便于中文用户检索):Work 模式下用 run_command 启动常驻进程(代理内核、本地服务等)后,工具调用会永远不返回——界面一直显示「命令正在运行」,点「停止」无效,「重试 / 从最后一步重试」只弹一个 2.5 秒的提示「等待当前回复结束」,只有重启 Chatbox 才能恢复(因为重启清空了内存里的 generation runtime)。根因:主进程只在子进程 stdio 全关闭(close 事件)时才返回结果,而常驻孙进程继承了工具的管道句柄,close 永远不来;超时/取消用的 taskkill /PID … /T /F 又因为父 powershell 已经退出而失效,杀不掉孤儿进程。规避:用 Start-Process -WindowStyle Hidden(走 ShellExecute 路径)或 WMI Win32_Process Create 启动常驻进程;单纯重定向 stdout 无效(已实测)。卡住后杀掉那个泄漏进程即可解锁,无需重启。