Skip to content

Session cache: peek is a pure read; the session owner refills it - #973

Merged
GLinnik21 merged 6 commits into
mainfrom
sansio/p1-peek
Oct 24, 2026
Merged

GLinnik21 merged 6 commits into
mainfrom
sansio/p1-peek

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Summary

Pilot P1 of the Sans-IO series (docs/sans-io.md). session::peek() is now a pure read of the session cache: no clock, no storage read, no worker. Refilling the cache becomes the session owner's job, carried as an effect and answered as an event.

  • peek() (plex/src/plex/session.rs) used to read Instant::now() on every call, and to submit a background read (schedule_refresh → storage_worker::submit) when the cache was cold or a locked read's retry was due. It now returns what the cache holds. The peek_at / drain_refresh_for_test / CACHE_NOW_FOR_TEST test hooks go with it.

  • The refill lane:

    • Bridge::land_session_cache(d) tells the owner what the cache lacks (SessionEvent::CacheObserved(RefreshNeed)).
    • The owner emits SessionFx::RefreshCache { req, generation }.
    • The session adapter runs the read in its own slot, and a panic or a refused submit reads as Refused.
    • The answer returns as SessionEvent::CacheRefreshed { req, outcome }.
  • The owner's bookkeeping (CacheRefresh { Idle, InFlight, Backoff } in session/src/auth/owner.rs) is private: it sits outside SessionInit, the snapshot and the replay subhash. A locked file backs off for LOCKED_RETRY_MS on the frame tick (cx.tick.ms), measured from when the backoff was armed, so the u32 tick wrapping cannot hold it.

  • A refresh can't be stranded. If the owner is in flight but the adapter lost the job (replaced or dropped), the Bridge answers Refused. It does that only for a request it actually began, so an effect still queued for the next frame is left alone.

  • Controlled runs: controlled Home refuses RefreshCache loudly, like the other session IO effects. The recorder keeps the two cache events off the tape (off_tape).

  • Ledgers:

    Rule Lines removed Total (pinned)
    workers schedule_refresh::storage_worker::submit 27 → 26
    globals peek_settled::peek; the no-op let _ = peek(); in data/src/search/scope.rs (two lines) 105 → 102
    forks one refresh_if_current_locked clock line; the other two are re-keyed to read_into_cache_locked 62 → 61
  • Clock gate: wall now also scans plex/src/plex/session.rs and session/src/auth/owner*.rs. The write timing moves into persistence::write_session_timed, an IO body outside the scan, and logs the same line.

  • Docs: plex/src/plex/CLAUDE.md (the peek() bullets, LOCKED_RETRY), docs/agent-reference.md, docs/distribution.md, two test-file headers and five stale comments.

No Makefile, Cargo, workflow or module-layout change, so there is no build-bench table.

Verification

  • peek_never_reads_storage was written first, and failed on ae611ee (left: 1 right: 0). It passes now.
  • New tests:
    • owner: 10 cases in owner::tests::cache_refresh (each need, Transient per generation, Refused, Settled/Superseded, tick wrap, the backoff after 2^31 ms, a stale answer, sign-out in flight);
    • bridge: an_unloaded_cache_is_refilled_by_the_owner_within_a_few_frames, a_replaced_adapter_cannot_strand_an_in_flight_refresh, a_refresh_effect_still_queued_is_not_reconciled_as_lost, a_controlled_run_refuses_a_cache_refresh_loudly;
    • adapter: a_cache_refresh_job_that_panics_is_answered_refused.
    • Both review-fix tests failed before their fix.
  • make check on the committed head ff14ceb: green.
    • plx_session test result: ok. 295 passed; 0 failed.
    • App hostsim 1043 passed; 0 failed.
    • Harness Ran 539 tests / OK.
    • check-deps: all gates green.
  • A planted Instant::now() in peek(), and one in owner.rs, each fail wall.
  • make check-nodef: clean.
  • make check-replay: 3 fixtures, 6 replays, 0 failures. All six replays read verdict=SAME, and no fixture was re-recorded.

Known, not in this PR

  • Replay never fills the session cache. A recording installs it through the boot load; a replay doesn't. So peek_settled() stays None for a whole replay, and the account menu would not build in one. No fixture reaches that path. Installing initial.session.persisted at replay boot is a separate change.
  • tests/controlled_bootstrap.py fails at its first case: normal boot still mints/persists its own identity expects auth.json, which the app replaced with state/session.json in 0.7: forward-port 0.6.x persistence, sign-in and consent with in-place upgrade #105. make check doesn't run the script, and it was not run on the base.

Closes #972

🤖 Generated with Claude Code

