Skip to content

Fixture session adapter: park the cache refresh instead of starting a worker job - #979

Merged
GLinnik21 merged 2 commits into
mainfrom
sansio/fixture-cache-refresh
Oct 24, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
sansio/fixture-cache-refresh

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #978

Since #973, every app frame runs the session owner's cache refill. While the process-global session cache is Unloaded, the owner emits RefreshCache. That happens in a fresh process, or after any test that drops a TempSession. SessionAdapter::begin_cache_refresh then submitted a real storage-worker job, even for Resources::Fixture, the test resource boundary. The answer, AppMsg::Session(CacheRefreshed), landed on whichever frame the worker beat, so every Bridge::for_test message stream depended on timing.

home_worker_results_cross_the_addressed_dispatcher_ingest_once taps every result. It panicked with wrong result type when that answer landed between its frames. That happened in three of four CI test jobs on #977, and never locally.

Change

  • Fixture adapters park the refresh. A fixture adapter parks the production job (refresh_cache_job) in FixtureResources and submits nothing, the way StoreRunner::Held parks store jobs. It runs only when a test asks, on the test thread, through SessionAdapter::run_held_cache_refresh and Bridge::run_held_cache_refresh_for_test.
  • The outcome comes back on the next result pass. take_cache_refresh hands it back then.
  • A parked refresh still reads as held. cache_refresh_req covers it, so land_session_cache's reconcile reads it as held, not lost.
  • Live adapters are unchanged. The only non-test edits are doc comments, plus cache_refresh_req becoming a block with the same live expression.
  • Side effect removed: before this change, a fixture Bridge test with no TempSession ran the refill against the canonical auth paths. It could install a developer's real auth.json into the process-wide cache for later tests to read.

Rejected alternatives

Alternative Why not
Run the job inline at begin login_frames_never_wait_for_the_session_io_lock holds the session IO lock across 30 fixture frames and asserts no read.
Answer from FixtureResources.disk The refill tests need the real job to fill the cache.

Tests

  • New regression test: a_fixture_adapter_submits_no_storage_worker_job_for_a_cache_refresh.
  • Live-path test: a_live_adapter_begins_a_cache_refresh_without_taking_the_session_io_lock covers what login_frames_never_wait_for_the_session_io_lock can no longer see through a fixture. A live adapter begins the refresh inside a FrameScope while the IO lock is held, then settles after the lock is released. Making the live begin take the lock fails it (main-thread block: session storage I/O).
  • Debug check: a debug_assert! catches a parked refresh being overwritten.
  • Home test: it now starts from an Unloaded cache and drains the worker between its frames. Its tap stays strict, and nothing prefills the cache.
  • Before and after: on the old adapter, both tests failed on every run; after the fix, both pass.
  • Refill tests in plex_session_app_tests: they keep every assertion. Their frames helper, and the one test that runs the queued effect itself, now run the parked refresh where they used to drain the worker.

Gates, run on the committed tree

Gate Result
make check exit 0. The app crate passed 938 (default features) and 1051 (hostsim); every test result: line is ok with 0 failed.
make check-nodef exit 0
make check-replay 3 fixtures × resolve/targets, all verdict=SAME (run on the first commit; the review-fix commit is test and doc only)

Review

One review, verdict MERGE. Its should-fix (the live IO-lock coverage above) and its four notes are applied: the Home test's premise is now asserted, the parked-slot debug_assert! is added, the run_held_cache_refresh doc names the lock, and stale wording is fixed.

ARM make was not run: no live behaviour changed.

🤖 Generated with Claude Code

GLinnik21 and others added 2 commits October 24, 2026 11:00
… worker job (#978)

Since #973 every app frame runs the session owner's cache refill. While the process-global session
cache is Unloaded (a fresh process, or after any test that dropped a TempSession), the owner emits
RefreshCache and SessionAdapter::begin_cache_refresh submitted a real storage-worker job, even for
Resources::Fixture, the test resource boundary. The answer, AppMsg::Session(CacheRefreshed), landed
on whichever later frame the worker beat, so every Bridge::for_test message stream depended on
timing. home_worker_results_cross_the_addressed_dispatcher_ingest_once taps every result and
panicked "wrong result type" when it landed between its frames (three of four CI jobs on #977).

A fixture adapter now parks the production job (refresh_cache_job) in FixtureResources, the way
StoreRunner::Held parks store jobs, and submits nothing. It runs only when a test asks, on the test
thread (SessionAdapter::run_held_cache_refresh, Bridge::run_held_cache_refresh_for_test), and
take_cache_refresh hands the outcome back on the next result pass. cache_refresh_req covers a parked
refresh, so land_session_cache's reconcile still reads it as held, not lost. Live adapters, including
the live-resources-for-test ones, are untouched.

Regression tests: the adapter-level a_fixture_adapter_submits_no_storage_worker_job_for_a_cache_refresh,
and the Home test now starts from an Unloaded cache and drains the worker between its frames (its tap
stays strict and nothing prefills the cache). Both failed on the old behaviour every time. The
refill tests in plex_session_app_tests keep every assertion; their frames helper (and the one test
that runs the queued effect itself) now also runs the parked refresh where it used to drain the worker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test and doc only.

- Add a_live_adapter_begins_a_cache_refresh_without_taking_the_session_io_lock: the live
  adapter's begin_cache_refresh runs while this thread holds the session IO lock inside a
  FrameScope and must return None without taking the lock or reading; the job then runs on the
  worker once the lock is released. The login-frame test's refill half only exercised the parked
  fixture branch, so a live begin that took the lock would have passed it.
- home_retention_tests: assert the premise (refresh_need() is Some) after invalidate_for_test(),
  and say why: invalidate_for_test leaves a Revoked cache alone.
- FixtureResources: debug_assert that the single parked slot is Idle before parking, so a
  silently overwritten job is caught.
- run_held_cache_refresh: document that the job takes the session IO lock on the caller's
  thread (not under with_io_for_test, not inside a FrameScope).
- Fix wording the change made false: "run on the storage worker", "loses its job's ticket", "the
  queue took the job", "the queue refused nothing"; drop the drain and invalidate in
  a_replaced_adapter_cannot_strand_an_in_flight_refresh and the drain after
  run_held_cache_refresh_for_test, which had nothing left to do, and assert the need instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 marked this pull request as ready for review October 24, 2026 09:14
@GLinnik21
GLinnik21 merged commit 774b611 into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the sansio/fixture-cache-refresh branch October 24, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixture Bridges start a real session-cache refill, so a test tap can see a stray result

1 participant