Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Use zsh as the terminal shell. An empty
.zshrcis enough. - Add a project with a git repo and a project action with Run automatically when a new worktree is created (
"runOnWorktreeCreate": true), for exampleecho setup-finished. - Start 10 threads in new worktrees, one after another. I used
t3 thread start <project> "hello" --worktree main --provider devReplay. - After the setup actions finish, count the setup shells that are still running.
Expected behavior
Each setup action exits 0 and its shell is back at an idle prompt, so the runner closes the setup terminal. #13673 added this: "after the script exits 0, the runner closes its setup shell if it is idle."
Actual behavior
All 10 setup actions exited 0, but 6 of the 10 setup shells stayed open at an idle prompt in their worktrees.
After the completion sentinel, ProjectSetupScriptRunner waits for the prompt (#16290) and then calls closeIdle once. It treats the first partial line as the prompt. zsh 5.7.1 often writes the end of its redraw, \e[?1h\e=\e[?2004h (its line editor turning bracketed paste back on), separately from the prompt text. When that last write lands during closeIdle's process check, the terminal's activity mark changes, and closeIdle keeps the shell as if someone were using it. All 6 skips in my runs were this case: no running subprocess, and a mark that changed by 1.
Each affected thread keeps an extra idle shell in its terminal drawer, with the worktree as its working directory. From the code, closeOnSettle runs closeIdle again when the thread settles and should close it then. I have not observed that.
bash 5.1+ likely has the same problem in the other order: bash 5.2.15 writes \e[?2004h before the prompt text, as a separate write in 2 of 3 bare-pty runs.
Related: #44350 / #44351 had the same symptom for settle actions and switched those to close, leaving setup actions on closeIdle. #45605 is a different reason a setup terminal can stay open (pkttyagent on systemd before 250).
Impact
Minor bug or occasional failure
Version or commit
main @ 58a4e59
Environment
Linux, zsh 5.7.1 with an empty .zshrc, isolated dev:server, Replay (dev) agent, no account. Not checked: macOS, fish, Nushell, PowerShell, or prompt themes.
Logs or stack traces
# Temporary logging around closeIdle (not committed). Times are relative to the start of its process check.
# One of the 6 skips:
skip busy=false mark 22 -> 23
-0.3 ms output "…:0\r\n\r\e[0m\e[27m\e[24m\e[J% \e[K"
+0.5 ms output "\e[?1h\e=\e[?2004h"
# One of the 4 closes:
close busy=false mark 31 -> 31
-0.4 ms output "\e[0m\e[27m\e[24m\e[J% \e[K\e[?1h\e=\e[?2004h"Workaround
Close the setup terminal by hand.
Activity