Repository navigation
Description
Summary
workspace::view::tests::test_terminal_model_isnt_leaked asserts that a terminal model's Arc is fully dropped once its tab closes, checked via Weak::upgrade() returning None. It passes in isolation but fails under full-parallel suite load because the local-tty "PTY reader" OS thread holds a strong clone of the model Arc and is not always joined when the tab closes, so a strong reference lingers process-wide. This is the least deterministic of the flake set — it is a thread-lifecycle/join-ordering issue, not a single global to reset — and I am labeling it honestly as such. It currently reports as a failure on contributors' full-suite PR gate runs.
Affected tests
workspace::view::tests::test_terminal_model_isnt_leaked—app/src/workspace/view_tests.rs:1987
Reproduction
Full suite (intermittent — fails under parallel load, most consistently in the full run):
cargo test -p warp --lib
Passes in isolation:
cargo test -p warp --lib -- --exact workspace::view::tests::test_terminal_model_isnt_leaked
# => ok. 1 passed
--test-threads=1 does not reliably fix it: the leaking reference is held by a detached OS thread (a "PTY reader"), not a test task, so serializing test tasks does not guarantee the thread has dropped its Arc by assertion time.
Observed failure:
thread 'workspace::view::tests::test_terminal_model_isnt_leaked' panicked at app/src/workspace/view_tests.rs:1987:9:
The terminal model should not exist once the tab is closed.
Accompanying log lines seen in the same run (both relevant to the mechanism):
[WARN] warp::terminal::local_tty::terminal_manager: No event loop handle to join when dropping terminal manager.
[WARN] warp::terminal::view: Session abandoned before bootstrap for shell None on ssh false
Root cause
The assertion is a pure Arc::strong_count check via Weak::upgrade() on the specific model Arc — there is no global registry:
// app/src/workspace/view_tests.rs:1974-1990
let model = workspace.get_active_session_terminal_model(ctx); // the exact Arc
let terminal_model = Arc::downgrade(&model);
...
remove_tab(...); // close the tab
...
assert!(terminal_model.upgrade().is_none(), "The terminal model should not exist once the tab is closed.");get_active_session_terminal_model returns the same Arc<FairMutex<TerminalModel>> created at terminal_manager.rs:353. A strong clone of that Arc is moved into the PTY reader OS thread:
// app/src/terminal/local_tty/event_loop.rs:44
struct EventLoop { ... terminal: Arc<FairMutex<TerminalModel>>, ... }
// app/src/terminal/local_tty/event_loop.rs:323
fn spawn(mut self) -> JoinHandle<()> {
thread::Builder::new().name("PTY reader").spawn(move || { ... }) // moves the strong Arc into the thread
}That thread is only joined in the manager's Drop, and only if the join handle was set:
// app/src/terminal/local_tty/terminal_manager.rs:188
impl Drop for TerminalManager { fn drop(&mut self) { self.shutdown_event_loop(); } }
// app/src/terminal/local_tty/terminal_manager.rs:500-519
fn shutdown_event_loop(&mut self) {
// send Message::Shutdown ...
if let Some(join_handle) = self.event_loop_handle.take() {
join_handle.join()...;
} else {
log::warn!("No event loop handle to join when dropping terminal manager.");
}
}Critically, event_loop_handle is assigned only at the end of the async shell-determination callback on_shell_determined (terminal_manager.rs:670-677), which is spawned via ctx.spawn(...) (terminal_manager.rs:448-477). This opens two race windows, both process-global because the PTY thread is detached:
- The manager is dropped before
on_shell_determinedruns ("Session abandoned before bootstrap", view.rs:28372).event_loop_handleis stillNone, soDrophits the else-branch, logs "No event loop handle to join", and never joins — a spawned thread's strongArccan linger. - The manager is dropped after the thread is running, but the
Shutdownsend / join ordering leaves the thread transiently holding the strongArcwhile the test drains effects.
Under full-parallel load, a PTY reader thread from an earlier or concurrent session is still alive holding a TerminalModel Arc, and this test's own model has not been dropped synchronously by the time upgrade() runs — so the leak check sees a live reference. The full-suite path uses the real thread-spawning manager (local_tty feature is on for cargo test -p warp --lib; the mock manager, which spawns no thread, is the #[cfg] else at pane_group/mod.rs:6046), which is why the two log lines above appear.
Honest limitation: I could not reduce this to a single static to reset or a fully deterministic minimal reproduction the way the other clusters allow. The evidence points clearly at the detached PTY reader thread's strong Arc outliving tab close via the un-joined / late-join path, but the exact interleaving that leaves the reference live at assertion time is load-dependent. This ticket is filed on the reproduction evidence and the mechanism, labeled undiagnosed at the interleaving level.
Fix direction
- Ensure the PTY reader thread is deterministically joined (or its strong
Arcdropped) before the tab-close path returns — close the window whereevent_loop_handleisNonebecauseon_shell_determinedhas not yet run, so teardown either cancels the pending spawn or waits for the handle. - Failing a full production fix, make the test robust to the thread's asynchronous teardown: after
remove_tab, drive effects / wait with a bounded poll for theWeakto become unupgradable rather than asserting immediately, so a correctly-shutting-down thread is not misreported as a leak.
Related
Related: #13853 (warp_editor render::tests Once-poisoning — same class, different crate) and the sibling flake tickets filed alongside this one: #13972, #13973, #13974
Activity
warp-for-oss commentedon Jul 19, 2026
@fbartho
Here's what I found while triaging this issue:
This appears to be a real intermittent full-suite test flake in terminal/tab teardown. The current code supports the concern that terminal shutdown may still be holding the model when the test asserts immediate deallocation, but the exact failing interleaving remains load-dependent.
Maintainer details
I concluded that intermittent full-suite failure in the terminal model leak test appears tied to local TTY event-loop teardown after tab close..
Triage summary
This looks like a real intermittent test flake in terminal/tab teardown rather than a user-facing billing/support issue. The report's specific mechanism is mostly supported by the current code: the leak test expects the active terminal model to be dropped immediately after tab removal, but local TTY sessions can have a PTY reader thread that still owns a strong reference to the same terminal model while shutdown is being coordinated.
Reproducibility
Medium. The issue includes a concrete full-suite command, exact failing test and panic text, and notes that the same test passes in isolation. Because the failure is reported as load-dependent and I did not confirm a deterministic local failure, this should not be treated as high reproducibility yet.
Likely root cause
The current code supports a lifecycle race around local terminal teardown.
test_terminal_model_isnt_leakedrecords aWeakreference to the active terminal model, removes the tab, drains one app update, then asserts that the weak reference can no longer be upgraded. Local TTY session creation stores the terminal model inTerminalManager, passes the same model into the terminal surface, and later starts a separate PTY event-loop thread that owns a strongArc<FairMutex<TerminalModel>>.The event-loop thread handle is initially
NoneonTerminalManagerand is assigned only after the async shell-determination callback creates the PTY and starts the event loop.TerminalManager::dropsends shutdown and joins only when that handle is present; otherwise it logs that there is no event-loop handle to join. This makes the reporter's proposed race plausible: tab close can reach terminal teardown before the callback has recorded a join handle, or while the PTY reader thread still transiently owns the model.Relevant files checked:
app/src/workspace/view_tests.rsapp/src/workspace/view.rsapp/src/pane_group/mod.rsapp/src/terminal/local_tty/terminal_manager.rsapp/src/terminal/local_tty/event_loop.rsapp/src/terminal/view.rsDuplicate check
I scanned all open non-PR issues in
warpdotdev/warpand also checked recently closed issues from the last seven days. No existing issue matched this specific test name, assertion, terminal-model leak, or PTY reader lifecycle warning closely enough to mark this as a duplicate. Nearby open issues such as sibling full-suite flakes describe different process-global state/cache causes.This is my automated analysis and may be incorrect. A maintainer will verify the details.
Powered by Oz
fbartho commentedon Jul 21, 2026
I dug into this locally and the reported mechanism doesn't hold up. Instrumenting the full-suite failure shows the leaked TerminalModel is retained with a strong-count of 3 and never spawns a PTY reader thread — across an entire suite run only two reader threads are ever created, and both are joined cleanly, so the "detached PTY reader thread holds the Arc / no event-loop handle to join" path is not what's leaking here.
The real cause is a model-retention leak on the product side. After the tab closes, the terminal model's direct owners (the terminal manager, view, input, and PTY controller) all drop and release their references, yet three strong refs survive permanently. Clearing the test executor's pending task callbacks and spawned futures does not release the model, so this isn't a test-harness artifact — the refs live in the app subscription registry: a subscription closure captures the terminal model (directly or via a handle to a model that holds it) and is never torn down on tab close, keeping the largest structure in the app alive.
I haven't yet pinned the exact subscription — the retaining closure captures the model indirectly, so per-holder Drop tracing didn't surface it. I'm attaching a structured evidence dump below so someone with deeper subscription-lifecycle knowledge can finish the naming. The load-dependence is just what makes the racing teardown ordering reproduce; nextest's process isolation masks it, plain
cargo test -p warp --libunder load reproduces it reliably.Instrumentation evidence
Repro: plain
cargo test -p warp --lib(full suite) failsworkspace::view::tests::test_terminal_model_isnt_leakedwith "The terminal model should not exist once the tab is closed." Reproduced on 6/6 full-suite runs; passes in isolation and undercargo nextest(process-per-test isolation masks it).Leak signature: at the assertion,
Arc::strong_count == 3, unchanged after 100ms of additional polling — a permanent leak, not a transient shutdown race.Disproving the PTY-reader-thread mechanism (instrumented spawn/drop of every TerminalManager, correlated by the leaked model's Arc pointer): suite-wide, only two reader threads are ever spawned; both managers drop with the join handle present and join cleanly. The leaking test's managers all drop with no reader thread ever spawned for the leaked model. The "No event loop handle to join" branch fires for ~257/258 managers suite-wide and is benign.
Direct owners confirmed to drop for the leaked model (pointer-correlated Drop tags): PtyController, TerminalView, Input. Also excluded (don't hold the Arc per source, or gated off in tests): Sessions, ModelEventDispatcher, ChannelEventListener, throughput recorder.
Holder registry (collision-free: register on Arc-clone into a holder, deregister on Drop, dump live holders for the leaked pointer at assert time — immune to pointer-address recycling across test instances). 13 sites instrumented, every run dumped
live_holders=[]:wire_up_pty_controller_with_surface'ssubscribe_to_view+subscribe_to_model(terminal_manager_util.rs:40/130— both capture the model strongly);terminal_view_adaptor's input-mode and session-sharer closures.Registry probe at leak time:
models=841 windows=1 subscriptions=3018 observations=96 task_callbacks=75 spawned_futures=33. After clearingtask_callbacks+spawned_futures(both → 0): still leaked → the retention lives inapp.subscriptions, and the capture is indirect (not any directly-instrumentedmodel.clone()).Suggested next step: enumerate
app.subscriptionsentries whose closure transitively holds the leaked model (framework-side subscription introspection), or bisect by clearing subscription groups. Likely fix shape: capture the model weakly (downgrade + lazy upgrade) in whichever subscription retains it, matching the documented weak-handle convention already interminal_manager_util.rs.