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
- Add a project script with
runOnSettle: true, command:touch /tmp/t3-settle-marker-$(date +%s) - Worktree thread A: let it finish, settle it -> marker appears (control)
- Worktree thread B: remove its worktree (let Storage Cleanup do it, or
git worktree remove), then settle it -> no marker, nothing logged - Worktree thread C: open + merge a PR from it and let Storage Cleanup remove the worktree (
worktreeOnMerge/ "settled for N days") -> the settle script never runs for that worktree
Real-world version: a settle script that tears down per-worktree Docker stacks. Over ~5 days, 18 threads on 7 worktrees were explicitly settled (settledOverride: "settled", all after the script was configured). All 7 worktrees were later removed by T3, and all 7 Docker stacks leaked.
Expected behavior
- A worktree's settle script runs before T3 removes that worktree, on every removal path (Storage Cleanup: merged, age-based, unchanged, thread delete). Or removal waits for the script to finish.
- If a settle script can't run because the worktree folder is missing, log a warning and/or show it in the UI instead of returning silently.
- (Ideally) settle-script runs and failures are visible somewhere, so users can confirm their teardown ran.
Actual behavior
ThreadSettlementServiceV2.cleanUpSettledThread returns early, with no log, when the worktree doesn't exist:
const worktreePath = settled.worktreePath;
if (worktreePath === null || !(yield* fileSystem.exists(worktreePath))) return;Storage Cleanup (apps/server/src/storageCleanup.ts) removes worktrees with git worktree remove (removeLinkedWorktree) and never calls ProjectSetupScriptRunner.runForThread. So any worktree it removes skips the settle script, and any settle after that hits the silent return above.
Evidence:
- No
settle-*terminal history exists in~/.t3/userdata/logs/terminals, which goes back months.runForThreadopenssettle-<scriptId>-<8hex>terminals. None of the threads was deleted or archived. - One stack was created minutes after one thread on its worktree settled. A second thread on the same worktree settled ~75 min later, and the stack survived.
- Traces (see logs) show one settle exiting at the
existscheck and another reachingrunForThread, ~40 min apart.
Not fully explained: some of these settles happened while the worktree may still have existed, and still no settle terminal was opened. Possibly a removal racing the thread.settled handler, or some settle routes not reaching it. Happy to collect specific spans if you tell me which.
Related: #33096 (closed as completed) asked for a hook before worktree deletion, but I can't find one in 0.1.9 or on main.
Impact
Major degradation or frequent failure
Version or commit
0.1.9 (stable). Code still present on main: ThreadSettlementService.ts:706
Environment
macOS (Apple Silicon), T3 Code desktop 0.1.9, git worktree per thread, default Storage Cleanup settings
Logs or stack traces
# server.trace.ndjson: two settles of worktree threads, ~40 min apart
# A: project has a runOnSettle script; worktree already removed
ThreadSettlementServiceV2.cleanUpSettledThread 0.94ms Success
ProjectionStore.getThread
terminal.closeOnSettle
# <- returns here: no second getThread, no runForThread, no warning
# B: worktree folder still exists
ThreadSettlementServiceV2.cleanUpSettledThread 2.5ms Success
ProjectionStore.getThread
terminal.closeOnSettle
ProjectionStore.getThread
ProjectSetupScriptRunner.runForThread
# processRunner.runProcessCore commands over the whole trace window:
# lsof, git, gh, ps, xcrun, emulator (no shell / package manager for any settle script)Screenshots, recordings, or supporting files
No response
Workaround
Make the teardown self-healing on the project side: on every environment start, prune resources whose worktree no longer appears in git worktree list. Don't rely on the settle hook.
Activity
fix(server): storage cleanup runs the settle script once and never fo…
test(server): settling a thread whose worktree is gone warns
THEtheChad commentedon Nov 23, 2026
Another data point, plus one thing on
main(d1a6c35) that looks relevant.Data point. On a 20 GB WSL2 host, two per-worktree Docker Compose stacks started by agents (7 and 4 containers) kept running for 2–3 days after the work on them ended. They were the most likely cause of memory exhaustion that made the host's WSL stop accepting new connections; we had to
wsl --shutdown. Our case differs from the one above in two ways:runOnSettlescript.So fixing the Storage Cleanup path alone wouldn't have caught it. It does show how much these leaks cost.
Observation.
thread.archivedandthread.deletedonly enqueue a sweep. They never run the settle script (ThreadSettlementService.ts:862-864). Archiving or deleting a thread without settling it looks like a third path where a configuredrunOnSettlescript never runs, alongside the two in this issue.Investigated and written with Claude Opus 5.5 (Claude Code), reviewed by Gemini 4 Neon; reviewed by me before posting.
juliusmarminge commentedon Nov 23, 2026
#40627, now on main: Settling a thread whose worktree is already missing now logs a warning containing the thread ID and missing path when a settle script is configured.
Not done: The issue still asks for settle scripts to run before worktree removal on every cleanup and deletion path, and for visibility into teardown runs and failures; this merge only adds the missing-worktree warning.
Closing; open a new issue if what is left still matters to you.