Repository navigation
Description
Summary
When the command wrapped by rtk proxy (or by the unknown-command fallback) spawns any background/daemon process, rtk keeps running after the wrapped command has already exited. All output is printed, the direct child is gone, but rtk never returns, so the calling shell (or the coding agent driving it through the hook) waits indefinitely. Killed instances accumulate as zombie rtk processes; after one evening of agent sessions I found 27 of them alive on a single machine.
This is the same mechanism as #2320 (reported for rtk dotnet on Linux), but it is not specific to dotnet or Linux: it lives in the generic proxy path in src/main.rs and reproduces deterministically on Windows.
Environment
- rtk 0.43.0 (winget,
rtk-x86_64-pc-windows-msvc) - Windows 11 Pro 10.0.26200
- The mechanism is platform-independent (fd/handle inheritance) — a unix repro is included below.
Deterministic reproduction
Windows (PowerShell):
PS> Measure-Command { rtk proxy cmd /c "start /b waitfor ZZZ /t 20 & exit /b 0" }
# rtk returns only after ~20.2s — exactly when the background waitfor dies.
PS> Measure-Command { cmd /c "start /b waitfor ZZZ /t 20 & exit /b 0" }
# ~0.1s without rtk. cmd.exe exits immediately in both cases.Linux/macOS equivalent:
$ time rtk proxy sh -c 'echo ready; sleep 20 & exit 0' # ~20s
$ time sh -c 'echo ready; sleep 20 & exit 0' # ~0sReplace the 20-second sleeper with a process that never exits (a build server, a file watcher, a background sync helper) and rtk never returns at all. That is the real-world case: the wrapped command finishes, its output is fully printed, and rtk hangs forever.
Root cause
In the proxy arm of src/main.rs (lines ~2531–2587 on current develop):
- The child is spawned with
Stdio::piped()for stdout and stderr. - Two reader threads pump the pipes until EOF.
- After
child.wait()returns, both threads arejoin()ed unconditionally.
EOF on those pipes does not arrive when the child exits — it arrives when the last handle to the write end closes. Any descendant of the child inherits the write ends (handle inheritance is table-wide on Windows; fds are inherited across fork on unix). A daemon or background job left behind by the child keeps the pipes open, so the join() blocks forever even though the wrapped command finished and its exit status is already known.
The unknown-command fallback with a matching TOML filter (run_fallback → .output() on a piped child) has the same exposure, since output() also drains the pipes to EOF. The stream::run_streaming capture paths share the pattern as well — that is the #2320 variant.
Impact
- Coding-agent setups that route shell commands through rtk (the primary use case) hang on every proxied command that leaves a daemon behind: build servers, watchers, language servers, package-manager helpers.
- Each hang leaks one live
rtkprocess; under concurrent agent workloads they pile up quickly and every one of them looks to the agent like a command that "never finishes".
Suggested fix
Once child.wait() has returned, the command is done and the exit code is known. Join the reader threads with a short grace period (enough to drain anything still buffered in the pipes), then detach any reader still blocked on an orphaned pipe. main() already ends with std::process::exit, which reaps detached threads. I have a PR ready for the proxy path and will link it here.
Activity
pszymkowiak commentedon Jul 5, 2026
🔍 Automated Triage
bughighSummary
Generic
rtk proxy/fallback path blocks forever joining stdout/stderr reader threads when a descendant process inherits and keeps the pipe write-ends open after the direct child exits; fix is to join with a grace period then detach orphaned readers (PR #2830 already open).📁 Relevant files
src/main.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
isacgalvao commentedon Jul 5, 2026
Fix: #2830
fix: warn execute-handoff executors against rtk-style proxies hanging…
whoisthiagosantana commentedon Aug 10, 2026
Confirming this on Linux with rtk 0.44.0, and adding one piece of information that I think raises the priority: LLM-agent hooks turn this from a niche bug into a per-command one.
Repro (Linux, rtk 0.44.0)
Your unix repro reproduces exactly as written:
rtkreturns exactly when the backgrounded process dies, not when the direct child exits — so with a daemon, watcher or dev server in place ofsleep, it does not return at all.Also worth noting for anyone landing here: v0.45.0 (2026-08-07) does not contain the fix. PR #2830 is still open against
develop.Why this is worse than it looks: the hook amplification
The documented way to get a command tracked without filtering it is
rtk proxy. That makes it the natural building block for a PreToolUse hook that wants full measurement coverage — commands with no dedicated filter are otherwise recorded withinput_tokens=0 / output_tokens=0, which is a meaningful share ofhistory.db(23.5% of rows on my machine).So the obvious hook is: ask
rtk hook claudefor a rewrite, and when there is none, wrap the command inrtk proxy bash -c '<original>'.That works, and it is what I deployed. But it means every unfiltered command the agent runs now goes through the proxy path — so the exposure is no longer "users who wrap dotnet or a build server", it is "any agent command that happens to leave a background process holding stdout/stderr". The failure mode is also unusually expensive in an agent context: the tool call blocks, the model waits, and nothing in the output indicates that
rtkis the reason. It looks like the command hung.Workaround, for whoever needs it before #2830 lands
In the hook, refuse to wrap when the command can leave something in the background — a
&that is not&&and not part of>&, ornohup/setsid/disown/screen/tmux:Measured over 33,290 agent Bash commands, this drops 1.25% of the otherwise-wrapped commands back to unmeasured. That trade is very asymmetric and worth taking as-is: a false positive costs one unmeasured command, a false negative hangs the session.
It is a heuristic, not a fix — a command that daemonizes without any of those tokens still hits the bug. The fix is #2830.
Is there anything blocking that PR? Happy to test a build on Linux if that helps.
AnshulJ999 commentedon Sep 9, 2026
OpenCode agents hang permanently on this - adding the OpenCode data point to the same mechanism.
deliberately-left-alive background process pinned the combination:
rtk wrapping the command (unknown-command fallback path, same as
rtk proxy)Remove any one and it completes. With all three, the agent hangs indefinitely -
OpenCode resolves tool completion on the stdio
closeevent rather than processexit, and OpenCode's 2-minute tool timeout does not settle the tool part, so real
sessions stalled 18-390 minutes before we isolated it with a test matrix.
Since OpenCode's shell-tool side is now fixed on their v2 branch
(anomalyco/opencode#46085), rtk is the remaining half for the 1.x ecosystem.
PR #2830 (grace period + detach after child exit) addresses exactly this and has
been open since July - would a review be possible? Happy to test the branch.