Skip to content

terminal::view: 5 tests fail in full-suite runs due to leaked global FeatureFlag state (AgentView never reset) #13972

Open

Description

@fbartho

Summary

Five terminal::view::tests pass in isolation but fail whenever the module (or the full warp lib suite) runs, because other tests in view_tests.rs flip the process-global FeatureFlag state via FeatureFlag::AgentView.set_enabled(true) and never reset it. The five failing tests do no flag setup and implicitly rely on AgentView defaulting to false; once an earlier test leaves the global true, they take the wrong code branches and their assertions fail. These currently report as failures on every contributor's full-suite PR gate.

Affected tests

All in app/src/terminal/view_tests.rs:

  • terminal::view::tests::test_insert
  • terminal::view::tests::test_insert_into_input
  • terminal::view::tests::test_viewport_iter_most_recent_at_bottom
  • terminal::view::tests::test_reinput_blocks
  • terminal::view::tests::test_scroll_position_doesnt_change_when_block_finished

Reproduction

Full suite (fails; the 5 appear among 12-14 failures depending on run):

cargo test -p warp --lib

The 5 tests pass when run together with no flag-setting test in the set:

cargo test -p warp --lib -- --exact \
  terminal::view::tests::test_insert \
  terminal::view::tests::test_insert_into_input \
  terminal::view::tests::test_viewport_iter_most_recent_at_bottom \
  terminal::view::tests::test_reinput_blocks \
  terminal::view::tests::test_scroll_position_doesnt_change_when_block_finished
# => test result: ok. 5 passed

Minimal deterministic reproduction — run a flag-setting test first, single-threaded, and the clean tests fail every time:

cargo test -p warp --lib -- --test-threads=1 --exact \
  terminal::view::tests::agent_view_lifecycle_updates_input_mode \
  terminal::view::tests::test_insert \
  terminal::view::tests::test_viewport_iter_most_recent_at_bottom \
  terminal::view::tests::test_scroll_position_doesnt_change_when_block_finished
# => test_insert FAILED, test_viewport_iter_most_recent_at_bottom FAILED,
#    test_scroll_position_doesnt_change_when_block_finished FAILED

--test-threads=1 does not help: this is process-global state carried forward across sequential tests, not a data race.

Observed assertion failures in the full run:

  • test_insert (view_tests.rs:2698): left: "One", right: "None" — a block selection that should have been cleared is retained.
  • test_insert_into_input (view_tests.rs:2824): Expected no selections in the blocklist but got Some(...).
  • test_viewport_iter_most_recent_at_bottom (view_tests.rs:3220): item 3 — a trailing zero-height viewport entry is missing.
  • test_reinput_blocks (view_tests.rs:4072): left: "pwd", right: "sudo pwd".
  • test_scroll_position_doesnt_change_when_block_finished (view_tests.rs:5310): ScrollTop(...) vs FollowsBottomOfMostRecentBlock.

Root cause

Feature-flag enabled-state is stored in a process-global array:

// crates/warp_features/src/lib.rs:918
static FLAG_STATES: [AtomicBool; cardinality::<FeatureFlag>()] =
    [const { AtomicBool::new(false) }; { cardinality::<FeatureFlag>() }];

set_enabled writes into it globally with no teardown, and its own guard documents that this is the wrong thing to do in a test:

// crates/warp_features/src/lib.rs:1038
pub fn set_enabled(self, enabled: bool) {
    if cfg!(test) && cfg!(not(feature = "integration_tests")) {
        panic!(
            "Tried to globally enable {self:?} in a test. Use FeatureFlag::{self:?}.override_enabled instead"
        );
    }
    FLAG_STATES[self as usize].store(enabled, Ordering::Relaxed);
}

view_tests.rs contains 22 set_enabled(true) calls (e.g. AgentView at lines 148, 737, 1476, 1535, 5141, 5322, 5383, 5443, 5506, 5562, 5608, 5690, 5817, 5865, 5923, 7439, 7485, 7565, 7877, 7944; CloudMode at 1477, 1536). None of them reset the flag afterward. Because these tests run under the integration_tests feature, the guard's panic is bypassed and the global write silently persists for the rest of the process.

The five failing tests read the flag and branch on it. With AgentView leaked true:

  • app/src/terminal/view.rs:19985 and :20028 guard clear_selected_blocks() with && !FeatureFlag::AgentView.is_enabled(). Leaked-on means the block selection is not cleared when typing in shell mode, so test_insert sees "One" selection instead of "None", and test_insert_into_input sees a leftover Some(...) selection.
  • app/src/terminal/block_list_viewport.rs:2040: if !FeatureFlag::AgentView.is_enabled() || block_height.as_f64() > 0. { return next; }. Leaked-on skips the trailing zero-height entry, so test_viewport_iter_most_recent_at_bottom panics on the missing item 3 and test_scroll_position_doesnt_change_when_block_finished computes a different content height / most-recent-block and resolves the scroll position differently.
  • test_reinput_blocks goes through reinput_commands → with_non_hidden_selected_blocks (view.rs:20954), whose filter uses the AgentView-dependent transcript_scope; the same non-clearing-and-scope divergence drops the sudo variant so the input box retains "pwd".

