Skip to content

Reset process-global caches across tests; key bootstrap cache on asset provider - #14041

Closed
fbartho wants to merge 8 commits into
warpdotdev:masterfrom
fbartho:fb/13974-global-cache-test-isolation
Closed

fbartho wants to merge 8 commits into
warpdotdev:masterfrom
fbartho:fb/13974-global-cache-test-isolation

Conversation

@fbartho

@fbartho fbartho commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13974

Summary

Three process-global, append-only caches leak state across tests in a shared-process run (plain cargo test -p warp --lib); cargo nextest's per-process isolation masks all three in CI. One of them is a real product bug beyond tests.

  1. EXPERIMENT_LAYER_MAPPINGS (experiments/mod.rs) — populated by experiments::init from shared test helpers, never cleared, so test_create_experiment_layer_mappings sees other tests' experiments.
  2. Telemetry event queue (telemetry) — global 1024-cap queue; prior tests' events make test_persist_events_doesnt_include_ugc_events see more than it recorded.
  3. BOOTSTRAP_CACHE (bootstrap.rs) — keyed only on ShellType, but the AssetProvider argument determines the script contents, so the first provider to populate a shell's entry wins for the life of the process. This is a latent correctness bug, not just test hygiene: harmless in production today only because a single AssetProvider exists there; any process with two providers (already true in tests) silently gets the wrong cached script.

Fixes

  • experiments: clear EXPERIMENT_LAYER_MAPPINGS at test entry + #[serial].
  • telemetry: existing clear_event_queue() at test entry + #[serial].
  • bootstrap (product fix): cache key widened to (ShellType, AssetCacheKey), where AssetCacheKey is declared by the provider: type identity by default (no implementor changes), and AssetCacheKey::for_instance for providers whose contents vary per instance.

Testing

Added regression test (bootstrap product fix)

The bootstrap product fix previously relied on test_trims_whitespace to catch the cross-provider leak, but that test is order-dependent — in a shared-process run it can flaky-pass when no production-asset-provider test happens to populate the Zsh entry first. Added terminal::bootstrap::tests::test_cache_is_keyed_on_asset_provider, which within a single test calls script_for_shell(ShellType::Bash, ...) with two distinct AssetProvider types returning different content and asserts each gets its own script. This is deterministic and order-independent.

Re-verified in this environment (cargo test -p warp --lib, shared-process):

No UI / computer-use proof: this is a headless test-infrastructure and internal-caching change with no user-facing surface.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Changelog

CHANGELOG-BUG-FIX: Fixed a bug where the bootstrap script cache could return the wrong script for a shell if more than one asset provider populated the cache for that shell type in the same process.

Originating thread: #13974

fbartho added 3 commits July 20, 2026 13:14
…cache

EXPERIMENT_LAYER_MAPPINGS is a process-global DashMap populated by
experiments::init, which several test helpers call (including the
shared test_util::terminal). It's never cleared, so this test sees
more than its own two test experiments once other tests have run
first in the same process -- masked by nextest's per-test process
isolation, but real under plain `cargo test`.

Clear the map before asserting, and run #[serial] so a concurrently
running experiments::init can't repopulate it mid-test.

Part of warpdotdev#13974.
… global queue

The telemetry event queue (warpui::telemetry, a 1024-cap
BoundedVecDeque behind a global Mutex) is process-global and
append-only. Any prior test that emits telemetry (e.g.
ExperimentTriggered, itself a symptom of the experiments-layer leak
fixed alongside this commit) leaves events queued, so this test sees
more events than it recorded itself once other tests have run first
in the same process.

Drain the queue via the existing clear_event_queue() helper before
recording this test's events, and run #[serial] so a concurrently
running event emitter can't repopulate it mid-test.

Part of warpdotdev#13974.
script_for_shell memoizes the fully-interpolated bootstrap script in
a process-global MemoMap keyed only on ShellType. The AssetProvider
argument determines the script's actual contents but wasn't part of
the key, so the first caller to populate a given ShellType's cache
entry wins for the rest of the process. Production only ever uses
one AssetProvider (crate::ASSETS), so this was invisible there, but
any other AssetProvider for the same ShellType -- a test fixture,
for instance -- silently receives the first provider's cached script
instead of its own.

Widen the cache key to (ShellType, TypeId), where the TypeId
identifies the concrete AssetProvider implementation. This requires
adding Any as a supertrait of AssetProvider so callers holding a
&dyn AssetProvider can key off .type_id(); Any is blanket-implemented
for all 'static types, so every existing implementor satisfies it
with no changes.

This is a real correctness fix, not just test hygiene: it also
resolves terminal::bootstrap::tests::test_trims_whitespace, which
was masked by nextest's per-test process isolation but fails under
plain `cargo test` once a real-ASSETS Zsh bootstrap has already
populated the cache in the same process.

