Repository navigation
Studio: stop tool calls from getting stuck in Running forever - #12234
Conversation
|
Codex review has converged on this PR.
|
NilayYadav
left a comment
There was a problem hiding this comment.
Review + reproduction evidence
Pinned review: 8d7fbc6ef4bbe746b77599fae6dd4877d061db84. No blocking findings, nothing pushed.
I reproduced the stuck tool call on fresh upstream main on Modal (L4, install.sh --local, logged in through the password form, Qwen3-4B-Instruct-2507-GGUF Q4_K_M picked in the model picker, project chat with Code on and Run automatically, 8 tabs each asking for 15 terminal commands one call at a time, Chromium 1400x1000). Same flow, same inputs on main and on main + this PR:
- main (fix reverted run): 27 of 959 terminal calls never returned (log has
execute_tool: name=terminalwith notool result). The composer showedRunning: echo done 401spast the 300s Max Tool Call Duration.py-spyon the Studio children that never exec'd: all 11 left at the end sit in_close_quietly(chat_generation_runs_db.py:126) <-weakref.finalize<-subprocess._execute_child<-spawn_prepared_launch<-_bash_exec. In CI the new test fails with "the forked child hung on a SQLite lock another thread held at the fork" on Linux and macOS. - PR head (run): 1,065 of 1,065 terminal calls returned, 0 stuck turns, 0 stuck children. The new test passes on Linux and macOS; on Windows it is skipped and the other 19 pass on both arms.
- Adjacent flows identical on main and the PR: plain reply, Python tool (
2**100correct), terminalecho, and Stop on a runningsleep 120(card goes to Cancelled in under 1s). - Performance, 7 runs each: warm connect+close 0.82us vs 0.81us, first connect 1072us vs 1010us. Tool launch with 32 pooled threads gets faster:
Popen(preexec_fn)5.2ms vs 2.6ms, because the child no longer closes 32 connections before exec. Nothing on the streaming path changes. - Differential tests: the new test fails on main (1 failed, 19 passed) and passes on the PR (20 passed).
One wording nit on the description: in my runs Stop did end the turn in the UI. What it cannot clear is the stuck launch left in the background. Maybe say "Stop ends the turn but the stuck launch stays behind".
Conclusion: real regression from #11525, fixed at the right place, no regressions found. Ready once upstream CI finishes green and someone other than the author has looked at it.
huggingface_hub closes its shared httpx client in every forked child through an at-fork hook. A tool or sidecar spawned with preexec_fn runs that hook before exec, and it blocks forever on an httpx lock another thread held at the fork, leaving the tool call stuck in Running. A before-fork hook now makes the live client's close a no-op outside the process that owns it, so the child keeps it referenced and execs.
|
Pushed a73163a on top of this branch. It closes the other instance of the same hang, the one the description mentions as the Hugging Face client's cleanup in the forked copy. huggingface_hub registers A deterministic test holds the pool lock in another thread while a |
|
Codex review has converged on this PR.
|
Lyxot
left a comment
There was a problem hiding this comment.
LGTM. Verified both hangs with deterministic repros on macOS and Linux; Codex converged and the remaining CI failures are main-side and already fixed on main.

Since the chat database started reusing connections, a terminal or Python tool call now and then never starts. Its card stays on Running far past Max Tool Call Duration and Stop cannot clear it. It is more likely when several chats are busy at once.
Starting a tool forks Studio, and the copy tried to close database connections owned by other threads. If one of them was mid-query at that moment, the copy waited forever on its lock. Now the copy leaves them alone and the tool starts normally.
With eight busy project chats on main, 29 of about 1,260 terminal calls got stuck this way. On this branch none of 1,306 did. #12087 fixed a different hang (the credential check on commands like
echo "A=$A") and closed the issue, but this one still happens with it merged. Two branch calls still stalled on the Hugging Face client's own cleanup in the forked copy, which is a separate issue.Refs #12048