Skip to content

terminal secrets: redaction tests race on the shared process-global SECRETS_REGEX, failing nondeterministically in parallel runs #13973

Open

Description

@fbartho

Summary

The secret-redaction tests each install their own regex set into a single process-global SECRETS_REGEX and then assert on the resulting detections. Run in parallel (or sequentially without teardown), one test overwrites another's regexes before its assertion runs, so the loser detects zero secrets instead of one and panics with left: 0, right: 1. Which member fails rotates run-to-run — the classic parallel-isolation signature — and all members pass in isolation. These currently report as failures on every contributor's full-suite PR gate.

Affected tests

Primary (app/src/terminal/model/grid/secrets_tests.rs):

  • terminal::model::grid::grid_handler::secrets::tests::test_secret_redacted_after_byte_processing (:34)
  • terminal::model::grid::grid_handler::secrets::tests::test_secret_redacted_after_multiple_byte_processing
  • terminal::model::grid::grid_handler::secrets::tests::test_secret_redaction_secret_remains_after_resize (:249)
  • terminal::model::grid::grid_handler::secrets::tests::test_secret_redaction_unobfuscated_secret_remains_after_byte_processing
  • terminal::model::grid::grid_handler::secrets::tests::test_bytes_processed_for_secrets_after_turning_redaction and the _on / _off_then_on / _on_then_off variants (:270, :301, :327, :362)

Secondary consumer of the same global, observed failing under full-suite load:

  • ai::blocklist::block::secret_redaction::tests::test_detect_secrets_no_regexes_configured

Other modules that also write the same global (relevant to serialization scope): app/src/ai/blocklist/block/secret_redaction_tests.rs, app/src/ai/blocklist/action_model/execute/grep_tests.rs, app/src/server/telemetry/secret_redaction.rs.

Reproduction

Full suite — the secrets member(s) that fail vary between runs:

cargo test -p warp --lib
# run A: fails test_secret_redaction_secret_remains_after_resize
# run B: fails test_secret_redacted_after_byte_processing (+ ai::blocklist ... test_detect_secrets_no_regexes_configured)
# run C: no secrets failures

The module self-pollutes even alone (5 pass / 5 fail):

cargo test -p warp --lib terminal::model::grid::grid_handler::secrets
# => test result: FAILED. 5 passed; 5 failed

Every named test passes in isolation:

cargo test -p warp --lib -- --exact terminal::model::grid::grid_handler::secrets::tests::test_secret_redacted_after_byte_processing
# => ok. 1 passed

--test-threads=1 does not fully fix it — the tests still share the same global with no teardown, so ordering alone can still overwrite regexes between sequential tests.

Observed panic (identical across members):

thread '…::test_secret_redacted_after_byte_processing' panicked at app/src/terminal/model/grid/secrets_tests.rs:50:5:
assertion `left == right` failed
  left: 0
 right: 1

Root cause

There is exactly one process-global regex registry for secret detection:

// app/src/terminal/model/secrets.rs:54
pub static ref SECRETS_REGEX: Mutex<Arc<SecretsRegex>> = Mutex::new(
    Arc::new(SecretsRegex {
        regex: regex_automata::meta::Regex::new_many(&[] as &[&str])...,
        ...
    })
);

Every test configures its own regexes into this single global via set_user_and_enterprise_secret_regexes (secrets.rs:351), e.g.:

// app/src/terminal/model/grid/secrets_tests.rs:35
crate::terminal::model::secrets::set_user_and_enterprise_secret_regexes(
    [&Regex::new("ABCD").expect("...")],
    std::iter::empty(),
);
...
assert_eq!(grid_handler.secrets.len(), 1);   // :50

The detection path reads the same global:

// app/src/ai/blocklist/block/secret_redaction.rs:26
let secrets_regex: Arc<SecretsRegex> = { SECRETS_REGEX.lock().clone() };

When two secret tests run concurrently (or sequentially without reset), test B's set_user_and_enterprise_secret_regexes(...) replaces test A's regexes — or resets toward a set that doesn't match A's input — before A's assert_eq!(secrets.len(), 1) runs. A then detects 0 secrets → left: 0, right: 1. Because the ordering that decides the loser varies, a different member fails each run, and sometimes none do.