Part of warpdotdev#13974.
@cla-bot cla-bot Bot added the cla-signed label Jul 20, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jul 20, 2026
@fbartho
fbartho marked this pull request as ready for review July 20, 2026 22:51
@warp-for-oss

warp-for-oss Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@fbartho

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #13974, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

warp-for-oss[bot]
warp-for-oss Bot previously requested changes Jul 20, 2026

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbartho

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #13974, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

@github-actions

Copy link
Copy Markdown
Contributor

Hi @fbartho — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@fbartho

fbartho commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

(Just commenting so stale-bot doesn't think this is dead).

@szgupta
szgupta requested a review from acarl005 July 29, 2026 15:58
…eyed cache

`test_trims_whitespace` only catches the BOOTSTRAP_CACHE cross-provider leak
by test-ordering luck (it can flaky-pass when no production-asset test runs
first). Add `test_cache_is_keyed_on_asset_provider`, which asserts within a
single test that two distinct `AssetProvider` types for the same `ShellType`
each receive their own script. This fails deterministically before the
`(ShellType, TypeId)` cache-key fix and passes after, regardless of ordering.

Co-Authored-By: Warp <[email protected]>
@warp-agent-staging
warp-agent-staging Bot requested a review from szgupta July 29, 2026 18:57
@acarl005

acarl005 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

/oz-review

@warp-for-oss

warp-for-oss Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

@acarl005

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot]
warp-for-oss Bot previously requested changes Aug 4, 2026

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR resets two process-global test caches before affected tests and widens the bootstrap script cache from ShellType to (ShellType, TypeId) with a regression test for distinct asset provider types.

Concerns

  • The new #[serial] annotations do not prevent unannotated tests from concurrently repopulating the same process-global experiment/telemetry state after the clears, so the shared-process tests can still be flaky under the default Rust test harness.
  • The bootstrap cache key is still based on provider type rather than provider instance or asset contents, leaving the same wrong-script collision for two providers of the same concrete type with different backing data.

Verdict

Found: 0 critical, 3 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread app/src/experiments/mod_tests.rs Resolved
Comment thread app/src/server/telemetry/mod_tests.rs Resolved
Comment thread app/src/terminal/bootstrap.rs Resolved
fbartho added 4 commits August 4, 2026 16:41
`#[serial]` only serializes against other `serial_test` tests. Roughly a
hundred tests reach `experiments::init` through `test_util::terminal`, none
of them annotated, so any of them can repopulate the process-global
`EXPERIMENT_LAYER_MAPPINGS` between this test's clear and its assertions.

Split the mapping builder into `build_experiment_layer_mappings`, which
writes into a caller-supplied map, so the test asserts on a map it owns and
never touches the global.
`#[serial]` only serializes against other `serial_test` tests, not against
every test that can emit telemetry, so a non-serial emitter can enqueue onto
the process-global `warpui::telemetry` queue after `clear_event_queue()` and
before the flush.

Build the events with `create_event`, which does not enqueue, and call
`persist_events_at_path` directly. This exercises the same UGC filtering
without reading the shared queue.
Keying `BOOTSTRAP_CACHE` on the provider's `TypeId` collapses two instances
of one provider type onto a single entry, so a provider whose contents vary
per instance is served the first instance's script.

Replace the `TypeId` key with `AssetCacheKey`, which `AssetProvider` declares
via `cache_key`. The default keys on the concrete type, which stays correct
for the stateless providers in the tree; a provider whose contents vary per
instance overrides it with `AssetCacheKey::for_instance`.
@fbartho

fbartho commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @acarl005.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss
warp-for-oss Bot dismissed stale reviews from themself August 5, 2026 02:31

Oz no longer requests changes for this pull request after the latest automated review.

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR isolates tests from process-global caches by moving experiment and telemetry assertions onto local state, and fixes the bootstrap script cache by including the asset provider cache key alongside ShellType. It also adds deterministic regression coverage for distinct provider types and per-instance providers.

Concerns

  • No blocking correctness, security, or spec-alignment concerns found in the annotated diff.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@fbartho

fbartho commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@acarl005 @szgupta This PR is still waiting for review. (Just trying to avoid the stale-bot)

@acarl005

Copy link
Copy Markdown
Contributor

Hi @fbartho. Thanks for looking into this but we're only committing to supporting cargo nextest.

@acarl005 acarl005 closed this Aug 13, 2026
@fbartho

fbartho commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

I understand @acarl005.

That said: did you notice the correctness bug for BOOTSTRAP_CACHE? Registering a second asset provider is legal, it just will cause a cache-key collision/wrong-asset-in-cache. You may want to capture that fix even if you don’t capture the rest of this PR.

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

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

app tests: three append-only process-global caches leak across tests (experiments layers, telemetry queue, bootstrap cache)

3 participants