GLinnik21 and others added 6 commits October 24, 2026 06:45
…(stage B)

The ledgers: delete the `schedule_refresh` worker line and the `peek_settled::peek` global line,
re-key the two surviving `refresh_if_current_locked` forks to `read_into_cache_locked` and drop the
third (the clock read is gone). The pins follow: workers 27->26, globals 105->104, forks 62->61.

The `wall` gate now also scans plex/src/plex/session.rs and the session owner files
(session/src/auth/owner*.rs). The canonical-write timing moves into
`persistence::write_session_timed`, an IO body outside the scan, so its log line is unchanged, and
the slow-refresh test's 200 ms bound becomes a clockless witness (the parked read has not returned
when the peeks finish).

Prose that said `peek` schedules or queues a refresh now says the session owner's `RefreshCache`
effect refills the cache: plex CLAUDE.md, agent-reference.md, distribution.md, the test headers and
four doc comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… (stage B)

`peek` no longer schedules a read, so the two plx_data restart tests that reopened the session
file through `peek` + `drain_for_test` now fill the cache explicitly with
`refresh_blocking_for_test`. Search's `scope::read_key*` called `peek` only to start that fill; the
call is a no-op now, so it goes, with its two `globals` ledger lines (data-search 6->4, pin
104->102).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y a begun refresh; prose

The session-cache backoff stored a deadline and compared it as a signed wrapping difference, so
a Backoff that nothing observed again flipped to "not over" once the tick ran 2^31 ms past it and
held a later need for another ~24.8 days. It now stores the tick it was ARMED at and holds while
`now.wrapping_sub(armed_ms) < LOCKED_RETRY_MS`. The generation semantics are unchanged.

`land_session_cache` answered Refused for a RefreshCache effect the drain budget had carried to
the next frame, before the adapter had begun it; the job then ran and its real answer was dropped
as stale. The Bridge now records the req of the last refresh it handed its adapter
(`cache_refresh_begun`) and the reconcile refuses only that req, so a replaced adapter still
reads as a refresh begun and lost.

Prose: "exactly one CacheRefreshed" is now "at most one", the Refused doc names the bridge as the
reporter of the dropped-adapter case, three comments no longer say peek() queues or forces a read,
and the off_tape doc claims only what the filter does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 088f6f7 into main Oct 24, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the sansio/p1-peek branch October 24, 2026 05:22
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
One conflict, in tests/test_harness.py: both sides lowered PINNED_LEDGER_TOTALS. The merged
totals are the sums of the `# count:` headers under ci/allow/<rule>/ on the merged tree:
workers 25, globals 101, forks 60, fxlanes 11. rust-modules/src/app/bridge.rs auto-merged:
Bridge has one struct literal (with_publications_and_stores), which initialises P1's
cache_refresh_begun and this branch's store_runner and late_store_jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
… worker job (#979)

Since #973, every app frame can run the session owner's cache refill. While the process-global
cache was Unloaded, SessionAdapter::begin_cache_refresh submitted a real storage-worker job even
under Resources::Fixture. Its CacheRefreshed answer landed on whichever frame the worker beat, so
fixture Bridge tests depended on timing: home_worker_results_cross_the_addressed_dispatcher_ingest_once
failed with "wrong result type" in three of four CI jobs on #977. A fixture-Bridge test with no
TempSession could also install a developer's real auth.json into the cache for later tests.

A fixture adapter now parks refresh_cache_job in FixtureResources, as StoreRunner::Held parks store
jobs, and runs it only when a test asks (run_held_cache_refresh). cache_refresh_req covers a parked
refresh, so the reconcile reads it as held. Live adapters are unchanged.

Tests: a_fixture_adapter_submits_no_storage_worker_job_for_a_cache_refresh; the Home test starts
from an Unloaded cache (premise asserted) and drains the worker between frames with its tap strict;
a_live_adapter_begins_a_cache_refresh_without_taking_the_session_io_lock keeps the live IO-lock
coverage that a fixture can no longer give; a debug_assert catches an overwritten parked refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
danzig666 pushed a commit to danzig666/plx-native that referenced this pull request Oct 24, 2026
home_worker_results_cross_the_addressed_dispatcher_ingest_once panicked on any
result that was not a HubsResult. Since upstream's plxnative#973 the session owner
refills its cache by a result of its own, which Home's first frame delivers, so
the test failed on upstream main as well (run alone, every time; in a full run
only by test order). It asks only that the Hubs store's results cross once, so
it now passes over other owners' results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KBgjCe8KH6Nnp3K51Fybrv
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.

session::peek() reads the clock and starts storage reads from the frame thread

1 participant