Note on the _turning_redaction* family: those tests additionally call grid_handler.obfuscate_secrets(...) (e.g. secrets_tests.rs:291), but obfuscation mode is per-GridHandler local state, not the shared global. The regex registry is the sole cross-test culprit — the "redaction toggle" in the test name should not be read as implying a redaction-mode global; there isn't one.

Fix direction

Serialize the secret tests into one group and give the global proper per-test scoping:

  • Mark the secret-redaction tests (across grid/secrets_tests.rs, ai/blocklist/block/secret_redaction_tests.rs, ai/blocklist/action_model/execute/grep_tests.rs, server/telemetry/secret_redaction.rs) with a shared #[serial] group so they cannot interleave on the global.
  • Additionally, either save and restore SECRETS_REGEX around each test (snapshot the Arc on entry, restore on drop via an RAII guard) or add a test-scoped override analogous to the feature-flag override_enabled pattern, so serialization is not the only line of defense.

Serialization alone reduces flakiness but leaves the tests coupled through the global; the save/restore (or scoped override) is what actually isolates them.

Related

Related: #13853 (warp_editor render::tests Once-poisoning — same class, different crate) and the sibling flake tickets filed alongside this one: #13972, #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:

    Thanks for the detailed flake report. The current code supports this as an actionable shared test-state bug: multiple tests configure one process-global secret-regex registry and then assert against detection paths that read it.

    Maintainer details

    I concluded that secret-redaction tests appear to race through shared process-global secret regex state, causing nondeterministic failures in full or module-level test runs..

    Initial triage

    This looks like an actionable test-isolation bug in the terminal secret-redaction stack. The report's core symptom is well-supported: multiple tests configure process-global secret regex state and then assert against detection behavior that reads that same global.

    Evidence

    • app/src/terminal/model/secrets.rs defines SECRETS_REGEX as a single process-global Mutex<Arc<SecretsRegex>>.
    • set_user_and_enterprise_secret_regexes replaces that global registry for future readers.
    • app/src/terminal/model/grid/secrets_tests.rs configures different regex sets in individual tests without a per-test restore. Those tests then scan grid contents through code in app/src/terminal/model/grid/secrets.rs, which clones SECRETS_REGEX during scanning.
    • app/src/ai/blocklist/block/secret_redaction.rs also clones SECRETS_REGEX in find_secrets_in_text_with_levels, so AI blocklist tests that expect empty or specific secret patterns can be affected by prior or concurrent tests.
    • app/src/ai/blocklist/action_model/execute/grep_tests.rs also writes the terminal secret regex global.

    Reproducibility

    High. The issue includes concrete cargo commands, affected test names, and an assertion failure, and the shared global state in the current code explains both the nondeterminism and the all-tests-pass-in-isolation behavior. I did not need additional reporter input to classify this.

    Likely fix direction

    Add explicit test isolation for secret-regex global state. A robust fix would provide a test helper/guard that snapshots and restores SECRETS_REGEX around each test that mutates it, and serialize the tests that mutate/read this process-global state so they cannot interleave while the override is active.

    One scope note: the report also mentions app/src/server/telemetry/secret_redaction.rs as a writer of the same global, but current code shows that module uses its own TELEMETRY_SECRETS_REGEX registry rather than SECRETS_REGEX. It may have analogous global-test-state considerations, but it is not evidence for this exact shared SECRETS_REGEX race.

    Duplicate search

    I compared against all open non-PR issues and recently closed issues within the 7-day dedupe window. I found related secret-redaction feature/behavior issues and sibling full-suite flake reports, but no likely duplicate for this specific SECRETS_REGEX test race.

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

    Powered by Oz

  2. added
    area:shell-terminal
    bug
    repro:high
    triaged
    on Jul 19, 2026
  3. fbartho commented on Jul 21, 2026

    @fbartho
    ContributorAuthor

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

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

  4. 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: #14040

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

Metadata

Metadata

Assignees

Labels

area: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