Skip to content

feat(cache): heal divergent tier 0 on ranged reads#385

Open
worstell wants to merge 1 commit into
mainfrom
worstell/tiered-heal-ranged-reads
Open

feat(cache): heal divergent tier 0 on ranged reads#385
worstell wants to merge 1 commit into
mainfrom
worstell/tiered-heal-ranged-reads

Conversation

@worstell

@worstell worstell commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Ranged pinned reads (client.ParallelGet chunks) served from a deeper tier can't backfill tier 0 — a partial body must never be stored as the whole object — so a stale/divergent tier-0 replica never converges under parallel downloads. Every chunk pays a wasted tier-0 open plus a deeper-tier fetch indefinitely.

When Tiered.Open serves a ranged body from a deeper tier, it now schedules an async full-object refresh of tier 0 from that tier. The refresh is:

  • Gated on the served version being the authoritative one tracked in the etag map, so a tier 0 that is legitimately newer than a lagging deeper tier is never overwritten (re-checked immediately before commit; a residual race self-corrects via invalidateStale on the next read).
  • Version-pinned (IfMatch on the source read) and aborted on any copy/mismatch failure.
  • Per-key deduplicated, bounded by a concurrency semaphore (opportunistic — skips when saturated, a later divergent read re-triggers), and drained on Close.

Full-body reads still heal via the existing inline backfill. Closes #368.

A ranged pinned read (client.ParallelGet chunk) served from a deeper tier
can't backfill tier 0, since a partial body must never be stored as the whole
object. A divergent/stale tier-0 replica therefore never converges under
parallel downloads: every chunk pays a wasted tier-0 open plus a deeper-tier
fetch, indefinitely.

When Tiered.Open serves a ranged body from a deeper tier, schedule an async
full-object refresh of tier 0 from that tier. It is gated on the served version
being the authoritative one tracked in the etag map, so a tier 0 that is
legitimately newer than a lagging deeper tier is never overwritten. Refreshes
are per-key deduplicated, bounded by a concurrency semaphore, and drained on
Close.

Closes #368

Amp-Thread-ID: https://ampcode.com/threads/T-019f3d90-8c5a-757c-87ff-308404f3b2bd
Co-authored-by: Amp <amp@ampcode.com>
@worstell worstell marked this pull request as ready for review July 7, 2026 19:32
@worstell worstell requested a review from a team as a code owner July 7, 2026 19:32
@worstell worstell requested review from joshfriend and removed request for a team July 7, 2026 19:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 558d198ef9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +660 to +662
// A ranged pinned read served from a deeper tier heals a stale tier 0
// asynchronously, since a partial body can't be backfilled (#368).
func TestTieredRangedReadHealsDivergentTier0(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove top-level test comments

/workspace/cachew/AGENTS.md explicitly says "NEVER add comments to top-level tests"; this new comment is attached directly to a top-level Test... function, and the next added test repeats the same pattern, so the commit violates the repository's documented review standard even though the test logic itself may be fine.

Useful? React with 👍 / 👎.

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.

Tiered: heal divergent lower tier detected by pinned range reads

1 participant