That the same file already defensively uses AgentView.override_enabled(false) in places (view_tests.rs:439, 798) is direct evidence the leak is known.

Fix direction

Replace the 22 global set_enabled(true) calls in view_tests.rs with the RAII thread-local override the module already uses in a couple of spots:

let _guard = FeatureFlag::AgentView.override_enabled(true); // reverts on drop

override_enabled (crates/warp_features/src/lib.rs:1067) writes a thread-local FLAG_OVERRIDES and returns an OverrideGuard (lib.rs:1192) that clears the override on drop, so no global write leaks across tests. This restores isolation without a per-test reset dance and matches the pattern the guard's own panic message prescribes.

Related

Related: #13853 (warp_editor render::tests Once-poisoning — same class, different crate) and the sibling flake tickets filed alongside this one: #13973, #13974, #13975

Activity

  1. warp-for-oss commented on Jul 19, 2026

    @warp-for-oss
    Contributor

    @fbartho

    Here's what I found while triaging this issue:

    This looks actionable from the provided reproduction and current code: the failing tests are consistent with global feature-flag state leaking between tests. No reporter follow-up appears necessary for initial triage.

    Maintainer details

    I concluded that full-suite terminal::view test failures appear to be caused by process-global AgentView feature-flag state leaking between tests..

    Triage summary

    This is an actionable test-isolation bug in the terminal view area. The report separates the observed failures from the proposed root cause, and code inspection supports the proposed cause.

    Evidence

    • crates/warp_features/src/lib.rs stores feature flag enabled state in the process-global FLAG_STATES array and FeatureFlag::set_enabled writes to it globally. The same file provides FeatureFlag::override_enabled, a scoped test override that is cleared when its guard is dropped.
    • app/src/terminal/view_tests.rs still contains many FeatureFlag::AgentView.set_enabled(true) calls, including early tests such as agent_view_lifecycle_updates_input_mode, and also has existing scoped AgentView.override_enabled(...) usage elsewhere.
    • The affected tests (test_insert, test_insert_into_input, test_viewport_iter_most_recent_at_bottom, test_reinput_blocks, and test_scroll_position_doesnt_change_when_block_finished) do not set up AgentView themselves and assert behavior that changes when AgentView is left enabled.
    • app/src/terminal/view.rs guards selection clearing with !FeatureFlag::AgentView.is_enabled(), and app/src/terminal/block_list_viewport.rs skips returning zero-height items when AgentView is enabled. Those branches line up with the reported assertion failures.

    Likely fix direction

    Replace the global set_enabled(true) calls in these tests with scoped FeatureFlag::AgentView.override_enabled(true) guards, or otherwise ensure the global flag state is restored after each test. The scoped override is the safer fit because the feature-flag crate documents it as the intended test API.

    Duplicate check

    I enumerated all open repository issues and also checked recently closed issues. Related sibling full-suite flake reports (#13973, #13974, #13975) cover different global-state or lifecycle failures, so this issue should not be marked as a duplicate.

    This is my automated analysis and may be incorrect. A maintainer will verify the details.

    Powered by Oz

  2. added
    area:agent
    area:shell-terminal
    bug
    repro:high
    triaged
    on Jul 19, 2026
  3. vorporeal commented on Jul 20, 2026

    @vorporeal
    Contributor

    hey @fbartho - we tend to use cargo nextest to run tests, which isolates tests into separate processes, which is why we haven't noticed this (and it doesn't affect our CI or ./script/presubmit).

    i notice you've opened a bunch of issues about this. is using cargo nextest an acceptable solution (instead of trying to patch all of these), or are you intending to open PRs with fixes?

  4. fbartho commented on Jul 20, 2026

    @fbartho
    ContributorAuthor

    Hey @vorporeal — I’ve largely been opening tickets that I’m willing to fix! (I’ve been using Claude as I work on other features, and I have an allergy to flaky tests. Claude loves to say “pre-existing issue” with no evidence, so any failing tests I look at super suspiciously)

    That said, what’s the policy of this project? In the case of feature flags, it’s unclear if this is likely to cause a correctness issue. I’m fine closing this ticket if you don’t judge it likely & I’ll just change my procedures.

  5. fbartho commented on Jul 21, 2026

    @fbartho
    ContributorAuthor

    I proactively attempted an implementation based on the ticket as it's currently written: #14039.

    If the ticket changes, I'm happy to update the PR to match a maintainer's guidance, just let me know!

  6. fbartho commented on Jul 28, 2026

    @fbartho
    ContributorAuthor

    Just nudging @oss-maintainers that this is still a real flake, and that I have a proposed fix here: #14039

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:agentarea:shell-terminalbugrepro:hightriagedwarp:auto-triage-review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions